From 501cfca82b50af3576390ca69ad436bbba74a483 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 30 Jul 2019 22:52:26 +0100 Subject: [PATCH] issue #543: make localhost_ansible_tests run locally --- .ci/localhost_ansible_tests.py | 15 ++++++++++++--- tests/ansible/tests/affinity_test.py | 6 ++++++ tests/image_prep/_container_setup.yml | 4 ++++ tests/image_prep/_user_accounts.yml | 2 ++ tests/image_prep/setup.yml | 11 ----------- tests/image_prep/shared_vars.yml | 5 +++++ 6 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 tests/image_prep/shared_vars.yml diff --git a/.ci/localhost_ansible_tests.py b/.ci/localhost_ansible_tests.py index 71542d21..b795da48 100755 --- a/.ci/localhost_ansible_tests.py +++ b/.ci/localhost_ansible_tests.py @@ -27,11 +27,20 @@ with ci_lib.Fold('job_setup'): os.chmod('../data/docker/mitogen__has_sudo_pubkey.key', int('0600', 7)) if not ci_lib.exists_in_path('sshpass'): - run("brew install sshpass") + run("brew install http://git.io/sshpass.rb") with ci_lib.Fold('machine_prep'): - if os.path.expanduser('~mitogen__user1') == '~mitogen_user1': + key_path = os.path.expanduser('~/.ssh/id_rsa') + if not os.path.exists(key_path): + run("ssh-keygen -N '' -f %s", key_path) + + auth_path = os.path.expanduser('~/.ssh/authorized_keys') + with open(auth_path, 'a') as fp: + fp.write(open(key_path + '.pub').read()) + os.chmod(auth_path, int('0600', 8)) + + if os.path.expanduser('~mitogen__user1') == '~mitogen__user1': os.chdir(IMAGE_PREP_DIR) run("ansible-playbook -i localhost, _user_accounts.yml") @@ -40,4 +49,4 @@ with ci_lib.Fold('ansible'): os.chdir(TESTS_DIR) playbook = os.environ.get('PLAYBOOK', 'all.yml') run('./run_ansible_playbook.py %s -l target %s', - playbook, HOSTS_DIR, ' '.join(sys.argv[1:])) + playbook, ' '.join(sys.argv[1:])) diff --git a/tests/ansible/tests/affinity_test.py b/tests/ansible/tests/affinity_test.py index 641455bd..ccd72243 100644 --- a/tests/ansible/tests/affinity_test.py +++ b/tests/ansible/tests/affinity_test.py @@ -1,6 +1,7 @@ import multiprocessing import os +import sys import tempfile import mock @@ -221,6 +222,11 @@ class MockLinuxPolicyTest(testlib.TestCase): for x in range(1, 4096, 32): policy.assign_subprocess() +MockLinuxPolicyTest = unittest2.skipIf( + condition=(not sys.platform.startswith('linuxPolicy')), + reason='select.select() not supported' +)(MockLinuxPolicyTest) + if __name__ == '__main__': unittest2.main() diff --git a/tests/image_prep/_container_setup.yml b/tests/image_prep/_container_setup.yml index 9d001f48..2a30f49d 100644 --- a/tests/image_prep/_container_setup.yml +++ b/tests/image_prep/_container_setup.yml @@ -1,5 +1,7 @@ - hosts: all + vars_files: + - shared_vars.yml strategy: linear gather_facts: false tasks: @@ -13,6 +15,8 @@ fi - hosts: all + vars_files: + - shared_vars.yml strategy: mitogen_free # Can't gather facts before here. gather_facts: true diff --git a/tests/image_prep/_user_accounts.yml b/tests/image_prep/_user_accounts.yml index 5f1bf0dc..e6ace82f 100644 --- a/tests/image_prep/_user_accounts.yml +++ b/tests/image_prep/_user_accounts.yml @@ -5,6 +5,8 @@ # - hosts: all + vars_files: + - shared_vars.yml gather_facts: true strategy: mitogen_free become: true diff --git a/tests/image_prep/setup.yml b/tests/image_prep/setup.yml index 760da0f6..2c37c6bb 100644 --- a/tests/image_prep/setup.yml +++ b/tests/image_prep/setup.yml @@ -1,14 +1,3 @@ -- hosts: all - gather_facts: false - tasks: - - set_fact: - # Hacktacular.. but easiest place for it with current structure. - sudo_group: - MacOSX: admin - Debian: sudo - Ubuntu: sudo - CentOS: wheel - - include: _container_setup.yml - include: _user_accounts.yml diff --git a/tests/image_prep/shared_vars.yml b/tests/image_prep/shared_vars.yml new file mode 100644 index 00000000..4be7babe --- /dev/null +++ b/tests/image_prep/shared_vars.yml @@ -0,0 +1,5 @@ +sudo_group: + MacOSX: admin + Debian: sudo + Ubuntu: sudo + CentOS: wheel