diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2018-10-02 08:47:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-02 08:47:53 -0700 |
commit | 89c5804fe0ca3ece7587adb5d5c974dbc494f721 (patch) | |
tree | 042a10e85f659e8ce3d8ab1841752392e53b353d /contrib/python/podman/test | |
parent | 08898cb5ac982c9f160e50731616a5ca27e56a09 (diff) | |
parent | ff38edaafefa1cdac9a87a1a08b8f4fcd94ae996 (diff) | |
download | podman-89c5804fe0ca3ece7587adb5d5c974dbc494f721.tar.gz podman-89c5804fe0ca3ece7587adb5d5c974dbc494f721.tar.bz2 podman-89c5804fe0ca3ece7587adb5d5c974dbc494f721.zip |
Merge pull request #1563 from jwhonce/wip/pods
Implement pod varlink bindings
Diffstat (limited to 'contrib/python/podman/test')
-rw-r--r-- | contrib/python/podman/test/test_pods_ctnrs.py | 65 | ||||
-rw-r--r-- | contrib/python/podman/test/test_pods_no_ctnrs.py | 94 | ||||
-rwxr-xr-x | contrib/python/podman/test/test_runner.sh | 2 |
3 files changed, 160 insertions, 1 deletions
diff --git a/contrib/python/podman/test/test_pods_ctnrs.py b/contrib/python/podman/test/test_pods_ctnrs.py new file mode 100644 index 000000000..c5733091c --- /dev/null +++ b/contrib/python/podman/test/test_pods_ctnrs.py @@ -0,0 +1,65 @@ +import os +from test.podman_testcase import PodmanTestCase + +import podman +from podman import FoldedString + +pod = None + + +class TestPodsCtnrs(PodmanTestCase): + @classmethod + def setUpClass(cls): + # Populate storage + super().setUpClass() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + + def setUp(self): + self.tmpdir = os.environ['TMPDIR'] + self.host = os.environ['PODMAN_HOST'] + + self.pclient = podman.Client(self.host) + + def test_010_populate(self): + global pod + + pod = self.pclient.pods.create('pod1') + self.assertEqual('pod1', pod.name) + + img = self.pclient.images.get('docker.io/library/alpine:latest') + ctnr = img.container(pod=pod.id) + + pod.refresh() + self.assertEqual('1', pod.numberofcontainers) + self.assertEqual(ctnr.id, pod.containersinfo[0]['id']) + + def test_015_one_shot(self): + global pod + + details = pod.inspect() + state = FoldedString(details.containers[0]['state']) + self.assertEqual(state, 'configured') + + pod = pod.start() + status = FoldedString(pod.containersinfo[0]['status']) + # Race on whether container is still running or finished + self.assertIn(status, ('exited', 'running')) + + pod = pod.restart() + status = FoldedString(pod.containersinfo[0]['status']) + self.assertIn(status, ('exited', 'running')) + + killed = pod.kill() + self.assertEqual(pod, killed) + + def test_999_remove(self): + global pod + + ident = pod.remove(force=True) + self.assertEqual(ident, pod.id) + + with self.assertRaises(StopIteration): + next(self.pclient.pods.list()) diff --git a/contrib/python/podman/test/test_pods_no_ctnrs.py b/contrib/python/podman/test/test_pods_no_ctnrs.py new file mode 100644 index 000000000..48b4f74e4 --- /dev/null +++ b/contrib/python/podman/test/test_pods_no_ctnrs.py @@ -0,0 +1,94 @@ +import os +import unittest + +import podman +import varlink + +ident = None +pod = None + + +class TestPodsNoCtnrs(unittest.TestCase): + def setUp(self): + self.tmpdir = os.environ['TMPDIR'] + self.host = os.environ['PODMAN_HOST'] + + self.pclient = podman.Client(self.host) + + def test_010_create(self): + global ident + + actual = self.pclient.pods.create('pod0') + self.assertIsNotNone(actual) + ident = actual.id + + def test_015_list(self): + global ident, pod + + actual = next(self.pclient.pods.list()) + self.assertEqual('pod0', actual.name) + self.assertEqual(ident, actual.id) + self.assertEqual('Created', actual.status) + self.assertEqual('0', actual.numberofcontainers) + self.assertFalse(actual.containersinfo) + pod = actual + + def test_020_get(self): + global ident, pod + + actual = self.pclient.pods.get(pod.id) + self.assertEqual('pod0', actual.name) + self.assertEqual(ident, actual.id) + self.assertEqual('Created', actual.status) + self.assertEqual('0', actual.numberofcontainers) + self.assertFalse(actual.containersinfo) + + def test_025_inspect(self): + global ident, pod + + details = pod.inspect() + self.assertEqual(ident, details.id) + self.assertEqual('pod0', details.config['name']) + self.assertIsNone(details.containers) + + def test_030_ident_no_ctnrs(self): + global ident, pod + + actual = pod.kill() + self.assertEqual(pod, actual) + + actual = pod.pause() + self.assertEqual(pod, actual) + + actual = pod.unpause() + self.assertEqual(pod, actual) + + actual = pod.stop() + self.assertEqual(pod, actual) + + def test_045_raises_no_ctnrs(self): + global ident, pod + + with self.assertRaises(podman.NoContainersInPod): + pod.start() + + with self.assertRaises(podman.NoContainersInPod): + pod.restart() + + with self.assertRaises(podman.NoContainerRunning): + next(pod.stats()) + + with self.assertRaises(varlink.error.MethodNotImplemented): + pod.top() + + with self.assertRaises(varlink.error.MethodNotImplemented): + pod.wait() + + def test_999_remove(self): + global ident, pod + + actual = pod.remove() + self.assertEqual(ident, actual) + + with self.assertRaises(StopIteration): + next(self.pclient.pods.list()) diff --git a/contrib/python/podman/test/test_runner.sh b/contrib/python/podman/test/test_runner.sh index 76432cf47..ce518e7ed 100755 --- a/contrib/python/podman/test/test_runner.sh +++ b/contrib/python/podman/test/test_runner.sh @@ -14,7 +14,7 @@ fi export PATH=../../../bin:$PATH function usage { - echo 1>&2 $0 [-v] [-h] [test.TestCase|test.TestCase.step] + echo 1>&2 $0 '[-v] [-h] [test.<TestCase>|test.<TestCase>.<step>]' } while getopts "vh" arg; do |