From 2654985278ba7c8bdd3aa81b216b011e964d9af1 Mon Sep 17 00:00:00 2001 From: James Laska Date: Sun, 24 Jan 2016 10:14:09 -0500 Subject: [PATCH] Fix test_become to work in travis --- test_pytest_ansible.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/test_pytest_ansible.py b/test_pytest_ansible.py index dce91f4a..123522f0 100644 --- a/test_pytest_ansible.py +++ b/test_pytest_ansible.py @@ -307,7 +307,9 @@ def test_func(ansible_module): def test_become(testdir, option): - '''FIXME + '''Test --ansible-become* parameters. This test doesn't actually 'sudo', + but verifies that 'sudo' was attempted by asserting + '--ansible-become-user=' fails as expected. ''' src = ''' import pytest @@ -322,22 +324,28 @@ def test_func(ansible_module): assert contacted assert len(contacted) == len(ansible_module.inventory_manager.list_hosts('localhost')) for result in contacted.values(): - print result - print os.environ - assert 'failed' in result - assert result['failed'] + assert 'failed' in result, "Missing expected field in JSON response: failed" + assert result['failed'], "Test did not fail as expected" if ansible.__version__.startswith('2'): assert 'module_stderr' in result - assert 'sudo: a password is required' in result['module_stderr'] + assert 'sudo: unknown user: asdfasdf' in result['module_stderr'] + # assert 'sudo: a password is required' in result['module_stderr'] else: - assert 'msg' in result - assert re.match('\[sudo via ansible, [^\]]*\] password:', result['msg']) is not None + assert 'msg' in result, "Missing expected field in JSON response: msg" + assert 'sudo: unknown user: asdfasdf' in result['msg'] + # assert re.match('\[sudo via ansible, [^\]]*\] password:', result['msg']) is not None # "sudo: must be setuid root" ''' % str(option.inventory) testdir.makepyfile(src) - result = testdir.runpytest(*option.args + ['--ansible-inventory', str(option.inventory), - '--ansible-host-pattern', 'localhost', '--ansible-become']) + result = testdir.runpytest( + *option.args + [ + '--ansible-inventory', str(option.inventory), + '--ansible-host-pattern', 'localhost', # run against a single host + '--ansible-become', # Enable become support + '--ansible-become-user', 'asdfasdf' # Connect using a bogus username + ] + ) assert result.ret == EXIT_OK assert result.parseoutcomes()['passed'] == 1