yield s
def convert_to_explicit(spec: ServiceSpec) -> None:
+ existing_daemons = self.mgr.cache.get_daemons_by_service(spec.service_name())
placements = HostAssignment(
spec=spec,
hosts=self.mgr.inventory.all_specs(),
- get_daemons_func=self.mgr.cache.get_daemons_by_service
+ daemons=existing_daemons,
).place()
- existing_daemons = self.mgr.cache.get_daemons_by_service(spec.service_name())
-
# We have to migrate, only if the new scheduler would remove daemons
if len(placements) >= len(existing_daemons):
return
ha = HostAssignment(
spec=spec,
hosts=self._hosts_with_daemon_inventory(),
- get_daemons_func=self.cache.get_daemons_by_service,
+ daemons=self.cache.get_daemons_by_service(spec.service_name()),
)
ha.validate()
hosts = ha.place()
HostAssignment(
spec=spec,
hosts=self.inventory.all_specs(), # All hosts, even those without daemon refresh
- get_daemons_func=self.cache.get_daemons_by_service,
+ daemons=self.cache.get_daemons_by_service(spec.service_name()),
).validate()
self.log.info('Saving service %s spec with placement %s' % (
def __init__(self,
spec, # type: ServiceSpec
hosts: List[orchestrator.HostSpec],
- get_daemons_func, # type: Callable[[str],List[orchestrator.DaemonDescription]]
+ daemons: List[orchestrator.DaemonDescription],
filter_new_host=None, # type: Optional[Callable[[str],bool]]
scheduler=None, # type: Optional[BaseScheduler]
):
- assert spec and get_daemons_func
+ assert spec
self.spec = spec # type: ServiceSpec
self.scheduler = scheduler if scheduler else SimpleScheduler(self.spec)
self.hosts: List[orchestrator.HostSpec] = hosts
self.filter_new_host = filter_new_host
self.service_name = spec.service_name()
- self.daemons = get_daemons_func(self.service_name)
+ self.daemons = daemons
def hosts_by_label(self, label: str) -> List[orchestrator.HostSpec]:
return [h for h in self.hosts if label in h.labels]
return mk_spec, hosts
-def run_scheduler_test(results, mk_spec, hosts, get_daemons_func, key_elems):
+def run_scheduler_test(results, mk_spec, hosts, daemons, key_elems):
key = ' '.join('N' if e is None else str(e) for e in key_elems)
try:
assert_res = get_result(k(key), results)
host_res = HostAssignment(
spec=spec,
hosts=hosts,
- get_daemons_func=get_daemons_func).place()
+ daemons=daemons,
+ ).place()
if isinstance(host_res, list):
e = ', '.join(repr(h.hostname) for h in host_res)
assert False, f'`(k("{key}"), exactly({e})),` not found'
host_res = HostAssignment(
spec=spec,
hosts=hosts,
- get_daemons_func=get_daemons_func).place()
+ daemons=daemons
+ ).place()
assert_res(sorted([h.hostname for h in host_res]))
except Exception as e:
results=test_explicit_scheduler_results,
mk_spec=mk_spec,
hosts=hosts,
- get_daemons_func=lambda _: [],
+ daemons=[],
key_elems=(host_key, explicit_key, count, spec_section_key)
)
results=test_scheduler_daemons_results,
mk_spec=mk_spec,
hosts=hosts,
- get_daemons_func=lambda _: dds,
+ daemons=dds,
key_elems=(host_key, explicit_key, count, daemons_key, spec_section_key)
)
hosts = HostAssignment(
spec=spec,
hosts=[HostSpec(h, labels=['foo']) for h in hosts],
- get_daemons_func=lambda _: daemons).place()
+ daemons=daemons
+ ).place()
assert sorted([h.hostname for h in hosts]) == sorted(expected)
hosts = HostAssignment(
spec=ServiceSpec(service_type, placement=placement),
hosts=[HostSpec(h, labels=['foo']) for h in hosts],
- get_daemons_func=lambda _: daemons).place()
+ daemons=daemons,
+ ).place()
assert len(hosts) == expected_len
for h in [h.hostname for h in hosts]:
assert h in in_set
hosts = HostAssignment(
spec=ServiceSpec(service_type, placement=placement),
hosts=[HostSpec(h) for h in hosts],
- get_daemons_func=lambda _: daemons).place()
+ daemons=daemons,
+ ).place()
assert len(hosts) == expected_len
for h in must_have:
assert h in [h.hostname for h in hosts]
hosts = HostAssignment(
spec=ServiceSpec(service_type, placement=placement),
hosts=[HostSpec(h) for h in hosts],
- get_daemons_func=lambda _: daemons).place()
+ daemons=daemons,
+ ).place()
assert str(e.value) == expected
hosts = HostAssignment(
spec=spec,
hosts=[HostSpec(h) for h in hosts],
- get_daemons_func=lambda _: daemons).place()
+ daemons=daemons,
+ ).place()
assert sorted([h.hostname for h in hosts]) in expected