From 277eb726b97a0bb31137e33fd3e5d1a7a4784188 Mon Sep 17 00:00:00 2001 From: Emilien Macchi Date: Mon, 17 Jun 2019 14:13:49 -0400 Subject: [PATCH] runner: implement container_exist On podman, we can run "podman container exists" command to check if whether or not a container does exist. This will be used later when we'll reduce our usage of "podman inspect". Change-Id: I6dfbfe9da3d216cadaca77a53a0d5223c9cbd57d --- paunch/runner.py | 10 ++++++++++ paunch/tests/test_runner.py | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/paunch/runner.py b/paunch/runner.py index cffaf76..01680b9 100644 --- a/paunch/runner.py +++ b/paunch/runner.py @@ -273,6 +273,11 @@ class DockerRunner(BaseRunner): "by %s" % self.cont_cmd) return True + def container_exist(self, name, quiet=False): + self.log.warning("container_exist isn't supported " + "by %s" % self.cont_cmd) + return True + class PodmanRunner(BaseRunner): @@ -342,3 +347,8 @@ class PodmanRunner(BaseRunner): cmd = ['podman', 'image', 'exists', name] (_, _, returncode) = self.execute(cmd, self.log, quiet) return returncode == 0 + + def container_exist(self, name, quiet=False): + cmd = ['podman', 'container', 'exists', name] + (_, _, returncode) = self.execute(cmd, self.log, quiet) + return returncode == 0 diff --git a/paunch/tests/test_runner.py b/paunch/tests/test_runner.py index fe042fc..fa9776d 100644 --- a/paunch/tests/test_runner.py +++ b/paunch/tests/test_runner.py @@ -424,3 +424,13 @@ class PodmanRunner(TestBaseRunner): self.assert_execute( popen, ['podman', 'image', 'exists', 'one'] ) + + @mock.patch('subprocess.Popen') + def test_container_exist(self, popen): + self.mock_execute(popen, '', '', 0) + + self.runner = runner.PodmanRunner('tester') + self.runner.container_exist('one') + self.assert_execute( + popen, ['podman', 'container', 'exists', 'one'] + )