From 473723504643fd86898f43718d0643d34eff71d7 Mon Sep 17 00:00:00 2001 From: Shweta Bhosale Date: Wed, 16 Apr 2025 18:04:35 +0530 Subject: [PATCH] mgr/cephadm: Add command to stop host drain Fixes: https://tracker.ceph.com/issues/70950 Signed-off-by: Shweta Bhosale (cherry picked from commit 7f2f0288e891e840661a14e25bec74e97ed1523b) --- src/pybind/mgr/cephadm/module.py | 12 ++++++++++++ src/pybind/mgr/cephadm/tests/test_cephadm.py | 10 ++++++++++ src/pybind/mgr/orchestrator/_interface.py | 8 ++++++++ src/pybind/mgr/orchestrator/module.py | 7 +++++++ 4 files changed, 37 insertions(+) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 6ee03a1c696..343fa2b3360 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -4204,6 +4204,18 @@ Then run the following: return "Scheduled to remove the following daemons from host '{}'\n{}".format(hostname, daemons_table) + @handle_orch_error + @host_exists() + def stop_drain_host(self, hostname: str) -> str: + if not self.inventory.has_label(hostname, '_no_schedule'): + raise OrchestratorValidationError(f'The host {hostname} is currently not draining.') + self.remove_host_label(hostname, '_no_schedule') + self.remove_host_label(hostname, SpecialHostLabels.DRAIN_CONF_KEYRING) + # stop osd removal for the host osds which are in to_remove_osds queue + osds = [d.daemon_id for d in self.cache.get_daemons_by_type('osd', hostname)] + self.stop_remove_osds(osds) + return f'Stopped host drain for {hostname}' + def trigger_connect_dashboard_rgw(self) -> None: self.need_connect_dashboard_rgw = True self.event.set() diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 946d165c702..b43c5e8d727 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -2664,6 +2664,16 @@ Traceback (most recent call last): cephadm_module.drain_host('host1', force=True, zap_osd_devices=True) _rm_osds.assert_called_with([], zap=True) + @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]')) + @mock.patch("cephadm.CephadmOrchestrator.stop_remove_osds") + @mock.patch("cephadm.inventory.HostCache.get_daemons_by_host", lambda *a, **kw: []) + def test_stop_host_drain(self, _stop_rm_osds, cephadm_module): + # pass force=true in these tests to bypass _admin label check + with with_host(cephadm_module, 'host1', refresh_hosts=False, rm_with_force=True): + cephadm_module.drain_host('host1') + cephadm_module.stop_drain_host('host1') + _stop_rm_osds.assert_called_with([]) + def test_process_ls_output(self, cephadm_module): sample_ls_output = """[ { diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 90adece1856..501487a80ff 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -454,6 +454,14 @@ class Orchestrator(object): """ raise NotImplementedError() + def stop_drain_host(self, hostname: str) -> OrchResult[str]: + """ + stop draining daemons of a host + + :param hostname: hostname + """ + raise NotImplementedError() + def update_host_addr(self, host: str, addr: str) -> OrchResult[str]: """ Update a host's address diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index 779eac9d56d..8cf7aa42949 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -690,6 +690,13 @@ class OrchestratorCli(OrchestratorClientMixin, MgrModule, raise_if_exception(completion) return HandleCommandResult(stdout=completion.result_str()) + @_cli_write_command('orch host drain stop') + def _stop_drain_host(self, hostname: str) -> HandleCommandResult: + """drain all daemons from a host""" + completion = self.stop_drain_host(hostname) + raise_if_exception(completion) + return HandleCommandResult(stdout=completion.result_str()) + @_cli_write_command('orch host set-addr') def _update_set_addr(self, hostname: str, addr: str) -> HandleCommandResult: """Update a host address""" -- 2.39.5