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())
>>> 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:
('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",