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
This commit is contained in:
Michele Baldessari 2020-11-12 19:21:48 +01:00
parent 5d171180e2
commit 78e49e2862
2 changed files with 3 additions and 3 deletions

View File

@ -259,7 +259,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)

View File

@ -647,7 +647,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)
@ -790,7 +790,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)