def __init__(self,
spec, # type: ServiceSpec
- get_hosts_func, # type: Callable
+ hosts: List[orchestrator.HostSpec],
get_daemons_func, # type: Callable[[str],List[orchestrator.DaemonDescription]]
filter_new_host=None, # type: Optional[Callable[[str],bool]]
scheduler=None, # type: Optional[BaseScheduler]
):
- assert spec and get_hosts_func and get_daemons_func
+ assert spec and get_daemons_func
self.spec = spec # type: ServiceSpec
self.scheduler = scheduler if scheduler else SimpleScheduler(self.spec)
- self.hosts: List[orchestrator.HostSpec] = get_hosts_func(as_hostspec=True)
+ 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)
spec = mk_spec()
host_res = HostAssignment(
spec=spec,
- get_hosts_func=get_hosts_func,
+ hosts=get_hosts_func(),
get_daemons_func=get_daemons_func).place()
if isinstance(host_res, list):
e = ', '.join(repr(h.hostname) for h in host_res)
spec = mk_spec()
host_res = HostAssignment(
spec=spec,
- get_hosts_func=get_hosts_func,
+ hosts=get_hosts_func(),
get_daemons_func=get_daemons_func).place()
assert_res(sorted([h.hostname for h in host_res]))
),
])
def test_node_assignment(service_type, placement, hosts, daemons, expected):
- def get_hosts_func(label=None, as_hostspec=False):
- if as_hostspec:
- return [HostSpec(h, labels=['foo']) for h in hosts]
- return hosts
-
service_id = None
if service_type == 'rgw':
service_id = 'realm.zone'
hosts = HostAssignment(
spec=spec,
- get_hosts_func=get_hosts_func,
+ hosts=[HostSpec(h, labels=['foo']) for h in hosts],
get_daemons_func=lambda _: daemons).place()
assert sorted([h.hostname for h in hosts]) == sorted(expected)
])
def test_node_assignment2(service_type, placement, hosts,
daemons, expected_len, in_set):
- def get_hosts_func(label=None, as_hostspec=False):
- if as_hostspec:
- return [HostSpec(h, labels=['foo']) for h in hosts]
- return hosts
-
hosts = HostAssignment(
spec=ServiceSpec(service_type, placement=placement),
- get_hosts_func=get_hosts_func,
+ hosts=[HostSpec(h, labels=['foo']) for h in hosts],
get_daemons_func=lambda _: daemons).place()
assert len(hosts) == expected_len
for h in [h.hostname for h in hosts]:
])
def test_node_assignment3(service_type, placement, hosts,
daemons, expected_len, must_have):
- def get_hosts_func(label=None, as_hostspec=False):
- if as_hostspec:
- return [HostSpec(h) for h in hosts]
- return hosts
-
hosts = HostAssignment(
spec=ServiceSpec(service_type, placement=placement),
- get_hosts_func=get_hosts_func,
+ hosts=[HostSpec(h) for h in hosts],
get_daemons_func=lambda _: daemons).place()
assert len(hosts) == expected_len
for h in must_have:
),
])
def test_bad_specs(service_type, placement, hosts, daemons, expected):
- def get_hosts_func(label=None, as_hostspec=False):
- if as_hostspec:
- return [HostSpec(h) for h in hosts]
- return hosts
with pytest.raises(OrchestratorValidationError) as e:
hosts = HostAssignment(
spec=ServiceSpec(service_type, placement=placement),
- get_hosts_func=get_hosts_func,
+ hosts=[HostSpec(h) for h in hosts],
get_daemons_func=lambda _: daemons).place()
assert str(e.value) == expected
])
def test_active_assignment(service_type, placement, hosts, daemons, expected):
- def get_hosts_func(label=None, as_hostspec=False):
- if as_hostspec:
- return [HostSpec(h) for h in hosts]
- return hosts
spec = ServiceSpec(service_type=service_type,
service_id=None,
hosts = HostAssignment(
spec=spec,
- get_hosts_func=get_hosts_func,
+ hosts=[HostSpec(h) for h in hosts],
get_daemons_func=lambda _: daemons).place()
assert sorted([h.hostname for h in hosts]) in expected