From dabb3bd3b36354d36562bd9e780115f1daf7d74e Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Mon, 27 Jan 2025 14:33:28 -0500 Subject: [PATCH] cephadm: move get_legacy_daemon_fsid to data_utils 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 --- src/cephadm/cephadm.py | 23 +---------------------- src/cephadm/cephadmlib/data_utils.py | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index a8616980e4dd8..9e6062aef4ec4 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -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', diff --git a/src/cephadm/cephadmlib/data_utils.py b/src/cephadm/cephadmlib/data_utils.py index 9caef3f72e5fc..9920c39991303 100644 --- a/src/cephadm/cephadmlib/data_utils.py +++ b/src/cephadm/cephadmlib/data_utils.py @@ -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]]: -- 2.39.5