From: Michael Fritch Date: Wed, 20 May 2020 01:20:35 +0000 (-0600) Subject: mgr/orch: allow MDS with explicit naming X-Git-Tag: v17.0.0~2283^2~2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=ac61f51f6a80f1abdde3bb3b548724e43e809039;p=ceph.git mgr/orch: allow MDS with explicit naming Fixes: https://tracker.ceph.com/issues/45617 Signed-off-by: Michael Fritch --- diff --git a/src/pybind/mgr/cephadm/tests/test_spec.py b/src/pybind/mgr/cephadm/tests/test_spec.py index a15e327e17e35..731a4587026c9 100644 --- a/src/pybind/mgr/cephadm/tests/test_spec.py +++ b/src/pybind/mgr/cephadm/tests/test_spec.py @@ -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( diff --git a/src/pybind/mgr/orchestrator/_interface.py b/src/pybind/mgr/orchestrator/_interface.py index 471529b8350f7..fd854b04c236f 100644 --- a/src/pybind/mgr/orchestrator/_interface.py +++ b/src/pybind/mgr/orchestrator/_interface.py @@ -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()