Skip to content

Commit 9fffb6c

Browse files
authored
Merge branch 'master' into become_chdir
2 parents 726ab79 + a51909e commit 9fffb6c

File tree

98 files changed

+1322
-848
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1322
-848
lines changed

.ci/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ for doing `setup.py install` while pulling a Docker container, for example.
2828

2929
### Environment Variables
3030

31-
* `TARGET_COUNT`: number of targets for `debops_` run. Defaults to 2.
3231
* `DISTRO`: the `mitogen_` tests need a target Docker container distro. This
3332
name comes from the Docker Hub `mitogen` user, i.e. `mitogen/$DISTRO-test`
3433
* `DISTROS`: the `ansible_` tests can run against multiple targets

.ci/ansible_install.py

-11
This file was deleted.

.ci/ansible_tests.py

+15-31
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
import os
77
import signal
88
import sys
9-
import textwrap
9+
10+
import jinja2
1011

1112
import ci_lib
1213

1314

15+
TEMPLATES_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible/templates')
1416
TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible')
1517
HOSTS_DIR = os.path.join(ci_lib.TMP, 'hosts')
1618

@@ -33,7 +35,7 @@ def pause_if_interactive():
3335

3436

3537
with ci_lib.Fold('docker_setup'):
36-
containers = ci_lib.make_containers()
38+
containers = ci_lib.container_specs(ci_lib.DISTROS)
3739
ci_lib.start_containers(containers)
3840

3941

@@ -52,37 +54,19 @@ def pause_if_interactive():
5254
distros[container['distro']].append(container['name'])
5355
families[container['family']].append(container['name'])
5456

57+
jinja_env = jinja2.Environment(
58+
loader=jinja2.FileSystemLoader(searchpath=TEMPLATES_DIR),
59+
lstrip_blocks=True, # Remove spaces and tabs from before a block
60+
trim_blocks=True, # Remove first newline after a block
61+
)
62+
inventory_template = jinja_env.get_template('test-targets.j2')
5563
inventory_path = os.path.join(HOSTS_DIR, 'target')
64+
5665
with open(inventory_path, 'w') as fp:
57-
fp.write('[test-targets]\n')
58-
fp.writelines(
59-
"%(name)s "
60-
"ansible_host=%(hostname)s "
61-
"ansible_port=%(port)s "
62-
"ansible_python_interpreter=%(python_path)s "
63-
"ansible_user=mitogen__has_sudo_nopw "
64-
"ansible_password=has_sudo_nopw_password"
65-
"\n"
66-
% container
67-
for container in containers
68-
)
69-
70-
for distro, hostnames in sorted(distros.items(), key=lambda t: t[0]):
71-
fp.write('\n[%s]\n' % distro)
72-
fp.writelines('%s\n' % name for name in hostnames)
73-
74-
for family, hostnames in sorted(families.items(), key=lambda t: t[0]):
75-
fp.write('\n[%s]\n' % family)
76-
fp.writelines('%s\n' % name for name in hostnames)
77-
78-
fp.write(textwrap.dedent(
79-
'''
80-
[linux:children]
81-
test-targets
82-
83-
[linux_containers:children]
84-
test-targets
85-
'''
66+
fp.write(inventory_template.render(
67+
containers=containers,
68+
distros=distros,
69+
families=families,
8670
))
8771

8872
ci_lib.dump_file(inventory_path)

.ci/azure-pipelines-steps.yml

+13-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ steps:
1414
versionSpec: '$(python.version)'
1515
condition: ne(variables['python.version'], '')
1616

17+
- script: |
18+
set -o errexit
19+
set -o nounset
20+
set -o pipefail
21+
22+
aws ecr-public get-login-password | docker login --username AWS --password-stdin public.ecr.aws
23+
displayName: Authenticate to container registry
24+
condition: eq(variables['Agent.OS'], 'Linux')
25+
env:
26+
AWS_ACCESS_KEY_ID: $(AWS_ACCESS_KEY_ID)
27+
AWS_SECRET_ACCESS_KEY: $(AWS_SECRET_ACCESS_KEY)
28+
AWS_DEFAULT_REGION: $(AWS_DEFAULT_REGION)
29+
1730
- script: |
1831
set -o errexit
1932
set -o nounset
@@ -90,7 +103,3 @@ steps:
90103
91104
"$PYTHON" -m tox -e "$(tox.env)"
92105
displayName: "Run tests"
93-
env:
94-
AWS_ACCESS_KEY_ID: $(AWS_ACCESS_KEY_ID)
95-
AWS_SECRET_ACCESS_KEY: $(AWS_SECRET_ACCESS_KEY)
96-
AWS_DEFAULT_REGION: $(AWS_DEFAULT_REGION)

.ci/azure-pipelines.yml

+11-19
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,26 @@ trigger:
1616
- docs-master
1717

1818
jobs:
19-
- job: mac11
19+
- job: mac12
2020
# vanilla Ansible is really slow
2121
timeoutInMinutes: 120
2222
steps:
2323
- template: azure-pipelines-steps.yml
2424
pool:
25-
# https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md
26-
vmImage: macOS-11
25+
# https://github.com/actions/runner-images/blob/main/images/macos/macos-12-Readme.md
26+
vmImage: macOS-12
2727
strategy:
2828
matrix:
29-
Mito_27:
30-
tox.env: py27-mode_mitogen
3129
Mito_312:
32-
python.version: '3.12'
3330
tox.env: py312-mode_mitogen
34-
35-
Loc_27_210:
36-
tox.env: py27-mode_localhost-ansible2.10
37-
Loc_312_9:
38-
python.version: '3.12'
39-
tox.env: py312-mode_localhost-ansible9
40-
41-
Van_27_210:
42-
tox.env: py27-mode_localhost-ansible2.10-strategy_linear
43-
Van_312_9:
44-
python.version: '3.12'
45-
tox.env: py312-mode_localhost-ansible9-strategy_linear
31+
Loc_312_10:
32+
tox.env: py312-mode_localhost-ansible10
33+
Van_312_10:
34+
tox.env: py312-mode_localhost-ansible10-strategy_linear
4635

4736
- job: Linux
4837
pool:
49-
# https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2004-Readme.md
38+
# https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2004-Readme.md
5039
vmImage: ubuntu-20.04
5140
steps:
5241
- template: azure-pipelines-steps.yml
@@ -163,3 +152,6 @@ jobs:
163152
Ans_312_9:
164153
python.version: '3.12'
165154
tox.env: py312-mode_ansible-ansible9
155+
Ans_312_10:
156+
python.version: '3.12'
157+
tox.env: py312-mode_ansible-ansible10

.ci/ci_lib.py

+29-19
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
)
2828
)
2929

