]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/orch: allow MDS with explicit naming
authorMichael Fritch <mfritch@suse.com>
Wed, 20 May 2020 01:20:35 +0000 (19:20 -0600)
committerMichael Fritch <mfritch@suse.com>
Wed, 20 May 2020 01:25:38 +0000 (19:25 -0600)
Fixes: https://tracker.ceph.com/issues/45617
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/pybind/mgr/cephadm/tests/test_spec.py
src/pybind/mgr/orchestrator/_interface.py

index a15e327e17e35dddc3281c183b27063b538faa71..731a4587026c96f4e46411085cbd4ebab17f4a88 100644 (file)
@@ -338,6 +338,35 @@ def test_spec_octopus():
         True
     ),
 
+    # https://tracker.ceph.com/issues/45617
+    (
+        # daemon_id does not contain hostname
+        ServiceSpec(
+            service_type='mds',
+            service_id="a",
+        ),
+        DaemonDescription(
+            daemon_type='mds',
+            daemon_id="a",
+            hostname="host1",
+        ),
+        True
+    ),
+    (
+        # daemon_id only contains hostname
+        ServiceSpec(
+            service_type='mds',
+            service_id="host1",
+        ),
+        DaemonDescription(
+            daemon_type='mds',
+            daemon_id="host1",
+            hostname="host1",
+        ),
+        True
+    ),
+
+
     # https://tracker.ceph.com/issues/45293
     (
         NFSServiceSpec(
index 471529b8350f763d4dba66f908963aa8d912f5fc..fd854b04c236f85edfbac76f66428aa06f767f89 100644 (file)
@@ -1306,21 +1306,37 @@ class DaemonDescription(object):
 
     def service_id(self):
         def _match():
-            if self.hostname:
+            err = OrchestratorError("DaemonDescription: Cannot calculate service_id: " \
+                    f"daemon_id='{self.daemon_id}' hostname='{self.hostname}'")
+
+            if not self.hostname:
+                # TODO: can a DaemonDescription exist without a hostname?
+                raise err
+
+            if self.hostname == self.daemon_id:
+                # daemon_id == "hostname"
+                return self.daemon_id
+
+            elif self.hostname in self.daemon_id:
                 # daemon_id == "service_id.hostname"
                 # daemon_id == "service_id.hostname.random"
-                p = re.compile(r'(.*)\.%s(\.{1}\w+)?$' % (self.hostname))
-                m = p.match(self.daemon_id)
-                if m:
-                    return m.group(1)
-
+                pre, post = self.daemon_id.rsplit(self.hostname, 1)
+                if not pre.endswith('.'):
+                    # '.' sep missing at front of hostname
+                    raise err
+                elif post and not post.startswith('.'):
+                    # '.' sep missing at end of hostname
+                    raise err
+                return pre[:-1]
+
+            # daemon_id == "service_id.random"
             if self.daemon_type == 'rgw':
                 v = self.daemon_id.split('.')
                 if len(v) in [3, 4]:
                     return '.'.join(v[0:2])
 
-            raise OrchestratorError("DaemonDescription: Cannot calculate service_id: " \
-                    f"daemon_id='{self.daemon_id}' hostname='{self.hostname}'")
+            # daemon_id == "service_id"
+            return self.daemon_id
 
         if self.daemon_type in ['mds', 'nfs', 'iscsi', 'rgw']:
             return _match()