Merge "runner: test if image exists before running inspect"

This commit is contained in:
Zuul 2019-01-09 21:56:51 +00:00 committed by Gerrit Code Review
commit 74bf3fa33b
2 changed files with 26 additions and 1 deletions

View File

@ -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')

View File

@ -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']
)