30+
31+
IMAGE_TEMPLATE = os.environ.get(
32+
'MITOGEN_TEST_IMAGE_TEMPLATE',
33+
'public.ecr.aws/n5z0e8q9/%(distro)s-test',
34+
)
35+
36+
3037
_print = print
3138
def print(*args, **kwargs):
3239
file = kwargs.get('file', sys.stdout)
@@ -193,8 +200,6 @@ def __exit__(self, _1, _2, _3): pass
193200
DISTRO = os.environ.get('DISTRO', 'debian9')
194201
# Used only when MODE=ansible
195202
DISTROS = os.environ.get('DISTROS', 'centos6 centos8 debian9 debian11 ubuntu1604 ubuntu2004').split()
196-
TARGET_COUNT = int(os.environ.get('TARGET_COUNT', '2'))
197-
BASE_PORT = 2200
198203
TMP = TempDir().path
199204

200205

@@ -217,6 +222,7 @@ def __exit__(self, _1, _2, _3): pass
217222
def get_docker_hostname():
218223
"""Return the hostname where the docker daemon is running.
219224
"""
225+
# Duplicated in testlib
220226
url = os.environ.get('DOCKER_HOST')
221227
if url in (None, 'http+docker://localunixsocket'):
222228
return 'localhost'
@@ -225,27 +231,34 @@ def get_docker_hostname():
225231
return parsed.netloc.partition(':')[0]
226232

227233

