From: Adam King Date: Tue, 2 May 2023 22:59:18 +0000 (-0400) Subject: mgr/cephadm: verify mon spec exists before trying to grab from spec store X-Git-Tag: v18.1.0~61^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F51612%2Fhead;p=ceph.git mgr/cephadm: verify mon spec exists before trying to grab from spec store In a normal deployment, we generally shouldn't have to worry about this. This is more for teuthology which does deployments in a weird way that can cause there to be no mon spec in the cluster. Fixes an issue seen when backporting the mon crush location work to quincy where an upgrade test would fail with ``` [WRN] UPGRADE_REDEPLOY_DAEMON: Upgrading daemon mon.b on host smithi047 failed. Upgrade daemon: mon.b: Service mon not found. ``` Signed-off-by: Adam King (cherry picked from commit 8aab7beefbb52f47573ad7fce932552ad5c0b2fa) --- diff --git a/src/pybind/mgr/cephadm/services/cephadmservice.py b/src/pybind/mgr/cephadm/services/cephadmservice.py index 9272bccdd9f1..d79ed2a28988 100644 --- a/src/pybind/mgr/cephadm/services/cephadmservice.py +++ b/src/pybind/mgr/cephadm/services/cephadmservice.py @@ -651,15 +651,20 @@ class MonService(CephService): def generate_config(self, daemon_spec: CephadmDaemonDeploySpec) -> Tuple[Dict[str, Any], List[str]]: daemon_spec.final_config, daemon_spec.deps = super().generate_config(daemon_spec) - mon_spec = cast(MONSpec, self.mgr.spec_store[daemon_spec.service_name].spec) - if mon_spec.crush_locations: - if daemon_spec.host in mon_spec.crush_locations: - # the --crush-location flag only supports a single bucket=loc pair so - # others will have to be handled later. The idea is to set the flag - # for the first bucket=loc pair in the list in order to facilitate - # replacing a tiebreaker mon (https://docs.ceph.com/en/quincy/rados/operations/stretch-mode/#other-commands) - c_loc = mon_spec.crush_locations[daemon_spec.host][0] - daemon_spec.final_config['crush_location'] = c_loc + # realistically, we expect there to always be a mon spec + # in a real deployment, but the way teuthology deploys some daemons + # it's possible there might not be. For that reason we need to + # verify the service is present in the spec store. + if daemon_spec.service_name in self.mgr.spec_store: + mon_spec = cast(MONSpec, self.mgr.spec_store[daemon_spec.service_name].spec) + if mon_spec.crush_locations: + if daemon_spec.host in mon_spec.crush_locations: + # the --crush-location flag only supports a single bucket=loc pair so + # others will have to be handled later. The idea is to set the flag + # for the first bucket=loc pair in the list in order to facilitate + # replacing a tiebreaker mon (https://docs.ceph.com/en/quincy/rados/operations/stretch-mode/#other-commands) + c_loc = mon_spec.crush_locations[daemon_spec.host][0] + daemon_spec.final_config['crush_location'] = c_loc return daemon_spec.final_config, daemon_spec.deps