]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/cephadm: no gibberish suffix for some services
authorSage Weil <sage@redhat.com>
Thu, 20 Feb 2020 22:47:05 +0000 (16:47 -0600)
committerSage Weil <sage@redhat.com>
Thu, 20 Feb 2020 22:47:05 +0000 (16:47 -0600)
Lots of services only need to appear once per node; no need to create a
unique name.  (In fact, most of these *won't* run more than once per
node because they bind to a standard port.)

Signed-off-by: Sage Weil <sage@redhat.com>
src/pybind/mgr/cephadm/module.py
src/pybind/mgr/cephadm/tests/test_cephadm.py

index 28b40f662fc1fccbd755f8e686d7426db0caf9d1..f7a9be70587c68d656af371d7b448418a01fd1a5 100644 (file)
@@ -952,11 +952,16 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
     def notify(self, notify_type, notify_id):
         pass
 
-    def get_unique_name(self, host, existing, prefix=None, forcename=None):
-        # type: (str, List[orchestrator.DaemonDescription], Optional[str], Optional[str]) -> str
+    def get_unique_name(self, daemon_type, host, existing, prefix=None,
+                        forcename=None):
+        # type: (str, str, List[orchestrator.DaemonDescription], Optional[str], Optional[str]) -> str
         """
         Generate a unique random service name
         """
+        suffix = daemon_type not in [
+            'mon', 'crash',
+            'prometheus', 'node-exporter', 'grafana', 'alertmanager',
+        ]
         if forcename:
             if len([d for d in existing if d.daemon_id == forcename]):
                 raise RuntimeError('specified name %s already in use', forcename)
@@ -969,8 +974,10 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
                 name = prefix + '.'
             else:
                 name = ''
-            name += host + '.' + ''.join(random.choice(string.ascii_lowercase)
-                            for _ in range(6))
+            name += host
+            if suffix:
+                name += '.' + ''.join(random.choice(string.ascii_lowercase)
+                                      for _ in range(6))
             if len([d for d in existing if d.daemon_id == name]):
                 self.log('name %s exists, trying again', name)
                 continue
@@ -1929,7 +1936,8 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
         for host, _, name in hosts_without_daemons:
             if (len(our_daemons) + num_added) >= spec.count:
                 break
-            daemon_id = self.get_unique_name(host, daemons, spec.name, name)
+            daemon_id = self.get_unique_name(daemon_type, host, daemons,
+                                             spec.name, name)
             self.log.debug('placing %s.%s on host %s' % (daemon_type, daemon_id, host))
             args.append((daemon_id, host))
             # add to daemon list so next name(s) will also be unique
@@ -2145,7 +2153,8 @@ class CephadmOrchestrator(MgrModule, orchestrator.OrchestratorClientMixin):
             args = []
             for host_spec in spec.placement.hosts:
                 host = host_spec.hostname
-                name = host_spec.name or self.get_unique_name(host, daemons)
+                name = host_spec.name or self.get_unique_name('mgr', host,
+                                                              daemons)
                 args.append((name, host))
             c = self._create_mgr(args)
             c.add_progress('Creating MGRs', self)
index 092cd0c94da9ab1ba27a8017142c71d6329061c6..ca0c9be6fa3451bf42c259c34e5555b3b040b632 100644 (file)
@@ -55,8 +55,10 @@ class TestCephadm(object):
         existing = [
             DaemonDescription(daemon_type='mon', daemon_id='a')
         ]
-        new_mon = cephadm_module.get_unique_name('myhost', existing, 'mon')
-        match_glob(new_mon, 'mon.myhost.*')
+        new_mon = cephadm_module.get_unique_name('mon', 'myhost', existing)
+        match_glob(new_mon, 'myhost')
+        new_mgr = cephadm_module.get_unique_name('mgr', 'myhost', existing)
+        match_glob(new_mgr, 'myhost.*')
 
     @mock.patch("cephadm.module.CephadmOrchestrator._get_connection")
     @mock.patch("cephadm.module.CephadmOrchestrator._run_cephadm", _run_cephadm('[]'))