Skip to content

Commit 36f3e3b

Browse files
authored
Merge pull request #816 from moreati/issue815
Expand coverage of mitogen/<distro>-test docker images
2 parents 60fbea4 + 6f28e11 commit 36f3e3b

26 files changed

+333
-161
lines changed

.ci/azure-pipelines.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
Mito27Debian_27:
4646
python.version: '2.7'
4747
MODE: mitogen
48-
DISTRO: debian
48+
DISTRO: debian9
4949

5050
#MitoPy27CentOS6_26:
5151
#python.version: '2.7'
@@ -60,12 +60,12 @@ jobs:
6060
Mito37Debian_27:
6161
python.version: '3.7'
6262
MODE: mitogen
63-
DISTRO: debian
63+
DISTRO: debian9
6464

6565
Mito39Debian_27:
6666
python.version: '3.9'
6767
MODE: mitogen
68-
DISTRO: debian
68+
DISTRO: debian9
6969
VER: 2.10.0
7070

7171
#Py26CentOS7:

tests/ansible/integration/become/sudo_nonexistent.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@
1212

1313
- name: Verify raw module output.
1414
assert:
15-
that: |
16-
out.failed and (
17-
('sudo: unknown user: slartibartfast' in out.msg) or
18-
('sudo: unknown user: slartibartfast' in out.module_stderr)
19-
)
15+
that:
16+
- out.failed
17+
# sudo-1.8.6p3-29.el6_10.3 on RHEL & CentOS 6.10 (final release)
18+
# removed user/group error messages, as defence against CVE-2019-14287.
19+
- >-
20+
('sudo: unknown user: slartibartfast' in out.module_stderr | default(out.msg))
21+
or (ansible_facts.os_family == 'RedHat' and ansible_facts.distribution_version == '6.10')

tests/ansible/integration/runner/custom_binary_single_null.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@
1515
- "out.failed"
1616
- "out.results[0].failed"
1717
- "out.results[0].msg.startswith('MODULE FAILURE')"
18-
- "out.results[0].module_stdout.startswith('/bin/sh: ')"
18+
# On Ubuntu 16.04 /bin/sh is dash 0.5.8. It treats custom_binary_single_null
19+
# as a valid executable. There's no error message, and rc == 0.
1920
- |
20-
out.results[0].module_stdout.endswith('custom_binary_single_null: cannot execute binary file\r\n') or
21-
out.results[0].module_stdout.endswith('custom_binary_single_null: Exec format error\r\n')
21+
out.results[0].module_stdout.startswith('/bin/sh: ')
22+
or (ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_version == '16.04')
23+
- |
24+
out.results[0].module_stdout.endswith((
25+
'custom_binary_single_null: cannot execute binary file\r\n',
26+
'custom_binary_single_null: Exec format error\r\n',
27+
'custom_binary_single_null: cannot execute binary file: Exec format error\r\n',
28+
))
29+
or (ansible_facts.distribution == 'Ubuntu' and ansible_facts.distribution_version == '16.04')
2230
2331
2432
# Can't test this: Mitogen returns 126, 2.5.x returns 126, 2.4.x discarded the

tests/image_prep/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ See ../README.md for a (mostly) description of the accounts created.
1414

1515
## Building the containers
1616

