From: John Mulligan Date: Mon, 24 Feb 2025 19:20:42 +0000 (-0500) Subject: cephadm: replace image listing in infer_local_ceph_image X-Git-Tag: testing/wip-vshankar-testing-20250411.090237-debug~42^2~3 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=5b34735432724292ecf76385b209004453f60d67;p=ceph-ci.git 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 --- diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index edae1ba8f1d..4c2b17bba31 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -89,6 +89,7 @@ from cephadmlib.container_engines import ( check_container_engine, find_container_engine, normalize_container_id, + parsed_container_image_list, parsed_container_mem_usage, pull_command, registry_login, @@ -477,16 +478,11 @@ def infer_local_ceph_image(ctx: CephadmContext, container_path: str) -> Optional :return: The most recent local ceph image (already pulled) """ - # '|' special character is used to separate the output fields into: - # - Repository@digest - # - Image Id - # - Image Tag - # - Image creation date - out, _, _ = call_throws(ctx, - [container_path, 'images', - '--filter', 'label=ceph=True', - '--filter', 'dangling=false', - '--format', '{{.Repository}}@{{.Digest}}|{{.ID}}|{{.Tag}}|{{.CreatedAt}}']) + images = parsed_container_image_list( + ctx, + filters=['dangling=false', 'label=ceph=True'], + container_path=container_path, + ) container_info = None 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 logger.debug(f"Using container info for daemon '{daemon}'") break - for image in out.splitlines(): - if image and not image.isspace(): - (digest, image_id, tag, created_date) = image.lstrip().split('|') - if container_info is not None and image_id not in container_info.image_id: - continue - if digest and not digest.endswith('@'): - logger.info(f"Using ceph image with id '{image_id}' and tag '{tag}' created on {created_date}\n{digest}") - return digest + for image in images: + if container_info is not None and image.image_id not in container_info.image_id: + continue + if image.digest: + logger.info(f"Using ceph image with id '{image.image_id}' and tag '{image.tag}' created on {image.created}\n{image.name}") + return image.name if container_info is not None: logger.warning(f"Not using image '{container_info.image_id}' as it's not in list of non-dangling images with ceph=True label") return None diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index ba91857e9fb..d17374e01de 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -673,13 +673,11 @@ quay.ceph.io/ceph-ci/ceph@sha256:eeddcc536bb887b36b959e887d5984dd7a3f008a23aa1f2 @sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29|1b58ca4f6dfd||2025-01-16 22:53:46 +0000 UTC ''' ), - 'expected': '@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29', # YIKES! + 'expected': '1b58ca4f6dfd', # YIKES! }, ], ) - @mock.patch('os.listdir', return_value=[]) - @mock.patch('cephadm.logger') - def test_infer_local_ceph_image(self, _logger, _listdir, params): + def test_infer_local_ceph_image(self, params, funkypatch): ctx = _cephadm.CephadmContext() ctx.fsid = '00000000-0000-0000-0000-0000deadbeez' ctx.container_engine = mock_podman() @@ -687,12 +685,12 @@ quay.ceph.io/ceph-ci/ceph@sha256:eeddcc536bb887b36b959e887d5984dd7a3f008a23aa1f2 cinfo = params.get('container_info', None) out = params.get('images_output', '') expected = params.get('expected', None) - with mock.patch('cephadm.call_throws', return_value=(out, '', '')): - with mock.patch('cephadm.get_container_info', return_value=cinfo): - image = _cephadm.infer_local_ceph_image( - ctx, ctx.container_engine - ) - assert image == expected + funkypatch.patch('cephadmlib.call_wrappers.call').return_value = out, '', 0 + funkypatch.patch('cephadm.get_container_info').return_value = cinfo + image = _cephadm.infer_local_ceph_image( + ctx, ctx.container_engine + ) + assert image == expected @pytest.mark.parametrize('daemon_filter, by_name, daemon_list, container_stats, output', [