Skip to content

Commit 7fd0d34

Browse files
committed
tests/ansible: Spec.port() test & mitogen_via= fix.
ansible_ssh_port was not respected.
1 parent 1f77d24 commit 7fd0d34

4 files changed

Lines changed: 109 additions & 0 deletions

File tree

ansible_mitogen/transport_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ def password(self):
509509

510510
def port(self):
511511
return (
512+
self._host_vars.get('ansible_ssh_port') or
512513
self._host_vars.get('ansible_port') or
513514
C.DEFAULT_REMOTE_PORT
514515
)

tests/ansible/hosts/transport_config.hosts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,9 @@ tc-become-pass-unset
4141
tc-become-pass-password ansible_become_password=apassword
4242
tc-become-pass-pass ansible_become_pass=apass
4343
tc-become-pass-both ansible_become_password=a.b.c ansible_become_pass=c.b.a
44+
45+
# port()
46+
tc-port-unset
47+
tc-port-explicit-port ansible_port=1234
48+
tc-port-explicit-ssh ansible_ssh_port=4321
49+
tc-port-both ansible_port=1717 ansible_ssh_port=1532

tests/ansible/integration/transport_config/all.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
- include: become_user.yml
44
- include: become.yml
55
- include: password.yml
6+
- include: port.yml
67
- include: python_path.yml
78
- include: remote_addr.yml
89
- include: remote_user.yml
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Each case is followed by mitogen_via= case to test hostvars pass.
2+
3+
4+
# No port set
5+
- name: integration/transport_config/port.yml
6+
hosts: tc-port-unset
7+
tasks:
8+
- include: ../_mitogen_only.yml
9+
- {mitogen_get_stack: {}, register: out}
10+
- assert:
11+
that:
12+
- out.result|length == 1
13+
- out.result[0].method == "ssh"
14+
- out.result[0].kwargs.port == None
15+
16+
# Not set, mitogen_via=
17+
- hosts: tc-port-explicit-ssh
18+
vars: {mitogen_via: tc-port-unset}
19+
tasks:
20+
- include: ../_mitogen_only.yml
21+
- {mitogen_get_stack: {}, register: out}
22+
- assert:
23+
that:
24+
- out.result|length == 2
25+
- out.result[0].method == "ssh"
26+
- out.result[0].kwargs.port == None
27+
- out.result[1].method == "ssh"
28+
- out.result[1].kwargs.port == 4321
29+
30+
# ansible_ssh_port=
31+
- hosts: tc-port-explicit-ssh
32+
tasks:
33+
- include: ../_mitogen_only.yml
34+
- {mitogen_get_stack: {}, register: out}
35+
- assert:
36+
that:
37+
- out.result|length == 1
38+
- out.result[0].method == "ssh"
39+
- out.result[0].kwargs.port == 4321
40+
41+
- hosts: tc-port-explicit-unset
42+
vars: {mitogen_via: tc-port-explicit-ssh}
43+
tasks:
44+
- include: ../_mitogen_only.yml
45+
- {mitogen_get_stack: {}, register: out}
46+
- assert:
47+
that:
48+
- out.result|length == 2
49+
- out.result[0].method == "ssh"
50+
- out.result[1].kwargs.port == 4321
51+
- out.result[1].method == "ssh"
52+
- out.result[0].kwargs.port == None
53+
54+
# ansible_port=
55+
- hosts: tc-port-explicit-port
56+
tasks:
57+
- include: ../_mitogen_only.yml
58+
- {mitogen_get_stack: {}, register: out}
59+
- assert:
60+
that:
61+
- out.result|length == 1
62+
- out.result[0].method == "ssh"
63+
- out.result[0].kwargs.port == 1234
64+
65+
- hosts: tc-port-unset
66+
vars: {mitogen_via: tc-port-explicit-port}
67+
tasks:
68+
- include: ../_mitogen_only.yml
69+
- {mitogen_get_stack: {}, register: out}
70+
- assert:
71+
that:
72+
- out.result|length == 2
73+
- out.result[0].method == "ssh"
74+
- out.result[0].kwargs.port == 1234
75+
- out.result[1].method == "ssh"
76+
- out.result[1].kwargs.port == None
77+
78+
79+
# both, ssh takes precedence
80+
- hosts: tc-port-both
81+
tasks:
82+
- include: ../_mitogen_only.yml
83+
- {mitogen_get_stack: {}, register: out}
84+
- assert:
85+
that:
86+
- out.result|length == 1
87+
- out.result[0].method == "ssh"
88+
- out.result[0].kwargs.port == 1532
89+
90+
- hosts: tc-port-unset
91+
vars: {mitogen_via: tc-port-both}
92+
tasks:
93+
- include: ../_mitogen_only.yml
94+
- {mitogen_get_stack: {}, register: out}
95+
- assert:
96+
that:
97+
- out.result|length == 2
98+
- out.result[0].method == "ssh"
99+
- out.result[0].kwargs.port == 1532
100+
- out.result[1].method == "ssh"
101+
- out.result[1].kwargs.port == None

0 commit comments

Comments
 (0)