]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: split get_unit_name into two functions
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 25 Jul 2023 20:46:01 +0000 (16:46 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Mon, 11 Sep 2023 17:34:11 +0000 (13:34 -0400)
The previous version of get_unit_name was effectively overloaded,
so that you could pass either an fsid, daemon_type, & daemon_id OR
pass an fsid and a "daemon_type" only that wasn't actually a daemon_type
but rather the instance name of the systemd service. Separate the
two use cases into two functions, making the naming more correct and
the code more audit-able overall.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py

index 2721a6333d6cc820e907854c3701f32d2179cc4f..9842cf5a4e43064baece4dcbddec319c655519b4 100755 (executable)
@@ -1883,13 +1883,21 @@ def move_files(ctx, src, dst, uid=None, gid=None):
             os.chown(dst_file, uid, gid)
 
 
-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 DaemonIdentity(fsid, daemon_type, daemon_id).unit_name
-    else:
-        return 'ceph-%s@%s' % (fsid, daemon_type)
+def get_unit_name(
+    fsid: str, daemon_type: str, daemon_id: Union[str, int]
+) -> str:
+    """Return the name of the systemd unit given an fsid, a daemon_type,
+    and the daemon_id.
+    """
+    # TODO: fully replace get_unit_name with DaemonIdentity instances
+    return DaemonIdentity(fsid, daemon_type, daemon_id).unit_name
+
+
+def get_unit_name_by_instance(fsid: str, instance: str) -> str:
+    """Return the name of the systemd unit given an fsid and the name
+    of the instance (the stuff after the @-sign and before the file extension).
+    """
+    return 'ceph-%s@%s' % (fsid, instance)
 
 
 def get_unit_name_by_daemon_name(ctx: CephadmContext, fsid: str, name: str) -> str:
@@ -7251,7 +7259,7 @@ def _rm_cluster(ctx: CephadmContext, keep_logs: bool, zap_osds: bool) -> None:
             continue
         if d['style'] != 'cephadm:v1':
             continue
-        disable_systemd_service(get_unit_name(ctx.fsid, d['name']))
+        disable_systemd_service(get_unit_name_by_instance(ctx.fsid, d['name']))
 
     # cluster units
     for unit_name in ['ceph-%s.target' % ctx.fsid]: