runner: test if image exists before running inspect
When we run: $ podman inspect --type image --format exists <image> Against a non-existing image, we end up with message like: error getting image <image>: unable to find <image> in local storage unable to find a name and tag match for <image> in repotags The messages can confuse the operators, and we don't want that. Podman will have a command called: $ podman image exists <image> Which would return 0 if the image actually exists. So before running the inspect command, we verify that the image actually exists. If the container CMD is Podman, the new function will test that the image exists and if not the inspect won't run. No change for Docker as the command isn't implemented in it. Change-Id: Ie16ca7377e8e5e5c63d9630cf6d26e0bc8df6b1a Related: https://github.com/containers/libpod/issues/1845
This commit is contained in:
parent
63a8b2b06e
commit
42c5cc9df4
|
@ -81,8 +81,24 @@ class BaseRunner(object):
|
|||
|
||||
return [c for c in cmd_stdout.split()]
|
||||
|
||||
def image_exist(self, name, quiet=False):
|
||||
# the command only exists in podman.
|
||||
if self.cont_cmd != 'podman':
|
||||
self.log.warning("image_exist isn't supported "
|
||||
"by %s" % self.cont_cmd)
|
||||
return 0
|
||||
cmd = ['podman', 'image', 'exists', name]
|
||||
(cmd_stdout, cmd_stderr, returncode) = self.execute(
|
||||
cmd, self.log, quiet)
|
||||
return returncode
|
||||
|
||||
def inspect(self, name, output_format=None, o_type='container',
|
||||
quiet=False):
|
||||
img_exist = self.image_exist(name)
|
||||
# We want to verify if the image exists before inspecting it.
|
||||
# Context: https://github.com/containers/libpod/issues/1845
|
||||
if img_exist != 0:
|
||||
return
|
||||
cmd = [self.cont_cmd, 'inspect', '--type', o_type]
|
||||
if output_format:
|
||||
cmd.append('--format')
|
||||
|
|
|
@ -414,4 +414,13 @@ four-12345678 four
|
|||
|
||||
|
||||
class PodmanRunner(TestBaseRunner):
|
||||
pass
|
||||
|
||||
@mock.patch('subprocess.Popen')
|
||||
def test_image_exist(self, popen):
|
||||
self.mock_execute(popen, '', '', 0)
|
||||
|
||||
self.runner = runner.PodmanRunner('tester')
|
||||
self.runner.image_exist('one')
|
||||
self.assert_execute(
|
||||
popen, ['podman', 'image', 'exists', 'one']
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue