mirror of
https://github.com/containers/podman.git
synced 2025-05-21 00:56:36 +08:00
Refactor docker-py compatibility tests
* Add which python client is being used to run tests, see "python client" below. * Remove redundate code from test classes * Update/Add comments to modules and classes ======================================================= test session starts ======================================================== platform linux -- Python 3.10.0, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 python client -- DockerClient rootdir: /home/jhonce/Projects/go/src/github.com/containers/podman plugins: requests-mock-1.8.0 collected 33 items test/python/docker/compat/test_containers.py ...s.............. [ 54%] test/python/docker/compat/test_images.py ............ [ 90%] test/python/docker/compat/test_system.py ... [100%] Note: Follow-up PRs will verify the test results and expand the tests. Signed-off-by: Jhon Honce <jhonce@redhat.com>
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user