From b87c966697d36ef51f1e62425d77200667e651ae Mon Sep 17 00:00:00 2001 From: Redouane Kachach Date: Wed, 2 Mar 2022 12:38:42 +0100 Subject: [PATCH] mgr/cephadm: check spec host when adding osd Fixes: https://tracker.ceph.com/issues/47872 Signed-off-by: Redouane Kachach --- src/pybind/mgr/cephadm/module.py | 4 ++++ src/pybind/mgr/cephadm/tests/test_cephadm.py | 5 +++++ src/pybind/mgr/orchestrator/module.py | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 0bba96b8c512e..65f7d2443f44d 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -2208,6 +2208,10 @@ Then run the following: @handle_orch_error def create_osds(self, drive_group: DriveGroupSpec) -> str: + hosts: List[HostSpec] = self.inventory.all_specs() + filtered_hosts: List[str] = drive_group.placement.filter_matching_hostspecs(hosts) + if not filtered_hosts: + return "Invalid 'host:device' spec: host not found in cluster. Please check 'ceph orch host ls' for available hosts" return self.osd_service.create_from_spec(drive_group) def _preview_osdspecs(self, diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index e0669ecf10e93..6ce21c6c433b8 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -811,6 +811,11 @@ class TestCephadm(object): c = cephadm_module.create_osds(dg) out = wait(cephadm_module, c) assert out == "Created no osd(s) on host test; already created?" + bad_dg = DriveGroupSpec(placement=PlacementSpec(host_pattern='invalid_hsot'), + data_devices=DeviceSelection(paths=[''])) + c = cephadm_module.create_osds(bad_dg) + out = wait(cephadm_module, c) + assert "Invalid 'host:device' spec: host not found in cluster" in out @mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}')) def test_create_noncollocated_osd(self, cephadm_module): diff --git a/src/pybind/mgr/orchestrator/module.py b/src/pybind/mgr/orchestrator/module.py index f33ecd50d021c..4ef15b1236506 100644 --- a/src/pybind/mgr/orchestrator/module.py +++ b/src/pybind/mgr/orchestrator/module.py @@ -799,7 +799,7 @@ Usage: method=method, ) except (TypeError, KeyError, ValueError) as e: - msg = f"Invalid host:device spec: '{svc_arg}': {e}" + usage + msg = f"Invalid 'host:device' spec: '{svc_arg}': {e}" + usage return HandleCommandResult(-errno.EINVAL, stderr=msg) completion = self.create_osds(drive_group) -- 2.39.5