Skip to content

Commit adbad76

Browse files
committed
Merge remote-tracking branch 'origin/543-darwin-ansible-ci'
* origin/543-darwin-ansible-ci: issue #543: install virtualenv for Azure issue #543: dumb fix for file vs. stat :( issue #543: disable host key checking issue #543: create ~/.ssh if it doesn't exist issue #543: Hide Mitogen test users from gdm issue #543: skip test that's hard to do on Mac issue #543: use key from Git, newer ssh-keygen unsupported by Paramiko image_prep: ensure Mac users can SSH without manual intervention issue #543: make localhost_ansible_tests run locally issue #543: add Ansible job to Azure matrix issue #543: localhost_ansible scripts.
2 parents c7e2b03 + 57db3a3 commit adbad76

File tree

10 files changed

+122
-14
lines changed

10 files changed

+122
-14
lines changed

.ci/azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
Mito27_27:
1616
python.version: '2.7'
1717
MODE: mitogen
18+
Ans280_27:
19+
python.version: '2.7'
20+
MODE: localhost_ansible
1821

1922

2023
- job: Linux

.ci/localhost_ansible_install.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
import ci_lib
4+
5+
batches = [
6+
[
7+
# Must be installed separately, as PyNACL indirect requirement causes
8+
# newer version to be installed if done in a single pip run.
9+
'pip install "pycparser<2.19" "idna<2.7"',
10+
'pip install '
11+
'-r tests/requirements.txt '
12+
'-r tests/ansible/requirements.txt',
13+
]
14+
]
15+
16+
ci_lib.run_batches(batches)

.ci/localhost_ansible_tests.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python
2+
# Run tests/ansible/all.yml under Ansible and Ansible-Mitogen
3+
4+
import glob
5+
import os
6+
import shutil
7+
import sys
8+
9+
import ci_lib
10+
from ci_lib import run
11+
12+
13+
TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible')
14+
IMAGE_PREP_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/image_prep')
15+
HOSTS_DIR = os.path.join(TESTS_DIR, 'hosts')
16+
KEY_PATH = os.path.join(TESTS_DIR, '../data/docker/mitogen__has_sudo_pubkey.key')
17+
18+
19+
with ci_lib.Fold('unit_tests'):
20+
os.environ['SKIP_MITOGEN'] = '1'
21+
ci_lib.run('./run_tests -v')
22+
23+
24+
with ci_lib.Fold('job_setup'):
25+
# Don't set -U as that will upgrade Paramiko to a non-2.6 compatible version.
26+
run("pip install -q virtualenv ansible==%s", ci_lib.ANSIBLE_VERSION)
27+
28+
os.chmod(KEY_PATH, int('0600', 8))
29+
if not ci_lib.exists_in_path('sshpass'):
30+
run("brew install http://git.io/sshpass.rb")
31+
32+
33+
with ci_lib.Fold('machine_prep'):
34+
ssh_dir = os.path.expanduser('~/.ssh')
35+
if not os.path.exists(ssh_dir):
36+
os.makedirs(ssh_dir, int('0700', 8))
37+
38+
key_path = os.path.expanduser('~/.ssh/id_rsa')
39+
shutil.copy(KEY_PATH, key_path)
40+
41+
auth_path = os.path.expanduser('~/.ssh/authorized_keys')
42+
os.system('ssh-keygen -y -f %s >> %s' % (key_path, auth_path))
43+
os.chmod(auth_path, int('0600', 8))
44+
45+
if os.path.expanduser('~mitogen__user1') == '~mitogen__user1':
46+
os.chdir(IMAGE_PREP_DIR)
47+
run("ansible-playbook -c local -i localhost, _user_accounts.yml")
48+
49+
50+
with ci_lib.Fold('ansible'):
51+
os.chdir(TESTS_DIR)
52+
playbook = os.environ.get('PLAYBOOK', 'all.yml')
53+
run('./run_ansible_playbook.py %s -l target %s',
54+
playbook, ' '.join(sys.argv[1:]))

tests/ansible/integration/context_service/remote_name.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- meta: end_play
88
when: not is_mitogen
99

