]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/tests/test_orchestrator: test PlacementSpec parsing
authorSage Weil <sage@redhat.com>
Fri, 21 Feb 2020 16:57:32 +0000 (10:57 -0600)
committerSage Weil <sage@redhat.com>
Mon, 24 Feb 2020 13:39:46 +0000 (07:39 -0600)
Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/tests/test_orchestrator.py

index 30347796973b17f5d0eb8eab383c1c1a90dfa286..e1747b10bf166de45599559e80b8607e248ffda3 100644 (file)
@@ -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)
index 1fc62e04fe9be2c76f105c8d915d4340b955fb86..3b51636041574bf53064a9631a3f92aacad47f6e 100644 (file)
@@ -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"),