From: Redouane Kachach Date: Wed, 2 Mar 2022 11:38:42 +0000 (+0100) Subject: mgr/cephadm: check spec host when adding osd X-Git-Tag: v18.0.0~1156^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F45217%2Fhead;p=ceph.git mgr/cephadm: check spec host when adding osd Fixes: https://tracker.ceph.com/issues/47872 Signed-off-by: Redouane Kachach --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 0bba96b8c512..65f7d2443f44 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 e0669ecf10e9..6ce21c6c433b 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 f33ecd50d021..4ef15b123650 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)