From: John Mulligan Date: Mon, 27 Jan 2025 23:08:21 +0000 (-0500) Subject: cephadm: convert some calls to list_daemons to daemons_summary X-Git-Tag: v20.3.0~256^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ae23ced9c9947c99a55195b2e6f414a9fb9c91bc;p=ceph.git cephadm: convert some calls to list_daemons to daemons_summary Convert some call sites using list_daemons with detail=False to use the new daemons_summary function from cephadmlib.listing. Signed-off-by: John Mulligan --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 983a8349b2c..a367957d900 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -193,7 +193,11 @@ from cephadmlib.daemons import ( NodeProxy, ) from cephadmlib.agent import http_query -from cephadmlib.listing import daemons_matching, LegacyDaemonEntry +from cephadmlib.listing import ( + LegacyDaemonEntry, + daemons_matching, + daemons_summary, +) FuncT = TypeVar('FuncT', bound=Callable) @@ -309,7 +313,7 @@ def infer_fsid(func: FuncT) -> FuncT: if cp.has_option('global', 'fsid'): fsids.add(cp.get('global', 'fsid')) - daemon_list = list_daemons(ctx, detail=False) + daemon_list = daemons_summary(ctx) for daemon in daemon_list: if not is_fsid(daemon['fsid']): # 'unknown' fsid @@ -353,7 +357,7 @@ def infer_config(func: FuncT) -> FuncT: return os.path.join(data_dir, 'config') def get_mon_daemon_name(fsid: str) -> Optional[str]: - daemon_list = list_daemons(ctx, detail=False) + daemon_list = daemons_summary(ctx) for daemon in daemon_list: if ( daemon.get('name', '').startswith('mon.') @@ -4359,7 +4363,7 @@ def _rm_cluster(ctx: CephadmContext, keep_logs: bool, zap_osds: bool) -> None: # stop + disable individual daemon units sd_paths = [] - for d in list_daemons(ctx, detail=False): + for d in daemons_summary(ctx): if d['fsid'] != ctx.fsid: continue if d['style'] != 'cephadm:v1': @@ -4683,7 +4687,7 @@ def update_service_for_daemon(ctx: CephadmContext, def command_update_osd_service(ctx: CephadmContext) -> int: """update service for provided daemon""" update_daemons = [f'osd.{osd_id}' for osd_id in ctx.osd_ids.split(',')] - daemons = list_daemons(ctx, detail=False, type_of_daemon='osd') + daemons = daemons_summary(ctx, daemon_type='osd') if not daemons: raise Error(f'Daemon {ctx.osd_ids} does not exists on this host') available_daemons = [d['name'] for d in daemons] diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index f33f269c78e..192621ab961 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -979,9 +979,9 @@ class TestCephAdm(object): r'Cannot infer an fsid', ), ]) - @mock.patch('cephadm.call') - @mock.patch('cephadm.logger') - def test_infer_fsid(self, _logger, _call, fsid, ceph_conf, list_daemons, result, err, cephadm_fs): + def test_infer_fsid(self, fsid, ceph_conf, list_daemons, result, err, cephadm_fs, funkypatch): + funkypatch.patch('cephadm.logger') + funkypatch.patch('cephadm.call') # build the context ctx = _cephadm.CephadmContext() ctx.fsid = fsid @@ -997,6 +997,9 @@ class TestCephAdm(object): ctx.config = f.path # test + funkypatch.patch( + 'cephadmlib.listing.daemons_summary' + ).return_value = list_daemons with mock.patch('cephadm.list_daemons', return_value=list_daemons): if err: with pytest.raises(_cephadm.Error, match=err):