From: Sage Weil Date: Tue, 3 Mar 2020 21:28:47 +0000 (-0600) Subject: mgr/orch: PlacementSpec.from_strings: take a string *or* a list X-Git-Tag: v15.1.1~74^2~8 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e334da4b09d35476da65a9ed4e8f6c337cf1dfc2;p=ceph.git mgr/orch: PlacementSpec.from_strings: take a string *or* a list The string can be ' ', ';', or ',' separated. Signed-off-by: Sage Weil --- diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index b04eaf97887..88fadadf7eb 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -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: diff --git a/src/pybind/mgr/tests/test_orchestrator.py b/src/pybind/mgr/tests/test_orchestrator.py index 8d74754262a..08a043b814a 100644 --- a/src/pybind/mgr/tests/test_orchestrator.py +++ b/src/pybind/mgr/tests/test_orchestrator.py @@ -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",