Merge pull request #60425 from ShwetaBhosale1/orch_host_drain-attempt_to_drain_non_existing_host_must_fail

mgr/cephadm: ceph orch host drain command to return error for invalid hostname

Reviewed-by: Adam King <adking@redhat.com>
Reviewed-by: Anuradha Gadge <Anuradha.Gadge@ibm.com>
This commit is contained in:
Adam King 2024-11-04 12:03:18 -05:00 committed by GitHub
commit 0a586d2926
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 4 deletions

View File

@ -3986,6 +3986,7 @@ Then run the following:
return self.to_remove_osds.all_osds()
@handle_orch_error
@host_exists()
def drain_host(self, hostname: str, force: bool = False, keep_conf_keyring: bool = False, zap_osd_devices: bool = False) -> str:
"""
Drain all daemons from a host.

View File

@ -2841,16 +2841,23 @@ Traceback (most recent call last):
with cephadm_module.async_timeout_handler('hostC', 'very slow', 999):
cephadm_module.wait_async(_timeout())
@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('[]'))
@mock.patch("cephadm.CephadmOrchestrator.remove_osds")
@mock.patch("cephadm.CephadmOrchestrator.add_host_label", lambda *a, **kw: None)
@mock.patch("cephadm.inventory.HostCache.get_daemons_by_host", lambda *a, **kw: [])
def test_host_drain_zap(self, _rm_osds, cephadm_module):
# pass force=true in these tests to bypass _admin label check
cephadm_module.drain_host('host1', force=True, zap_osd_devices=False)
assert _rm_osds.called_with([], zap=False)
with with_host(cephadm_module, 'test', refresh_hosts=False, rm_with_force=True):
cephadm_module.drain_host('test', force=True, zap_osd_devices=False)
assert _rm_osds.called_with([], zap=False)
cephadm_module.drain_host('host1', force=True, zap_osd_devices=True)
assert _rm_osds.called_with([], zap=True)
with with_host(cephadm_module, 'test', refresh_hosts=False, rm_with_force=True):
cephadm_module.drain_host('test', force=True, zap_osd_devices=True)
assert _rm_osds.called_with([], zap=True)
with pytest.raises(OrchestratorError, match=r"Cannot find host 'host1' in the inventory."):
cephadm_module.drain_host('host1', force=True, zap_osd_devices=True)
assert _rm_osds.called_with([], zap=True)
def test_process_ls_output(self, cephadm_module):
sample_ls_output = """[