Skip to content

Commit 28e08ef

Browse files
committed
ci: Reduce number of Jobs by parameterizing Mitogen Docker SSH tests
This reduces the number of jobs from 48 to 24. The Mitogen part of the test suite has been parameterized on the Linux container targets to be run against. Both the Ansible tests & Mitogen tests now use the same source of truth to control which targets to use: environment variable MITOGEN_TEST_DISTRO_SPECS. This replaces the two mutually exclusive env vars DISTRO and DISTROS. I've also removed vestgial traces of an unused env var MITOGEN_TEST_DISTRO. Parameterization adapted from https://eli.thegreenplace.net/2014/04/02/dynamically-generating-python-test-cases refs #1058, #1059
1 parent 9859e44 commit 28e08ef

File tree

13 files changed

+101
-138
lines changed

13 files changed

+101
-138
lines changed

.ci/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ for doing `setup.py install` while pulling a Docker container, for example.
2828

2929
### Environment Variables
3030

31-
* `DISTRO`: the `mitogen_` tests need a target Docker container distro. This
32-
name comes from the Docker Hub `mitogen` user, i.e. `mitogen/$DISTRO-test`
33-
* `DISTROS`: the `ansible_` tests can run against multiple targets
34-
simultaneously, which speeds things up. This is a space-separated list of
35-
DISTRO names, but additionally, supports:
31+
* `MITOGEN_TEST_DISTRO_SPECS`: a space delimited list of distro specs to run
32+
the tests against. (e.g. `centos6 ubuntu2004-py3*4`). Each spec determines
33+
the Linux distribution, target Python interepreter & number of instances.
34+
Only distributions with a pre-built Linux container image can be used.
3635
* `debian-py3`: when generating Ansible inventory file, set
3736
`ansible_python_interpreter` to `python3`, i.e. run a test where the
3837
target interpreter is Python 3.
3938
* `debian*16`: generate 16 Docker containers running Debian. Also works
4039
with -py3.
4140

41+
* `MITOGEN_TEST_IMAGE_TEMPLATE`: specifies the Linux container image name,
42+
and hence the container registry used for test targets.

.ci/ansible_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def pause_if_interactive():
3535

3636

3737
with ci_lib.Fold('docker_setup'):
38-
containers = ci_lib.container_specs(ci_lib.DISTROS)
38+
containers = ci_lib.container_specs(ci_lib.DISTRO_SPECS.split())
3939
ci_lib.start_containers(containers)
4040

4141

.ci/ci_lib.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
)
2929

3030

