diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2022-03-01 15:20:38 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-01 15:20:38 -0500 |
commit | f0c6114a3949a4b1617c5472e70e933fa2bd5c82 (patch) | |
tree | 6a9bbe929dd0b726a46b223c2b93e065f1d0034c /test/python/docker/__init__.py | |
parent | 8bdda91ab738d634528259581c8adebe1db007b4 (diff) | |
parent | 7729afe9793632673c978b347ccbd999b5152042 (diff) | |
download | podman-f0c6114a3949a4b1617c5472e70e933fa2bd5c82.tar.gz podman-f0c6114a3949a4b1617c5472e70e933fa2bd5c82.tar.bz2 podman-f0c6114a3949a4b1617c5472e70e933fa2bd5c82.zip |
Merge pull request #13380 from jwhonce/wip/docker-py
Refactor docker-py compatibility tests
Diffstat (limited to 'test/python/docker/__init__.py')
-rw-r--r-- | test/python/docker/__init__.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/test/python/docker/__init__.py b/test/python/docker/__init__.py index 816667b82..d46f465f7 100644 --- a/test/python/docker/__init__.py +++ b/test/python/docker/__init__.py @@ -1,4 +1,6 @@ -import configparser +""" +Helpers for integration tests using DockerClient +""" import json import os import pathlib @@ -11,7 +13,7 @@ from docker import DockerClient from .compat import constant -class Podman(object): +class PodmanAPI: """ Instances hold the configuration and setup for running podman commands """ @@ -53,17 +55,13 @@ location = "mirror.localhost:5000" """ - with open(os.environ["CONTAINERS_REGISTRIES_CONF"], "w") as w: - w.write(conf) + with open(os.environ["CONTAINERS_REGISTRIES_CONF"], "w") as file: + file.write(conf) - os.environ["CNI_CONFIG_PATH"] = os.path.join( - self.anchor_directory, "cni", "net.d" - ) + os.environ["CNI_CONFIG_PATH"] = os.path.join(self.anchor_directory, "cni", "net.d") os.makedirs(os.environ["CNI_CONFIG_PATH"], exist_ok=True) self.cmd.append("--network-config-dir=" + os.environ["CNI_CONFIG_PATH"]) - cni_cfg = os.path.join( - os.environ["CNI_CONFIG_PATH"], "87-podman-bridge.conflist" - ) + cni_cfg = os.path.join(os.environ["CNI_CONFIG_PATH"], "87-podman-bridge.conflist") # json decoded and encoded to ensure legal json buf = json.loads( """ @@ -93,8 +91,8 @@ location = "mirror.localhost:5000" } """ ) - with open(cni_cfg, "w") as w: - json.dump(buf, w) + with open(cni_cfg, "w") as file: + json.dump(buf, file) def open(self, command, *args, **kwargs): """Podman initialized instance to run a given command @@ -111,6 +109,7 @@ location = "mirror.localhost:5000" shell = kwargs.get("shell", False) + # pylint: disable=consider-using-with return subprocess.Popen( cmd, shell=shell, @@ -144,9 +143,11 @@ location = "mirror.localhost:5000" ) def tear_down(self): + """Delete test environment.""" shutil.rmtree(self.anchor_directory, ignore_errors=True) def restore_image_from_cache(self, client: DockerClient): + """Populate images from cache.""" path = os.path.join(self.image_cache, constant.ALPINE_TARBALL) if not os.path.exists(path): img = client.images.pull(constant.ALPINE) @@ -157,5 +158,6 @@ location = "mirror.localhost:5000" self.run("load", "-i", path, check=True) def flush_image_cache(self): - for f in pathlib.Path(self.image_cache).glob("*.tar"): - f.unlink(f) + """Delete image cache.""" + for file in pathlib.Path(self.image_cache).glob("*.tar"): + file.unlink(missing_ok=True) |