From 4580eaac65360f56524d8a8ae3dfe4c50c52c6ad Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Fri, 28 Feb 2020 16:55:31 -0600 Subject: [PATCH] mgr/cephadm: use _apply() helper for all apply_ methods Clean up a few that were missed (due to racing PRs, presumably). 'creation' -> 'update', since an apply doesn't necessarily create (it may destroy!). Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 39 +++++++++++--------- src/pybind/mgr/cephadm/tests/test_cephadm.py | 12 +++--- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 0c4fda57dc754..a005e944fea89 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2188,10 +2188,14 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): # type: (orchestrator.ServiceSpec) -> orchestrator.Completion return self._add_daemon('mgr', spec, self._create_mgr) - def apply_mgr(self, spec): + def _apply(self, spec): + self.log.info('Saving service %s spec' % spec.service_name()) self.spec_store.save(spec) self._kick_serve_loop() - return trivial_result("Scheduled MGR creation..") + return trivial_result("Scheduled %s update..." % spec.service_type) + + def apply_mgr(self, spec): + return self._apply(spec) def _apply_mgr(self, spec): # type: (orchestrator.ServiceSpec) -> AsyncCompletion @@ -2202,9 +2206,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): return self._add_daemon('mds', spec, self._create_mds, self._config_mds) def apply_mds(self, spec: orchestrator.ServiceSpec) -> orchestrator.Completion: - self.spec_store.save(spec) - self._kick_serve_loop() - return trivial_result("Scheduled MDS creation..") + return self._apply(spec) def _apply_mds(self, spec): # type: (orchestrator.ServiceSpec) -> AsyncCompletion @@ -2263,9 +2265,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): return self._create_daemon('rgw', rgw_id, host, keyring=keyring) def apply_rgw(self, spec): - self.spec_store.save(spec) - self._kick_serve_loop() - return trivial_result("Scheduled RGW creation..") + return self._apply(spec) def _apply_rgw(self, spec): # type: (orchestrator.ServiceSpec) -> AsyncCompletion @@ -2287,9 +2287,7 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): keyring=keyring) def apply_rbd_mirror(self, spec): - self.spec_store.save(spec) - self._kick_serve_loop() - return trivial_result("Scheduled rbd-mirror creation..") + return self._apply(spec) def _apply_rbd_mirror(self, spec): # type: (orchestrator.ServiceSpec) -> AsyncCompletion @@ -2496,9 +2494,7 @@ receivers: return self._apply_service('prometheus', spec, self._create_prometheus) def apply_prometheus(self, spec): - self.spec_store.save(spec) - self._kick_serve_loop() - return trivial_result("Scheduled prometheus creation..") + return self._apply(spec) def add_node_exporter(self, spec): # type: (orchestrator.ServiceSpec) -> AsyncCompletion @@ -2506,9 +2502,7 @@ receivers: self._create_node_exporter) def apply_node_exporter(self, spec): - self.spec_store.save(spec) - self._kick_serve_loop() - return trivial_result("Scheduled node-exporter creation..") + return self._apply(spec) def _apply_node_exporter(self, spec): # type: (orchestrator.ServiceSpec) -> AsyncCompletion @@ -2525,7 +2519,10 @@ receivers: def apply_grafana(self, spec): # type: (orchestrator.ServiceSpec) -> AsyncCompletion - return self._apply_service('grafana', spec, self.add_grafana) + return self._apply(spec) + + def _apply_grafana(self, spec): + return self._apply_service('grafana', spec, self._create_grafana) @async_map_completion def _create_grafana(self, daemon_id, host): @@ -2536,6 +2533,10 @@ receivers: return self._add_daemon('alertmanager', spec, self._create_alertmanager) def apply_alertmanager(self, spec): + # type: (orchestrator.ServiceSpec) -> AsyncCompletion + return self._apply(spec) + + def _apply_alertmanager(self, spec): # type: (orchestrator.ServiceSpec) -> AsyncCompletion return self._apply_service('alertmanager', spec, self._create_alertmanager) @@ -2842,6 +2843,8 @@ receivers: super_completions.extend(self.trigger_deployment('mds', self._apply_mds)) super_completions.extend(self.trigger_deployment('rgw', self._apply_rgw)) super_completions.extend(self.trigger_deployment('rbd-mirror', self._apply_rbd_mirror)) + super_completions.extend(self.trigger_deployment('grafana', self._apply_grafana)) + super_completions.extend(self.trigger_deployment('alertmanager', self._apply_alertmanager)) # Not implemented diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index c629613ba5c57..4893d0851d6ec 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -414,7 +414,7 @@ class TestCephadm(object): spec = ServiceSpec(placement=ps, service_type='mgr') c = cephadm_module.apply_mgr(spec) _save_spec.assert_called_with(spec) - assert wait(cephadm_module, c) == 'Scheduled MGR creation..' + assert wait(cephadm_module, c) == 'Scheduled mgr update...' @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) @mock.patch("cephadm.module.CephadmOrchestrator.send_command") @@ -429,7 +429,7 @@ class TestCephadm(object): spec = ServiceSpec(placement=ps, service_type='mds') c = cephadm_module.apply_mds(spec) _save_spec.assert_called_with(spec) - assert wait(cephadm_module, c) == 'Scheduled MDS creation..' + assert wait(cephadm_module, c) == 'Scheduled mds update...' @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) @mock.patch("cephadm.module.CephadmOrchestrator.send_command") @@ -444,7 +444,7 @@ class TestCephadm(object): spec = ServiceSpec(placement=ps, service_type='rgw') c = cephadm_module.apply_rgw(spec) _save_spec.assert_called_with(spec) - assert wait(cephadm_module, c) == 'Scheduled RGW creation..' + assert wait(cephadm_module, c) == 'Scheduled rgw update...' @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) @mock.patch("cephadm.module.CephadmOrchestrator.send_command") @@ -459,7 +459,7 @@ class TestCephadm(object): spec = ServiceSpec(placement=ps, service_type='rbd-mirror') c = cephadm_module.apply_rbd_mirror(spec) _save_spec.assert_called_with(spec) - assert wait(cephadm_module, c) == 'Scheduled rbd-mirror creation..' + assert wait(cephadm_module, c) == 'Scheduled rbd-mirror update...' @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) @mock.patch("cephadm.module.CephadmOrchestrator.send_command") @@ -474,7 +474,7 @@ class TestCephadm(object): spec = ServiceSpec(placement=ps, service_type='prometheus') c = cephadm_module.apply_prometheus(spec) _save_spec.assert_called_with(spec) - assert wait(cephadm_module, c) == 'Scheduled prometheus creation..' + assert wait(cephadm_module, c) == 'Scheduled prometheus update...' @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) @mock.patch("cephadm.module.CephadmOrchestrator.send_command") @@ -489,7 +489,7 @@ class TestCephadm(object): spec = ServiceSpec(placement=ps, service_type='node_exporter') c = cephadm_module.apply_node_exporter(spec) _save_spec.assert_called_with(spec) - assert wait(cephadm_module, c) == 'Scheduled node-exporter creation..' + assert wait(cephadm_module, c) == 'Scheduled node_exporter update...' @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('{}')) @mock.patch("cephadm.module.CephadmOrchestrator.send_command") -- 2.39.5