From 378d51879eef01b47487f8b868bfdb7c94332f7a Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Fri, 11 Sep 2020 13:21:29 +0200 Subject: [PATCH] mgr/cephadm: move _apply_all_services to serve.py Signed-off-by: Sebastian Wagner (cherry picked from commit 3ff6a38c48aa5a113148f682af92389b13bd42aa) --- src/pybind/mgr/cephadm/module.py | 16 ---------------- src/pybind/mgr/cephadm/serve.py | 19 ++++++++++++++++++- src/pybind/mgr/cephadm/tests/fixtures.py | 4 ++-- src/pybind/mgr/cephadm/tests/test_cephadm.py | 6 +++--- .../mgr/cephadm/tests/test_migration.py | 4 ++-- 5 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 06cd08997ff..da93918d5b6 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1980,22 +1980,6 @@ To check that the host is reachable: r = False return r - def _apply_all_services(self): - r = False - specs = [] # type: List[ServiceSpec] - for sn, spec in self.spec_store.specs.items(): - specs.append(spec) - for spec in specs: - try: - if self._apply_service(spec): - r = True - except Exception as e: - self.log.exception('Failed to apply %s spec %s: %s' % ( - spec.service_name(), spec, e)) - self.events.for_service(spec, 'ERROR', 'Failed to apply: ' + str(e)) - - return r - def _check_pool_exists(self, pool, service_name): logger.info(f'Checking pool "{pool}" exists for service {service_name}') if not self.rados.pool_exists(pool): diff --git a/src/pybind/mgr/cephadm/serve.py b/src/pybind/mgr/cephadm/serve.py index 74cb760c086..f00e61f2167 100644 --- a/src/pybind/mgr/cephadm/serve.py +++ b/src/pybind/mgr/cephadm/serve.py @@ -10,6 +10,7 @@ except ImportError: remoto = None from ceph.deployment import inventory +from ceph.deployment.service_spec import ServiceSpec import orchestrator from cephadm.utils import forall_hosts, cephadmNoImage, str_to_datetime @@ -63,7 +64,7 @@ class CephadmServe: if self.mgr.migration.is_migration_ongoing(): continue - if self.mgr._apply_all_services(): + if self._apply_all_services(): continue # did something, refresh self.mgr._check_daemons() @@ -369,3 +370,19 @@ class CephadmServe: 'detail': daemon_detail, } self.mgr.set_health_checks(self.mgr.health_checks) + + def _apply_all_services(self) -> bool: + r = False + specs = [] # type: List[ServiceSpec] + for sn, spec in self.mgr.spec_store.specs.items(): + specs.append(spec) + for spec in specs: + try: + if self.mgr._apply_service(spec): + r = True + except Exception as e: + self.log.exception('Failed to apply %s spec %s: %s' % ( + spec.service_name(), spec, e)) + self.mgr.events.for_service(spec, 'ERROR', 'Failed to apply: ' + str(e)) + + return r diff --git a/src/pybind/mgr/cephadm/tests/fixtures.py b/src/pybind/mgr/cephadm/tests/fixtures.py index c263c81bfc7..5548c53e2ef 100644 --- a/src/pybind/mgr/cephadm/tests/fixtures.py +++ b/src/pybind/mgr/cephadm/tests/fixtures.py @@ -126,7 +126,7 @@ def with_host(m: CephadmOrchestrator, name, refresh_hosts=True): def assert_rm_service(cephadm, srv_name): assert wait(cephadm, cephadm.remove_service(srv_name)) == f'Removed service {srv_name}' - cephadm._apply_all_services() + CephadmServe(cephadm)._apply_all_services() @contextmanager @@ -138,7 +138,7 @@ def with_service(cephadm_module: CephadmOrchestrator, spec: ServiceSpec, meth, h specs = [d.spec for d in wait(cephadm_module, cephadm_module.describe_service())] assert spec in specs - cephadm_module._apply_all_services() + CephadmServe(cephadm_module)._apply_all_services() dds = wait(cephadm_module, cephadm_module.list_daemons()) own_dds = [dd for dd in dds if dd.service_name() == spec.service_name()] diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index cb98bf46bb2..143ce9206df 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -409,7 +409,7 @@ class TestCephadm(object): _run_cephadm.return_value = (['{}'], '', 0) - assert cephadm_module._apply_all_services() == False + assert CephadmServe(cephadm_module)._apply_all_services() == False _run_cephadm.assert_any_call( 'test', 'osd', 'ceph-volume', @@ -738,7 +738,7 @@ class TestCephadm(object): c = cephadm_module.apply_mds(spec) out = wait(cephadm_module, c) match_glob(out, "Scheduled mds.fsname update...") - cephadm_module._apply_all_services() + CephadmServe(cephadm_module)._apply_all_services() [daemon] = cephadm_module.cache.daemons['host1'].keys() @@ -749,7 +749,7 @@ class TestCephadm(object): c = cephadm_module.apply_mds(spec) out = wait(cephadm_module, c) match_glob(out, "Scheduled mds.fsname update...") - cephadm_module._apply_all_services() + CephadmServe(cephadm_module)._apply_all_services() ok_to_stop.assert_called_with([daemon[4:]]) diff --git a/src/pybind/mgr/cephadm/tests/test_migration.py b/src/pybind/mgr/cephadm/tests/test_migration.py index 4b86c224673..8536c4e1962 100644 --- a/src/pybind/mgr/cephadm/tests/test_migration.py +++ b/src/pybind/mgr/cephadm/tests/test_migration.py @@ -26,7 +26,7 @@ def test_migrate_scheduler(cephadm_module: CephadmOrchestrator): assert wait(cephadm_module, c) == 'Scheduled rgw.r.z update...' # with pytest.raises(OrchestratorError, match="cephadm migration still ongoing. Please wait, until the migration is complete."): - cephadm_module._apply_all_services() + CephadmServe(cephadm_module)._apply_all_services() cephadm_module.migration_current = 0 cephadm_module.migration.migrate() @@ -36,7 +36,7 @@ def test_migrate_scheduler(cephadm_module: CephadmOrchestrator): CephadmServe(cephadm_module)._refresh_hosts_and_daemons() cephadm_module.migration.migrate() - cephadm_module._apply_all_services() + CephadmServe(cephadm_module)._apply_all_services() out = {o.hostname for o in wait(cephadm_module, cephadm_module.list_daemons())} assert out == {'host1', 'host2'} -- 2.47.3