Skip to content

Commit 748f5f6

Browse files
committed
tests/ansible: Spec.remote_addr() test & mitogen_via= fix.
ansible_ssh_host was not respected.
1 parent 8fd641c commit 748f5f6

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

ansible_mitogen/transport_config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,9 @@ def inventory_name(self):
447447
return self._inventory_name
448448

449449
def remote_addr(self):
450+
# play_context.py::MAGIC_VARIABLE_MAPPING
450451
return (
452+
self._host_vars.get('ansible_ssh_host') or
451453
self._host_vars.get('ansible_host') or
452454
self._inventory_name
453455
)

tests/ansible/hosts/transport_config.hosts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,19 @@
33

44

55
# tansport()
6-
tc-transport-unset
6+
tc-transport-unset
77
tc-transport-local ansible_connection=local
88

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

0 commit comments

Comments
 (0)