Skip to content

Commit

Permalink
fix(events-subcontext): subcontext was missing when log events cloned
Browse files Browse the repository at this point in the history
since the `clone` uses pickle that uses the object `__getstate__`
we missed adding the subcontext there if empty, and object would
be created with it set to None.
  • Loading branch information
fruch committed Dec 11, 2022
1 parent 3afa632 commit d007cef
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions sdcm/sct_events/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ def __getstate__(self):
if subcontext := getattr(self, "subcontext"):
attrs["subcontext"] = [self.attribute_with_value_for_json(attributes_list=event.subcontext_fields,
event=event) for event in subcontext]
else:
attrs["subcontext"] = []
return attrs

def __str__(self):
Expand Down
3 changes: 2 additions & 1 deletion unit_tests/test_sct_events_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ class Y(SctEvent):
y.to_json(),
f'{{"base": "Y", "type": null, "subtype": null, "event_timestamp": {y.event_timestamp}, '
f'"source_timestamp": null, '
f'"severity": "UNKNOWN", "event_id": "fa4a84a2-968b-474c-b188-b3bac4be8527", "log_level": 30}}'
f'"severity": "UNKNOWN", "event_id": "fa4a84a2-968b-474c-b188-b3bac4be8527", "log_level": 30, '
f'"subcontext": []}}'
)

def test_publish(self):
Expand Down
25 changes: 24 additions & 1 deletion unit_tests/test_sct_events_continuous_events_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sdcm.sct_events import Severity
from sdcm.sct_events.continuous_event import ContinuousEventsRegistry, ContinuousEventRegistryException
from sdcm.sct_events.database import get_pattern_to_event_to_func_mapping, CompactionEvent, \
IndexSpecialColumnErrorEvent, ScyllaServerStatusEvent
IndexSpecialColumnErrorEvent, ScyllaServerStatusEvent, DatabaseLogEvent
from sdcm.sct_events.loaders import GeminiStressEvent
from sdcm.sct_events.nemesis import DisruptionEvent
from sdcm.sct_events.nodetool import NodetoolEvent
Expand Down Expand Up @@ -107,6 +107,29 @@ def test_add_nemesis_sub_context_to_information_event(self):
# Validate that the event subcontext is serialized
assert event.to_json()

def test_add_nemesis_sub_context_to_db_log_event(self):
event = DatabaseLogEvent.ABORTING_ON_SHARD()
# event not during nemesis
assert event.subcontext == []

# cloned events should have empty subcontext as well
cloned_event = event.clone()
assert cloned_event.subcontext == []

number_of_insertions = 2
for i in range(number_of_insertions):
DisruptionEvent(node=uuid.uuid1(), nemesis_name=f"test{i}", publish_event=False).begin_event()
GeminiStressEvent(node=uuid.uuid1(), cmd="gemini hello", publish_event=False).begin_event()

event = DatabaseLogEvent.ABORTING_ON_SHARD().clone()
event.add_info(node="n1", line="kernel: Linux version", line_number=0)
assert event.msgfmt == ('({0.base} {0.severity}) period_type={0.period_type} event_id={0.event_id} '
'during_nemesis=test0,test1: type={0.type} regex={0.regex} '
'line_number={0.line_number} node={0.node}\n{0.line}')

# Validate that the event subcontext is serialized
assert event.to_json()

def test_adding_a_non_continuous_event_raises_error(self,
registry: ContinuousEventsRegistry,
info_event):
Expand Down

0 comments on commit d007cef

Please sign in to comment.