-
Notifications
You must be signed in to change notification settings - Fork 21
/
conftest.py
87 lines (72 loc) · 2.17 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import subprocess
from os import path
import pytest
import testinfra
TUMBLEWEED_CONTAINER = ["registry.opensuse.org/opensuse/tumbleweed:latest"]
LEAP_CONTAINERS = [
"registry.opensuse.org/opensuse/leap:15.3",
"registry.opensuse.org/opensuse/leap:15.2",
]
SLE_CONTAINERS = [
"registry.suse.com/suse/sle15:15.3",
"registry.suse.com/suse/sle15:15.2",
"registry.suse.com/suse/sle15:15.1",
"registry.suse.com/suse/sles12sp5:latest",
]
CONTAINER_IMAGES = TUMBLEWEED_CONTAINER + LEAP_CONTAINERS + SLE_CONTAINERS
CONTAINER_IMAGE_CHOICES = {
"tumbleweed": TUMBLEWEED_CONTAINER,
"leap": LEAP_CONTAINERS,
"sle": SLE_CONTAINERS,
}
def pytest_addoption(parser):
parser.addoption(
"--container",
help="container images to run the tests against",
nargs="+",
default=CONTAINER_IMAGES,
)
def pytest_generate_tests(metafunc):
if "container" in metafunc.fixturenames:
containers = metafunc.config.getoption("container")
images = []
distros = list(CONTAINER_IMAGE_CHOICES.keys())
for opt in containers:
if opt in distros:
for img in CONTAINER_IMAGE_CHOICES[opt]:
images.append(img)
else:
images.append(opt)
metafunc.parametrize("container", images, indirect=True)
@pytest.fixture(scope="session")
def container(request):
container_url = getattr(request, "param", TUMBLEWEED_CONTAINER[0])
container_id = (
subprocess.check_output(
[
"podman",
"run",
"-d",
"-it",
container_url,
"/bin/sh",
]
)
.decode()
.strip()
)
subprocess.check_call(
[
"podman",
"cp",
path.abspath(
path.join(
path.dirname(__file__),
"update-ca-certificates",
)
),
container_id + ":" + "/bin/update-ca-certificates",
],
)
yield testinfra.get_host(f"podman://{container_id}")
subprocess.check_call(["podman", "rm", "-f", container_id])