Exemplo n.º 1
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')
Exemplo n.º 2
0
 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")
Exemplo n.º 3
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())
Exemplo n.º 4
0
    def test_get_events_by_period_type(
            self, populated_registry: ContinuousEventsRegistry,
            nodetool_stress_event: NodetoolEvent):
        count_of_begun_events_pre = len(
            populated_registry.get_events_by_period(
                period_type=EventPeriod.BEGIN))
        nodetool_stress_event.begin_event()
        found_events = populated_registry.get_events_by_period(
            period_type=EventPeriod.BEGIN)

        assert len(found_events) == count_of_begun_events_pre + 1
    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"
        )