17
17
from pytest_container .pod import Pod , PodData , PodLauncher
18
18
from testinfra .host import Host
19
19
20
+ # we want to have useful pod/container names for interactive debugging and log dumping, but still allow parallel tests
21
+ # (with e.g. xdist) so disambiguate them with the pid
22
+ TEST_INSTANCE = str (os .getpid ())
23
+
20
24
TASKS_IMAGE = os .environ .get ('TASKS_IMAGE' , 'ghcr.io/cockpit-project/tasks:latest' )
21
25
ROOT_DIR = Path (__file__ ).parent .parent
22
26
COMMON_LAUNCH_ARGS = ['--stop-timeout=0' , '--security-opt=label=disable' ]
@@ -113,7 +117,7 @@ def pod(config: Config, pytestconfig) -> PodData:
113
117
# RabbitMQ
114
118
containers .append (Container (
115
119
url = 'docker.io/rabbitmq' ,
116
- extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , 'cockpituous-rabbitmq' ],
120
+ extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , f 'cockpituous-rabbitmq- { TEST_INSTANCE } ' ],
117
121
volume_mounts = [
118
122
BindMount ('/etc/rabbitmq' , host_path = config .rabbitmq , flags = [VolumeFlag .READ_ONLY ]),
119
123
BindMount ('/run/secrets/webhook' , host_path = config .webhook , flags = [VolumeFlag .READ_ONLY ]),
@@ -123,7 +127,7 @@ def pod(config: Config, pytestconfig) -> PodData:
123
127
# minio S3 store
124
128
containers .append (Container (
125
129
url = 'quay.io/minio/minio' ,
126
- extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , 'cockpituous-s3' ],
130
+ extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , f 'cockpituous-s3- { TEST_INSTANCE } ' ],
127
131
# that's what we want, but not in latest release yet: https://github.com/dcermak/pytest_container/issues/182
128
132
# extra_entrypoint_args=['server', '/data', '--console-address', ':9001'],
129
133
entry_point = EntrypointSelection .BASH ,
@@ -143,7 +147,7 @@ def pod(config: Config, pytestconfig) -> PodData:
143
147
containers .append (Container (
144
148
url = 'quay.io/minio/mc' ,
145
149
custom_entry_point = '/bin/sh' ,
146
- extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , 'cockpituous-mc' ],
150
+ extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , f 'cockpituous-mc- { TEST_INSTANCE } ' ],
147
151
volume_mounts = [
148
152
BindMount ('/etc/pki/ca-trust/source/anchors/ca.pem' , host_path = config .secrets / 'ca.pem' ,
149
153
flags = [VolumeFlag .READ_ONLY ]),
@@ -153,7 +157,7 @@ def pod(config: Config, pytestconfig) -> PodData:
153
157
# tasks
154
158
containers .append (Container (
155
159
url = TASKS_IMAGE ,
156
- extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , 'cockpituous-tasks' ],
160
+ extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , f 'cockpituous-tasks- { TEST_INSTANCE } ' ],
157
161
volume_mounts = [
158
162
BindMount ('/run/secrets/webhook' , host_path = config .webhook , flags = [VolumeFlag .READ_ONLY ]),
159
163
BindMount ('/run/secrets/tasks' , host_path = config .tasks , flags = [VolumeFlag .READ_ONLY ]),
@@ -186,7 +190,7 @@ def pod(config: Config, pytestconfig) -> PodData:
186
190
if have_webhook_container :
187
191
containers .append (Container (
188
192
url = TASKS_IMAGE ,
189
- extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , 'cockpituous-webhook' ],
193
+ extra_launch_args = [* COMMON_LAUNCH_ARGS , '--name' , f 'cockpituous-webhook- { TEST_INSTANCE } ' ],
190
194
# that's what we want, but https://github.com/dcermak/pytest_container/issues/182
191
195
# extra_entrypoint_args=['webhook'],
192
196
volume_mounts = [
@@ -203,8 +207,9 @@ def pod(config: Config, pytestconfig) -> PodData:
203
207
containers = containers ,
204
208
forwarded_ports = [
205
209
# BUG: host_port= would be nice to make S3 log URLs work; but it has no effect:
206
- # https://github.com/dcermak/pytest_container/issues/190
207
- PortForwarding (container_port = 9000 , host_port = 9000 ), # S3
210
+ # https://github.com/dcermak/pytest_container/issues/190; but also, we want to keep the test
211
+ # parallel-friendly
212
+ PortForwarding (container_port = 9000 ), # S3
208
213
PortForwarding (container_port = 9001 ), # minio console
209
214
]
210
215
)
@@ -215,7 +220,8 @@ def pod(config: Config, pytestconfig) -> PodData:
215
220
for c in containers :
216
221
c ._is_local = True
217
222
218
- with PodLauncher (pod_cockpituous , rootdir = pytestconfig .rootpath , pod_name = 'cockpituous' ) as launcher :
223
+ with PodLauncher (pod_cockpituous , rootdir = pytestconfig .rootpath ,
224
+ pod_name = f'cockpituous-{ TEST_INSTANCE } ' ) as launcher :
219
225
launcher .launch_pod ()
220
226
221
227
# run minio in lieu of extra_entrypoint_args
0 commit comments