From: Sage Weil Date: Thu, 20 Feb 2020 22:47:05 +0000 (-0600) Subject: mgr/cephadm: no gibberish suffix for some services X-Git-Tag: v15.1.1~330^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=3305010b9fcb6af479ca9474f13d7474c7210a25;p=ceph.git mgr/cephadm: no gibberish suffix for some services 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 --- diff --git a/src/pybind/mgr/cephadm/module.py b/src/pybind/mgr/cephadm/module.py index 28b40f662fc1..f7a9be70587c 100644 --- a/src/pybind/mgr/cephadm/module.py +++ b/src/pybind/mgr/cephadm/module.py @@ -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) diff --git a/src/pybind/mgr/cephadm/tests/test_cephadm.py b/src/pybind/mgr/cephadm/tests/test_cephadm.py index 092cd0c94da9..ca0c9be6fa34 100644 --- a/src/pybind/mgr/cephadm/tests/test_cephadm.py +++ b/src/pybind/mgr/cephadm/tests/test_cephadm.py @@ -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('[]'))