17-
``./build_docker_images.sh``
18-
19-
Requires Ansible 2.3.x.x in order to target CentOS 5
17+
No single version of Ansible supports every Linux distribution that we target.
18+
To workaround this [Tox](https://tox.readthedocs.io) is used, to install and
19+
run multiple versions of Ansible, in Python virtualenvs.
2020

21+
``tox``
2122

2223
## Preparing an OS X box
2324

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
- name: Start containers
2+
hosts: all
3+
strategy: mitogen_free
4+
gather_facts: false
5+
tasks:
6+
- name: Fetch container images
7+
docker_image:
8+
name: "{{ docker_base }}"
9+
delegate_to: localhost
10+
11+
- name: Start containers
12+
docker_container:
13+
name: "{{ inventory_hostname }}"
14+
image: "{{ docker_base }}"
15+
command: /bin/bash
16+
hostname: "mitogen-{{ inventory_hostname }}"
17+
detach: true
18+
interactive: true
19+
tty: true
20+
delegate_to: localhost
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
- name: Prepare images
2+
hosts: all
3+
strategy: mitogen_free
4+
gather_facts: true
5+
tasks:
6+
- name: Commit containers
7+
command: >
8+
docker commit
9+
--change 'EXPOSE 22'
10+
--change 'CMD ["/usr/sbin/sshd", "-D"]'
11+
{{ inventory_hostname }}
12+
public.ecr.aws/n5z0e8q9/{{ inventory_hostname }}-test
13+
delegate_to: localhost
14+
15+
- name: Stop containers
16+
command: >
17+
docker rm -f {{ inventory_hostname }}
18+
delegate_to: localhost

tests/image_prep/_container_setup.yml

Lines changed: 57 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,88 @@
11

22
- hosts: all
3-
vars_files:
4-
- shared_vars.yml
53
strategy: linear
64
gather_facts: false
75
tasks:
8-
- raw: >
9-
if ! python -c ''; then
10-
if type -p yum; then
11-
yum -y install python;
12-
else
13-
apt-get -y update && apt-get -y install python;
14-
fi;
6+
- name: Install bootstrap packages
7+
raw: |
8+
set -o errexit
9+
set -o nounset
10+
if type -p yum; then
11+
yum -y install {{ bootstrap_packages | join(' ') }}
12+
else
13+
apt-get -y update
14+
apt-get -y --no-install-recommends install {{ bootstrap_packages | join(' ') }}
1515
fi
16+
when: bootstrap_packages | length
1617

1718
- hosts: all
18-
vars_files:
19-
- shared_vars.yml
2019
strategy: mitogen_free
20+
# Resource limitation, my laptop freezes doing every container concurrently
21+
serial: 4
2122
# Can't gather facts before here.
2223
gather_facts: true
2324
vars:
2425
distro: "{{ansible_distribution}}"
25-
ver: "{{ansible_distribution_major_version}}"
26-
27-
packages:
28-
common:
29-
- openssh-server
30-
- rsync
31-
- strace
32-
- sudo
33-
Debian:
34-
"9":
35-
- libjson-perl
36-
- python-virtualenv
37-
- locales
38-
CentOS:
39-
"5":
40-
- perl
41-
- sudo
42-
#- perl-JSON -- skipped on CentOS 5, packages are a pain.
43-
"6":
44-
- perl-JSON
45-
"7":
46-
- perl-JSON
47-
- python-virtualenv
48-
4926
tasks:
5027
- when: ansible_virtualization_type != "docker"
5128
meta: end_play
5229

53-
- name: Ensure requisite Debian packages are installed
30+
- name: Ensure requisite apt packages are installed
5431
apt:
55-
name: "{{packages.common + packages[distro][ver]}}"
56-
state: installed
32+
name: "{{ common_packages + packages }}"
33+
state: present
34+
install_recommends: false
5735
update_cache: true
58-
when: distro == "Debian"
36+
when: ansible_pkg_mgr == 'apt'
5937

60-
- name: Ensure requisite Red Hat packaed are installed
38+
- name: Ensure requisite yum packages are installed
6139
yum:
62-
name: "{{packages.common + packages[distro][ver]}}"
63-
state: installed
40+
name: "{{ common_packages + packages }}"
41+
state: present
6442
update_cache: true
65-
when: distro == "CentOS"
43+
when: ansible_pkg_mgr == 'yum'
6644

67-
- name: Clean up apt cache
68-
command: apt-get clean
69-
when: distro == "Debian"
45+
- name: Ensure requisite dnf packages are installed
46+
dnf:
47+
name: "{{ common_packages + packages }}"
48+
state: present
49+
update_cache: true
50+
when: ansible_pkg_mgr == 'dnf'
51+
52+
- name: Clean up package cache
53+
vars:
54+
clean_command:
55+
apt: apt-get clean
56+
yum: yum clean all
57+
dnf: dnf clean all
58+
command: "{{ clean_command[ansible_pkg_mgr] }}"
59+
args:
60+
warn: false
7061

7162
- name: Clean up apt package lists
7263
shell: rm -rf {{item}}/*
7364
with_items:
7465
- /var/cache/apt
7566
- /var/lib/apt/lists
76-
when: distro == "Debian"
67+
when: ansible_pkg_mgr == 'apt'
7768

78-
- name: Clean up yum cache
79-
command: yum clean all
80-
when: distro == "CentOS"
69+
- name: Configure /usr/bin/python
70+
command: alternatives --set python /usr/bin/python3.8
71+
args:
72+
creates: /usr/bin/python
73+
when: inventory_hostname in ["centos8"]
8174

8275
- name: Enable UTF-8 locale on Debian
8376
copy:
8477
dest: /etc/locale.gen
8578
content: |
8679
en_US.UTF-8 UTF-8
8780
fr_FR.UTF-8 UTF-8
88-
when: distro == "Debian"
81+
when: ansible_pkg_mgr == 'apt'
8982

9083
- name: Generate UTF-8 locale on Debian
9184
shell: locale-gen
92-
when: distro == "Debian"
85+
when: ansible_pkg_mgr == 'apt'
9386

9487
- name: Write Unicode into /etc/environment
9588
copy:
@@ -115,16 +108,6 @@
115108
permit :mitogen__group
116109
permit :root
117110
118-
- name: Vanilla Ansible needs simplejson on CentOS 5.
119-
shell: mkdir -p /usr/lib/python2.4/site-packages/simplejson/
120-
when: distro == "CentOS" and ver == "5"
121-
122-
- name: Vanilla Ansible needs simplejson on CentOS 5.
123-
synchronize:
124-
dest: /usr/lib/python2.4/site-packages/simplejson/
125-
src: ../../ansible_mitogen/compat/simplejson/
126-
when: distro == "CentOS" and ver == "5"
127-
128111
- name: Set root user password and shell
129112
user:
130113
name: root
@@ -182,8 +165,9 @@
182165
- name: Install CentOS wheel sudo rule
183166
lineinfile:
184167
path: /etc/sudoers
185-
line: "%wheel ALL=(ALL) ALL"
186-
when: distro == "CentOS"
168+
regexp: '#* *%wheel +ALL=(ALL) +ALL'
169+
line: "%wheel ALL=(ALL) ALL"
170+
when: ansible_os_family == 'RedHat'
187171

188172
- name: Enable SSH banner
189173
lineinfile:
@@ -202,6 +186,15 @@
202186
regexp: '.*session.*required.*pam_loginuid.so'
203187
line: session optional pam_loginuid.so
204188

189+
# Normally this would be removed by systemd-networkd-wait-online. If
190+
# present ssh works only for root. The message displayed is
191+
# > System is booting up. Unprivileged users are not permitted to log in
192+
# > yet. Please come back later. For technical details, see pam_nologin(8).
193+
- name: Remove login lockout
194+
file:
195+
path: /run/nologin
196+
state: absent
197+
205198
- name: Install convenience script for running an straced Python
206199
copy:
207200
mode: 'u+rwx,go=rx'

tests/image_prep/_user_accounts.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,11 @@
55
#
66

77
- hosts: all
8-
vars_files:
9-
- shared_vars.yml
108
gather_facts: true
119
strategy: mitogen_free
1210
become: true
1311
vars:
1412
distro: "{{ansible_distribution}}"
15-
ver: "{{ansible_distribution_major_version}}"
16-
1713
special_users:
1814
- has_sudo
1915
- has_sudo_nopw
@@ -172,6 +168,8 @@
172168
with_items:
173169
- mitogen__pw_required
174170
- mitogen__require_tty_pw_required
171+
when:
172+
- ansible_virtualization_type != "docker"
175173

176174
- name: Allow passwordless sudo for require_tty/readonly_homedir
177175
lineinfile:
@@ -181,10 +179,14 @@
181179
with_items:
182180
- mitogen__require_tty
183181
- mitogen__readonly_homedir
182+
when:
183+
- ansible_virtualization_type != "docker"
184184

185185
- name: Allow passwordless for many accounts
186186
lineinfile:
187187
path: /etc/sudoers
188188
line: "{{lookup('pipe', 'whoami')}} ALL = (mitogen__{{item}}:ALL) NOPASSWD:ALL"
189189
validate: '/usr/sbin/visudo -cf %s'
190190
with_items: "{{normal_users}}"
191+
when:
192+
- ansible_virtualization_type != "docker"

tests/image_prep/ansible.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11

22
[defaults]
3+
deprecation_warnings = false
34
strategy_plugins = ../../ansible_mitogen/plugins/strategy
45
retry_files_enabled = false
56
display_args_to_stdout = True
67
no_target_syslog = True
78
host_key_checking = False
9+
10+
[inventory]
11+
unparsed_is_fatal = true

0 commit comments

Comments
 (0)