From: Sage Weil Date: Fri, 21 Feb 2020 16:57:32 +0000 (-0600) Subject: mgr/tests/test_orchestrator: test PlacementSpec parsing X-Git-Tag: v15.1.1~282^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=6f65caa61100d00c8710ac744672ad3ca995245c;p=ceph.git mgr/tests/test_orchestrator: test PlacementSpec parsing Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 30347796973..e1747b10bf1 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -1192,6 +1192,18 @@ class PlacementSpec(object): # in the orchestrator backend. self.hosts = hosts + def __repr__(self): + kv = [] + if self.count: + kv.append('count=%d' % self.count) + if self.label: + kv.append('label=%s' % self.label) + if self.hosts: + kv.append('hosts=%s' % self.hosts) + if self.all_hosts: + kv.append('all=true') + return "PlacementSpec(%s)" % (' '.join(kv)) + @classmethod def from_dict(cls, data): _cls = cls(**data) diff --git a/src/pybind/mgr/tests/test_orchestrator.py b/src/pybind/mgr/tests/test_orchestrator.py index 1fc62e04fe9..3b516360415 100644 --- a/src/pybind/mgr/tests/test_orchestrator.py +++ b/src/pybind/mgr/tests/test_orchestrator.py @@ -10,7 +10,7 @@ from orchestrator import raise_if_exception, RGWSpec, Completion, ProgressRefere servicespec_validate_add from orchestrator import InventoryHost, ServiceDescription, DaemonDescription from orchestrator import OrchestratorValidationError -from orchestrator import HostPlacementSpec +from orchestrator import HostPlacementSpec, PlacementSpec @pytest.mark.parametrize("test_input,expected, require_network", @@ -30,6 +30,21 @@ def test_parse_host_placement_specs(test_input, expected, require_network): assert ret == expected assert str(ret) == test_input +@pytest.mark.parametrize( + "test_input,expected", + [ + ('', "PlacementSpec()"), + ("3", "PlacementSpec(count=3)"), + ("host1 host2", "PlacementSpec(hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"), + ('2 host1 host2', "PlacementSpec(count=2 hosts=[HostPlacementSpec(hostname='host1', network='', name=''), HostPlacementSpec(hostname='host2', network='', name='')])"), + ('label:foo', "PlacementSpec(label=foo)"), + ('3 label:foo', "PlacementSpec(count=3 label=foo)"), + ('*', 'PlacementSpec(all=true)'), + ]) +def test_parse_placement_specs(test_input, expected): + ret = PlacementSpec.from_strings(test_input.split()) + assert str(ret) == expected + @pytest.mark.parametrize("test_input", # wrong subnet [("myhost:1.1.1.1/24"),