diff options
| author | zhangguanzhang <guanzhangzhang@gmail.com> | 2020-06-12 19:54:10 +0800 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-12 19:54:10 +0800 | 
| commit | 64eae15aa7905dd49f4a348f6b4765dfb4d9dd91 (patch) | |
| tree | 2914c20a2e0e15383da50334cad89b9b85b209a1 /test/dockerpy/common.py | |
| parent | 3218736cff4b718b8fe855759687cb66f19d6e1e (diff) | |
| parent | 8aa5cf3d45998bc92eaafd67ab2a59e3722bade4 (diff) | |
| download | podman-64eae15aa7905dd49f4a348f6b4765dfb4d9dd91.tar.gz podman-64eae15aa7905dd49f4a348f6b4765dfb4d9dd91.tar.bz2 podman-64eae15aa7905dd49f4a348f6b4765dfb4d9dd91.zip  | |
Merge pull request #1 from containers/master
# sync
Diffstat (limited to 'test/dockerpy/common.py')
| -rw-r--r-- | test/dockerpy/common.py | 64 | 
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)  | 