31+
DISTRO_SPECS = os.environ.get(
32+
'MITOGEN_TEST_DISTRO_SPECS',
33+
'centos6 centos8 debian9 debian11 ubuntu1604 ubuntu2004',
34+
)
3135
IMAGE_TEMPLATE = os.environ.get(
3236
'MITOGEN_TEST_IMAGE_TEMPLATE',
3337
'public.ecr.aws/n5z0e8q9/%(distro)s-test',
@@ -196,10 +200,6 @@ def __exit__(self, _1, _2, _3): pass
196200

197201

198202
GIT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
199-
# Used only when MODE=mitogen
200-
DISTRO = os.environ.get('DISTRO', 'debian9')
201-
# Used only when MODE=ansible
202-
DISTROS = os.environ.get('DISTROS', 'centos6 centos8 debian9 debian11 ubuntu1604 ubuntu2004').split()
203203
TMP = TempDir().path
204204

205205

.ci/mitogen_py24_tests.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
os.environ.update({
99
'NOCOVERAGE': '1',
1010
'UNIT2': '/usr/local/python2.4.6/bin/unit2',
11-
12-
'MITOGEN_TEST_DISTRO': ci_lib.DISTRO,
1311
'MITOGEN_LOG_LEVEL': 'debug',
1412
'SKIP_ANSIBLE': '1',
1513
})

.ci/mitogen_tests.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import ci_lib
77

88
os.environ.update({
9-
'MITOGEN_TEST_DISTRO': ci_lib.DISTRO,
109
'MITOGEN_LOG_LEVEL': 'debug',
1110
'SKIP_ANSIBLE': '1',
1211
})

.github/workflows/tests.yml

Lines changed: 6 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -67,80 +67,14 @@ jobs:
6767
python_version: '3.13'
6868
tox_env: py313-mode_ansible-ansible10-strategy_linear
6969

70-
- name: Mito_27_centos6
71-
tox_env: py27-mode_mitogen-distro_centos6
72-
- name: Mito_27_centos7
73-
tox_env: py27-mode_mitogen-distro_centos7
74-
- name: Mito_27_centos8
75-
tox_env: py27-mode_mitogen-distro_centos8
76-
- name: Mito_27_debian9
77-
tox_env: py27-mode_mitogen-distro_debian9
78-
- name: Mito_27_debian10
79-
tox_env: py27-mode_mitogen-distro_debian10
80-
- name: Mito_27_debian11
81-
tox_env: py27-mode_mitogen-distro_debian11
82-
- name: Mito_27_ubuntu1604
83-
tox_env: py27-mode_mitogen-distro_ubuntu1604
84-
- name: Mito_27_ubuntu1804
85-
tox_env: py27-mode_mitogen-distro_ubuntu1804
86-
- name: Mito_27_ubuntu2004
87-
tox_env: py27-mode_mitogen-distro_ubuntu2004
88-
89-
- name: Mito_36_centos6
90-
python_version: '3.6'
91-
tox_env: py36-mode_mitogen-distro_centos6
92-
- name: Mito_36_centos7
93-
python_version: '3.6'
94-
tox_env: py36-mode_mitogen-distro_centos7
95-
- name: Mito_36_centos8
96-
python_version: '3.6'
97-
tox_env: py36-mode_mitogen-distro_centos8
98-
- name: Mito_36_debian9
99-
python_version: '3.6'
100-
tox_env: py36-mode_mitogen-distro_debian9
101-
- name: Mito_36_debian10
102-
python_version: '3.6'
103-
tox_env: py36-mode_mitogen-distro_debian10
104-
- name: Mito_36_debian11
105-
python_version: '3.6'
106-
tox_env: py36-mode_mitogen-distro_debian11
107-
- name: Mito_36_ubuntu1604
108-
python_version: '3.6'
109-
tox_env: py36-mode_mitogen-distro_ubuntu1604
110-
- name: Mito_36_ubuntu1804
111-
python_version: '3.6'
112-
tox_env: py36-mode_mitogen-distro_ubuntu1804
113-
- name: Mito_36_ubuntu2004
70+
- name: Mito_27
71+
tox_env: py27-mode_mitogen
72+
- name: Mito_36
11473
python_version: '3.6'
115-
tox_env: py36-mode_mitogen-distro_ubuntu2004
116-
117-
- name: Mito_313_centos6
118-
python_version: '3.13'
119-
tox_env: py313-mode_mitogen-distro_centos6
120-
- name: Mito_313_centos7
121-
python_version: '3.13'
122-
tox_env: py313-mode_mitogen-distro_centos7
123-
- name: Mito_313_centos8
124-
python_version: '3.13'
125-
tox_env: py313-mode_mitogen-distro_centos8
126-
- name: Mito_313_debian9
127-
python_version: '3.13'
128-
tox_env: py313-mode_mitogen-distro_debian9
129-
- name: Mito_313_debian10
130-
python_version: '3.13'
131-
tox_env: py313-mode_mitogen-distro_debian10
132-
- name: Mito_313_debian11
133-
python_version: '3.13'
134-
tox_env: py313-mode_mitogen-distro_debian11
135-
- name: Mito_313_ubuntu1604
136-
python_version: '3.13'
137-
tox_env: py313-mode_mitogen-distro_ubuntu1604
138-
- name: Mito_313_ubuntu1804
139-
python_version: '3.13'
140-
tox_env: py313-mode_mitogen-distro_ubuntu1804
141-
- name: Mito_313_ubuntu2004
74+
tox_env: py36-mode_mitogen
75+
- name: Mito_313
14276
python_version: '3.13'
143-
tox_env: py313-mode_mitogen-distro_ubuntu2004
77+
tox_env: py313-mode_mitogen
14478

14579
steps:
14680
- uses: actions/checkout@v4

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ To avail of fixes in an unreleased version, please download a ZIP file
2121
In progress (unreleased)
2222
------------------------
2323

24+
* :gh:issue:`1159` CI: Reduce number of Jobs by parameterizing Mitogen Docker
25+
SSH tests
2426

2527

2628
v0.3.13 (2024-10-09)

tests/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,19 @@ and run the tests there.
3030
1. Run ``test``
3131

3232

33-
# Selecting a target distribution
33+
# Selecting target distributions
3434

35-
Docker target images exist for testing against CentOS and Debian, with the
36-
default being Debian. To select CentOS, specify `MITOGEN_TEST_DISTRO=centos` in
37-
the environment.
35+
Linux container images for testing are available at
36+
37+
- https://github.com/orgs/mitogen-hq/packages
38+
- https://public.ecr.aws/n5z0e8q9
39+
40+
The images used are determined by two environment variables
41+
42+
- `MITOGEN_TEST_DISTRO_SPECS`
43+
- `MITOGEN_TEST_IMAGE_TEMPLATE`
44+
45+
Defaults for these can be found in `.ci/ci_lib.py` & `tests/testlib.py`
3846

3947

4048
# User Accounts

tests/fakessh_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import testlib
88

99

10+
@unittest.skip('broken')
1011
class RsyncTest(testlib.DockerMixin, testlib.TestCase):
11-
@unittest.skip('broken')
1212
def test_rsync_from_master(self):
1313
context = self.docker_ssh_any()
1414

@@ -24,7 +24,6 @@ def test_rsync_from_master(self):
2424
self.assertTrue(context.call(os.path.exists, '/tmp/data'))
2525
self.assertTrue(context.call(os.path.exists, '/tmp/data/simple_pkg/a.py'))
2626

27-
@unittest.skip('broken')
2827
def test_rsync_between_direct_children(self):
2928
# master -> SSH -> mitogen__has_sudo_pubkey -> rsync(.ssh) -> master ->
3029
# mitogen__has_sudo -> rsync

tests/ssh_test.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_okay(self):
3737
self.assertEqual(3, context.call(plain_old_module.add, 1, 2))
3838

3939

40-
class SshTest(testlib.DockerMixin, testlib.TestCase):
40+
class SshMixin(testlib.DockerMixin):
4141
def test_debug_decoding(self):
4242
# ensure filter_debug_logs() decodes the logged string.
4343
capture = testlib.LogCapturer()
@@ -176,7 +176,18 @@ def test_accept_enforce_host_keys(self):
176176
fp.close()
177177

178178

179-
class BannerTest(testlib.DockerMixin, testlib.TestCase):
179+
for distro_spec in testlib.DISTRO_SPECS.split():
180+
dockerized_ssh = testlib.DockerizedSshDaemon(distro_spec)
181+
klass_name = 'SshTest%s' % (dockerized_ssh.distro.capitalize(),)
182+
klass = type(
183+
klass_name,
184+
(SshMixin, testlib.TestCase),
185+
{'dockerized_ssh': dockerized_ssh},
186+
)
187+
globals()[klass_name] = klass
188+
189+
190+
class BannerMixin(testlib.DockerMixin):
180191
# Verify the ability to disambiguate random spam appearing in the SSHd's
181192
# login banner from a legitimate password prompt.
182193
def test_verbose_enabled(self):
@@ -193,6 +204,17 @@ def test_verbose_enabled(self):
193204
context.shutdown(wait=True)
194205

195206

207+
for distro_spec in testlib.DISTRO_SPECS.split():
208+
dockerized_ssh = testlib.DockerizedSshDaemon(distro_spec)
209+
klass_name = 'BannerTest%s' % (dockerized_ssh.distro.capitalize(),)
210+
klass = type(
211+
klass_name,
212+
(BannerMixin, testlib.TestCase),
213+
{'dockerized_ssh': dockerized_ssh},
214+
)
215+
globals()[klass_name] = klass
216+
217+
196218
class StubPermissionDeniedTest(StubSshMixin, testlib.TestCase):
197219
def test_classic_prompt(self):
198220
self.assertRaises(mitogen.ssh.PasswordError,

0 commit comments

Comments
 (0)