]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: error trying to get ceph auth entry for crash daemon
authorJuan Miguel Olmo Martínez <jolmomar@redhat.com>
Wed, 27 May 2020 11:24:38 +0000 (13:24 +0200)
committerSebastian Wagner <sebastian.wagner@suse.com>
Tue, 14 Jul 2020 09:39:06 +0000 (11:39 +0200)
If your cluster has nodes with a . in the name. This will happen.

Signed-off-by: Juan Miguel Olmo Martínez <jolmomar@redhat.com>
(cherry picked from commit 68cfa109b46bb627cfdfe624815aa01ed6b6c39b)

src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/services/iscsi.py
src/pybind/mgr/cephadm/tests/test_utils.py [new file with mode: 0644]
src/pybind/mgr/cephadm/upgrade.py
src/pybind/mgr/cephadm/utils.py

index 9160a2cde0407a288c256b67504368aaba52e102..6ecb117be57fdc0eb857c0f17834c032ad7f3e49 100644 (file)
@@ -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)
index 89939ce31f0d92b03c540e7277f78720ba980b9d..68aad45d2fa3fbea972faa8f5be0152a7fdddebf 100644 (file)
@@ -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 (file)
index 0000000..9ae6d61
--- /dev/null
@@ -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")
index 7e5445204d8f1d494bb1b4ba109d81c935a3c5a6..f76ba33cce4c8982110d3c56f2bc6bdbe312e6eb 100644 (file)
@@ -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', {
index 290011843e08da793ef6f1780e8b231c921e602d..4000a3329fc854511d5b4a1887212c4619497981 100644 (file)
@@ -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 <crash> 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")