From ec9890a37d072280f4d28d801daaf1ed53a06d6a Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Tue, 9 Jun 2020 15:51:28 +0200 Subject: [PATCH] mgr/cephadm: add test for ok-to-stop Signed-off-by: Sebastian Wagner (cherry picked from commit 5c91f1b897beaca476bb1ef178ef332fe092bae3) --- src/pybind/mgr/cephadm/tests/test_cephadm.py | 30 +++++++++++++++++++ .../ceph/deployment/service_spec.py | 12 ++++---- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index e80728c3871e0..e2da403e7409a 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -536,6 +536,36 @@ class TestCephadm(object): assert_rm_service(cephadm_module, spec.service_name()) + @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) + @mock.patch("cephadm.services.cephadmservice.CephadmService.ok_to_stop") + def test_daemon_ok_to_stop(self, ok_to_stop, cephadm_module: CephadmOrchestrator): + spec = ServiceSpec( + 'mds', + service_id='fsname', + placement=PlacementSpec(hosts=['host1', 'host2']) + ) + with with_host(cephadm_module, 'host1'), with_host(cephadm_module, 'host2'): + c = cephadm_module.apply_mds(spec) + out = wait(cephadm_module, c) + match_glob(out, "Scheduled mds.fsname update...") + cephadm_module._apply_all_services() + + [daemon] = cephadm_module.cache.daemons['host1'].keys() + + spec.placement.set_hosts(['host2']) + + ok_to_stop.side_effect = False + + c = cephadm_module.apply_mds(spec) + out = wait(cephadm_module, c) + match_glob(out, "Scheduled mds.fsname update...") + cephadm_module._apply_all_services() + + ok_to_stop.assert_called_with([daemon[4:]]) + + assert_rm_daemon(cephadm_module, spec.service_name(), 'host1') # verifies ok-to-stop + assert_rm_daemon(cephadm_module, spec.service_name(), 'host2') + @mock.patch("cephadm.module.CephadmOrchestrator._get_connection") @mock.patch("remoto.process.check") diff --git a/src/python-common/ceph/deployment/service_spec.py b/src/python-common/ceph/deployment/service_spec.py index 4d86d6fc167f5..4d0d732d5bccb 100644 --- a/src/python-common/ceph/deployment/service_spec.py +++ b/src/python-common/ceph/deployment/service_spec.py @@ -151,11 +151,7 @@ class PlacementSpec(object): self.hosts = [] # type: List[HostPlacementSpec] if hosts: - if all([isinstance(host, HostPlacementSpec) for host in hosts]): - self.hosts = hosts # type: ignore - else: - self.hosts = [HostPlacementSpec.parse(x, require_network=False) # type: ignore - for x in hosts if x] + self.set_hosts(hosts) self.count = count # type: Optional[int] @@ -181,7 +177,11 @@ class PlacementSpec(object): def set_hosts(self, hosts): # To backpopulate the .hosts attribute when using labels or count # in the orchestrator backend. - self.hosts = hosts + if all([isinstance(host, HostPlacementSpec) for host in hosts]): + self.hosts = hosts # type: ignore + else: + self.hosts = [HostPlacementSpec.parse(x, require_network=False) # type: ignore + for x in hosts if x] def filter_matching_hosts(self, _get_hosts_func: Callable) -> List[str]: return self.filter_matching_hostspecs(_get_hosts_func(as_hostspec=True)) -- 2.39.5