From: Michael Fritch Date: Wed, 18 Nov 2020 02:36:29 +0000 (-0700) Subject: cephadm: reference the last local image by digest X-Git-Tag: v15.2.9~88^2~25 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=4805acd7ebe9613faae20a0af3f65b506e6e296a;p=ceph.git cephadm: reference the last local image by digest 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 (cherry picked from commit 4cf49997c3af7428d2767e72f62f6b875e55c51d) --- diff --git a/src/cephadm/cephadm b/src/cephadm/cephadm index 33f2de1038516..bd14ef60fcb02 100755 --- a/src/cephadm/cephadm +++ b/src/cephadm/cephadm @@ -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 diff --git a/src/cephadm/tests/test_cephadm.py b/src/cephadm/tests/test_cephadm.py index c9e2769ed33ca..5487f43b3a88c 100644 --- a/src/cephadm/tests/test_cephadm.py +++ b/src/cephadm/tests/test_cephadm.py @@ -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