10+
# Too much hassle to make this work for OSX
11+
- meta: end_play
12+
when: ansible_system != 'Linux'
13+
1014
- shell: 'cat /proc/$PPID/cmdline | tr \\0 \\n'
1115
register: out
1216
- debug: var=out

tests/ansible/tests/affinity_test.py

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

22
import multiprocessing
33
import os
4+
import sys
45
import tempfile
56

67
import mock
@@ -221,6 +222,11 @@ def test_high_cpus(self):
221222
for x in range(1, 4096, 32):
222223
policy.assign_subprocess()
223224

225+
MockLinuxPolicyTest = unittest2.skipIf(
226+
condition=(not sys.platform.startswith('linuxPolicy')),
227+
reason='select.select() not supported'
228+
)(MockLinuxPolicyTest)
229+
224230

225231
if __name__ == '__main__':
226232
unittest2.main()

tests/image_prep/_container_setup.yml

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

22
- hosts: all
3+
vars_files:
4+
- shared_vars.yml
35
strategy: linear
46
gather_facts: false
57
tasks:
@@ -13,6 +15,8 @@
1315
fi
1416
1517
- hosts: all
18+
vars_files:
19+
- shared_vars.yml
1620
strategy: mitogen_free
1721
# Can't gather facts before here.
1822
gather_facts: true

tests/image_prep/_user_accounts.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#
66

77
- hosts: all
8+
vars_files:
9+
- shared_vars.yml
810
gather_facts: true
911
strategy: mitogen_free
1012
become: true
@@ -73,21 +75,45 @@
7375
- user:
7476
name: "mitogen__{{item}}"
7577
shell: /bin/bash
76-
groups: "{{user_groups[item]|default(['mitogen__group'])}}"
78+
groups: |
79+
{{
80+
['com.apple.access_ssh'] +
81+
(user_groups[item] | default(['mitogen__group']))
82+
}}
7783
password: "{{item}}_password"
7884
with_items: "{{all_users}}"
7985
when: ansible_system == 'Darwin'
8086

81-
- name: Hide users from login window.
82-
with_items: "{{all_users}}"
87+
- name: Hide users from login window (Darwin).
8388
when: ansible_system == 'Darwin'
89+
with_items: "{{all_users}}"
8490
osx_defaults:
8591
array_add: true
8692
domain: /Library/Preferences/com.apple.loginwindow
8793
type: array
8894
key: HiddenUsersList
8995
value: ['mitogen_{{item}}']
9096

97+
- name: Check if AccountsService is used
98+
stat:
99+
path: /var/lib/AccountsService/users
100+
register: out
101+
102+
- name: Hide users from login window (Linux).
103+
when: ansible_system == 'Linux' and out.stat.exists
104+
with_items: "{{all_users}}"
105+
copy:
106+
dest: /var/lib/AccountsService/users/mitogen__{{item}}
107+
content: |
108+
[User]
109+
SystemAccount=true
110+
111+
- name: Restart AccountsService (Linux).
112+
when: ansible_system == 'Linux' and out.stat.exists
113+
service:
114+
name: accounts-daemon
115+
restarted: true
116+
91117
- name: Readonly homedir for one account
92118
shell: "chown -R root: ~mitogen__readonly_homedir"
93119

tests/image_prep/ansible.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ strategy_plugins = ../../ansible_mitogen/plugins/strategy
44
retry_files_enabled = false
55
display_args_to_stdout = True
66
no_target_syslog = True
7+
host_key_checking = False

tests/image_prep/setup.yml

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

2-
- hosts: all
3-
gather_facts: false
4-
tasks:
5-
- set_fact:
6-
# Hacktacular.. but easiest place for it with current structure.
7-
sudo_group:
8-
MacOSX: admin
9-
Debian: sudo
10-
Ubuntu: sudo
11-
CentOS: wheel
12-
132
- include: _container_setup.yml
143
- include: _user_accounts.yml

tests/image_prep/shared_vars.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
sudo_group:
2+
MacOSX: admin
3+
Debian: sudo
4+
Ubuntu: sudo
5+
CentOS: wheel

0 commit comments

Comments
 (0)