Skip to content

Commit

Permalink
tests/ansible: Spec.remote_addr() test & mitogen_via= fix.
Browse files Browse the repository at this point in the history
ansible_ssh_host was not respected.
  • Loading branch information
dw committed Feb 12, 2019
1 parent 8fd641c commit 748f5f6
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ansible_mitogen/transport_config.py
Expand Up @@ -447,7 +447,9 @@ def inventory_name(self):
return self._inventory_name

def remote_addr(self):
# play_context.py::MAGIC_VARIABLE_MAPPING
return (
self._host_vars.get('ansible_ssh_host') or
self._host_vars.get('ansible_host') or
self._inventory_name
)
Expand Down
10 changes: 9 additions & 1 deletion tests/ansible/hosts/transport_config.hosts
Expand Up @@ -3,11 +3,19 @@


# tansport()
tc-transport-unset
tc-transport-unset
tc-transport-local ansible_connection=local

# python_path()
tc-python-path-unset
tc-python-path-hostvar ansible_python_interpreter=/hostvar/path/to/python
tc-python-path-local-unset ansible_connection=local
tc-python-path-local-explicit ansible_connection=local ansible_python_interpreter=/a/b/c

# remote_addr()
tc-remote-addr-unset # defaults to inventory_hostname
tc-remote-addr-explicit-ssh ansible_ssh_host=ansi.ssh.host
tc-remote-addr-explicit-host ansible_host=ansi.host
tc-remote-addr-explicit-both ansible_ssh_host=a.b.c ansible_host=b.c.d


1 change: 1 addition & 0 deletions tests/ansible/integration/transport_config/all.yml
@@ -1,2 +1,3 @@
- include: python_path.yml
- include: remote_addr.yml
- include: transport.yml
95 changes: 95 additions & 0 deletions tests/ansible/integration/transport_config/remote_addr.yml
@@ -0,0 +1,95 @@

# Each case is followed by mitogen_via= case to test hostvars method.


# When no ansible_host/ansible_ssh_host= is set, hostname is same as inventory
# name.
- name: integration/transport_config/remote_addr.yml
hosts: tc-remote-addr-unset
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert_equal:
left: out.result[0].kwargs.hostname
right: "tc-remote-addr-unset"

- hosts: tc-remote-addr-unset
vars: {mitogen_via: tc-remote-addr-explicit-ssh}
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert_equal:
left: out.result[0].kwargs.hostname
right: "ansi.ssh.host"
- assert_equal:
left: out.result[1].kwargs.hostname
right: "tc-remote-addr-unset"


# ansible_ssh_host=

- hosts: tc-remote-addr-explicit-ssh
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert_equal:
left: out.result[0].kwargs.hostname
right: "ansi.ssh.host"

- hosts: tc-remote-addr-explicit-ssh
vars: {mitogen_via: tc-remote-addr-unset}
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert_equal:
left: out.result[0].kwargs.hostname
right: "tc-remote-addr-unset"
- assert_equal:
left: out.result[1].kwargs.hostname
right: "ansi.ssh.host"


# ansible_host=

- hosts: tc-remote-addr-explicit-host
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert_equal:
left: out.result[0].kwargs.hostname
right: "ansi.host"

- hosts: tc-remote-addr-explicit-host
vars: {mitogen_via: tc-remote-addr-unset}
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert_equal:
left: out.result[0].kwargs.hostname
right: "tc-remote-addr-unset"
- assert_equal:
left: out.result[1].kwargs.hostname
right: "ansi.host"


# both; ansible_ssh_host= takes precedence according to play_context.py.

- hosts: tc-remote-addr-explicit-both
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert_equal:
left: out.result[0].kwargs.hostname
right: "a.b.c"

- hosts: tc-remote-addr-explicit-both
vars: {mitogen_via: tc-remote-addr-unset}
tasks:
- include: ../_mitogen_only.yml
- {mitogen_get_stack: {}, register: out}
- assert_equal:
left: out.result[0].kwargs.hostname
right: "tc-remote-addr-unset"
- assert_equal:
left: out.result[1].kwargs.hostname
right: "a.b.c"

0 comments on commit 748f5f6

Please sign in to comment.