def test_without_errors(self):
     event = CDCReaderStressEvent.start(node=[], stress_cmd="c-s", log_file_name="1.log")
     self.assertEqual(event.severity, Severity.NORMAL)
     self.assertEqual(event.node, "[]")
     self.assertEqual(event.stress_cmd, "c-s")
     self.assertEqual(event.log_file_name, "1.log")
     self.assertIsNone(event.errors)
     self.assertEqual(str(event), "(CDCReaderStressEvent Severity.NORMAL): type=start node=[]\nstress_cmd=c-s")
     self.assertEqual(event, pickle.loads(pickle.dumps(event)))
Пример #2
0
    def _run_stress(self, loader, loader_idx, cpu_idx):  # pylint: disable=unused-argument
        loader_node_logdir = Path(loader.logdir)
        if not loader_node_logdir.exists():
            loader_node_logdir.mkdir()

        worker_count = self.max_workers
        worker_id = loader_idx * self.stress_num + cpu_idx
        log_file_name = loader_node_logdir.joinpath(
            f'cdclogreader-l{loader_idx}-{worker_id}-{uuid.uuid4()}.log')
        LOGGER.debug('cdc-stressor local log: %s', log_file_name)

        self.build_stress_command(worker_id, worker_count)

        LOGGER.info(self.stress_cmd)
        docker = RemoteDocker(
            loader,
            CDCLOG_READER_IMAGE,
            extra_docker_opts=
            f'--network=host --label shell_marker={self.shell_marker}')

        # Update cdc-stressor with last changes.
        docker.run(cmd="go get -u github.com/piodul/cdc-stressor",
                   timeout=self.timeout,
                   ignore_status=True,
                   log_file=log_file_name,
                   verbose=True)

        node_cmd = f'STRESS_TEST_MARKER={self.shell_marker}; {self.stress_cmd}'

        CDCReaderStressEvent.start(node=loader,
                                   stress_cmd=self.stress_cmd).publish()

        try:
            result = docker.run(cmd=node_cmd,
                                timeout=self.timeout + self.shutdown_timeout,
                                ignore_status=True,
                                log_file=log_file_name,
                                verbose=True)
            if not result.ok:
                CDCReaderStressEvent.error(
                    node=loader,
                    stress_cmd=self.stress_cmd,
                    errors=result.stderr.split("\n")).publish()
            return result
        except Exception as exc:
            CDCReaderStressEvent.failure(node=loader,
                                         stress_cmd=self.stress_cmd,
                                         errors=[
                                             format_stress_cmd_error(exc),
                                         ]).publish()
        finally:
            CDCReaderStressEvent.finish(node=loader,
                                        stress_cmd=self.stress_cmd).publish()
 def test_with_errors(self):
     event = CDCReaderStressEvent.failure(node="node1", errors=["e1", "e2"])
     self.assertEqual(event.severity, Severity.CRITICAL)
     self.assertEqual(event.node, "node1")
     self.assertIsNone(event.stress_cmd)
     self.assertIsNone(event.log_file_name)
     self.assertEqual(event.errors, ["e1", "e2"])
     self.assertEqual(
         str(event),
         "(CDCReaderStressEvent Severity.CRITICAL): type=failure node=node1\nstress_cmd=None\nerrors:\n\ne1\ne2"
     )
     self.assertEqual(event, pickle.loads(pickle.dumps(event)))
Пример #4
0
 def test_without_errors(self):
     event = CDCReaderStressEvent.start(node=[], stress_cmd="c-s", log_file_name="1.log")
     self.assertEqual(event.severity, Severity.NORMAL)
     self.assertEqual(event.node, "[]")
     self.assertEqual(event.stress_cmd, "c-s")
     self.assertEqual(event.log_file_name, "1.log")
     self.assertIsNone(event.errors)
     event.event_id = "aed3946d-33a8-4f68-b56c-1d09f71f5da9"
     self.assertEqual(str(event),
                      "(CDCReaderStressEvent Severity.NORMAL) period_type=not-set "
                      "event_id=aed3946d-33a8-4f68-b56c-1d09f71f5da9: type=start node=[]\nstress_cmd=c-s")
     self.assertEqual(event, pickle.loads(pickle.dumps(event)))
Пример #5
0
 def test_with_errors(self):
     event = CDCReaderStressEvent.failure(node="node1", errors=["e1", "e2"])
     self.assertEqual(event.severity, Severity.CRITICAL)
     self.assertEqual(event.node, "node1")
     self.assertIsNone(event.stress_cmd)
     self.assertIsNone(event.log_file_name)
     self.assertEqual(event.errors, ["e1", "e2"])
     event.event_id = "3c5deb9e-7a67-49ee-9295-c7e986b015a9"
     self.assertEqual(
         str(event),
         "(CDCReaderStressEvent Severity.CRITICAL) period_type=not-set "
         "event_id=3c5deb9e-7a67-49ee-9295-c7e986b015a9: type=failure node=node1"
         "\nerrors:\n\ne1\ne2")
     self.assertEqual(event, pickle.loads(pickle.dumps(event)))