]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: move get_legacy_daemon_fsid to data_utils
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 27 Jan 2025 19:33:28 +0000 (14:33 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 29 Jan 2025 19:24:51 +0000 (14:24 -0500)
This function has few dependencies and is essentially a wrapper over
get_legacy_config_fsid a function that is already in data_utils.
Continue reducing the size of cephadm by moving this function out
of cephadm.py.

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

index a8616980e4dd8f3921bcf6fbae527fc81488c482..9e6062aef4ec496bbdfe1deb82bfdf649ec0c884 100755 (executable)
@@ -93,7 +93,7 @@ from cephadmlib.container_engines import (
 )
 from cephadmlib.data_utils import (
     dict_get_join,
-    get_legacy_config_fsid,
+    get_legacy_daemon_fsid,
     is_fsid,
     normalize_image_digest,
     try_convert_datetime,
@@ -738,27 +738,6 @@ def lookup_unit_name_by_daemon_name(ctx: CephadmContext, fsid: str, name: str) -
         raise Error('Failed to get unit name for {}'.format(daemon))
 
 
-def get_legacy_daemon_fsid(ctx, cluster,
-                           daemon_type, daemon_id, legacy_dir=None):
-    # type: (CephadmContext, str, str, Union[int, str], Optional[str]) -> Optional[str]
-    fsid = None
-    if daemon_type == 'osd':
-        try:
-            fsid_file = os.path.join(ctx.data_dir,
-                                     daemon_type,
-                                     'ceph-%s' % daemon_id,
-                                     'ceph_fsid')
-            if legacy_dir is not None:
-                fsid_file = os.path.abspath(legacy_dir + fsid_file)
-            with open(fsid_file, 'r') as f:
-                fsid = f.read().strip()
-        except IOError:
-            pass
-    if not fsid:
-        fsid = get_legacy_config_fsid(cluster, legacy_dir=legacy_dir)
-    return fsid
-
-
 def create_daemon_dirs(
     ctx: CephadmContext,
     ident: 'DaemonIdentity',
index 9caef3f72e5fcea1014c66b775c53df50fdf6b85..9920c399913038f40ed8e538c57d8a5f9875d56b 100644 (file)
@@ -9,9 +9,10 @@ import logging
 
 from configparser import ConfigParser
 
-from typing import Dict, Any, Optional, Iterable, List
+from typing import Dict, Any, Optional, Iterable, List, Union
 
 from .constants import DATEFMT, DEFAULT_REGISTRY
+from .context import CephadmContext
 from .exceptions import Error
 
 
@@ -205,6 +206,30 @@ def get_legacy_config_fsid(
     return None
 
 
+def get_legacy_daemon_fsid(
+    ctx: CephadmContext,
+    cluster: str,
+    daemon_type: str,
+    daemon_id: Union[int, str],
+    legacy_dir: Optional[str] = None,
+) -> Optional[str]:
+    fsid = None
+    if daemon_type == 'osd':
+        try:
+            fsid_file = os.path.join(
+                ctx.data_dir, daemon_type, 'ceph-%s' % daemon_id, 'ceph_fsid'
+            )
+            if legacy_dir is not None:
+                fsid_file = os.path.abspath(legacy_dir + fsid_file)
+            with open(fsid_file, 'r') as f:
+                fsid = f.read().strip()
+        except IOError:
+            pass
+    if not fsid:
+        fsid = get_legacy_config_fsid(cluster, legacy_dir=legacy_dir)
+    return fsid
+
+
 def _extract_host_info_from_applied_spec(
     f: Iterable[str],
 ) -> List[Dict[str, str]]: