summaryrefslogtreecommitdiff
path: root/test/python/docker/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/python/docker/__init__.py')
-rw-r--r--test/python/docker/__init__.py30
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)