def populated_registry(
        self, registry: ContinuousEventsRegistry
    ) -> Generator[ContinuousEventsRegistry, None, None]:
        for _ in range(100):
            NodetoolEvent(nodetool_command="mock cmd", publish_event=False)

        yield registry
Beispiel #2
0
    def test_nodetool_cmd_with_options(self):
        begin_event_timestamp = 1623596860.1202102
        event = NodetoolEvent(
            nodetool_command=
            "scrub --skip-corrupted drop_table_during_repair_ks_0",
            node='1.0.0.121',
            options="more options",
            publish_event=False)
        event.event_id = "ef4aeb1a-c004-40e4-af14-9d87a0526408"
        event.begin_event()
        event.begin_timestamp = event.event_timestamp = begin_event_timestamp
        self.assertEqual(
            str(event),
            '(NodetoolEvent Severity.NORMAL) period_type=begin event_id=ef4aeb1a-c004-40e4-af14-9d87a0526408: '
            'nodetool_command=scrub node=1.0.0.121 options=--skip-corrupted drop_table_during_repair_ks_0 more options'
        )

        # validate duration calculation
        with mock.patch('time.time', return_value=begin_event_timestamp + 1):
            event.end_event()
            self.assertEqual(
                str(event),
                '(NodetoolEvent Severity.NORMAL) period_type=end event_id=ef4aeb1a-c004-40e4-af14-9d87a0526408 '
                'duration=1s: nodetool_command=scrub node=1.0.0.121 options=--skip-corrupted '
                'drop_table_during_repair_ks_0 more options')
 def test_publish_not_called(self, publish):
     event = NodetoolEvent(nodetool_command="scrub",
                           node='1.0.0.121',
                           options="",
                           publish_event=False)
     event.begin_event()
     self.assertFalse(publish.called,
                      "Publish function was called unexpectedly")
Beispiel #4
0
 def test_nodetool_serialization_to_json(self):
     event = NodetoolEvent(
         nodetool_command=
         "scrub --skip-corrupted drop_table_during_repair_ks_0",
         node='1.0.0.121',
         options="more options",
         publish_event=False)
     event.event_id = "c2561d8b-97ca-44fb-b5b1-8bcc0d437318"
     event.begin_event()
     self.assertTrue(event.to_json())
    def test_duration_format(self, duration_input, duration_formatted):
        event = NodetoolEvent(
            nodetool_command=
            "scrub --skip-corrupted drop_table_during_repair_ks_0",
            node='1.0.0.121',
            options="more options",
            publish_event=False)

        event.duration = duration_input
        self.assertEqual(duration_formatted, event.duration_formatted)
Beispiel #6
0
 def test_nodetool_cmd_with_options(self):
     event = NodetoolEvent(
         type="scrub --skip-corrupted drop_table_during_repair_ks_0",
         subtype='start',
         severity=Severity.NORMAL,
         node='1.0.0.121',
         options="more options")
     self.assertEqual(
         str(event),
         '(NodetoolEvent Severity.NORMAL): type=scrub subtype=start node=1.0.0.121 options=--skip-corrupted '
         'drop_table_during_repair_ks_0 more options')
Beispiel #7
0
 def test_nodetool_failure(self):
     event = NodetoolEvent(
         type="scrub --skip-corrupted drop_table_during_repair_ks_0",
         subtype='end',
         severity=Severity.ERROR,
         node='1.0.0.121',
         error="Failed with status 1",
         full_traceback="Traceback:")
     self.assertEqual(
         str(event),
         '(NodetoolEvent Severity.ERROR): type=scrub subtype=end node=1.0.0.121 options=--skip-corrupted '
         'drop_table_during_repair_ks_0 error=Failed with status 1\nTraceback:'
     )
Beispiel #8
0
    def test_nodetool_cmd_no_options(self):
        event = NodetoolEvent(
            type="scrub --skip-corrupted drop_table_during_repair_ks_0",
            subtype='start',
            severity=Severity.NORMAL,
            node='1.0.0.121',
            options="")
        self.assertEqual(
            str(event),
            "(NodetoolEvent Severity.NORMAL): type=scrub subtype=start node=1.0.0.121 options=--skip-corrupted "
            "drop_table_during_repair_ks_0")

        event = NodetoolEvent(
            type="scrub --skip-corrupted drop_table_during_repair_ks_0",
            subtype='end',
            severity=Severity.NORMAL,
            node='1.0.0.121',
            duration="20s",
            options="")
        self.assertEqual(
            str(event),
            '(NodetoolEvent Severity.NORMAL): type=scrub subtype=end node=1.0.0.121 '
            'options=--skip-corrupted drop_table_during_repair_ks_0 duration=20s'
        )
    def test_nodetool_failure(self):
        event = NodetoolEvent(nodetool_command="scrub --skip-corrupted drop_table_during_repair_ks_0", node='1.0.0.121',
                              options="more options", publish_event=False)
        event.event_id = "c2561d8b-97ca-44fb-b5b1-8bcc0d437318"
        event.begin_event()

        event.add_error(["Failed with status 1"])
        event.full_traceback = "Traceback:"
        event.duration = 90358
        event.end_event()
        self.assertEqual(
            str(event),
            '(NodetoolEvent Severity.NORMAL) period_type=end event_id=c2561d8b-97ca-44fb-b5b1-8bcc0d437318 '
            'duration=1d1h5m58s: nodetool_command=scrub node=1.0.0.121 options=--skip-corrupted '
            'drop_table_during_repair_ks_0 more '
            'options errors=[\'Failed with status 1\']\nTraceback:'
        )
    def test_nodetool_cmd_no_options(self):
        event = NodetoolEvent(nodetool_command="scrub", node='1.0.0.121',
                              options="", publish_event=False)
        event.event_id = "3c8e2362-a987-4eff-953f-9cd1ad2017e5"
        event.begin_event()
        self.assertEqual(
            str(event),
            "(NodetoolEvent Severity.NORMAL) period_type=begin event_id=3c8e2362-a987-4eff-953f-9cd1ad2017e5: "
            "nodetool_command=scrub node=1.0.0.121"
        )

        event.duration = 20.325
        event.end_event()
        self.assertEqual(
            str(event),
            "(NodetoolEvent Severity.NORMAL) period_type=end event_id=3c8e2362-a987-4eff-953f-9cd1ad2017e5 "
            "duration=20.325s: nodetool_command=scrub node=1.0.0.121"
        )
    def test_add_event(self, registry: ContinuousEventsRegistry):
        # continuous events are added to the registry on event instantiation
        event = NodetoolEvent(nodetool_command="mock cmd")

        assert event in registry.continuous_events
 def nodetool_event(self) -> Generator[NodetoolEvent, None, None]:
     yield NodetoolEvent(nodetool_command="mock_cmd", publish_event=False)