Skip to content

Commit 21ad299

Browse files
committed
tests/ansible: Spec.remote_user() test & mitogen_via= fix.
ansible_ssh_user precedence was incorrect.
1 parent 748f5f6 commit 21ad299

File tree

4 files changed

+103
-1
lines changed

4 files changed

+103
-1
lines changed

ansible_mitogen/transport_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ def remote_addr(self):
456456

457457
def remote_user(self):
458458
return (
459-
self._host_vars.get('ansible_user') or
460459
self._host_vars.get('ansible_ssh_user') or
460+
self._host_vars.get('ansible_user') or
461461
C.DEFAULT_REMOTE_USER
462462
)
463463

tests/ansible/hosts/transport_config.hosts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,9 @@ tc-remote-addr-explicit-ssh ansible_ssh_host=ansi.ssh.host
1818
tc-remote-addr-explicit-host ansible_host=ansi.host
1919
tc-remote-addr-explicit-both ansible_ssh_host=a.b.c ansible_host=b.c.d
2020

21+
# remote_addr()
22+
tc-remote-user-unset # defaults to C.DEFAULT_REMOTE_USER
23+
tc-remote-user-explicit-ssh ansible_ssh_user=ansi-ssh-user
24+
tc-remote-user-explicit-user ansible_user=ansi-user
25+
tc-remote-user-explicit-both ansible_user=a.b.c ansible_ssh_user=c.b.a
2126

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- include: python_path.yml
22
- include: remote_addr.yml
3+
- include: remote_user.yml
34
- include: transport.yml
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
2+
# Each case is followed by mitogen_via= case to test hostvars method.
3+
4+
5+
# When no ansible_user/ansible_ssh_user= is set, username is
6+
# C.DEFAULT_REMOTE_USER.
7+
- name: integration/transport_config/remote_user.yml
8+
hosts: tc-remote-user-unset
9+
tasks:
10+
- include: ../_mitogen_only.yml
11+
- {mitogen_get_stack: {}, register: out}
12+
- assert_equal:
13+
left: out.result[0].kwargs.username
14+
# We set DEFAULT_REMOTE_USER in our ansible.cfg
15+
right: "ansible-cfg-remote-user"
16+
17+
- hosts: tc-remote-user-unset
18+
vars: {mitogen_via: tc-remote-user-explicit-ssh}
19+
tasks:
20+
- include: ../_mitogen_only.yml
21+
- {mitogen_get_stack: {}, register: out}
22+
- assert_equal:
23+
left: out.result[0].kwargs.username
24+
right: "ansi-ssh-user"
25+
- assert_equal:
26+
left: out.result[1].kwargs.username
27+
right: "ansible-cfg-remote-user"
28+
29+
30+
# ansible_ssh_user=
31+
32+
- hosts: tc-remote-user-explicit-ssh
33+
tasks:
34+
- include: ../_mitogen_only.yml
35+
- {mitogen_get_stack: {}, register: out}
36+
- assert_equal:
37+
left: out.result[0].kwargs.username
38+
right: "ansi-ssh-user"
39+
40+
- hosts: tc-remote-user-explicit-ssh
41+
vars: {mitogen_via: tc-remote-user-unset}
42+
tasks:
43+
- include: ../_mitogen_only.yml
44+
- {mitogen_get_stack: {}, register: out}
45+
- assert_equal:
46+
left: out.result[0].kwargs.username
47+
right: "ansible-cfg-remote-user"
48+
- assert_equal:
49+
left: out.result[1].kwargs.username
50+
right: "ansi-ssh-user"
51+
52+
53+
# ansible_user=
54+
55+
- hosts: tc-remote-user-explicit-user
56+
tasks:
57+
- include: ../_mitogen_only.yml
58+
- {mitogen_get_stack: {}, register: out}
59+
- assert_equal:
60+
left: out.result[0].kwargs.username
61+
right: "ansi-user"
62+
63+
- hosts: tc-remote-user-explicit-host
64+
vars: {mitogen_via: tc-remote-user-unset}
65+
tasks:
66+
- include: ../_mitogen_only.yml
67+
- {mitogen_get_stack: {}, register: out}
68+
- assert_equal:
69+
left: out.result[0].kwargs.username
70+
right: "ansible-cfg-remote-user"
71+
- assert_equal:
72+
left: out.result[1].kwargs.username
73+
right: "ansi-user"
74+
75+
76+
# both; ansible_ssh_user= takes precedence according to play_context.py.
77+
78+
- hosts: tc-remote-user-explicit-both
79+
tasks:
80+
- include: ../_mitogen_only.yml
81+
- {mitogen_get_stack: {}, register: out}
82+
- assert_equal:
83+
left: out.result[0].kwargs.username
84+
right: "c.b.a"
85+
86+
- hosts: tc-remote-user-explicit-both
87+
vars: {mitogen_via: tc-remote-user-unset}
88+
tasks:
89+
- include: ../_mitogen_only.yml
90+
- {mitogen_get_stack: {}, register: out}
91+
- assert_equal:
92+
left: out.result[0].kwargs.username
93+
right: "ansible-cfg-remote-user"
94+
- assert_equal:
95+
left: out.result[1].kwargs.username
96+
right: "c.b.a"

0 commit comments

Comments
 (0)