Skip to content

Commit 21e002a

Browse files
authored
Merge pull request #1168 from moreati/issue1083-become_pass
tests: Re-enable become/sudo tests, fix them on macOS runners
2 parents 257d602 + 8a34b92 commit 21e002a

File tree

8 files changed

+114
-86
lines changed

8 files changed

+114
-86
lines changed

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ In progress (unreleased)
2323

2424
* :gh:issue:`905` :mod:`ansible_mitogen`: Support templated SSH command
2525
arguments (e.g. ``ansible_ssh_args``, ``ansible_ssh_extra_args``).
26+
* :gh:issue:`692` tests: Fix and re-enable several sudo tests
2627

2728

2829
v0.3.14 (2024-10-16)

tests/ansible/integration/action/make_tmp_path.yml

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -142,17 +142,16 @@
142142
# readonly homedir
143143
#
144144

145-
# TODO: https://github.com/dw/mitogen/issues/692
146-
# - name: "Try writing to temp directory for the readonly_homedir user"
147-
# become: true
148-
# become_user: mitogen__readonly_homedir
149-
# custom_python_run_script:
150-
# script: |
151-
# from ansible.module_utils.basic import get_module_path
152-
# path = get_module_path() + '/foo.txt'
153-
# result['path'] = path
154-
# open(path, 'w').write("bar")
155-
# register: tmp_path
145+
- name: Try writing to temp directory for the readonly_homedir user
146+
become: true
147+
become_user: mitogen__readonly_homedir
148+
custom_python_run_script:
149+
script: |
150+
from ansible.module_utils.basic import get_module_path
151+
path = get_module_path() + '/foo.txt'
152+
result['path'] = path
153+
open(path, 'w').write("bar")
154+
register: tmp_path
156155

157156
#
158157
# modules get the same base dir

tests/ansible/integration/action/synchronize.yml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
delegate_to: localhost
4141
run_once: true
4242

43-
# TODO: https://github.com/dw/mitogen/issues/692
44-
# - file:
45-
# path: /tmp/sync-test.out
46-
# state: absent
47-
# become: true
43+
- name: Ensure clean slate
44+
become: true
45+
file:
46+
path: /tmp/sync-test.out
47+
state: absent
4848

4949
# exception: File "/tmp/venv/lib/python2.7/site-packages/ansible/plugins/action/__init__.py", line 129, in cleanup
5050
# exception: self._remove_tmp_path(self._connection._shell.tmpdir)
@@ -70,14 +70,14 @@
7070
outout={{ outout }}
7171
when: False
7272

73-
# TODO: https://github.com/dw/mitogen/issues/692
74-
# - file:
75-
# path: "{{item}}"
76-
# state: absent
77-
# become: true
78-
# with_items:
79-
# - /tmp/synchronize-action-key
80-
# - /tmp/sync-test
81-
# - /tmp/sync-test.out
73+
- name: Cleanup
74+
become: true
75+
file:
76+
path: "{{ item }}"
77+
state: absent
78+
with_items:
79+
- /tmp/synchronize-action-key
80+
- /tmp/sync-test
81+
- /tmp/sync-test.out
8282
tags:
8383
- synchronize

tests/ansible/integration/become/sudo_password.yml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
tasks:
66

77
- name: Ensure sudo password absent but required.
8-
shell: whoami
98
become: true
109
become_user: mitogen__pw_required
10+
command:
11+
cmd: whoami
1112
register: out
13+
changed_when: false
1214
ignore_errors: true
1315
when:
1416
# https://github.com/ansible/ansible/pull/70785
@@ -32,10 +34,12 @@
3234
or is_mitogen
3335

3436
- name: Ensure password sudo incorrect.
35-
shell: whoami
3637
become: true
3738
become_user: mitogen__pw_required
39+
command:
40+
cmd: whoami
3841
register: out
42+
changed_when: false
3943
vars:
4044
ansible_become_pass: nopes
4145
ignore_errors: true
@@ -59,18 +63,27 @@
5963
or ansible_version.full is version("2.11", ">=", strict=True)
6064
or is_mitogen
6165

62-
# TODO: https://github.com/dw/mitogen/issues/692
63-
# - name: Ensure password sudo succeeds.
64-
# shell: whoami
65-
# become: true
66-
# become_user: mitogen__pw_required
67-
# register: out
68-
# vars:
69-
# ansible_become_pass: pw_required_password
66+
- block:
67+
- name: Ensure password sudo succeeds
68+
become: true
69+
become_user: mitogen__pw_required
70+
vars:
71+
ansible_become_pass: pw_required_password
72+
command:
73+
cmd: whoami
74+
register: sudo_password_success_whoami
75+
changed_when: false
7076

71-
# - assert:
72-
# that:
73-
# - out.stdout == 'mitogen__pw_required'
77+
- assert:
78+
that:
79+
- sudo_password_success_whoami.stdout == 'mitogen__pw_required'
80+
fail_msg: |
81+
sudo_password_success_whoami={{ sudo_password_success_whoami }}
82+
when:
83+
# https://github.com/ansible/ansible/pull/70785
84+
- ansible_facts.distribution not in ["MacOSX"]
85+
or ansible_version.full is version("2.11", ">=", strict=True)
86+
or is_mitogen
7487
tags:
7588
- sudo
7689
- sudo_password

