def test_continuous_event_with_error(self): gemini_stress_event = GeminiStressEvent(node="node", cmd="gemini_cmd", publish_event=False) begin_event_timestamp = 1623596860.1202102 gemini_stress_event.event_id = "14f35b64-2fcc-4b6e-a09d-4aeaf4faa543" begin_event = gemini_stress_event.begin_event() begin_event.event_timestamp = begin_event.begin_timestamp = begin_event_timestamp self.assertEqual( str(begin_event), '(GeminiStressEvent Severity.NORMAL) period_type=begin ' 'event_id=14f35b64-2fcc-4b6e-a09d-4aeaf4faa543: node=node gemini_cmd=gemini_cmd' ) self.assertEqual(begin_event.event_timestamp, begin_event_timestamp) self.assertEqual(begin_event.timestamp, begin_event_timestamp) self.assertEqual(begin_event, pickle.loads(pickle.dumps(gemini_stress_event))) gemini_stress_event.add_error(errors=["error1", "error2"]) gemini_stress_event.severity = Severity.ERROR gemini_stress_event.end_event() gemini_stress_event.event_timestamp = gemini_stress_event.end_timestamp = 1623597850.6610544 self.assertEqual( str(gemini_stress_event), '(GeminiStressEvent Severity.ERROR) period_type=end ' 'event_id=14f35b64-2fcc-4b6e-a09d-4aeaf4faa543 duration=16m30s: node=node gemini_cmd=gemini_cmd' '\nerrors=[\'error1\', \'error2\']') self.assertEqual(gemini_stress_event, pickle.loads(pickle.dumps(gemini_stress_event)))
def test_continuous_event_with_result(self): gemini_stress_event = GeminiStressEvent(node="node", cmd="cat", publish_event=False) begin_event_timestamp = 1623596860.1202102 gemini_stress_event.event_id = "14f35b64-2fcc-4b6e-a09d-4aeaf4faa543" begin_event = gemini_stress_event.begin_event() begin_event.event_timestamp = begin_event.begin_timestamp = begin_event_timestamp self.assertEqual( str(begin_event), '(GeminiStressEvent Severity.NORMAL) period_type=begin ' 'event_id=14f35b64-2fcc-4b6e-a09d-4aeaf4faa543: node=node gemini_cmd=cat' ) self.assertEqual(begin_event.event_timestamp, begin_event_timestamp) self.assertEqual(begin_event.timestamp, begin_event_timestamp) self.assertEqual(begin_event, pickle.loads(pickle.dumps(begin_event))) gemini_stress_event.add_result( result=Result(stdout=" \n\nline1\n line2 \nline3\n ", stderr="\terr\t", exited=1)) result = "Exit code: 1\nCommand output: [' line2 ', 'line3']\n" gemini_stress_event.end_event() gemini_stress_event.event_timestamp = gemini_stress_event.end_timestamp = 1623599860.1202102 self.assertEqual(gemini_stress_event.result, result) self.assertEqual( str(gemini_stress_event), '(GeminiStressEvent Severity.NORMAL) period_type=end ' 'event_id=14f35b64-2fcc-4b6e-a09d-4aeaf4faa543 duration=50m0s: node=node gemini_cmd=cat\n' 'result=Exit code: 1\nCommand output: [\' line2 \', \'line3\']\n\n' 'errors=[\'Command error: \\terr\\t\\n\']') self.assertEqual(gemini_stress_event, pickle.loads(pickle.dumps(gemini_stress_event)))
def _run_gemini(self, node, loader_idx): logdir = os.path.join(self.outputdir, node.name) os.makedirs(logdir, exist_ok=True) log_file_name = os.path.join( logdir, 'gemini-l%s-%s.log' % (loader_idx, uuid.uuid4())) gemini_cmd = self._generate_gemini_command() with GeminiEventsPublisher(node=node, gemini_log_filename=log_file_name) as publisher, \ GeminiStressEvent(node=node, cmd=gemini_cmd, log_file_name=log_file_name) as gemini_stress_event: try: publisher.event_id = gemini_stress_event.event_id gemini_stress_event.log_file_name = log_file_name result = node.remoter.run(cmd=gemini_cmd, timeout=self.timeout, ignore_status=False, log_file=log_file_name) # sleep to gather all latest log messages time.sleep(5) except Exception as details: # pylint: disable=broad-except LOGGER.error(details) result = getattr(details, "result", NotGeminiErrorResult(details)) if result.exited: gemini_stress_event.add_result(result=result) gemini_stress_event.severity = Severity.ERROR else: if result.stderr: gemini_stress_event.add_result(result=result) gemini_stress_event.severity = Severity.WARNING return node, result, self.gemini_result_file
def test_add_multiple_events(self, registry: ContinuousEventsRegistry): pre_insertion_item_count = len(registry.continuous_events) number_of_insertions = 10 for _ in range(number_of_insertions): GeminiStressEvent(node="2323432", cmd="gemini hello", publish_event=False) assert pre_insertion_item_count + number_of_insertions == len( registry.continuous_events)
def test_continuous_event_without_result(self): gemini_stress_event = GeminiStressEvent(node="node", cmd="cat", publish_event=False) begin_event_timestamp = 1623596860.1202102 gemini_stress_event.event_id = "14f35b64-2fcc-4b6e-a09d-4aeaf4faa543" begin_event = gemini_stress_event.begin_event() begin_event.event_timestamp = begin_event.begin_timestamp = begin_event_timestamp self.assertEqual( str(begin_event), '(GeminiStressEvent Severity.NORMAL) period_type=begin ' 'event_id=14f35b64-2fcc-4b6e-a09d-4aeaf4faa543: node=node gemini_cmd=cat' ) self.assertEqual(begin_event.event_timestamp, begin_event_timestamp) self.assertEqual(begin_event.timestamp, begin_event_timestamp) self.assertEqual(begin_event, pickle.loads(pickle.dumps(begin_event))) gemini_stress_event.end_event() gemini_stress_event.event_timestamp = gemini_stress_event.end_timestamp = 1623696860.1202102 self.assertEqual(gemini_stress_event.result, '') self.assertEqual( str(gemini_stress_event), '(GeminiStressEvent Severity.NORMAL) period_type=end ' 'event_id=14f35b64-2fcc-4b6e-a09d-4aeaf4faa543 duration=1d3h46m40s: node=node gemini_cmd=cat' ) self.assertEqual(gemini_stress_event, pickle.loads(pickle.dumps(gemini_stress_event)))
def gemini_stress_event(self) -> Generator[GeminiStressEvent, None, None]: yield GeminiStressEvent(node="mock_node", cmd="gemini mock cmd", publish_event=False)