Skip to content

Commit 5b34735

Browse files
cephadm: replace image listing in infer_local_ceph_image
Replace the custom code listing images in the local container store with the new parsed_container_image_list function. Signed-off-by: John Mulligan <[email protected]>
1 parent ff8e064 commit 5b34735

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

src/cephadm/cephadm.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
check_container_engine,
9090
find_container_engine,
9191
normalize_container_id,
92+
parsed_container_image_list,
9293
parsed_container_mem_usage,
9394
pull_command,
9495
registry_login,
@@ -477,16 +478,11 @@ def infer_local_ceph_image(ctx: CephadmContext, container_path: str) -> Optional
477478
478479
:return: The most recent local ceph image (already pulled)
479480
"""
480-
# '|' special character is used to separate the output fields into:
481-
# - Repository@digest
482-
# - Image Id
483-
# - Image Tag
484-
# - Image creation date
485-
out, _, _ = call_throws(ctx,
486-
[container_path, 'images',
487-
'--filter', 'label=ceph=True',
488-
'--filter', 'dangling=false',
489-
'--format', '{{.Repository}}@{{.Digest}}|{{.ID}}|{{.Tag}}|{{.CreatedAt}}'])
481+
images = parsed_container_image_list(
482+
ctx,
483+
filters=['dangling=false', 'label=ceph=True'],
484+
container_path=container_path,
485+
)
490486

491487
container_info = None
492488
daemon_name = ctx.name if ('name' in ctx and ctx.name and '.' in ctx.name) else None
@@ -497,14 +493,12 @@ def infer_local_ceph_image(ctx: CephadmContext, container_path: str) -> Optional
497493
logger.debug(f"Using container info for daemon '{daemon}'")
498494
break
499495

500-
for image in out.splitlines():
501-
if image and not image.isspace():
502-
(digest, image_id, tag, created_date) = image.lstrip().split('|')
503-
if container_info is not None and image_id not in container_info.image_id:
504-
continue
505-
if digest and not digest.endswith('@'):
506-
logger.info(f"Using ceph image with id '{image_id}' and tag '{tag}' created on {created_date}\n{digest}")
507-
return digest
496+
for image in images:
497+
if container_info is not None and image.image_id not in container_info.image_id:
498+
continue
499+
if image.digest:
500+
logger.info(f"Using ceph image with id '{image.image_id}' and tag '{image.tag}' created on {image.created}\n{image.name}")
501+
return image.name
508502
if container_info is not None:
509503
logger.warning(f"Not using image '{container_info.image_id}' as it's not in list of non-dangling images with ceph=True label")
510504
return None

src/cephadm/tests/test_cephadm.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -673,26 +673,24 @@ def test_dict_get_join(self):
673673
<none>@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29|1b58ca4f6dfd|<none>|2025-01-16 22:53:46 +0000 UTC
674674
'''
675675
),
676-
'expected': '<none>@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29', # YIKES!
676+
'expected': '1b58ca4f6dfd', # YIKES!
677677
},
678678
],
679679
)
680-
@mock.patch('os.listdir', return_value=[])
681-
@mock.patch('cephadm.logger')
682-
def test_infer_local_ceph_image(self, _logger, _listdir, params):
680+
def test_infer_local_ceph_image(self, params, funkypatch):
683681
ctx = _cephadm.CephadmContext()
684682
ctx.fsid = '00000000-0000-0000-0000-0000deadbeez'
685683
ctx.container_engine = mock_podman()
686684

687685
cinfo = params.get('container_info', None)
688686
out = params.get('images_output', '')
689687
expected = params.get('expected', None)
690-
with mock.patch('cephadm.call_throws', return_value=(out, '', '')):
691-
with mock.patch('cephadm.get_container_info', return_value=cinfo):
692-
image = _cephadm.infer_local_ceph_image(
693-
ctx, ctx.container_engine
694-
)
695-
assert image == expected
688+
funkypatch.patch('cephadmlib.call_wrappers.call').return_value = out, '', 0
689+
funkypatch.patch('cephadm.get_container_info').return_value = cinfo
690+
image = _cephadm.infer_local_ceph_image(
691+
ctx, ctx.container_engine
692+
)
693+
assert image == expected
696694

697695
@pytest.mark.parametrize('daemon_filter, by_name, daemon_list, container_stats, output',
698696
[

0 commit comments

Comments
 (0)