From 7e496911451b5d6fca9766fe1e294c7e5e5523ff Mon Sep 17 00:00:00 2001 From: Michele Baldessari Date: Thu, 12 Nov 2020 19:21:48 +0100 Subject: [PATCH] Fix inspect images calls to not use the index format keyword Via https://review.opendev.org/#/c/752937/ we added the following code: if container_image: image_id_str = self.runner.inspect( container_image, "{{index .Id}}", o_type='image') if str(image_id_str).strip() != inspect_info.get('Image'): self.log.debug("Deleting container (image updated): " "%s" % container) self.runner.remove_container(container) return True This code works fine in docker: [root@controller-0 ~]# docker inspect --type image --format '{{index .Id}}' f6ec0f326154 sha256:f6ec0f326154a80b6844a03c2de2904bbbefea6cdf87acb606ff869ace1a8dd4 But is problematic in podman (both on 1.6.4 and 2.1.1 versions): [root@controller-0 ~]# podman inspect --type image --format '{{index .Id}}' undercloud-0.ctlplane.redhat.local:8787/rh-osbs/rhosp16-openstack-cinder-volume:16.2_20201110.2-hotfixupdate2 ERRO[0000] Error printing inspect output: Template parsing error: template: image:1:8: executing "image" at <.Id>: can't evaluate field Id in type *entities.ImageInspectReport This has the side-effect of restarting all containers at each identical redeploy. We can just drop the 'index' in the query since it works in both docker and podman: [root@controller-0 ~]# docker inspect --type image --format '{{.Id}}' f6ec0f326154 sha256:f6ec0f326154a80b6844a03c2de2904bbbefea6cdf87acb606ff869ace1a8dd4 [root@controller-0 ~]# podman inspect --type image --format '{{.Id}}' 5093412f3a08 Change-Id: I8b1fbbb7499a69e7a131fd8650c6f50fb4ab978e Closes-Bug: #1904043 --- paunch/builder/base.py | 2 +- paunch/tests/test_builder_base.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/paunch/builder/base.py b/paunch/builder/base.py index 875d723..f0a4671 100644 --- a/paunch/builder/base.py +++ b/paunch/builder/base.py @@ -248,7 +248,7 @@ class BaseBuilder(object): if container_image: image_id_str = self.runner.inspect( - container_image, "{{index .Id}}", o_type='image') + container_image, "{{.Id}}", o_type='image') if str(image_id_str).strip() != inspect_info.get('Image'): self.log.debug("Deleting container (image updated): " "%s" % container) diff --git a/paunch/tests/test_builder_base.py b/paunch/tests/test_builder_base.py index aaf0587..7eb09d5 100644 --- a/paunch/tests/test_builder_base.py +++ b/paunch/tests/test_builder_base.py @@ -652,7 +652,7 @@ three-12345678 three''', '', 0), calls = [ mock.call('one'), mock.call('127.0.0.1:8787/centos:7', - '{{index .Id}}', + '{{.Id}}', o_type='image') ] mock_inspect.has_calls(calls) @@ -795,7 +795,7 @@ three-12345678 three''', '', 0), calls = [ mock.call('one'), mock.call('127.0.0.1:8787/centos:7', - '{{index .Id}}', + '{{.Id}}', o_type='image') ] mock_inspect.has_calls(calls)