From ab8d7095979322613e5cfcdd6f96befc299b408e Mon Sep 17 00:00:00 2001 From: Shweta Bhosale Date: Tue, 22 Oct 2024 16:55:08 +0530 Subject: [PATCH] mgr/cephadm: orch host drain command does not return error for invalid hostname Fixes: https://tracker.ceph.com/issues/68681 Signed-off-by: Shweta Bhosale --- src/pybind/mgr/cephadm/module.py | 1 + src/pybind/mgr/cephadm/tests/test_cephadm.py | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 5216c489064..c0cbd044a38 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -3892,6 +3892,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. diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 5a485f98be3..8c032a2e38b 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -2840,16 +2840,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 = """[