From 8ba75d82ec96e4b3e2f15682cc2062f35d0c241a Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 12 Feb 2019 14:33:36 +0000 Subject: [PATCH] tests/ansible: Spec.become() test --- tests/ansible/hosts/transport_config.hosts | 4 ++ .../integration/transport_config/all.yml | 1 + .../integration/transport_config/become.yml | 68 +++++++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 tests/ansible/integration/transport_config/become.yml diff --git a/tests/ansible/hosts/transport_config.hosts b/tests/ansible/hosts/transport_config.hosts index cb64d87b..1546b26f 100644 --- a/tests/ansible/hosts/transport_config.hosts +++ b/tests/ansible/hosts/transport_config.hosts @@ -23,3 +23,7 @@ tc-password-unset tc-password-explicit-ssh ansible_ssh_pass=ansi-ssh-pass tc-password-explicit-user ansible_password=ansi-pass tc-password-explicit-both ansible_password=a.b.c ansible_ssh_pass=c.b.a + +# become() +tc-become-unset +tc-become-set diff --git a/tests/ansible/integration/transport_config/all.yml b/tests/ansible/integration/transport_config/all.yml index a9880ffc..f259f0a0 100644 --- a/tests/ansible/integration/transport_config/all.yml +++ b/tests/ansible/integration/transport_config/all.yml @@ -1,3 +1,4 @@ +- include: become.yml - include: password.yml - include: python_path.yml - include: remote_addr.yml diff --git a/tests/ansible/integration/transport_config/become.yml b/tests/ansible/integration/transport_config/become.yml new file mode 100644 index 00000000..baa2085e --- /dev/null +++ b/tests/ansible/integration/transport_config/become.yml @@ -0,0 +1,68 @@ +# Each case is followed by mitogen_via= case to test hostvars method. + + +# No become set. +- name: integration/transport_config/become.yml + hosts: tc-become-unset + tasks: + - include: ../_mitogen_only.yml + - {mitogen_get_stack: {}, register: out} + - assert: + that: + - out.result|length == 1 + - out.result[0].method == "ssh" + - out.result[0].kwargs.username == "ansible-cfg-remote-user" + +- hosts: tc-become-unset + vars: {mitogen_via: becomeuser@tc-become-set} + tasks: + - include: ../_mitogen_only.yml + - {mitogen_get_stack: {}, register: out} + - assert: + that: + - out.result|length == 3 + - out.result[0].method == "ssh" + - out.result[0].kwargs.username == "ansible-cfg-remote-user" + + - out.result[1].method == "sudo" + - out.result[1].kwargs.username == "becomeuser" + + - out.result[2].method == "ssh" + - out.result[2].kwargs.hostname == "tc-become-unset" + + +# Become set. +- name: integration/transport_config/become.yml + hosts: tc-become-set + become: true + become_user: becomeuser + tasks: + - include: ../_mitogen_only.yml + - {mitogen_get_stack: {}, register: out} + - assert: + that: + - out.result|length == 2 + - out.result[0].method == "ssh" + - out.result[0].kwargs.username == "ansible-cfg-remote-user" + - out.result[1].method == "sudo" + - out.result[1].kwargs.username == "becomeuser" + +- hosts: tc-become-set + vars: {mitogen_via: tc-become-unset} + become: true + become_user: becomeuser + tasks: + - include: ../_mitogen_only.yml + - {mitogen_get_stack: {}, register: out} + - assert: + that: + - out.result|length == 3 + - out.result[0].method == "ssh" + - out.result[0].kwargs.hostname == "tc-become-unset" + - out.result[0].kwargs.username == "ansible-cfg-remote-user" + + - out.result[1].method == "ssh" + - out.result[1].kwargs.hostname == "tc-become-set" + + - out.result[2].method == "sudo" + - out.result[2].kwargs.username == "becomeuser"