From 4805acd7ebe9613faae20a0af3f65b506e6e296a Mon Sep 17 00:00:00 2001 From: Michael Fritch Date: Tue, 17 Nov 2020 19:36:29 -0700 Subject: [PATCH] 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) --- src/cephadm/cephadm | 17 ++++++++++------- src/cephadm/tests/test_cephadm.py | 9 +++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) 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 -- 2.39.5