From dc22f7f47d6931ec4494313b9c754aeb3ffe7858 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 25 Jul 2023 16:36:31 -0400 Subject: [PATCH] cephadm: add unit_name property to DaemonIdentity Replace some uses of get_unit_name with the new method. Signed-off-by: John Mulligan --- src/cephadm/cephadm.py | 5 ++--- src/cephadm/cephadmlib/daemon_identity.py | 4 ++++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index c096b091baba4..2721a6333d6cc 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -1887,7 +1887,7 @@ def get_unit_name(fsid, daemon_type, daemon_id=None): # type: (str, str, Optional[Union[int, str]]) -> str # accept either name or type + id if daemon_id is not None: - return 'ceph-%s@%s.%s' % (fsid, daemon_type, daemon_id) + return DaemonIdentity(fsid, daemon_type, daemon_id).unit_name else: return 'ceph-%s@%s' % (fsid, daemon_type) @@ -5803,9 +5803,8 @@ def get_deployment_type(ctx: CephadmContext, daemon_type: str, daemon_id: str) - deployment_type: DeploymentType = DeploymentType.DEFAULT if ctx.reconfig: deployment_type = DeploymentType.RECONFIG - unit_name = get_unit_name(ctx.fsid, daemon_type, daemon_id) - (_, state, _) = check_unit(ctx, unit_name) ident = DaemonIdentity(ctx.fsid, daemon_type, daemon_id) + (_, state, _) = check_unit(ctx, ident.unit_name) if state == 'running' or is_container_running(ctx, CephContainer.for_daemon(ctx, ident, 'bash')): # if reconfig was set, that takes priority over redeploy. If # this is considered a fresh deployment at this stage, diff --git a/src/cephadm/cephadmlib/daemon_identity.py b/src/cephadm/cephadmlib/daemon_identity.py index fad0c96561a4a..3a84ee425222f 100644 --- a/src/cephadm/cephadmlib/daemon_identity.py +++ b/src/cephadm/cephadmlib/daemon_identity.py @@ -39,6 +39,10 @@ class DaemonIdentity: name = f'ceph-{self.fsid}-{self.daemon_type}-{self.daemon_id}' return name.replace('.', '-') + @property + def unit_name(self) -> str: + return f'ceph-{self.fsid}@{self.daemon_type}.{self.daemon_id}' + @classmethod def from_name(cls, fsid: str, name: str) -> 'DaemonIdentity': daemon_type, daemon_id = name.split('.', 1) -- 2.39.5