]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm: convert some calls to list_daemons to daemons_summary
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 27 Jan 2025 23:08:21 +0000 (18:08 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 11 Feb 2025 21:08:05 +0000 (16:08 -0500)
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 <jmulligan@redhat.com>
src/cephadm/cephadm.py
src/cephadm/tests/test_cephadm.py

index 983a8349b2ca73ce646774dcc600553aebbb4df0..a367957d900f81fd48c40a379593995b51004870 100755 (executable)
@@ -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]
index f33f269c78e3bf90450d96da535bf774d433e84a..192621ab961dfc0823ea4a98c77cd55618cb0a2b 100644 (file)
@@ -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):