Skip to content

Commit b57e0f0

Browse files
authored
Merge pull request ceph#62848 from ShwetaBhosale1/fix_issue_70950_add_command_to_stop_host_drain
mgr/cephadm: Add command to stop host drain Reviewed-by: Adam King <[email protected]>
2 parents fdb0872 + 7f2f028 commit b57e0f0

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
@@ -4204,6 +4204,18 @@ def drain_host(self, hostname: str, force: bool = False, keep_conf_keyring: bool
42044204

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

4207+
@handle_orch_error
4208+
@host_exists()
4209+
def stop_drain_host(self, hostname: str) -> str:
4210+
if not self.inventory.has_label(hostname, '_no_schedule'):
4211+
raise OrchestratorValidationError(f'The host {hostname} is currently not draining.')
4212+
self.remove_host_label(hostname, '_no_schedule')
4213+
self.remove_host_label(hostname, SpecialHostLabels.DRAIN_CONF_KEYRING)
4214+
# stop osd removal for the host osds which are in to_remove_osds queue
4215+
osds = [d.daemon_id for d in self.cache.get_daemons_by_type('osd', hostname)]
4216+
self.stop_remove_osds(osds)
4217+
return f'Stopped host drain for {hostname}'
4218+
42074219
def trigger_connect_dashboard_rgw(self) -> None:
42084220
self.need_connect_dashboard_rgw = True
42094221
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
@@ -2664,6 +2664,16 @@ def test_host_drain_zap(self, _rm_osds, cephadm_module):
26642664
cephadm_module.drain_host('host1', force=True, zap_osd_devices=True)
26652665
_rm_osds.assert_called_with([], zap=True)
26662666

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

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)