tests/ansible/integration/become/sudo_requiretty.yml

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,38 @@
33
- name: integration/become/sudo_requiretty.yml
44
hosts: test-targets
55
tasks:
6-
# - include_tasks: ../_mitogen_only.yml
6+
# AIUI Vanilla Ansible cannot do sudo when requiretty configured
7+
- include_tasks: ../_mitogen_only.yml
78

8-
# TODO: https://github.com/dw/mitogen/issues/692
9-
# - name: Verify we can login to a non-passworded requiretty account
10-
# shell: whoami
11-
# become: true
12-
# become_user: mitogen__require_tty
13-
# register: out
9+
- name: Verify we can login to a non-passworded requiretty account
10+
become: true
11+
become_user: mitogen__require_tty
12+
command:
13+
cmd: whoami
14+
changed_when: false
15+
register: sudo_require_tty_whoami
1416

15-
# - assert:
16-
# that:
17-
# - out.stdout == 'mitogen__require_tty'
17+
- assert:
18+
that:
19+
- sudo_require_tty_whoami.stdout == 'mitogen__require_tty'
20+
fail_msg: |
21+
sudo_require_tty_whoami={{ sudo_require_tty_whoami }}
1822
23+
- name: Verify we can login to a passworded requiretty account
24+
become: true
25+
become_user: mitogen__require_tty_pw_required
26+
vars:
27+
ansible_become_pass: require_tty_pw_required_password
28+
command:
29+
cmd: whoami
30+
changed_when: false
31+
register: sudo_require_tty_password_whoami
1932

20-
# ---------------
21-
22-
# TODO: https://github.com/dw/mitogen/issues/692
23-
# - name: Verify we can login to a passworded requiretty account
24-
# shell: whoami
25-
# become: true
26-
# become_user: mitogen__require_tty_pw_required
27-
# vars:
28-
# ansible_become_pass: require_tty_pw_required_password
29-
# register: out
30-
31-
# - assert:
32-
# that:
33-
# - out.stdout == 'mitogen__require_tty_pw_required'
33+
- assert:
34+
that:
35+
- sudo_require_tty_password_whoami.stdout == 'mitogen__require_tty_pw_required'
36+
fail_msg: |
37+
sudo_require_tty_password_whoami={{ sudo_require_tty_password_whoami }}
3438
tags:
3539
- mitogen_only
3640
- sudo

tests/ansible/integration/playbook_semantics/with_items.yml

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,39 @@
33

44
- name: integration/playbook_semantics/with_items.yml
55
hosts: test-targets
6+
gather_facts: true
67
tasks:
8+
- block:
9+
- name: Spin up a few interpreters
10+
become: true
11+
vars:
12+
ansible_become_user: "mitogen__user{{ item }}"
13+
command:
14+
cmd: whoami
15+
with_sequence: start=1 end=3
16+
register: first_run
17+
changed_when: false
718

8-
# TODO: https://github.com/dw/mitogen/issues/692
9-
# - name: Spin up a few interpreters
10-
# shell: whoami
11-
# become: true
12-
# vars:
13-
# ansible_become_user: "mitogen__user{{item}}"
14-
# with_sequence: start=1 end=3
15-
# register: first_run
19+
- name: Reuse them
20+
become: true
21+
vars:
22+
ansible_become_user: "mitogen__user{{ item }}"
23+
command:
24+
cmd: whoami
25+
with_sequence: start=1 end=3
26+
register: second_run
27+
changed_when: false
1628

17-
# - name: Reuse them
18-
# shell: whoami
19-
# become: true
20-
# vars:
21-
# ansible_become_user: "mitogen__user{{item}}"
22-
# with_sequence: start=1 end=3
23-
# register: second_run
24-
25-
# - name: Verify first and second run matches expected username.
26-
# assert:
27-
# that:
28-
# - first_run.results[item|int].stdout == ("mitogen__user%d" % (item|int + 1))
29-
# - first_run.results[item|int].stdout == second_run.results[item|int].stdout
30-
# with_sequence: start=0 end=2
31-
tags:
32-
- custom_python_new_style_module
29+
- name: Verify first and second run matches expected username.
30+
vars:
31+
user_expected: "mitogen__user{{ item | int + 1 }}"
32+
assert:
33+
that:
34+
- first_run.results[item | int].stdout == user_expected
35+
- second_run.results[item | int].stdout == user_expected
36+
with_sequence: start=0 end=2
37+
when:
38+
# https://github.com/ansible/ansible/pull/70785
39+
- ansible_facts.distribution not in ["MacOSX"]
40+
or ansible_version.full is version("2.11", ">=", strict=True)
41+
or is_mitogen

tests/image_prep/_user_accounts.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
- user:
7474
name: "mitogen__{{item}}"
7575
shell: /bin/bash
76+
group: staff
7677
groups: |
7778
{{
7879
['com.apple.access_ssh'] +

tests/image_prep/ansible.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ retry_files_enabled = false
66
display_args_to_stdout = True
77
no_target_syslog = True
88
host_key_checking = False
9+
stdout_callback = yaml
910

1011
[inventory]
1112
unparsed_is_fatal = true

0 commit comments

Comments
 (0)