if self.filter_logic not in ['AND', 'OR']:
raise DriveGroupValidationError('filter_logic must be either <AND> or <OR>')
- def __repr__(self) -> str:
- keys = [
- key for key in self._supported_features if getattr(self, key) is not None
- ]
- if 'encrypted' in keys and not self.encrypted:
- keys.remove('encrypted')
- if 'objectstore' in keys and self.objectstore == 'bluestore':
- keys.remove('objectstore')
- return "DriveGroupSpec(name={}->{})".format(
- self.service_id,
- ', '.join('{}={}'.format(key, repr(getattr(self, key))) for key in keys)
- )
-
- def __eq__(self, other: Any) -> bool:
- return repr(self) == repr(other)
-
yaml.add_representer(DriveGroupSpec, DriveGroupSpec.yaml_representer)
)
def __repr__(self) -> str:
- return "{}({!r})".format(self.__class__.__name__, self.__dict__)
+ y = yaml.dump(cast(dict, self), default_flow_style=False)
+ return f"{self.__class__.__name__}.from_json(yaml.safe_load('''{y}'''))"
def __eq__(self, other: Any) -> bool:
return (self.__class__ == other.__class__
assert 'default_webhook_urls' in spec.user_data.keys()
+
+def test_repr():
+ val = """ServiceSpec.from_json(yaml.safe_load('''service_type: crash
+service_name: crash
+placement:
+ count: 42
+'''))"""
+ obj = eval(val)
+ assert obj.service_type == 'crash'
+ assert val == repr(obj)
+
@pytest.mark.parametrize("spec1, spec2, eq",
[
(