summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dockerpy/containers.py46
-rw-r--r--test/e2e/build/Dockerfile.test-cp-root-dir2
-rw-r--r--test/e2e/cp_test.go38
-rw-r--r--test/e2e/create_test.go15
-rw-r--r--test/e2e/logs_test.go12
-rw-r--r--test/e2e/pod_create_test.go15
-rw-r--r--test/e2e/run_test.go15
-rw-r--r--test/test_dockerpy/README.md (renamed from test/dockerpy/README.md)0
-rw-r--r--test/test_dockerpy/__init__.py (renamed from test/dockerpy/__init__.py)0
-rw-r--r--test/test_dockerpy/common.py (renamed from test/dockerpy/common.py)25
-rw-r--r--test/test_dockerpy/constant.py (renamed from test/dockerpy/constant.py)0
-rw-r--r--test/test_dockerpy/test_containers.py194
-rw-r--r--test/test_dockerpy/test_images.py (renamed from test/dockerpy/images.py)5
-rw-r--r--test/test_dockerpy/test_info_version.py46
14 files changed, 360 insertions, 53 deletions
diff --git a/test/dockerpy/containers.py b/test/dockerpy/containers.py
deleted file mode 100644
index d70ec932c..000000000
--- a/test/dockerpy/containers.py
+++ /dev/null
@@ -1,46 +0,0 @@
-
-import unittest
-import docker
-import requests
-import os
-from docker import Client
-from . import constant
-from . import common
-
-client = common.get_client()
-
-class TestContainers(unittest.TestCase):
-
- podman = None
-
- def setUp(self):
- super().setUp()
- common.run_top_container()
-
- def tearDown(self):
- common.remove_all_containers()
- common.remove_all_images()
- return super().tearDown()
-
- @classmethod
- def setUpClass(cls):
- super().setUpClass()
- common.enable_sock(cls)
-
- @classmethod
- def tearDownClass(cls):
- common.terminate_connection(cls)
- return super().tearDownClass()
-
- def test_inspect_container(self):
- # Inspect bogus container
- with self.assertRaises(requests.HTTPError):
- client.inspect_container("dummy")
- # Inspect valid container
- container = client.inspect_container(constant.TOP)
- self.assertIn(constant.TOP , container["Name"])
-
-
-if __name__ == '__main__':
- # Setup temporary space
- unittest.main()
diff --git a/test/e2e/build/Dockerfile.test-cp-root-dir b/test/e2e/build/Dockerfile.test-cp-root-dir
new file mode 100644
index 000000000..9f7de7c32
--- /dev/null
+++ b/test/e2e/build/Dockerfile.test-cp-root-dir
@@ -0,0 +1,2 @@
+FROM scratch
+COPY Dockerfile.test-cp-root-dir /
diff --git a/test/e2e/cp_test.go b/test/e2e/cp_test.go
index 6ae54ba34..3f9b12e0a 100644
--- a/test/e2e/cp_test.go
+++ b/test/e2e/cp_test.go
@@ -296,4 +296,42 @@ var _ = Describe("Podman cp", func() {
os.Remove("testfile1")
})
+ It("podman cp the root directory from the ctr to an existing directory on the host ", func() {
+ imgName := "test-cp-root-dir:latest"
+ DockerfileName := "Dockerfile.test-cp-root-dir"
+ ctrName := "test-container-cp-root"
+
+ session := podmanTest.PodmanNoCache([]string{"build", "-f", "build/" + DockerfileName, "-t", imgName, "build/"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ testDirPath := filepath.Join(podmanTest.RunRoot, "TestDirForCp")
+
+ session = podmanTest.Podman([]string{"create", "--name", ctrName, imgName, "dummy"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ err := os.Mkdir(testDirPath, 0755)
+ Expect(err).To(BeNil())
+ defer os.RemoveAll(testDirPath)
+
+ // Copy the root directory of the container to an existing directory
+ session = podmanTest.Podman([]string{"cp", ctrName + ":/", testDirPath})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ // The file should be in the directory,
+ // not one layer too much of the directory called merged
+ checkFile := filepath.Join(testDirPath, DockerfileName)
+ _, err = os.Stat(checkFile)
+ Expect(err).To(BeNil())
+
+ session = podmanTest.Podman([]string{"container", "rm", ctrName})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+
+ session = podmanTest.PodmanNoCache([]string{"rmi", "-f", imgName})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ })
})
diff --git a/test/e2e/create_test.go b/test/e2e/create_test.go
index b9a1ff83d..822e470f2 100644
--- a/test/e2e/create_test.go
+++ b/test/e2e/create_test.go
@@ -429,4 +429,19 @@ var _ = Describe("Podman create", func() {
Expect(len(data)).To(Equal(1))
Expect(data[0].HostConfig.NanoCpus).To(Equal(int64(nanoCPUs)))
})
+
+ It("podman create --replace", func() {
+ // Make sure we error out with --name.
+ session := podmanTest.Podman([]string{"create", "--replace", ALPINE, "/bin/sh"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(125))
+
+ // Create and replace 5 times in a row the "same" container.
+ ctrName := "testCtr"
+ for i := 0; i < 5; i++ {
+ session = podmanTest.Podman([]string{"create", "--replace", "--name", ctrName, ALPINE, "/bin/sh"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ }
+ })
})
diff --git a/test/e2e/logs_test.go b/test/e2e/logs_test.go
index f36163ccc..f9446e0c6 100644
--- a/test/e2e/logs_test.go
+++ b/test/e2e/logs_test.go
@@ -288,4 +288,16 @@ var _ = Describe("Podman logs", func() {
logc.WaitWithDefaultTimeout()
Expect(logc).To(Exit(0))
})
+
+ It("follow output stopped container", func() {
+ containerName := "logs-f"
+
+ logc := podmanTest.Podman([]string{"run", "--name", containerName, "-d", ALPINE})
+ logc.WaitWithDefaultTimeout()
+ Expect(logc).To(Exit(0))
+
+ results := podmanTest.Podman([]string{"logs", "-f", containerName})
+ results.WaitWithDefaultTimeout()
+ Expect(results).To(Exit(0))
+ })
})
diff --git a/test/e2e/pod_create_test.go b/test/e2e/pod_create_test.go
index a7d5783cb..8d07f6290 100644
--- a/test/e2e/pod_create_test.go
+++ b/test/e2e/pod_create_test.go
@@ -305,4 +305,19 @@ var _ = Describe("Podman pod create", func() {
data := check.InspectPodToJSON()
Expect(data.ID).To(Equal(string(id)))
})
+
+ It("podman pod create --replace", func() {
+ // Make sure we error out with --name.
+ session := podmanTest.Podman([]string{"pod", "create", "--replace", ALPINE, "/bin/sh"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(125))
+
+ // Create and replace 5 times in a row the "same" pod.
+ podName := "testCtr"
+ for i := 0; i < 5; i++ {
+ session = podmanTest.Podman([]string{"pod", "create", "--replace", "--name", podName})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ }
+ })
})
diff --git a/test/e2e/run_test.go b/test/e2e/run_test.go
index 59215c7e5..76944b3db 100644
--- a/test/e2e/run_test.go
+++ b/test/e2e/run_test.go
@@ -931,4 +931,19 @@ USER mail`
session.WaitWithDefaultTimeout()
Expect(session.ExitCode()).To(Equal(0))
})
+
+ It("podman run --replace", func() {
+ // Make sure we error out with --name.
+ session := podmanTest.Podman([]string{"create", "--replace", ALPINE, "/bin/sh"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(125))
+
+ // Run and replace 5 times in a row the "same" container.
+ ctrName := "testCtr"
+ for i := 0; i < 5; i++ {
+ session := podmanTest.Podman([]string{"run", "--detach", "--replace", "--name", ctrName, ALPINE, "/bin/sh"})
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ }
+ })
})
diff --git a/test/dockerpy/README.md b/test/test_dockerpy/README.md
index 32e426d58..32e426d58 100644
--- a/test/dockerpy/README.md
+++ b/test/test_dockerpy/README.md
diff --git a/test/dockerpy/__init__.py b/test/test_dockerpy/__init__.py
index e69de29bb..e69de29bb 100644
--- a/test/dockerpy/__init__.py
+++ b/test/test_dockerpy/__init__.py
diff --git a/test/dockerpy/common.py b/test/test_dockerpy/common.py
index fdacb49be..975b13dc6 100644
--- a/test/dockerpy/common.py
+++ b/test/test_dockerpy/common.py
@@ -23,13 +23,30 @@ def podman():
binary = "bin/podman"
return binary
-def restore_image_from_cache():
- client.load_image(constant.ImageCacheDir+alpineDict["tarballName"])
+def restore_image_from_cache(TestClass):
+ alpineImage = os.path.join(constant.ImageCacheDir , alpineDict["tarballName"])
+ if not os.path.exists(alpineImage):
+ os.makedirs(constant.ImageCacheDir)
+ client.pull(constant.ALPINE)
+ response = client.get_image(constant.ALPINE)
+ image_tar = open(alpineImage,mode="wb")
+ image_tar.write(response.data)
+ image_tar.close()
+ else :
+ TestClass.podman = subprocess.run(
+ [
+ podman(), "load", "-i", alpineImage
+ ],
+ shell=False,
+ stdin=subprocess.DEVNULL,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ )
def run_top_container():
- client.pull(constant.ALPINE)
- c = client.create_container(constant.ALPINE,name=constant.TOP)
+ c = client.create_container(image=constant.ALPINE,command='/bin/sleep 5',name=constant.TOP)
client.start(container=c.get("Id"))
+ return c.get("Id")
def enable_sock(TestClass):
TestClass.podman = subprocess.Popen(
diff --git a/test/dockerpy/constant.py b/test/test_dockerpy/constant.py
index 8a3f1d984..8a3f1d984 100644
--- a/test/dockerpy/constant.py
+++ b/test/test_dockerpy/constant.py
diff --git a/test/test_dockerpy/test_containers.py b/test/test_dockerpy/test_containers.py
new file mode 100644
index 000000000..34fe82c18
--- /dev/null
+++ b/test/test_dockerpy/test_containers.py
@@ -0,0 +1,194 @@
+
+import unittest
+import docker
+import requests
+import os
+from docker import Client
+from . import constant
+from . import common
+import time
+
+client = common.get_client()
+
+class TestContainers(unittest.TestCase):
+
+ podman = None
+ topContainerId = ""
+
+ def setUp(self):
+ super().setUp()
+ common.restore_image_from_cache(self)
+ TestContainers.topContainerId = common.run_top_container()
+
+ def tearDown(self):
+ common.remove_all_containers()
+ common.remove_all_images()
+ return super().tearDown()
+
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ common.enable_sock(cls)
+
+ @classmethod
+ def tearDownClass(cls):
+ common.terminate_connection(cls)
+ return super().tearDownClass()
+
+ def test_inspect_container(self):
+ # Inspect bogus container
+ with self.assertRaises(requests.HTTPError) as error:
+ client.inspect_container("dummy")
+ self.assertEqual(error.exception.response.status_code, 404)
+ # Inspect valid container by name
+ container = client.inspect_container(constant.TOP)
+ self.assertIn(TestContainers.topContainerId , container["Id"])
+ # Inspect valid container by Id
+ container = client.inspect_container(TestContainers.topContainerId)
+ self.assertIn(constant.TOP , container["Name"])
+
+ def test_create_container(self):
+ # Run a container with detach mode
+ container = client.create_container(image="alpine", detach=True)
+ self.assertEqual(len(container),2)
+
+
+ def test_start_container(self):
+ # Start bogus container
+ with self.assertRaises(requests.HTTPError) as error:
+ client.start("dummy")
+ self.assertEqual(error.exception.response.status_code, 404)
+
+ # Podman docs says it should give a 304 but returns with no response
+ # # Start a already started container should return 304
+ # response = client.start(container=TestContainers.topContainerId)
+ # self.assertEqual(error.exception.response.status_code, 304)
+
+ # Create a new container and validate the count
+ client.create_container(image=constant.ALPINE,name="container2")
+ containers = client.containers(quiet=True,all=True)
+ self.assertEqual(len(containers),2)
+
+ def test_stop_container(self):
+ # Stop bogus container
+ with self.assertRaises(requests.HTTPError) as error:
+ client.stop("dummy")
+ self.assertEqual(error.exception.response.status_code, 404)
+
+ # Validate the container state
+ container = client.inspect_container(constant.TOP)
+ self.assertEqual(container["State"]["Status"], "running")
+
+ # Stop a running container and validate the state
+ client.stop(TestContainers.topContainerId)
+ container = client.inspect_container(constant.TOP)
+ self.assertIn(container["State"]["Status"],"stopped exited",)
+
+ def test_restart_container(self):
+ # Restart bogus container
+ with self.assertRaises(requests.HTTPError) as error:
+ client.restart("dummy")
+ self.assertEqual(error.exception.response.status_code, 404)
+
+ # Validate the container state
+ client.stop(TestContainers.topContainerId)
+ container = client.inspect_container(constant.TOP)
+ self.assertEqual(container["State"]["Status"], "stopped")
+
+ # restart a running container and validate the state
+ client.restart(TestContainers.topContainerId)
+ container = client.inspect_container(constant.TOP)
+ self.assertEqual(container["State"]["Status"], "running")
+
+ def test_remove_container(self):
+ # Remove bogus container
+ with self.assertRaises(requests.HTTPError) as error:
+ client.remove_container("dummy")
+ self.assertEqual(error.exception.response.status_code, 404)
+
+ # Remove container by ID with force
+ client.remove_container(TestContainers.topContainerId, force=True)
+ containers = client.containers()
+ self.assertEqual(len(containers),0)
+
+ def test_remove_container_without_force(self):
+ # Validate current container count
+ containers = client.containers()
+ self.assertTrue(len(containers),1)
+
+ # Remove running container should throw error
+ with self.assertRaises(requests.HTTPError) as error:
+ client.remove_container(TestContainers.topContainerId)
+ self.assertEqual(error.exception.response.status_code, 500)
+
+ # Remove container by ID with force
+ client.stop(TestContainers.topContainerId)
+ client.remove_container(TestContainers.topContainerId)
+ containers = client.containers()
+ self.assertEqual(len(containers),0)
+
+ def test_pause_container(self):
+ # Pause bogus container
+ with self.assertRaises(requests.HTTPError) as error:
+ client.pause("dummy")
+ self.assertEqual(error.exception.response.status_code, 404)
+
+ # Validate the container state
+ container = client.inspect_container(constant.TOP)
+ self.assertEqual(container["State"]["Status"], "running")
+
+ # Pause a running container and validate the state
+ client.pause(container)
+ container = client.inspect_container(constant.TOP)
+ self.assertEqual(container["State"]["Status"], "paused")
+
+ def test_pause_stoped_container(self):
+ # Stop the container
+ client.stop(TestContainers.topContainerId)
+
+ # Pause exited container should trow error
+ with self.assertRaises(requests.HTTPError) as error:
+ client.pause(TestContainers.topContainerId)
+ self.assertEqual(error.exception.response.status_code, 500)
+
+
+ def test_unpause_container(self):
+ # Unpause bogus container
+ with self.assertRaises(requests.HTTPError) as error:
+ client.unpause("dummy")
+ self.assertEqual(error.exception.response.status_code, 404)
+
+ # Validate the container state
+ client.pause(TestContainers.topContainerId)
+ container = client.inspect_container(constant.TOP)
+ self.assertEqual(container["State"]["Status"], "paused")
+
+ # Pause a running container and validate the state
+ client.unpause(TestContainers.topContainerId)
+ container = client.inspect_container(constant.TOP)
+ self.assertEqual(container["State"]["Status"], "running")
+
+ def test_list_container(self):
+
+ # Add container and validate the count
+ client.create_container(image="alpine", detach=True)
+ containers = client.containers(all=True)
+ self.assertEqual(len(containers),2)
+
+ # Not working for now......checking
+ # # List container with filter by id
+ # filters = {'id':TestContainers.topContainerId}
+ # filteredContainers = client.containers(all=True,filters = filters)
+ # self.assertEqual(len(filteredContainers) , 1)
+
+ # # List container with filter by name
+ # filters = {'name':constant.TOP}
+ # filteredContainers = client.containers(all=True,filters = filters)
+ # self.assertEqual(len(filteredContainers) , 1)
+
+ @unittest.skip("Not Supported yet")
+ def test_rename_container(self):
+ # rename bogus container
+ with self.assertRaises(requests.HTTPError) as error:
+ client.rename(container="dummy", name="newname")
+ self.assertEqual(error.exception.response.status_code, 404)
diff --git a/test/dockerpy/images.py b/test/test_dockerpy/test_images.py
index 1e07d25c7..c88353b79 100644
--- a/test/dockerpy/images.py
+++ b/test/test_dockerpy/test_images.py
@@ -14,7 +14,7 @@ class TestImages(unittest.TestCase):
podman = None
def setUp(self):
super().setUp()
- client.pull(constant.ALPINE)
+ common.restore_image_from_cache(self)
def tearDown(self):
common.remove_all_images()
@@ -73,9 +73,8 @@ class TestImages(unittest.TestCase):
self.assertEqual(len(allImages), 1)
# Add more images
client.pull(constant.BB)
- client.pull(constant.NGINX)
allImages = client.images()
- self.assertEqual(len(allImages) , 3)
+ self.assertEqual(len(allImages) , 2)
# List images with filter
diff --git a/test/test_dockerpy/test_info_version.py b/test/test_dockerpy/test_info_version.py
new file mode 100644
index 000000000..be1a2aab9
--- /dev/null
+++ b/test/test_dockerpy/test_info_version.py
@@ -0,0 +1,46 @@
+import unittest
+import docker
+from docker import Client
+from . import constant
+from . import common
+
+client = common.get_client()
+
+class TestInfo_Version(unittest.TestCase):
+
+ podman = None
+ topContainerId = ""
+
+ def setUp(self):
+ super().setUp()
+ common.restore_image_from_cache(self)
+ TestInfo_Version.topContainerId = common.run_top_container()
+
+ def tearDown(self):
+ common.remove_all_containers()
+ common.remove_all_images()
+ return super().tearDown()
+
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+ common.enable_sock(cls)
+
+ @classmethod
+ def tearDownClass(cls):
+ common.terminate_connection(cls)
+ return super().tearDownClass()
+
+
+ def test_Info(self):
+ self.assertIsNotNone(client.info())
+
+ def test_info_container_details(self):
+ info = client.info()
+ self.assertEqual(info["Containers"],1)
+ client.create_container(image=constant.ALPINE)
+ info = client.info()
+ self.assertEqual(info["Containers"],2)
+
+ def test_version(self):
+ self.assertIsNotNone(client.version())