From 0af14051f4077c6d8cb80ca1b9ddc4d8b5b34f19 Mon Sep 17 00:00:00 2001 From: Redouane Kachach Date: Mon, 29 May 2023 18:10:15 +0200 Subject: [PATCH] mgr/cephadm: validate host label before removing Fixes: https://tracker.ceph.com/issues/61494 Signed-off-by: Redouane Kachach (cherry picked from commit 9eaafb90311053c4241b471092108cbaf3352c23) --- src/pybind/mgr/cephadm/module.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 37fe3b4ac58f0..66418d6c7837b 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -1739,10 +1739,14 @@ Then run the following: "It is recommended to add the _admin label to another host" " before completing this operation.\nIf you're certain this is" " what you want rerun this command with --force.") - self.inventory.rm_label(host, label) - self.log.info('Removed label %s to host %s' % (label, host)) + if self.inventory.has_label(host, label): + self.inventory.rm_label(host, label) + msg = f'Removed label {label} from host {host}' + else: + msg = f"Host {host} does not have label '{label}'. Please use 'ceph orch host ls' to list all the labels." + self.log.info(msg) self._kick_serve_loop() - return 'Removed label %s from host %s' % (label, host) + return msg def _host_ok_to_stop(self, hostname: str, force: bool = False) -> Tuple[int, str]: self.log.debug("running host-ok-to-stop checks") -- 2.39.5