mirror of
https://github.com/ceph/ceph
synced 2025-02-23 02:57:21 +00:00
python-common: Remove duplicated DriveGroupSpec.__repr__ and __eq__
Signed-off-by: Sebastian Wagner <sewagner@redhat.com>
This commit is contained in:
parent
38b52f715f
commit
b91f81801a
@ -330,21 +330,5 @@ class DriveGroupSpec(ServiceSpec):
|
||||
if self.method == 'raw' and self.objectstore == 'filestore':
|
||||
raise DriveGroupValidationError('method raw only supports bluestore')
|
||||
|
||||
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)
|
||||
|
@ -668,7 +668,8 @@ class ServiceSpec(object):
|
||||
)
|
||||
|
||||
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__
|
||||
|
@ -342,6 +342,17 @@ def test_alertmanager_spec_2():
|
||||
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",
|
||||
[
|
||||
(
|
||||
|
Loading…
Reference in New Issue
Block a user