Merge "runner: test if image exists before running inspect"
This commit is contained in:
commit
74bf3fa33b
|
@ -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