]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: replace image listing in infer_local_ceph_image
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 24 Feb 2025 19:20:42 +0000 (14:20 -0500)
committerJohn Mulligan <jmulligan@redhat.com>
Thu, 27 Mar 2025 16:11:26 +0000 (12:11 -0400)
Replace the custom code listing images in the local container store with
the new parsed_container_image_list function.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/cephadm/cephadm.py
src/cephadm/tests/test_cephadm.py

index edae1ba8f1dd717b09c0d158d30479d5c6c52571..4c2b17bba31d772acfa08ac7fb85f2fdca9b6e72 100755 (executable)
@@ -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
index ba91857e9fbe10845d2542528f51575024e4059f..d17374e01de6fb33a5522bdd3ba5855ba0387c33 100644 (file)
@@ -673,13 +673,11 @@ quay.ceph.io/ceph-ci/ceph@sha256:eeddcc536bb887b36b959e887d5984dd7a3f008a23aa1f2
 <none>@sha256:863ae69e531b26a9cb609ecea17a477ef8f77aa11b2d398091d54c73a2464d29|1b58ca4f6dfd|<none>|2025-01-16 22:53:46 +0000 UTC
                     '''
                 ),
-                'expected': '<none>@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',
         [