Skip to content

Commit 7f2f028

Browse files
mgr/cephadm: Add command to stop host drain
Fixes: https://tracker.ceph.com/issues/70950 Signed-off-by: Shweta Bhosale <[email protected]>
1 parent f9a47a2 commit 7f2f028

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

src/pybind/mgr/cephadm/module.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4161,6 +4161,18 @@ def drain_host(self, hostname: str, force: bool = False, keep_conf_keyring: bool
41614161

41624162
return "Scheduled to remove the following daemons from host '{}'\n{}".format(hostname, daemons_table)
41634163

4164+
@handle_orch_error
4165+
@host_exists()
4166+
def stop_drain_host(self, hostname: str) -> str:
4167+
if not self.inventory.has_label(hostname, '_no_schedule'):
4168+
raise OrchestratorValidationError(f'The host {hostname} is currently not draining.')
4169+
self.remove_host_label(hostname, '_no_schedule')
4170+
self.remove_host_label(hostname, SpecialHostLabels.DRAIN_CONF_KEYRING)
4171+
# stop osd removal for the host osds which are in to_remove_osds queue
4172+
osds = [d.daemon_id for d in self.cache.get_daemons_by_type('osd', hostname)]
4173+
self.stop_remove_osds(osds)
4174+
return f'Stopped host drain for {hostname}'
4175+
41644176
def trigger_connect_dashboard_rgw(self) -> None:
41654177
self.need_connect_dashboard_rgw = True
41664178
self.event.set()

src/pybind/mgr/cephadm/tests/test_cephadm.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,16 @@ def test_host_drain_zap(self, _rm_osds, cephadm_module):
26632663
cephadm_module.drain_host('host1', force=True, zap_osd_devices=True)
26642664
_rm_osds.assert_called_with([], zap=True)
26652665

2666+
@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
2667+
@mock.patch("cephadm.CephadmOrchestrator.stop_remove_osds")
2668+
@mock.patch("cephadm.inventory.HostCache.get_daemons_by_host", lambda *a, **kw: [])
2669+
def test_stop_host_drain(self, _stop_rm_osds, cephadm_module):
2670+
# pass force=true in these tests to bypass _admin label check
2671+
with with_host(cephadm_module, 'host1', refresh_hosts=False, rm_with_force=True):
2672+
cephadm_module.drain_host('host1')
2673+
cephadm_module.stop_drain_host('host1')
2674+
_stop_rm_osds.assert_called_with([])
2675+
26662676
def test_process_ls_output(self, cephadm_module):
26672677
sample_ls_output = """[
26682678
{

src/pybind/mgr/orchestrator/_interface.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,14 @@ def drain_host(self, hostname: str, force: bool = False, keep_conf_keyring: bool
454454
"""
455455
raise NotImplementedError()
456456

457+
def stop_drain_host(self, hostname: str) -> OrchResult[str]:
458+
"""
459+
stop draining daemons of a host
460+
461+
:param hostname: hostname
462+
"""
463+
raise NotImplementedError()
464+
457465
def update_host_addr(self, host: str, addr: str) -> OrchResult[str]:
458466
"""
459467
Update a host's address

src/pybind/mgr/orchestrator/module.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,13 @@ def _drain_host(self, hostname: str, force: bool = False, keep_conf_keyring: boo
690690
raise_if_exception(completion)
691691
return HandleCommandResult(stdout=completion.result_str())
692692

693+
@_cli_write_command('orch host drain stop')
694+
def _stop_drain_host(self, hostname: str) -> HandleCommandResult:
695+
"""drain all daemons from a host"""
696+
completion = self.stop_drain_host(hostname)
697+
raise_if_exception(completion)
698+
return HandleCommandResult(stdout=completion.result_str())
699+
693700
@_cli_write_command('orch host set-addr')
694701
def _update_set_addr(self, hostname: str, addr: str) -> HandleCommandResult:
695702
"""Update a host address"""

0 commit comments

Comments
 (0)