]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: PlacementSpec.from_strings: take a string *or* a list
authorSage Weil <sage@redhat.com>
Tue, 3 Mar 2020 21:28:47 +0000 (15:28 -0600)
committerSage Weil <sage@redhat.com>
Sat, 7 Mar 2020 03:27:48 +0000 (21:27 -0600)
The string can be ' ', ';', or ',' separated.

Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/orchestrator/_interface.py
src/pybind/mgr/tests/test_orchestrator.py

index b04eaf97887ffedf6209c945dd7d7b296b8e58de..88fadadf7eb652f4a5d8aff2458783e29cf2ece2 100644 (file)
@@ -1312,8 +1312,8 @@ class PlacementSpec(object):
             raise OrchestratorValidationError("num/count must be > 1")
 
     @classmethod
-    def from_strings(cls, strings):
-        # type: (Optional[List[str]]) -> PlacementSpec
+    def from_strings(cls, arg):
+        # type: (Optional[str]) -> PlacementSpec
         """
         A single integer is parsed as a count:
         >>> PlacementSpec.from_strings('3'.split())
@@ -1333,7 +1333,25 @@ class PlacementSpec(object):
         >>> PlacementSpec.from_strings(None)
         PlacementSpec()
         """
-        strings = strings or []
+        if arg is None:
+            strings = []
+        elif isinstance(arg, str):
+            if ' ' in arg:
+                strings = arg.split(' ')
+            elif ';' in arg:
+                strings = arg.split(';')
+            elif ',' in arg and '[' not in arg:
+                # FIXME: this isn't quite right.  we want to avoid breaking
+                # a list of mons with addrvecs... so we're basically allowing
+                # , most of the time, except when addrvecs are used.  maybe
+                # ok?
+                strings = arg.split(',')
+            else:
+                strings = [arg]
+        elif isinstance(arg, list):
+            strings = arg
+        else:
+            raise OrchestratorValidationError('invalid placement %s' % arg)
 
         count = None
         if strings:
index 8d74754262a0e340dd1cc5108461d03695d72cd3..08a043b814aa3726399baefc1848787e9ab76132 100644 (file)
@@ -41,10 +41,11 @@ def test_parse_host_placement_specs(test_input, expected, require_network):
         ('2 host1 host2', "PlacementSpec(count=2 hosts=host1,host2)"),
         ('label:foo', "PlacementSpec(label=foo)"),
         ('3 label:foo', "PlacementSpec(count=3 label=foo)"),
+        (['*'], 'PlacementSpec(all=true)'),
         ('*', 'PlacementSpec(all=true)'),
     ])
 def test_parse_placement_specs(test_input, expected):
-    ret = PlacementSpec.from_strings(test_input.split())
+    ret = PlacementSpec.from_strings(test_input)
     assert str(ret) == expected
 
 @pytest.mark.parametrize("test_input",