summaryrefslogtreecommitdiff
path: root/test/dockerpy/common.py
diff options
context:
space:
mode:
authorSujil02 <sushah@redhat.com>2020-06-07 22:25:31 -0400
committerSujil02 <sushah@redhat.com>2020-06-07 22:27:01 -0400
commit37428df4c2ea947a0ae663da5196eb17a8c6c040 (patch)
tree6d67cf6c02233068b9128faa1ad817491517df62 /test/dockerpy/common.py
parent1fcb6788a5d7471a7ca6215a40e36e21812a0f6e (diff)
downloadpodman-37428df4c2ea947a0ae663da5196eb17a8c6c040.tar.gz
podman-37428df4c2ea947a0ae663da5196eb17a8c6c040.tar.bz2
podman-37428df4c2ea947a0ae663da5196eb17a8c6c040.zip
Modify py test to start stop system service for each test
Start stop system service for each test class to make it east to integrate to CI Adds more tests Add some common methods shared between images and containers test. Signed-off-by: Sujil02 <sushah@redhat.com>
Diffstat (limited to 'test/dockerpy/common.py')
-rw-r--r--test/dockerpy/common.py64
1 files changed, 63 insertions, 1 deletions
diff --git a/test/dockerpy/common.py b/test/dockerpy/common.py
index 767a94ec0..fdacb49be 100644
--- a/test/dockerpy/common.py
+++ b/test/dockerpy/common.py
@@ -1,6 +1,68 @@
import docker
+import subprocess
+import os
+import sys
+import time
from docker import Client
+from . import constant
+alpineDict = {
+ "name": "docker.io/library/alpine:latest",
+ "shortName": "alpine",
+ "tarballName": "alpine.tar"}
def get_client():
- return docker.Client(base_url="unix:/run/podman/podman.sock")
+ client = docker.Client(base_url="http://localhost:8080",timeout=15)
+ return client
+
+client = get_client()
+
+def podman():
+ binary = os.getenv("PODMAN_BINARY")
+ if binary is None:
+ binary = "bin/podman"
+ return binary
+
+def restore_image_from_cache():
+ client.load_image(constant.ImageCacheDir+alpineDict["tarballName"])
+
+def run_top_container():
+ client.pull(constant.ALPINE)
+ c = client.create_container(constant.ALPINE,name=constant.TOP)
+ client.start(container=c.get("Id"))
+
+def enable_sock(TestClass):
+ TestClass.podman = subprocess.Popen(
+ [
+ podman(), "system", "service", "tcp:localhost:8080",
+ "--log-level=debug", "--time=0"
+ ],
+ shell=False,
+ stdin=subprocess.DEVNULL,
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ )
+ time.sleep(2)
+
+def terminate_connection(TestClass):
+ TestClass.podman.terminate()
+ stdout, stderr = TestClass.podman.communicate(timeout=0.5)
+ if stdout:
+ print("\nService Stdout:\n" + stdout.decode('utf-8'))
+ if stderr:
+ print("\nService Stderr:\n" + stderr.decode('utf-8'))
+
+ if TestClass.podman.returncode > 0:
+ sys.stderr.write("podman exited with error code {}\n".format(
+ TestClass.podman.returncode))
+ sys.exit(2)
+
+def remove_all_containers():
+ containers = client.containers(quiet=True)
+ for c in containers:
+ client.remove_container(container=c.get("Id"), force=True)
+
+def remove_all_images():
+ allImages = client.images()
+ for image in allImages:
+ client.remove_image(image,force=True)