From 5f0012400866dcd9b4fcb3976adab72cd98fb481 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Juan=20Miguel=20Olmo=20Mart=C3=ADnez?= Date: Wed, 27 May 2020 13:24:38 +0200 Subject: [PATCH] cephadm: error trying to get ceph auth entry for crash daemon MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit If your cluster has nodes with a . in the name. This will happen. Signed-off-by: Juan Miguel Olmo Martínez (cherry picked from commit 68cfa109b46bb627cfdfe624815aa01ed6b6c39b) --- src/pybind/mgr/cephadm/module.py | 28 +++++++++--------- src/pybind/mgr/cephadm/services/iscsi.py | 2 +- src/pybind/mgr/cephadm/tests/test_utils.py | 34 ++++++++++++++++++++++ src/pybind/mgr/cephadm/upgrade.py | 4 +-- src/pybind/mgr/cephadm/utils.py | 27 +++++++++++------ 5 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 src/pybind/mgr/cephadm/tests/test_utils.py diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 9160a2cde0407..6ecb117be57fd 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -871,15 +871,15 @@ class CephadmOrchestrator(orchestrator.Orchestrator, MgrModule): def _run_cephadm(self, host: str, - entity: Optional[str], + entity: str, command: str, args: List[str], - addr: Optional[str] = None, - stdin: Optional[str] = None, - no_fsid=False, - error_ok=False, - image: Optional[str] = None, - env_vars: Optional[List[str]] = None, + addr: Optional[str] = "", + stdin: Optional[str] = "", + no_fsid: Optional[bool] = False, + error_ok: Optional[bool] = False, + image: Optional[str] = "", + env_vars: Optional[List[str]]= None, ) -> Tuple[List[str], List[str], int]: """ Run cephadm on the remote host with the given command + args @@ -1285,7 +1285,7 @@ you may want to run: if dd.daemon_type == 'osd': """ The osd count can't be determined by the Placement spec. - It's rather pointless to show a actual/expected representation + It's rather pointless to show a actual/expected representation here. So we're setting running = size for now. """ osd_count += 1 @@ -1583,13 +1583,13 @@ you may want to run: deps.append(dd.name()) return sorted(deps) - def _get_config_and_keyring(self, daemon_type, daemon_id, + def _get_config_and_keyring(self, daemon_type, daemon_id, host=None, keyring=None, extra_ceph_config=None): - # type: (str, str, Optional[str], Optional[str]) -> Dict[str, Any] + # type: (str, str, Optional[str], Optional[str], Optional[str]) -> Dict[str, Any] # keyring if not keyring: - ename = utils.name_to_auth_entity(daemon_type + '.' + daemon_id) + ename = utils.name_to_auth_entity(daemon_type, daemon_id, host=host) ret, keyring, err = self.check_mon_command({ 'prefix': 'auth get', 'entity': ename, @@ -1647,7 +1647,7 @@ you may want to run: else: # Ceph.daemons (mon, mgr, mds, osd, etc) cephadm_config = self._get_config_and_keyring( - daemon_type, daemon_id, + daemon_type, daemon_id, host, keyring=keyring, extra_ceph_config=extra_config.pop('config', '')) if extra_config: @@ -1880,7 +1880,7 @@ you may want to run: last_monmap = None # just in case clocks are skewed daemons = self.cache.get_daemons() - daemons_post = defaultdict(list) + daemons_post: Dict[str, List[orchestrator.DaemonDescription]] = defaultdict(list) for dd in daemons: # orphan? spec = self.spec_store.specs.get(dd.service_name(), None) @@ -2149,7 +2149,7 @@ you may want to run: if not host: raise OrchestratorError('no hosts defined') out, err, code = self._run_cephadm( - host, None, 'pull', [], + host, '', 'pull', [], image=image_name, no_fsid=True, error_ok=True) diff --git a/src/pybind/mgr/cephadm/services/iscsi.py b/src/pybind/mgr/cephadm/services/iscsi.py index 89939ce31f0d9..68aad45d2fa3f 100644 --- a/src/pybind/mgr/cephadm/services/iscsi.py +++ b/src/pybind/mgr/cephadm/services/iscsi.py @@ -25,7 +25,7 @@ class IscsiService(CephadmService): def create(self, igw_id, host, spec) -> str: ret, keyring, err = self.mgr.check_mon_command({ 'prefix': 'auth get-or-create', - 'entity': utils.name_to_auth_entity('iscsi') + '.' + igw_id, + 'entity': utils.name_to_auth_entity('iscsi', igw_id), 'caps': ['mon', 'profile rbd, ' 'allow command "osd blacklist", ' 'allow command "config-key get" with "key" prefix "iscsi/"', diff --git a/src/pybind/mgr/cephadm/tests/test_utils.py b/src/pybind/mgr/cephadm/tests/test_utils.py new file mode 100644 index 0000000000000..9ae6d61590c0c --- /dev/null +++ b/src/pybind/mgr/cephadm/tests/test_utils.py @@ -0,0 +1,34 @@ +import pytest + +from orchestrator import OrchestratorError +from cephadm.utils import name_to_auth_entity + +def test_name_to_auth_entity(fs): + + for daemon_type in ['rgw', 'rbd-mirror', 'nfs', "iscsi"]: + assert "client.%s.id1" % (daemon_type) == name_to_auth_entity(daemon_type, "id1", "host") + assert "client.%s.id1" % (daemon_type) == name_to_auth_entity(daemon_type, "id1", "") + assert "client.%s.id1" % (daemon_type) == name_to_auth_entity(daemon_type, "id1") + + assert "client.crash.host" == name_to_auth_entity("crash", "id1", "host") + with pytest.raises(OrchestratorError): + t = name_to_auth_entity("crash", "id1", "") + t = name_to_auth_entity("crash", "id1") + + assert "mon." == name_to_auth_entity("mon", "id1", "host") + assert "mon." == name_to_auth_entity("mon", "id1", "") + assert "mon." == name_to_auth_entity("mon", "id1") + + assert "mgr.id1" == name_to_auth_entity("mgr", "id1", "host") + assert "mgr.id1" == name_to_auth_entity("mgr", "id1", "") + assert "mgr.id1" == name_to_auth_entity("mgr", "id1") + + for daemon_type in ["osd", "mds", "client"]: + assert "%s.id1" % daemon_type == name_to_auth_entity(daemon_type, "id1", "host") + assert "%s.id1" % daemon_type == name_to_auth_entity(daemon_type, "id1", "") + assert "%s.id1" % daemon_type == name_to_auth_entity(daemon_type, "id1") + + with pytest.raises(OrchestratorError): + name_to_auth_entity("whatever", "id1", "host") + name_to_auth_entity("whatever", "id1", "") + name_to_auth_entity("whatever", "id1") diff --git a/src/pybind/mgr/cephadm/upgrade.py b/src/pybind/mgr/cephadm/upgrade.py index 7e5445204d8f1..f76ba33cce4c8 100644 --- a/src/pybind/mgr/cephadm/upgrade.py +++ b/src/pybind/mgr/cephadm/upgrade.py @@ -230,13 +230,13 @@ class CephadmUpgrade: # make sure host has latest container image out, err, code = self.mgr._run_cephadm( - d.hostname, None, 'inspect-image', [], + d.hostname, '', 'inspect-image', [], image=target_name, no_fsid=True, error_ok=True) if code or json.loads(''.join(out)).get('image_id') != target_id: logger.info('Upgrade: Pulling %s on %s' % (target_name, d.hostname)) out, err, code = self.mgr._run_cephadm( - d.hostname, None, 'pull', [], + d.hostname, '', 'pull', [], image=target_name, no_fsid=True, error_ok=True) if code: self._fail_upgrade('UPGRADE_FAILED_PULL', { diff --git a/src/pybind/mgr/cephadm/utils.py b/src/pybind/mgr/cephadm/utils.py index 290011843e08d..4000a3329fc85 100644 --- a/src/pybind/mgr/cephadm/utils.py +++ b/src/pybind/mgr/cephadm/utils.py @@ -2,7 +2,9 @@ import re from orchestrator import OrchestratorError -def name_to_config_section(name): +from typing import Optional + +def name_to_config_section(name: str) -> str: """ Map from daemon names to ceph entity names (as seen in config) """ @@ -14,17 +16,24 @@ def name_to_config_section(name): else: return 'mon' - -def name_to_auth_entity(name) -> str: +def name_to_auth_entity(daemon_type, # type: str + daemon_id, # type: str + host = "" # type Optional[str] = "" + ): """ - Map from daemon names to ceph entity names (as seen in config) + Map from daemon names/host to ceph entity names (as seen in config) """ - daemon_type = name.split('.', 1)[0] - if daemon_type in ['rgw', 'rbd-mirror', 'nfs', 'crash', 'iscsi']: - return 'client.' + name + if daemon_type in ['rgw', 'rbd-mirror', 'nfs', "iscsi"]: + return 'client.' + daemon_type + "." + daemon_id + elif daemon_type == 'crash': + if host == "": + raise OrchestratorError("Host not provided to generate auth entity name") + return 'client.' + daemon_type + "." + host elif daemon_type == 'mon': return 'mon.' - elif daemon_type in ['osd', 'mds', 'mgr', 'client']: - return name + elif daemon_type == 'mgr': + return daemon_type + "." + daemon_id + elif daemon_type in ['osd', 'mds', 'client']: + return daemon_type + "." + daemon_id else: raise OrchestratorError("unknown auth entity name") -- 2.39.5