Skip to content

Commit ae23ced

Browse files
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 <[email protected]>
1 parent de04896 commit ae23ced

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/cephadm/cephadm.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,11 @@
193193
NodeProxy,
194194
)
195195
from cephadmlib.agent import http_query
196-
from cephadmlib.listing import daemons_matching, LegacyDaemonEntry
196+
from cephadmlib.listing import (
197+
LegacyDaemonEntry,
198+
daemons_matching,
199+
daemons_summary,
200+
)
197201

198202

199203
FuncT = TypeVar('FuncT', bound=Callable)
@@ -309,7 +313,7 @@ def _infer_fsid(ctx: CephadmContext) -> Any:
309313
if cp.has_option('global', 'fsid'):
310314
fsids.add(cp.get('global', 'fsid'))
311315

312-
daemon_list = list_daemons(ctx, detail=False)
316+
daemon_list = daemons_summary(ctx)
313317
for daemon in daemon_list:
314318
if not is_fsid(daemon['fsid']):
315319
# 'unknown' fsid
@@ -353,7 +357,7 @@ def config_path(daemon_type: str, daemon_name: str) -> str:
353357
return os.path.join(data_dir, 'config')
354358

355359
def get_mon_daemon_name(fsid: str) -> Optional[str]:
356-
daemon_list = list_daemons(ctx, detail=False)
360+
daemon_list = daemons_summary(ctx)
357361
for daemon in daemon_list:
358362
if (
359363
daemon.get('name', '').startswith('mon.')
@@ -4359,7 +4363,7 @@ def _rm_cluster(ctx: CephadmContext, keep_logs: bool, zap_osds: bool) -> None:
43594363

43604364
# stop + disable individual daemon units
43614365
sd_paths = []
4362-
for d in list_daemons(ctx, detail=False):
4366+
for d in daemons_summary(ctx):
43634367
if d['fsid'] != ctx.fsid:
43644368
continue
43654369
if d['style'] != 'cephadm:v1':
@@ -4683,7 +4687,7 @@ def update_service_for_daemon(ctx: CephadmContext,
46834687
def command_update_osd_service(ctx: CephadmContext) -> int:
46844688
"""update service for provided daemon"""
46854689
update_daemons = [f'osd.{osd_id}' for osd_id in ctx.osd_ids.split(',')]
4686-
daemons = list_daemons(ctx, detail=False, type_of_daemon='osd')
4690+
daemons = daemons_summary(ctx, daemon_type='osd')
46874691
if not daemons:
46884692
raise Error(f'Daemon {ctx.osd_ids} does not exists on this host')
46894693
available_daemons = [d['name'] for d in daemons]

src/cephadm/tests/test_cephadm.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -979,9 +979,9 @@ def test_normalize_image_digest(self):
979979
r'Cannot infer an fsid',
980980
),
981981
])
982-
@mock.patch('cephadm.call')
983-
@mock.patch('cephadm.logger')
984-
def test_infer_fsid(self, _logger, _call, fsid, ceph_conf, list_daemons, result, err, cephadm_fs):
982+
def test_infer_fsid(self, fsid, ceph_conf, list_daemons, result, err, cephadm_fs, funkypatch):
983+
funkypatch.patch('cephadm.logger')
984+
funkypatch.patch('cephadm.call')
985985
# build the context
986986
ctx = _cephadm.CephadmContext()
987987
ctx.fsid = fsid
@@ -997,6 +997,9 @@ def test_infer_fsid(self, _logger, _call, fsid, ceph_conf, list_daemons, result,
997997
ctx.config = f.path
998998

999999
# test
1000+
funkypatch.patch(
1001+
'cephadmlib.listing.daemons_summary'
1002+
).return_value = list_daemons
10001003
with mock.patch('cephadm.list_daemons', return_value=list_daemons):
10011004
if err:
10021005
with pytest.raises(_cephadm.Error, match=err):

0 commit comments

Comments
 (0)