if self.hosts:
all_hosts = [hs.hostname for hs in hostspecs]
return [h.hostname for h in self.hosts if h.hostname in all_hosts]
- elif self.label:
+ if self.label:
return [hs.hostname for hs in hostspecs if self.label in hs.labels]
- elif self.host_pattern:
- all_hosts = [hs.hostname for hs in hostspecs]
+ all_hosts = [hs.hostname for hs in hostspecs]
+ if self.host_pattern:
return fnmatch.filter(all_hosts, self.host_pattern)
- else:
- # This should be caught by the validation but needs to be here for
- # get_host_selection_size
- return []
+ return all_hosts
def get_host_selection_size(self, hostspecs: Iterable[HostSpec]) -> int:
if self.count:
raise ServiceSpecValidationError("num/count must be > 1")
if self.count_per_host is not None and self.count_per_host < 1:
raise ServiceSpecValidationError("count-per-host must be >= 1")
+ if self.count_per_host is not None and not (
+ self.label
+ or self.hosts
+ or self.host_pattern
+ ):
+ raise ServiceSpecValidationError(
+ "count-per-host must be combined with label or hosts or host_pattern"
+ )
if self.count is not None and self.count_per_host is not None:
raise ServiceSpecValidationError("cannot combine count and count-per-host")
if (
('3 data[1-3]', "PlacementSpec(count=3, host_pattern='data[1-3]')"),
('3 data?', "PlacementSpec(count=3, host_pattern='data?')"),
('3 data*', "PlacementSpec(count=3, host_pattern='data*')"),
- ("count-per-host:4", "PlacementSpec(count_per_host=4)"),
+ ("count-per-host:4 label:foo", "PlacementSpec(count_per_host=4, label='foo')"),
])
def test_parse_placement_specs(test_input, expected):
ret = PlacementSpec.from_string(test_input)
('count:2 count-per-host:1'),
('host1=a host2=b count-per-host:2'),
('host1:10/8 count-per-host:2'),
+ ('count-per-host:2'),
]
)
def test_parse_placement_specs_raises(test_input):