228-
def make_containers(name_prefix='', port_offset=0):
234+
def container_specs(
235+
distros,
236+
base_port=2200,
237+
image_template=IMAGE_TEMPLATE,
238+
name_template='target-%(distro)s-%(index)d',
239+
):
229240
"""
230241
>>> import pprint
231-
>>> BASE_PORT=2200; DISTROS=['debian11', 'centos6']
232-
>>> pprint.pprint(make_containers())
242+
>>> pprint.pprint(container_specs(['debian11-py3', 'centos6']))
233243
[{'distro': 'debian11',
234244
'family': 'debian',
235245
'hostname': 'localhost',
236246
'image': 'public.ecr.aws/n5z0e8q9/debian11-test',
247+
'index': 1,
237248
'name': 'target-debian11-1',
238249
'port': 2201,
239-
'python_path': '/usr/bin/python'},
250+
'python_path': '/usr/bin/python3'},
240251
{'distro': 'centos6',
241252
'family': 'centos',
242253
'hostname': 'localhost',
243254
'image': 'public.ecr.aws/n5z0e8q9/centos6-test',
255+
'index': 2,
244256
'name': 'target-centos6-2',
245257
'port': 2202,
246258
'python_path': '/usr/bin/python'}]
247259
"""
248260
docker_hostname = get_docker_hostname()
261+
# Code duplicated in testlib.py, both should be updated together
249262
distro_pattern = re.compile(r'''
250263
(?P<distro>(?P<family>[a-z]+)[0-9]+)
251264
(?:-(?P<py>py3))?
@@ -256,30 +269,27 @@ def make_containers(name_prefix='', port_offset=0):
256269
i = 1
257270
lst = []
258271

259-
for distro in DISTROS:
272+
for distro in distros:
273+
# Code duplicated in testlib.py, both should be updated together
260274
d = distro_pattern.match(distro).groupdict(default=None)
261-
distro = d['distro']
262-
family = d['family']
263-
image = 'public.ecr.aws/n5z0e8q9/%s-test' % (distro,)
264275

265-
if d['py'] == 'py3':
276+
if d.pop('py') == 'py3':
266277
python_path = '/usr/bin/python3'
267278
else:
268279
python_path = '/usr/bin/python'
269280

270-
if d['count']:
271-
count = int(count)
272-
else:
273-
count = 1
281+
count = int(d.pop('count') or '1', 10)
274282

275283
for x in range(count):
276-
lst.append({
277-
"distro": distro, "family": family, "image": image,
278-
"name": name_prefix + ("target-%s-%s" % (distro, i)),
284+
d['index'] = i
285+
d.update({
286+
'image': image_template % d,
287+
'name': name_template % d,
279288
"hostname": docker_hostname,
280-
"port": BASE_PORT + i + port_offset,
289+
'port': base_port + i,
281290
"python_path": python_path,
282291
})
292+
lst.append(d)
283293
i += 1
284294

285295
return lst

.ci/debops_common_install.py

-6
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,10 @@
22

33
import ci_lib
44

5-
# Naturally DebOps only supports Debian.
6-
ci_lib.DISTROS = ['debian']
7-
85
ci_lib.run_batches([
96
[
107
'python -m pip --no-python-version-warning --disable-pip-version-check "debops[ansible]==2.1.2"',
118
],
12-
[
13-
'aws ecr-public get-login-password | docker login --username AWS --password-stdin public.ecr.aws',
14-
],
159
])
1610

1711
ci_lib.run('ansible-galaxy collection install debops.debops:==2.1.2')

.ci/debops_common_tests.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@
66
import ci_lib
77

88

9-
# DebOps only supports Debian.
10-
ci_lib.DISTROS = ['debian'] * ci_lib.TARGET_COUNT
11-
129
project_dir = os.path.join(ci_lib.TMP, 'project')
1310
vars_path = 'ansible/inventory/group_vars/debops_all_hosts.yml'
1411
inventory_path = 'ansible/inventory/hosts'
1512
docker_hostname = ci_lib.get_docker_hostname()
1613

1714

1815
with ci_lib.Fold('docker_setup'):
19-
containers = ci_lib.make_containers(port_offset=500, name_prefix='debops-')
16+
containers = ci_lib.container_specs(
17+
['debian*2'],
18+
base_port=2700,
19+
name_template='debops-target-%(distro)s-%(index)d',
20+
)
2021
ci_lib.start_containers(containers)
2122

2223

.ci/localhost_ansible_install.py

-8
This file was deleted.

.ci/mitogen_install.py

-14
This file was deleted.

.ci/mitogen_py24_install.py

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
import ci_lib
44

55
batches = [
6-
[
7-
'aws ecr-public get-login-password | docker login --username AWS --password-stdin public.ecr.aws',
8-
],
96
[
107
'curl https://dw.github.io/mitogen/binaries/ubuntu-python-2.4.6.tar.bz2 | sudo tar -C / -jxv',
118
]

0 commit comments

Comments
 (0)