]> git.apps.os.sepia.ceph.com Git - ceph.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)
committerSebastian Wagner <sebastian.wagner@suse.com>
Thu, 7 Jan 2021 12:02:21 +0000 (13:02 +0100)
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>
(cherry picked from commit 4cf49997c3af7428d2767e72f62f6b875e55c51d)

src/cephadm/cephadm
src/cephadm/tests/test_cephadm.py

index 33f2de1038516d6374ee004de67a73b262f1f1ca..bd14ef60fcb02472c12a950c1f75b15b72186bbb 100755 (executable)
@@ -1409,13 +1409,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