|
4 | 4 | import atexit |
5 | 5 | import errno |
6 | 6 | import os |
| 7 | +import re |
7 | 8 | import shlex |
8 | 9 | import shutil |
9 | 10 | import sys |
@@ -221,63 +222,60 @@ def get_docker_hostname(): |
221 | 222 | return parsed.netloc.partition(':')[0] |
222 | 223 |
|
223 | 224 |
|
224 | | -def image_for_distro(distro): |
225 | | - """Return the container image name or path for a test distro name. |
226 | | -
|
227 | | - The returned value is suitable for use with `docker pull`. |
228 | | -
|
229 | | - >>> image_for_distro('centos5') |
230 | | - 'public.ecr.aws/n5z0e8q9/centos5-test' |
231 | | - >>> image_for_distro('centos5-something_custom') |
232 | | - 'public.ecr.aws/n5z0e8q9/centos5-test' |
233 | | - """ |
234 | | - return 'public.ecr.aws/n5z0e8q9/%s-test' % (distro.partition('-')[0],) |
235 | | - |
236 | | - |
237 | 225 | def make_containers(name_prefix='', port_offset=0): |
238 | 226 | """ |
239 | 227 | >>> import pprint |
240 | | - >>> BASE_PORT=2200; DISTROS=['debian', 'centos6'] |
| 228 | + >>> BASE_PORT=2200; DISTROS=['debian11', 'centos6'] |
241 | 229 | >>> pprint.pprint(make_containers()) |
242 | | - [{'distro': 'debian', |
| 230 | + [{'distro': 'debian11', |
| 231 | + 'family': 'debian', |
243 | 232 | 'hostname': 'localhost', |
244 | | - 'image': 'public.ecr.aws/n5z0e8q9/debian-test', |
245 | | - 'name': 'target-debian-1', |
| 233 | + 'image': 'public.ecr.aws/n5z0e8q9/debian11-test', |
| 234 | + 'name': 'target-debian11-1', |
246 | 235 | 'port': 2201, |
247 | 236 | 'python_path': '/usr/bin/python'}, |
248 | 237 | {'distro': 'centos6', |
| 238 | + 'family': 'centos', |
249 | 239 | 'hostname': 'localhost', |
250 | 240 | 'image': 'public.ecr.aws/n5z0e8q9/centos6-test', |
251 | 241 | 'name': 'target-centos6-2', |
252 | 242 | 'port': 2202, |
253 | 243 | 'python_path': '/usr/bin/python'}] |
254 | 244 | """ |
255 | 245 | docker_hostname = get_docker_hostname() |
256 | | - firstbit = lambda s: (s+'-').split('-')[0] |
257 | | - secondbit = lambda s: (s+'-').split('-')[1] |
258 | | - |
| 246 | + distro_pattern = re.compile(r''' |
| 247 | + (?P<distro>(?P<family>[a-z]+)[0-9]+) |
| 248 | + (?:-(?P<py>py3))? |
| 249 | + (?:\*(?P<count>[0-9]+))? |
| 250 | + ''', |
| 251 | + re.VERBOSE, |
| 252 | + ) |
259 | 253 | i = 1 |
260 | 254 | lst = [] |
261 | 255 |
|
262 | 256 | for distro in DISTROS: |
263 | | - distro, star, count = distro.partition('*') |
264 | | - if star: |
| 257 | + d = distro_pattern.match(distro).groupdict(default=None) |
| 258 | + distro = d['distro'] |
| 259 | + family = d['family'] |
| 260 | + image = 'public.ecr.aws/n5z0e8q9/%s-test' % (distro,) |
| 261 | + |
| 262 | + if d['py'] == 'py3': |
| 263 | + python_path = '/usr/bin/python3' |
| 264 | + else: |
| 265 | + python_path = '/usr/bin/python' |
| 266 | + |
| 267 | + if d['count']: |
265 | 268 | count = int(count) |
266 | 269 | else: |
267 | 270 | count = 1 |
268 | 271 |
|
269 | 272 | for x in range(count): |
270 | 273 | lst.append({ |
271 | | - "distro": firstbit(distro), |
272 | | - "image": image_for_distro(distro), |
| 274 | + "distro": distro, "family": family, "image": image, |
273 | 275 | "name": name_prefix + ("target-%s-%s" % (distro, i)), |
274 | 276 | "hostname": docker_hostname, |
275 | 277 | "port": BASE_PORT + i + port_offset, |
276 | | - "python_path": ( |
277 | | - '/usr/bin/python3' |
278 | | - if secondbit(distro) == 'py3' |
279 | | - else '/usr/bin/python' |
280 | | - ) |
| 278 | + "python_path": python_path, |
281 | 279 | }) |
282 | 280 | i += 1 |
283 | 281 |
|
|
0 commit comments