From adec19e676abfb34a2c7e9ccb5d6721c27f44d1a Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Wed, 12 Feb 2020 15:59:05 -0600 Subject: [PATCH] mgr/orch: add --force arg to 'daemon rm' This is needed when removing mons. Signed-off-by: Sage Weil --- src/pybind/mgr/cephadm/module.py | 17 +++++++++++------ src/pybind/mgr/cephadm/tests/test_cephadm.py | 4 ++-- src/pybind/mgr/orchestrator.py | 4 ++-- src/pybind/mgr/orchestrator_cli/module.py | 7 ++++--- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 648d01adcf4..53cb3596eec 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1454,15 +1454,17 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): daemon_type=daemon_type, daemon_id=daemon_id).then(_proc_daemons) - def remove_daemons(self, names): - # type: (List[str]) -> orchestrator.Completion + def remove_daemons(self, names, force): + # type: (List[str], bool) -> orchestrator.Completion def _filter(daemons): args = [] for d in daemons: for name in names: if d.name() == name: args.append( - ('%s.%s' % (d.daemon_type, d.daemon_id), d.nodename) + ('%s.%s' % (d.daemon_type, d.daemon_id), + d.nodename, + force) ) if not args: raise OrchestratorError('Unable to find daemon(s) %s' % (names)) @@ -1769,13 +1771,16 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin): 'Reconfigured' if reconfig else 'Deployed', name, host) @async_map_completion - def _remove_daemon(self, name, host): + def _remove_daemon(self, name, host, force=False): """ Remove a daemon """ + self.log.debug('_remove_daemon %s on %s force=%s' % (name, host, force)) + args = ['--name', name] + if force: + args.extend(['--force']) out, err, code = self._run_cephadm( - host, name, 'rm-daemon', - ['--name', name]) + host, name, 'rm-daemon', args) self.log.debug('_remove_daemon code %s out %s' % (code, out)) if not code and host in self.daemon_cache: # remove item from cache diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index f555cbf6205..e201c5b29b9 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -151,7 +151,7 @@ class TestCephadm(object): with self._with_host(cephadm_module, 'test'): c = cephadm_module.list_daemons(refresh=True) wait(cephadm_module, c) - c = cephadm_module.remove_daemons(['osd.0']) + c = cephadm_module.remove_daemons(['osd.0'], False) out = wait(cephadm_module, c) assert out == ["Removed osd.0 from host 'test'"] @@ -237,7 +237,7 @@ class TestCephadm(object): with self._with_host(cephadm_module, 'test'): c = cephadm_module.list_daemons(refresh=True) wait(cephadm_module, c) - c = cephadm_module.remove_daemons(['rgw.myrgw.myhost.myid']) + c = cephadm_module.remove_daemons(['rgw.myrgw.myhost.myid'], False) out = wait(cephadm_module, c) assert out == ["Removed rgw.myrgw.myhost.myid from host 'test'"] diff --git a/src/pybind/mgr/orchestrator.py b/src/pybind/mgr/orchestrator.py index 1621d091a45..08868c7f8ce 100644 --- a/src/pybind/mgr/orchestrator.py +++ b/src/pybind/mgr/orchestrator.py @@ -878,8 +878,8 @@ class Orchestrator(object): """ raise NotImplementedError() - def remove_daemons(self, names): - # type: (List[str]) -> Completion + def remove_daemons(self, names, force): + # type: (List[str], bool) -> Completion """ Remove specific daemon(s). diff --git a/src/pybind/mgr/orchestrator_cli/module.py b/src/pybind/mgr/orchestrator_cli/module.py index 233c862d5e8..66031bf9cf1 100644 --- a/src/pybind/mgr/orchestrator_cli/module.py +++ b/src/pybind/mgr/orchestrator_cli/module.py @@ -532,13 +532,14 @@ Usage: @orchestrator._cli_write_command( 'orch daemon rm', - "name=names,type=CephString,n=N", + "name=names,type=CephString,n=N " + 'name=force,type=CephBool,req=false', 'Remove specific daemon(s)') - def _daemon_rm(self, names): + def _daemon_rm(self, names, force=False): for name in names: if '.' not in name: raise orchestrator.OrchestratorError('%s is not a valid daemon name' % name) - completion = self.remove_daemons(names) + completion = self.remove_daemons(names, force) self._orchestrator_wait([completion]) orchestrator.raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) -- 2.39.5