]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
cephadm: reference the last local image by digest
authorMichael Fritch <mfritch@suse.com>
Wed, 18 Nov 2020 02:36:29 +0000 (19:36 -0700)
committerMichael Fritch <mfritch@suse.com>
Wed, 18 Nov 2020 15:16:29 +0000 (08:16 -0700)
use the image digest rather than repo/tag combo when inferring the last
used local ceph image

Fixes: https://tracker.ceph.com/issues/48205
Signed-off-by: Michael Fritch <mfritch@suse.com>
src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 783a7b12db34f174842f39960ed6808f40b77ba5..5fd79f3ddd0c9c8281e06d2cc7029ebe6fe710e9 100755 (executable)
@@ -1406,13 +1406,16 @@ def get_last_local_ceph_image():
         [container_path, 'images',
          '--filter', 'label=ceph=True',
          '--filter', 'dangling=false',
-         '--format', '{{.Repository}} {{.Tag}}'])
-    for line in out.splitlines():
-        if len(line.split()) == 2:
-            repository, tag = line.split()
-            r = '{}:{}'.format(repository, tag)
-            logger.info('Using recent ceph image %s' % r)
-            return r
+         '--format', '{{.Repository}}@{{.Digest}}'])
+    return _filter_last_local_ceph_image(out)
+
+
+def _filter_last_local_ceph_image(out):
+    # str -> Optional[str]
+    for image in out.splitlines():
+        if image and not image.endswith('@'):
+            logger.info('Using recent ceph image %s' % image)
+            return image
     return None
 
 
index c9e2769ed33caeff054d054e6f450279e4b8f6a5..5487f43b3a88ccb85a6233fe41659f3bd6fe549f 100644 (file)
@@ -278,6 +278,15 @@ default via fe80::2480:28ec:5097:3fe2 dev wlp2s0 proto ra metric 20600 pref medi
         result = cd.dict_get_join({'a': 1}, 'a')
         assert result == 1
 
+    def test_last_local_images(self):
+        out = '''
+docker.io/ceph/daemon-base@
+docker.io/ceph/ceph:v15.2.5
+docker.io/ceph/daemon-base:octopus
+        '''
+        image = cd._filter_last_local_ceph_image(out)
+        assert image == 'docker.io/ceph/ceph:v15.2.5'
+
 
 class TestCustomContainer(unittest.TestCase):
     cc: cd.CustomContainer