summaryrefslogtreecommitdiff
path: root/test/dockerpy
diff options
context:
space:
mode:
authorSujil02 <sushah@redhat.com>2020-05-27 12:58:52 -0400
committerSujil02 <sushah@redhat.com>2020-06-04 16:04:34 -0400
commit359d67a68773747a269c407d9e62bee7f36d1d15 (patch)
treea8f0bd54906624e28ab8551a12abbe831efea80d /test/dockerpy
parent1f8c509fafb4ce41970c4f28ed55daec459c7520 (diff)
downloadpodman-359d67a68773747a269c407d9e62bee7f36d1d15.tar.gz
podman-359d67a68773747a269c407d9e62bee7f36d1d15.tar.bz2
podman-359d67a68773747a269c407d9e62bee7f36d1d15.zip
Adds docker py regression test.
Adds test to validate podman image endpoints. Adds readme on how to run python tests Adds contants file. Signed-off-by: Sujil02 <sushah@redhat.com>
Diffstat (limited to 'test/dockerpy')
-rw-r--r--test/dockerpy/README.md35
-rw-r--r--test/dockerpy/common.py6
-rw-r--r--test/dockerpy/constant.py11
-rw-r--r--test/dockerpy/images.py131
4 files changed, 183 insertions, 0 deletions
diff --git a/test/dockerpy/README.md b/test/dockerpy/README.md
new file mode 100644
index 000000000..2894fc8ab
--- /dev/null
+++ b/test/dockerpy/README.md
@@ -0,0 +1,35 @@
+# Dockerpy regression test
+
+Python test suite to validate Podman endpoints using dockerpy library
+
+Running tests
+=============
+To run the tests locally in your sandbox:
+
+#### Make sure that the Podman system service is running to do so
+
+```
+sudo podman --log-level=debug system service -t0 unix:/run/podman/podman.sock
+```
+#### Run the entire test
+
+```
+sudo PYTHONPATH=/usr/bin/python python -m dockerpy.images
+```
+
+Passing the -v option to your test script will instruct unittest.main() to enable a higher level of verbosity, and produce detailed output:
+
+```
+sudo PYTHONPATH=/usr/bin/python python -m unittest -v dockerpy.images
+```
+#### Run a specific test class
+
+```
+sudo PYTHONPATH=/usr/bin/python python -m unittest -v dockerpy.images.TestImages
+```
+
+#### Run a specific test within the test class
+
+```
+sudo PYTHONPATH=/usr/bin/python python -m unittest -v dockerpy.images.TestImages.test_list_images
+```
diff --git a/test/dockerpy/common.py b/test/dockerpy/common.py
new file mode 100644
index 000000000..767a94ec0
--- /dev/null
+++ b/test/dockerpy/common.py
@@ -0,0 +1,6 @@
+import docker
+from docker import Client
+
+
+def get_client():
+ return docker.Client(base_url="unix:/run/podman/podman.sock")
diff --git a/test/dockerpy/constant.py b/test/dockerpy/constant.py
new file mode 100644
index 000000000..e00457442
--- /dev/null
+++ b/test/dockerpy/constant.py
@@ -0,0 +1,11 @@
+BB = "docker.io/library/busybox:latest"
+NGINX = "docker.io/library/nginx:latest"
+ALPINE = "docker.io/library/alpine:latest"
+ALPINE_SHORTNAME = "alpine"
+ALPINELISTTAG = "docker.io/library/alpine:3.10.2"
+ALPINELISTDIGEST = "docker.io/library/alpine@sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb"
+ALPINEAMD64DIGEST = "docker.io/library/alpine@sha256:acd3ca9941a85e8ed16515bfc5328e4e2f8c128caa72959a58a127b7801ee01f"
+ALPINEAMD64ID = "961769676411f082461f9ef46626dd7a2d1e2b2a38e6a44364bcbecf51e66dd4"
+ALPINEARM64DIGEST = "docker.io/library/alpine@sha256:db7f3dcef3d586f7dd123f107c93d7911515a5991c4b9e51fa2a43e46335a43e"
+ALPINEARM64ID = "915beeae46751fc564998c79e73a1026542e945ca4f73dc841d09ccc6c2c0672"
+infra = "k8s.gcr.io/pause:3.2"
diff --git a/test/dockerpy/images.py b/test/dockerpy/images.py
new file mode 100644
index 000000000..07ea6c0f8
--- /dev/null
+++ b/test/dockerpy/images.py
@@ -0,0 +1,131 @@
+
+import unittest
+import docker
+import requests
+import os
+from docker import Client
+from . import constant
+from . import common
+
+client = common.get_client()
+
+class TestImages(unittest.TestCase):
+
+ def setUp(self):
+ super().setUp()
+ client.pull(constant.ALPINE)
+
+ def tearDown(self):
+ allImages = client.images()
+ for image in allImages:
+ client.remove_image(image,force=True)
+ return super().tearDown()
+
+# Inspect Image
+
+
+ def test_inspect_image(self):
+ # Check for error with wrong image name
+ with self.assertRaises(requests.HTTPError):
+ client.inspect_image("dummy")
+ alpine_image = client.inspect_image(constant.ALPINE)
+ self.assertIn(constant.ALPINE, alpine_image["RepoTags"])
+
+# Tag Image
+
+ # Validates if invalid image name is given a bad response is encountered.
+ def test_tag_invalid_image(self):
+ with self.assertRaises(requests.HTTPError):
+ client.tag("dummy","demo")
+
+
+
+ # Validates if the image is tagged successfully.
+ def test_tag_valid_image(self):
+ client.tag(constant.ALPINE,"demo",constant.ALPINE_SHORTNAME)
+ alpine_image = client.inspect_image(constant.ALPINE)
+ for x in alpine_image["RepoTags"]:
+ if("demo:alpine" in x):
+ self.assertTrue
+ self.assertFalse
+
+ # Validates if name updates when the image is retagged.
+ @unittest.skip("dosent work now")
+ def test_retag_valid_image(self):
+ client.tag(constant.ALPINE_SHORTNAME, "demo","rename")
+ alpine_image = client.inspect_image(constant.ALPINE)
+ self.assertNotIn("demo:test", alpine_image["RepoTags"])
+
+# List Image
+ # List All Images
+ def test_list_images(self):
+ allImages = client.images()
+ self.assertEqual(len(allImages), 1)
+ # Add more images
+ client.pull(constant.BB)
+ client.pull(constant.NGINX)
+ allImages = client.images()
+ self.assertEqual(len(allImages) , 3)
+
+
+ # List images with filter
+ filters = {'reference':'alpine'}
+ allImages = client.images(filters = filters)
+ self.assertEqual(len(allImages) , 1)
+
+# Search Image
+ def test_search_image(self):
+ response = client.search("alpine")
+ for i in response:
+ # Alpine found
+ if "docker.io/library/alpine" in i["Name"]:
+ self.assertTrue(True, msg="Image found")
+ self.assertFalse(False,msg="Image not found")
+
+# Image Exist (No docker-py support yet)
+
+# Remove Image
+ def test_remove_image(self):
+ # Check for error with wrong image name
+ with self.assertRaises(requests.HTTPError):
+ client.remove_image("dummy")
+ allImages = client.images()
+ self.assertEqual(len(allImages) , 1)
+ alpine_image = client.inspect_image(constant.ALPINE)
+ client.remove_image(alpine_image)
+ allImages = client.images()
+ self.assertEqual(len(allImages) , 0)
+
+# Image History
+ def test_image_history(self):
+ # Check for error with wrong image name
+ with self.assertRaises(requests.HTTPError):
+ client.remove_image("dummy")
+ imageHistory = client.history(constant.ALPINE)
+ alpine_image = client.inspect_image(constant.ALPINE)
+ for h in imageHistory:
+ if h["Id"] in alpine_image["Id"]:
+ self.assertTrue(True,msg="Image History validated")
+ self.assertFalse(False,msg="Unable to get image history")
+
+# Prune Image (No docker-py support yet)
+
+# Export Image
+
+ def test_export_image(self):
+ file = "/tmp/alpine-latest.tar"
+ # Check for error with wrong image name
+ with self.assertRaises(requests.HTTPError):
+ client.get_image("dummy")
+ response = client.get_image(constant.ALPINE)
+ image_tar = open(file,mode="wb")
+ image_tar.write(response.data)
+ image_tar.close()
+ os.stat(file)
+
+# Import|Load Image
+
+
+if __name__ == '__main__':
+ # Setup temporary space
+ unittest.main()