Skip to content

Commit e1456e8

Browse files
authored
Merge pull request #328 from mulkieran/issue_stratisd_3895
monitor_dbus_signals: check variant_level equality
2 parents c18bfbe + 0deba5b commit e1456e8

File tree

1 file changed

+47
-12
lines changed

1 file changed

+47
-12
lines changed

scripts/monitor_dbus_signals.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,33 @@ def __repr__(self):
110110
)
111111

112112

113+
class DifferentVariantLevel(Diff): # pylint: disable=too-few-public-methods
114+
"""
115+
Represents a case where the property value is correct but the variant
116+
level does not match. The variant levels among the GetManagedObjects
117+
result, the Properties.GetAll result and the PropertiesChanged signal
118+
value should always be the same, because both are encoded using dicts,
119+
and the values of the dicts are always defined as variant types, since
120+
they must be heterogeneous.
121+
"""
122+
123+
def __init__(
124+
self, object_path, interface_name, key, old_value, new_value
125+
): # pylint: disable=too-many-positional-arguments,too-many-arguments
126+
self.object_path = object_path
127+
self.interface_name = interface_name
128+
self.key = key
129+
self.old_value = old_value
130+
self.new_value = new_value
131+
132+
def __repr__(self):
133+
return (
134+
f"DifferentVariantLevel({self.object_path!r}, "
135+
f"{self.interface_name!r}, {self.key!r}, {self.old_value!r}, "
136+
f"{self.new_value!r})"
137+
)
138+
139+
113140
class NotInvalidatedProperty(Diff): # pylint: disable=too-few-public-methods
114141
"""
115142
Represents a case where the property should have been invalidated but
@@ -671,25 +698,33 @@ def _check_props(object_path, ifn, old_props, new_props):
671698
else EmitsChangedSignal.from_str(emits_signal_prop[0].attrib["value"])
672699
)
673700

674-
if new_value != old_value:
675-
if emits_signal is EmitsChangedSignal.TRUE:
676-
diffs.append(
677-
DifferentProperty(object_path, ifn, key, old_value, new_value)
678-
)
679-
680-
if (
681-
emits_signal is EmitsChangedSignal.INVALIDATES
682-
and old_value is not INVALIDATED
683-
):
701+
if old_value is INVALIDATED:
702+
if emits_signal is not EmitsChangedSignal.INVALIDATES:
684703
diffs.append(
685704
NotInvalidatedProperty(
686705
object_path, ifn, key, old_value, new_value
687706
)
688707
)
708+
else:
709+
assert hasattr(old_value, "variant_level")
710+
711+
if new_value != old_value:
712+
if emits_signal is EmitsChangedSignal.TRUE:
713+
diffs.append(
714+
DifferentProperty(
715+
object_path, ifn, key, old_value, new_value
716+
)
717+
)
689718

690-
if emits_signal is EmitsChangedSignal.CONST:
719+
if emits_signal is EmitsChangedSignal.CONST:
720+
diffs.append(
721+
ChangedProperty(object_path, ifn, key, old_value, new_value)
722+
)
723+
elif new_value.variant_level != old_value.variant_level:
691724
diffs.append(
692-
ChangedProperty(object_path, ifn, key, old_value, new_value)
725+
DifferentVariantLevel(
726+
object_path, ifn, key, old_value, new_value
727+
)
693728
)
694729

695730
return diffs

0 commit comments

Comments
 (0)