From 99fe9d48e6a28e75f104ce1f2e00f0151192cc11 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 12 Sep 2022 18:32:36 +0100 Subject: [PATCH 1/8] tests: Print task durations --- tests/ansible/ansible.cfg | 11 ++- tests/ansible/lib/callback/profile_tasks.py | 82 --------------------- 2 files changed, 7 insertions(+), 86 deletions(-) delete mode 100644 tests/ansible/lib/callback/profile_tasks.py diff --git a/tests/ansible/ansible.cfg b/tests/ansible/ansible.cfg index ad58a781..a6bc5312 100644 --- a/tests/ansible/ansible.cfg +++ b/tests/ansible/ansible.cfg @@ -1,5 +1,12 @@ [defaults] any_errors_fatal = true +# callback_whitelist naming will be deprecated in ansible-core >= 2.15. +# callbacks_enabled naming was added in ansible-core 2.11 +# profile_tasks: Displays timing for each task and summary table of top N tasks +# timer: Displays "Playbook run took 0 days, 0 hours, ..." +callback_whitelist = + profile_tasks, + timer inventory = hosts gathering = explicit strategy_plugins = ../../ansible_mitogen/plugins/strategy @@ -7,10 +14,6 @@ inventory_plugins = lib/inventory action_plugins = lib/action callback_plugins = lib/callback stdout_callback = yaml -stdout_whitelist = - profile_roles, - timer, - yaml vars_plugins = lib/vars library = lib/modules filter_plugins = lib/filters diff --git a/tests/ansible/lib/callback/profile_tasks.py b/tests/ansible/lib/callback/profile_tasks.py deleted file mode 100644 index 89d956ac..00000000 --- a/tests/ansible/lib/callback/profile_tasks.py +++ /dev/null @@ -1,82 +0,0 @@ -# profile_tasks.py: an Ansible plugin for timing tasks - -# Copyright (C) 2014 Jharrod LaFon -# https://github.com/jlafon/ansible-profile/ -# Included with permission - - -# The MIT License (MIT) -# -# Copyright (c) 2014 Jharrod LaFon -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - - -from ansible.plugins.callback import CallbackBase -import time - - -class CallbackModule(CallbackBase): - """ - A plugin for timing tasks - """ - def __init__(self): - super(CallbackModule, self).__init__() - self.stats = {} - self.current = None - - def playbook_on_task_start(self, name, is_conditional): - """ - Logs the start of each task - """ - if self.current is not None: - # Record the running time of the last executed task - self.stats[self.current] = time.time() - self.stats[self.current] - - # Record the start time of the current task - self.current = name - self.stats[self.current] = time.time() - - called = False - - def playbook_on_stats(self, stats): - """ - Prints the timings - """ - if CallbackModule.called: - return - CallbackModule.called = True - - # Record the timing of the very last task - if self.current is not None: - self.stats[self.current] = time.time() - self.stats[self.current] - - # Sort the tasks by their running time - results = sorted(self.stats.items(), - key=lambda value: value[1], reverse=True) - - # Just keep the top 10 - results = results[:10] - - # Print the timings - for name, elapsed in results: - print("{0:-<70}{1:->9}".format( - '{0} '.format(name), - ' {0:.02f}s'.format(elapsed))) - From 2e8bf738774a1eab9745e2fbc2008ecf8547a8c6 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 12 Sep 2022 18:33:37 +0100 Subject: [PATCH 2/8] tests: Print filename of a failed task (Ansible >= 2.11) --- tests/ansible/ansible.cfg | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ansible/ansible.cfg b/tests/ansible/ansible.cfg index a6bc5312..3d0bb122 100644 --- a/tests/ansible/ansible.cfg +++ b/tests/ansible/ansible.cfg @@ -19,6 +19,7 @@ library = lib/modules filter_plugins = lib/filters module_utils = lib/module_utils retry_files_enabled = False +show_task_path_on_failure = true # Added in ansible-core 2.11 display_args_to_stdout = True forks = 100 From 526422b74b3588d0dd8a08d8dc5c87ca5c14e85d Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 12 Sep 2022 18:46:21 +0100 Subject: [PATCH 3/8] tests: Name tasks For easier grep, and easier identification in task_profiler summaries. --- tests/ansible/bench/loop-20-templates.yml | 6 ++- tests/ansible/integration/action/copy.yml | 31 +++++++++------- .../integration/action/fixup_perms2__copy.yml | 37 ++++++------------- .../integration/action/remote_file_exists.yml | 16 +++----- .../integration/action/remove_tmp_path.yml | 3 +- .../integration/action/synchronize.yml | 12 ++++-- .../integration/action/transfer_data.yml | 26 ++++++------- .../async/result_binary_producing_json.yml | 3 +- .../async/result_shell_echo_hi.yml | 9 +++-- .../async/runner_two_simultaneous_jobs.yml | 3 +- .../integration/connection/_put_file.yml | 12 ++++-- .../connection/disconnect_during_module.yml | 7 +++- .../context_service/reconnection.yml | 3 +- .../context_service/remote_name.yml | 6 ++- .../integration/glibc_caches/resolv_conf.yml | 9 +++-- .../integration/local/cwd_preserved.yml | 3 +- .../playbook_semantics/environment.yml | 3 +- .../runner/_etc_environment_global.yml | 18 ++++++--- .../runner/_etc_environment_user.yml | 9 +++-- tests/ansible/integration/runner/atexit.yml | 12 ++---- .../runner/builtin_command_module.yml | 3 +- .../runner/environment_isolation.yml | 37 ++++++------------- .../integration/runner/missing_module.yml | 3 +- tests/ansible/integration/ssh/timeouts.yml | 6 ++- .../stub_connections/setns_lxc.yml | 3 +- .../stub_connections/setns_lxd.yml | 3 +- ..._109__target_has_old_ansible_installed.yml | 12 +++--- .../regression/issue_140__thread_pileup.yml | 3 +- ...ue_152__local_action_wrong_interpreter.yml | 6 ++- .../issue_152__virtualenv_python_fails.yml | 6 ++- .../issue_177__copy_module_failing.yml | 6 ++- ...32_ansiblemoduleerror_first_occurrence.yml | 7 +++- .../regression/issue_558_unarchive_failed.yml | 13 +++++-- .../issue_590__sys_modules_crap.yml | 2 +- .../issue_615__streaming_transfer.yml | 12 ++++-- tests/ansible/soak/_file_service_loop.yml | 6 ++- 36 files changed, 195 insertions(+), 161 deletions(-) diff --git a/tests/ansible/bench/loop-20-templates.yml b/tests/ansible/bench/loop-20-templates.yml index bae636ce..4035ea34 100644 --- a/tests/ansible/bench/loop-20-templates.yml +++ b/tests/ansible/bench/loop-20-templates.yml @@ -1,12 +1,14 @@ - name: bench/loop-20-templates.yml hosts: all tasks: - - file: + - name: Create loop templates dir + file: dest: /tmp/templates state: "{{item}}" with_items: ["absent", "directory"] - - copy: + - name: Copy loop files + copy: dest: /tmp/templates/{{item}} mode: 0755 content: diff --git a/tests/ansible/integration/action/copy.yml b/tests/ansible/integration/action/copy.yml index 8aae546a..5dadff9a 100644 --- a/tests/ansible/integration/action/copy.yml +++ b/tests/ansible/integration/action/copy.yml @@ -3,21 +3,22 @@ - name: integration/action/copy.yml hosts: test-targets tasks: - - copy: + - name: Create tiny file + copy: dest: /tmp/copy-tiny-file content: this is a tiny file. delegate_to: localhost - - copy: + - name: Create large file + copy: dest: /tmp/copy-large-file # Must be larger than Connection.SMALL_SIZE_LIMIT. content: "{% for x in range(200000) %}x{% endfor %}" delegate_to: localhost - # end of making files - - - file: + - name: Cleanup copied files + file: state: absent path: "{{item}}" with_items: @@ -26,28 +27,31 @@ - /tmp/copy-tiny-inline-file.out - /tmp/copy-large-inline-file.out - # end of cleaning out files - - - copy: + - name: Copy large file + copy: dest: /tmp/copy-large-file.out src: /tmp/copy-large-file - - copy: + - name: Copy tiny file + copy: dest: /tmp/copy-tiny-file.out src: /tmp/copy-tiny-file - - copy: + - name: Copy tiny inline file + copy: dest: /tmp/copy-tiny-inline-file.out content: "tiny inline content" - - copy: + - name: Copy large inline file + copy: dest: /tmp/copy-large-inline-file.out content: | {% for x in range(200000) %}y{% endfor %} # stat results - - stat: + - name: Stat copied files + stat: path: "{{item}}" with_items: - /tmp/copy-tiny-file.out @@ -64,7 +68,8 @@ - stat.results[3].stat.checksum == "d675f47e467eae19e49032a2cc39118e12a6ee72" fail_msg: stat={{stat}} - - file: + - name: Cleanup files + file: state: absent path: "{{item}}" with_items: diff --git a/tests/ansible/integration/action/fixup_perms2__copy.yml b/tests/ansible/integration/action/fixup_perms2__copy.yml index 652974d3..fa4765f8 100644 --- a/tests/ansible/integration/action/fixup_perms2__copy.yml +++ b/tests/ansible/integration/action/fixup_perms2__copy.yml @@ -6,10 +6,6 @@ - name: integration/action/fixup_perms2__copy.yml hosts: test-targets tasks: - # - # copy module (no mode). - # - - name: "Copy files (no mode)" copy: content: "" @@ -22,10 +18,6 @@ - out.stat.mode in ("0644", "0664") fail_msg: out={{out}} - # - # copy module (explicit mode). - # - - name: "Copy files from content: arg" copy: content: "" @@ -39,22 +31,20 @@ - out.stat.mode == "0400" fail_msg: out={{out}} - # - # copy module (existing disk files, no mode). - # - - - file: + - name: Cleanup local weird mode file + file: path: /tmp/weird-mode.out state: absent - - name: Create local test file. + - name: Create local weird mode file delegate_to: localhost copy: content: "weird mode" dest: "/tmp/weird-mode" mode: "1462" - - copy: + - name: Copy file with weird mode + copy: src: "/tmp/weird-mode" dest: "/tmp/weird-mode.out" @@ -66,11 +56,8 @@ - out.stat.mode in ("0644", "0664") fail_msg: out={{out}} - # - # copy module (existing disk files, preserve mode). - # - - - copy: + - name: Copy file with weird mode, preserving mode + copy: src: "/tmp/weird-mode" dest: "/tmp/weird-mode" mode: preserve @@ -83,11 +70,8 @@ - out.stat.mode == "1462" fail_msg: out={{out}} - # - # copy module (existing disk files, explicit mode). - # - - - copy: + - name: Copy file with weird mode, explicit mode + copy: src: "/tmp/weird-mode" dest: "/tmp/weird-mode" mode: "1461" @@ -101,7 +85,8 @@ - out.stat.mode == "1461" fail_msg: out={{out}} - - file: + - name: Cleanup + file: state: absent path: "{{item}}" with_items: diff --git a/tests/ansible/integration/action/remote_file_exists.yml b/tests/ansible/integration/action/remote_file_exists.yml index 28952f93..577e64a0 100644 --- a/tests/ansible/integration/action/remote_file_exists.yml +++ b/tests/ansible/integration/action/remote_file_exists.yml @@ -2,36 +2,32 @@ - name: integration/action/remote_file_exists.yml hosts: test-targets tasks: - - - file: + - name: Ensure does-not-exist doesnt + file: path: /tmp/does-not-exist state: absent - - action_passthrough: method: _remote_file_exists args: ['/tmp/does-not-exist'] register: out - - assert: that: out.result == False fail_msg: out={{out}} - # --- - - - copy: + - name: Ensure does-exist does + copy: dest: /tmp/does-exist content: "I think, therefore I am" - - action_passthrough: method: _remote_file_exists args: ['/tmp/does-exist'] register: out - - assert: that: out.result == True fail_msg: out={{out}} - - file: + - name: Cleanup + file: path: /tmp/does-exist state: absent tags: diff --git a/tests/ansible/integration/action/remove_tmp_path.yml b/tests/ansible/integration/action/remove_tmp_path.yml index 1df212c7..d90c90dc 100644 --- a/tests/ansible/integration/action/remove_tmp_path.yml +++ b/tests/ansible/integration/action/remove_tmp_path.yml @@ -10,7 +10,8 @@ # return a result with a 'src' attribute pointing into that directory. # - - copy: + - name: Ensure remove_tmp_path_test + copy: dest: /tmp/remove_tmp_path_test content: "{{ 123123 | random }}" register: out diff --git a/tests/ansible/integration/action/synchronize.yml b/tests/ansible/integration/action/synchronize.yml index f17d8fb8..aa87deaf 100644 --- a/tests/ansible/integration/action/synchronize.yml +++ b/tests/ansible/integration/action/synchronize.yml @@ -12,23 +12,27 @@ ansible_password: '' tasks: # must copy git file to set proper file mode. - - copy: + - name: Copy synchronize-action-key + copy: dest: /tmp/synchronize-action-key src: ../../../data/docker/mitogen__has_sudo_pubkey.key mode: u=rw,go= delegate_to: localhost - - file: + - name: Cleanup sync-test + file: path: /tmp/sync-test state: absent delegate_to: localhost - - file: + - name: Create sync-test + file: path: /tmp/sync-test state: directory delegate_to: localhost - - copy: + - name: Create syn-test item + copy: dest: /tmp/sync-test/item content: "item!" delegate_to: localhost diff --git a/tests/ansible/integration/action/transfer_data.yml b/tests/ansible/integration/action/transfer_data.yml index 343f45da..6d4faab5 100644 --- a/tests/ansible/integration/action/transfer_data.yml +++ b/tests/ansible/integration/action/transfer_data.yml @@ -2,47 +2,45 @@ - name: integration/action/transfer_data.yml hosts: test-targets tasks: - - - file: + - name: Cleanup transfer data + file: path: /tmp/transfer-data state: absent - # Ensure it JSON-encodes dicts. - - action_passthrough: + - name: Create JSON transfer data + action_passthrough: method: _transfer_data kwargs: remote_path: /tmp/transfer-data data: { "I am JSON": true } - - - slurp: + - name: Slurp JSON transfer data + slurp: src: /tmp/transfer-data register: out - - assert: that: | out.content|b64decode == '{"I am JSON": true}' fail_msg: out={{out}} - - # Ensure it handles strings. - - action_passthrough: + - name: Create text transfer data + action_passthrough: method: _transfer_data kwargs: remote_path: /tmp/transfer-data data: "I am text." - - - slurp: + - name: Slurp text transfer data + slurp: src: /tmp/transfer-data register: out - - assert: that: out.content|b64decode == 'I am text.' fail_msg: out={{out}} - - file: + - name: Cleanup transfer data + file: path: /tmp/transfer-data state: absent tags: diff --git a/tests/ansible/integration/async/result_binary_producing_json.yml b/tests/ansible/integration/async/result_binary_producing_json.yml index 4df46e76..942b356a 100644 --- a/tests/ansible/integration/async/result_binary_producing_json.yml +++ b/tests/ansible/integration/async/result_binary_producing_json.yml @@ -37,7 +37,8 @@ retries: 100000 delay: 0 - - slurp: + - name: Slurp async busy-poll + slurp: src: "{{ansible_user_dir}}/.ansible_async/{{job.ansible_job_id}}" register: result diff --git a/tests/ansible/integration/async/result_shell_echo_hi.yml b/tests/ansible/integration/async/result_shell_echo_hi.yml index d50a41b9..f327a965 100644 --- a/tests/ansible/integration/async/result_shell_echo_hi.yml +++ b/tests/ansible/integration/async/result_shell_echo_hi.yml @@ -4,14 +4,17 @@ hosts: test-targets tasks: - - shell: echo hi; echo there >&2 + - name: Async shell + shell: echo hi; echo there >&2 async: 100 poll: 0 register: job - - shell: sleep 1 + - name: Sleepy shell + shell: sleep 1 - - slurp: + - name: Slurp async shell + slurp: src: "{{ansible_user_dir}}/.ansible_async/{{job.ansible_job_id}}" register: result diff --git a/tests/ansible/integration/async/runner_two_simultaneous_jobs.yml b/tests/ansible/integration/async/runner_two_simultaneous_jobs.yml index a0fd125a..5678dbdd 100644 --- a/tests/ansible/integration/async/runner_two_simultaneous_jobs.yml +++ b/tests/ansible/integration/async/runner_two_simultaneous_jobs.yml @@ -5,7 +5,8 @@ # Start 2 duplicate jobs, verify they run concurrently. - - file: + - name: Cleanup semaphore file + file: path: /tmp/flurp state: absent diff --git a/tests/ansible/integration/connection/_put_file.yml b/tests/ansible/integration/connection/_put_file.yml index 3092e199..fb5c6014 100644 --- a/tests/ansible/integration/connection/_put_file.yml +++ b/tests/ansible/integration/connection/_put_file.yml @@ -1,19 +1,23 @@ --- -- shell: dd if=/dev/urandom of=/tmp/{{file_name}} bs=1024 count={{file_size}} +- name: Create {{ file_name }} + shell: dd if=/dev/urandom of=/tmp/{{ file_name }} bs=1024 count={{ file_size }} args: creates: /tmp/{{file_name}} delegate_to: localhost -- copy: +- name: Copy {{ file_name }} + copy: dest: /tmp/{{file_name}}.out src: /tmp/{{file_name}} -- stat: path=/tmp/{{file_name}} +- name: Stat created {{ file_name }} + stat: path=/tmp/{{ file_name }} register: original delegate_to: localhost -- stat: path=/tmp/{{file_name}}.out +- name: Stat copied {{ file_name }} + stat: path=/tmp/{{ file_name }}.out register: copied - assert: diff --git a/tests/ansible/integration/connection/disconnect_during_module.yml b/tests/ansible/integration/connection/disconnect_during_module.yml index 1c7b544a..5c74b0ed 100644 --- a/tests/ansible/integration/connection/disconnect_during_module.yml +++ b/tests/ansible/integration/connection/disconnect_during_module.yml @@ -9,10 +9,13 @@ - meta: end_play when: not is_mitogen - - delegate_to: localhost + - name: Run _disconnect_during_module.yml + delegate_to: localhost command: | ansible-playbook - -i "{{MITOGEN_INVENTORY_FILE}}" + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} integration/connection/_disconnect_during_module.yml args: chdir: ../.. diff --git a/tests/ansible/integration/context_service/reconnection.yml b/tests/ansible/integration/context_service/reconnection.yml index 4fc975a1..5ab2309f 100644 --- a/tests/ansible/integration/context_service/reconnection.yml +++ b/tests/ansible/integration/context_service/reconnection.yml @@ -13,7 +13,8 @@ custom_python_detect_environment: register: old_become_env - - become: true + - name: Kill ssh process + become: true shell: | bash -c "( sleep 3; kill -9 {{ssh_account_env.pid}}; ) & disown" diff --git a/tests/ansible/integration/context_service/remote_name.yml b/tests/ansible/integration/context_service/remote_name.yml index 17ade617..79fb8dea 100644 --- a/tests/ansible/integration/context_service/remote_name.yml +++ b/tests/ansible/integration/context_service/remote_name.yml @@ -10,7 +10,8 @@ - meta: end_play when: ansible_system != 'Linux' - - shell: 'cat /proc/$PPID/cmdline | tr \\0 \\n' + - name: Get cmdline + shell: 'cat /proc/$PPID/cmdline | tr \\0 \\n' register: out - debug: var=out @@ -19,7 +20,8 @@ - out.stdout is match('.*python([0-9.]+)?\(mitogen:[a-z]+@[^:]+:[0-9]+\)') fail_msg: out={{out}} - - shell: 'cat /proc/$PPID/cmdline | tr \\0 \\n' + - name: Get cmdline, with mitogen_mask_remote_name + shell: 'cat /proc/$PPID/cmdline | tr \\0 \\n' register: out vars: mitogen_mask_remote_name: true diff --git a/tests/ansible/integration/glibc_caches/resolv_conf.yml b/tests/ansible/integration/glibc_caches/resolv_conf.yml index e83ce38e..1b22b66c 100644 --- a/tests/ansible/integration/glibc_caches/resolv_conf.yml +++ b/tests/ansible/integration/glibc_caches/resolv_conf.yml @@ -15,12 +15,14 @@ - ansible_facts.virtualization_type == "docker" - ansible_facts.python.version_info[:2] >= [2, 5] - - shell: cp /etc/resolv.conf /tmp/resolv.conf + - name: Backup resolv.conf + shell: cp /etc/resolv.conf /tmp/resolv.conf when: - ansible_facts.virtualization_type == "docker" - ansible_facts.python.version_info[:2] >= [2, 5] - - shell: echo > /etc/resolv.conf + - name: Truncate resolv.conf + shell: echo > /etc/resolv.conf when: - ansible_facts.virtualization_type == "docker" - ansible_facts.python.version_info[:2] >= [2, 5] @@ -33,7 +35,8 @@ - ansible_facts.virtualization_type == "docker" - ansible_facts.python.version_info[:2] >= [2, 5] - - shell: cat /tmp/resolv.conf > /etc/resolv.conf + - name: Restore resolv.conf + shell: cat /tmp/resolv.conf > /etc/resolv.conf when: - ansible_facts.virtualization_type == "docker" - ansible_facts.python.version_info[:2] >= [2, 5] diff --git a/tests/ansible/integration/local/cwd_preserved.yml b/tests/ansible/integration/local/cwd_preserved.yml index c1dfc99d..70aec613 100644 --- a/tests/ansible/integration/local/cwd_preserved.yml +++ b/tests/ansible/integration/local/cwd_preserved.yml @@ -7,7 +7,8 @@ - name: integration/local/cwd_preserved.yml hosts: test-targets tasks: - - connection: local + - name: Get local cwd + connection: local command: pwd register: pwd diff --git a/tests/ansible/integration/playbook_semantics/environment.yml b/tests/ansible/integration/playbook_semantics/environment.yml index 69728981..eea000bd 100644 --- a/tests/ansible/integration/playbook_semantics/environment.yml +++ b/tests/ansible/integration/playbook_semantics/environment.yml @@ -3,7 +3,8 @@ - name: integration/playbook_semantics/environment.yml hosts: test-targets tasks: - - shell: echo $SOME_ENV + - name: Echo $SOME_ENV + shell: echo $SOME_ENV environment: SOME_ENV: 123 register: result diff --git a/tests/ansible/integration/runner/_etc_environment_global.yml b/tests/ansible/integration/runner/_etc_environment_global.yml index 7b769ef4..2d883d06 100644 --- a/tests/ansible/integration/runner/_etc_environment_global.yml +++ b/tests/ansible/integration/runner/_etc_environment_global.yml @@ -1,18 +1,21 @@ # /etc/environment -- file: +- name: Remove /etc/environment + file: path: /etc/environment state: absent become: true -- shell: echo $MAGIC_ETC_ENV +- name: Check MAGIC_ETC_ENV without + shell: echo $MAGIC_ETC_ENV register: echo - assert: that: echo.stdout == "" fail_msg: echo={{echo}} -- copy: +- name: Create /etc/environment + copy: dest: /etc/environment content: | MAGIC_ETC_ENV=555 @@ -23,14 +26,16 @@ #- mitogen_shutdown_all: #when: not is_mitogen -- shell: echo $MAGIC_ETC_ENV +- name: Check MAGIC_ETC_ENV with + shell: echo $MAGIC_ETC_ENV register: echo - assert: that: echo.stdout == "555" fail_msg: echo={{echo}} -- file: +- name: Cleanup /etc/environment + file: path: /etc/environment state: absent become: true @@ -40,7 +45,8 @@ - mitogen_shutdown_all: when: not is_mitogen -- shell: echo $MAGIC_ETC_ENV +- name: Check MAGIC_ETC_ENV without+shutdown + shell: echo $MAGIC_ETC_ENV register: echo - assert: diff --git a/tests/ansible/integration/runner/_etc_environment_user.yml b/tests/ansible/integration/runner/_etc_environment_user.yml index 9d9b831a..939ee8dc 100644 --- a/tests/ansible/integration/runner/_etc_environment_user.yml +++ b/tests/ansible/integration/runner/_etc_environment_user.yml @@ -1,6 +1,7 @@ # ~/.pam_environment -- file: +- name: Remove pam_environment + file: path: ~/.pam_environment state: absent @@ -11,7 +12,8 @@ that: echo.stdout == "" fail_msg: echo={{echo}} -- copy: +- name: Copy pam_environment + copy: dest: ~/.pam_environment content: | MAGIC_PAM_ENV=321 @@ -23,7 +25,8 @@ that: echo.stdout == "321" fail_msg: echo={{echo}} -- file: +- name: Cleanup pam_environment + file: path: ~/.pam_environment state: absent diff --git a/tests/ansible/integration/runner/atexit.yml b/tests/ansible/integration/runner/atexit.yml index 65673561..75509877 100644 --- a/tests/ansible/integration/runner/atexit.yml +++ b/tests/ansible/integration/runner/atexit.yml @@ -9,20 +9,16 @@ vars: path: /tmp/atexit-should-delete-this tasks: - - # - # Verify a run with a healthy atexit handler. Broken handlers cause an - # exception to be raised. - # - - - custom_python_run_script: + - name: Verify a run with a healthy atexit handler + custom_python_run_script: script: | import atexit, os, shutil path = '{{path}}' os.mkdir(path, int('777', 8)) atexit.register(shutil.rmtree, path) - - stat: + - name: Stat atexit file + stat: path: "{{path}}" register: out diff --git a/tests/ansible/integration/runner/builtin_command_module.yml b/tests/ansible/integration/runner/builtin_command_module.yml index 70ed94ba..06e058cd 100644 --- a/tests/ansible/integration/runner/builtin_command_module.yml +++ b/tests/ansible/integration/runner/builtin_command_module.yml @@ -3,7 +3,8 @@ hosts: test-targets gather_facts: true tasks: - - command: hostname + - name: Run hostname + command: hostname with_sequence: start=1 end={{end|default(1)}} register: out diff --git a/tests/ansible/integration/runner/environment_isolation.yml b/tests/ansible/integration/runner/environment_isolation.yml index c3e7b16e..b195a469 100644 --- a/tests/ansible/integration/runner/environment_isolation.yml +++ b/tests/ansible/integration/runner/environment_isolation.yml @@ -1,51 +1,38 @@ # issue #309: ensure process environment is restored after a module runs. - - name: integration/runner/environment_isolation.yml hosts: test-targets gather_facts: true tasks: - - # --- - # Verify custom env setting is cleared out. - # --- - - # Verify sane state first. - - custom_python_detect_environment: + - name: Verify custom env setting is cleared, control + custom_python_detect_environment: register: out - assert: that: not out.env.evil_key is defined fail_msg: out={{out}} - - - shell: echo 'hi' + - name: Verify custom env setting is cleared, with evil_key + shell: echo 'hi' environment: evil_key: evil - - # Verify environment was cleaned up. - - custom_python_detect_environment: + - name: Verify custom env setting is cleared, without evil_key + custom_python_detect_environment: register: out - assert: that: not out.env.evil_key is defined fail_msg: out={{out}} - - # --- - # Verify non-explicit module env mutations are cleared out. - # --- - - # Verify sane state first. - - custom_python_detect_environment: + - name: Verify non-explicit module env mutations are cleared, control + custom_python_detect_environment: register: out - assert: that: not out.env.evil_key is defined fail_msg: out={{out}} - - - custom_python_modify_environ: + - name: Verify non-explicit module env mutations are cleared, mutate evil_key + custom_python_modify_environ: key: evil_key val: evil - - # Verify environment was cleaned up. - - custom_python_detect_environment: + - name: Verify non-explicit module env mutations are cleared, without evil_key + custom_python_detect_environment: register: out - assert: that: not out.env.evil_key is defined diff --git a/tests/ansible/integration/runner/missing_module.yml b/tests/ansible/integration/runner/missing_module.yml index 676012d9..baa56b8b 100644 --- a/tests/ansible/integration/runner/missing_module.yml +++ b/tests/ansible/integration/runner/missing_module.yml @@ -3,7 +3,8 @@ hosts: test-targets[0] connection: local tasks: - - connection: local + - name: Run missing_module + connection: local command: | ansible -vvv -i "{{MITOGEN_INVENTORY_FILE}}" diff --git a/tests/ansible/integration/ssh/timeouts.yml b/tests/ansible/integration/ssh/timeouts.yml index d697905a..24b1c5bb 100644 --- a/tests/ansible/integration/ssh/timeouts.yml +++ b/tests/ansible/integration/ssh/timeouts.yml @@ -3,7 +3,8 @@ - name: integration/ssh/timeouts.yml hosts: test-targets tasks: - - connection: local + - name: Cause Ansible connection timeout + connection: local command: | ansible -vvv -i "{{MITOGEN_INVENTORY_FILE}}" @@ -16,7 +17,8 @@ ignore_errors: true when: is_mitogen - - assert: + - name: Verify connection timeout occurred + assert: that: - | '"changed": false' in out.stdout diff --git a/tests/ansible/integration/stub_connections/setns_lxc.yml b/tests/ansible/integration/stub_connections/setns_lxc.yml index 44717504..75d4207b 100644 --- a/tests/ansible/integration/stub_connections/setns_lxc.yml +++ b/tests/ansible/integration/stub_connections/setns_lxc.yml @@ -13,7 +13,8 @@ - include: _end_play_if_not_sudo_linux.yml - - command: | + - name: Run stub-lxc-info.py + command: | sudo -nE "{{lookup('env', 'VIRTUAL_ENV')}}/bin/ansible" -i localhost, -c setns diff --git a/tests/ansible/integration/stub_connections/setns_lxd.yml b/tests/ansible/integration/stub_connections/setns_lxd.yml index 841f7805..3f3bc291 100644 --- a/tests/ansible/integration/stub_connections/setns_lxd.yml +++ b/tests/ansible/integration/stub_connections/setns_lxd.yml @@ -13,7 +13,8 @@ - include: _end_play_if_not_sudo_linux.yml - - command: | + - name: Run ansible stub-lxc.py + command: | sudo -nE "{{lookup('env', 'VIRTUAL_ENV')}}/bin/ansible" -i localhost, -c setns diff --git a/tests/ansible/regression/issue_109__target_has_old_ansible_installed.yml b/tests/ansible/regression/issue_109__target_has_old_ansible_installed.yml index 5343989c..e6677e2d 100644 --- a/tests/ansible/regression/issue_109__target_has_old_ansible_installed.yml +++ b/tests/ansible/regression/issue_109__target_has_old_ansible_installed.yml @@ -9,8 +9,8 @@ when: - ansible_version.full is version('2.6', '<', strict=True) - # Copy the naughty 'ansible' into place. - - copy: + - name: Copy the naughty ansible into place + copy: dest: "{{ansible_user_dir}}/ansible.py" src: ansible.py @@ -20,15 +20,15 @@ - custom_python_detect_environment: register: env - # Verify interpreter config would actually trigger the bug. - - assert: + - name: Verify interpreter config would actually trigger the bug + assert: that: - env.cwd == ansible_user_dir - (not env.mitogen_loaded) or (env.python_path.count("") == 1) fail_msg: env={{env}} - # Run some new-style modules that 'from ansible.module_utils...' - - stat: + - name: Run some new-style from ansible.module_utils... modules + stat: path: / tags: - issue_109 diff --git a/tests/ansible/regression/issue_140__thread_pileup.yml b/tests/ansible/regression/issue_140__thread_pileup.yml index 23649f92..1f614634 100644 --- a/tests/ansible/regression/issue_140__thread_pileup.yml +++ b/tests/ansible/regression/issue_140__thread_pileup.yml @@ -17,7 +17,8 @@ - name: Delete remote file tree file: path=/tmp/filetree.out state=absent - - file: + - name: Recreate file tree + file: state: directory path: /tmp/filetree.out diff --git a/tests/ansible/regression/issue_152__local_action_wrong_interpreter.yml b/tests/ansible/regression/issue_152__local_action_wrong_interpreter.yml index c53d34e4..fe7f5f42 100644 --- a/tests/ansible/regression/issue_152__local_action_wrong_interpreter.yml +++ b/tests/ansible/regression/issue_152__local_action_wrong_interpreter.yml @@ -8,7 +8,8 @@ connection: local tasks: - - copy: + - name: Create /tmp/issue_152_interpreter.sh + copy: dest: /tmp/issue_152_interpreter.sh mode: u+x content: | @@ -26,7 +27,8 @@ - out.env.CUSTOM_INTERPRETER == "1" fail_msg: out={{out}} - - file: + - name: Cleanup /tmp/issue_152_interpreter.sh + file: path: /tmp/issue_152_interpreter.sh state: absent tags: diff --git a/tests/ansible/regression/issue_152__virtualenv_python_fails.yml b/tests/ansible/regression/issue_152__virtualenv_python_fails.yml index 34a57a8a..f4c47aba 100644 --- a/tests/ansible/regression/issue_152__virtualenv_python_fails.yml +++ b/tests/ansible/regression/issue_152__virtualenv_python_fails.yml @@ -7,11 +7,12 @@ # Can't use pip module because it can't create virtualenvs, must call it # directly. - - shell: virtualenv /tmp/issue_152_virtualenv + - name: Create /tmp/issue_152_virtualenv environment: https_proxy: "{{ lookup('env', 'https_proxy')|default('') }}" no_proxy: "{{ lookup('env', 'no_proxy')|default('') }}" PATH: "{{ lookup('env', 'PATH') }}" + shell: virtualenv /tmp/issue_152_virtualenv when: - lout.python.version.full is version('2.7', '>=', strict=True) @@ -29,7 +30,8 @@ when: - lout.python.version.full is version('2.7', '>=', strict=True) - - file: + - name: Cleanup /tmp/issue_152_virtualenv + file: path: /tmp/issue_152_virtualenv state: absent when: diff --git a/tests/ansible/regression/issue_177__copy_module_failing.yml b/tests/ansible/regression/issue_177__copy_module_failing.yml index 948621d3..c8dfc635 100644 --- a/tests/ansible/regression/issue_177__copy_module_failing.yml +++ b/tests/ansible/regression/issue_177__copy_module_failing.yml @@ -2,7 +2,8 @@ hosts: test-targets tasks: - - copy: + - name: Copy files + copy: src: /etc/{{item}} dest: /tmp/{{item}} mode: 0644 @@ -10,7 +11,8 @@ - passwd - hosts - - file: + - name: Cleanup files + file: path: /tmp/{{item}} state: absent with_items: diff --git a/tests/ansible/regression/issue_332_ansiblemoduleerror_first_occurrence.yml b/tests/ansible/regression/issue_332_ansiblemoduleerror_first_occurrence.yml index 2433e566..be069b1e 100644 --- a/tests/ansible/regression/issue_332_ansiblemoduleerror_first_occurrence.yml +++ b/tests/ansible/regression/issue_332_ansiblemoduleerror_first_occurrence.yml @@ -4,7 +4,12 @@ - name: regression/issue_332_ansiblemoduleerror_first_occurrence.yml hosts: test-targets tasks: - - file: path=/usr/bin/does-not-exist mode='a-s' state=file follow=yes + - name: Attempt to modify /usr/bin/does-not-exist + file: + path: /usr/bin/does-not-exist + mode: a-s + state: file + follow: true ignore_errors: true register: out diff --git a/tests/ansible/regression/issue_558_unarchive_failed.yml b/tests/ansible/regression/issue_558_unarchive_failed.yml index 23e9caad..829101cb 100644 --- a/tests/ansible/regression/issue_558_unarchive_failed.yml +++ b/tests/ansible/regression/issue_558_unarchive_failed.yml @@ -4,9 +4,16 @@ - name: regression/issue_558_unarchive_failed.yml hosts: test-targets tasks: - - file: state=absent path=/tmp/foo - - file: state=directory path=/tmp/foo - - unarchive: + - name: Cleanup /tmp/foo + file: + path: /tmp/foo + state: absent + - name: Create /tmp/foo + file: + path: /tmp/foo + state: directory + - name: Unarchive unarchive_test.tar + unarchive: src: "{{git_basedir}}/tests/data/unarchive_test.tar" dest: /tmp/foo # garbage doesn't work with BSD tar diff --git a/tests/ansible/regression/issue_590__sys_modules_crap.yml b/tests/ansible/regression/issue_590__sys_modules_crap.yml index bd4334b0..476701e3 100644 --- a/tests/ansible/regression/issue_590__sys_modules_crap.yml +++ b/tests/ansible/regression/issue_590__sys_modules_crap.yml @@ -1,4 +1,4 @@ -- name: regression/iss590__sys_modules_crap.yml +- name: regression/issue_590__sys_modules_crap.yml hosts: test-targets tasks: - meta: end_play diff --git a/tests/ansible/regression/issue_615__streaming_transfer.yml b/tests/ansible/regression/issue_615__streaming_transfer.yml index 1c69914d..8ec28499 100644 --- a/tests/ansible/regression/issue_615__streaming_transfer.yml +++ b/tests/ansible/regression/issue_615__streaming_transfer.yml @@ -9,19 +9,23 @@ mitogen_ssh_compression: false tasks: - block: - - shell: | + - name: Create /tmp/512mb.zero + shell: | dd if=/dev/zero of=/tmp/512mb.zero bs=1048576 count=512; chmod go= /tmp/512mb.zero - - fetch: + - name: Fetch /tmp/512mb.zero + fetch: src: /tmp/512mb.zero dest: /tmp/fetch-out - - file: + - name: Cleanup /tmp/512mb.zero + file: path: /tmp/512mb.zero state: absent - - file: + - name: Cleanup fetched file + file: path: /tmp/fetch-out state: absent become: false diff --git a/tests/ansible/soak/_file_service_loop.yml b/tests/ansible/soak/_file_service_loop.yml index 96111b3c..474abd07 100644 --- a/tests/ansible/soak/_file_service_loop.yml +++ b/tests/ansible/soak/_file_service_loop.yml @@ -1,6 +1,8 @@ - - file: + - name: Delete existing /tmp/foo- + file: path: /tmp/foo-{{inventory_hostname}} state: absent - - copy: + - name: Create /tmp/foo- + copy: dest: /tmp/foo-{{inventory_hostname}} content: "{{content}}" From 900760e913273e11a37af6be34e0cd0f516bb55f Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 12 Sep 2022 18:48:56 +0100 Subject: [PATCH 4/8] tests: Increase Ansible timeout to reduce false positives Was failing on my dsktop PC, with a spinning rust HDD --- tests/ansible/ansible.cfg | 2 +- .../delegate_to_template.yml | 4 ++-- .../connection_delegation/local_action.yml | 2 +- .../stack_construction.yml | 24 +++++++++---------- tests/ansible/integration/ssh/timeouts.yml | 2 ++ 5 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/ansible/ansible.cfg b/tests/ansible/ansible.cfg index 3d0bb122..ce4511f6 100644 --- a/tests/ansible/ansible.cfg +++ b/tests/ansible/ansible.cfg @@ -35,7 +35,7 @@ transport = ssh no_target_syslog = True # Required by integration/ssh/timeouts.yml -timeout = 10 +timeout = 30 # On Travis, paramiko check fails due to host key checking enabled. host_key_checking = False diff --git a/tests/ansible/integration/connection_delegation/delegate_to_template.yml b/tests/ansible/integration/connection_delegation/delegate_to_template.yml index 14ebc8d2..36de1657 100644 --- a/tests/ansible/integration/connection_delegation/delegate_to_template.yml +++ b/tests/ansible/integration/connection_delegation/delegate_to_template.yml @@ -33,7 +33,7 @@ 'kwargs': { 'check_host_keys': 'ignore', 'compression': True, - 'connect_timeout': 10, + 'connect_timeout': 30, 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, @@ -63,7 +63,7 @@ 'kwargs': { 'check_host_keys': 'ignore', 'compression': True, - 'connect_timeout': 10, + 'connect_timeout': 30, 'hostname': 'cd-normal-alias', 'identities_only': False, 'identity_file': null, diff --git a/tests/ansible/integration/connection_delegation/local_action.yml b/tests/ansible/integration/connection_delegation/local_action.yml index 921ff073..6176d770 100644 --- a/tests/ansible/integration/connection_delegation/local_action.yml +++ b/tests/ansible/integration/connection_delegation/local_action.yml @@ -22,7 +22,7 @@ { 'enable_lru': true, 'kwargs': { - 'connect_timeout': 10, + 'connect_timeout': 30, 'python_path': ["{{ansible_playbook_python}}"], 'remote_name': null, 'password': null, diff --git a/tests/ansible/integration/connection_delegation/stack_construction.yml b/tests/ansible/integration/connection_delegation/stack_construction.yml index ef468f1b..380b3198 100644 --- a/tests/ansible/integration/connection_delegation/stack_construction.yml +++ b/tests/ansible/integration/connection_delegation/stack_construction.yml @@ -41,7 +41,7 @@ right: [ { "kwargs": { - "connect_timeout": 10, + "connect_timeout": 30, "doas_path": null, "password": null, "python_path": ["/usr/bin/python"], @@ -70,7 +70,7 @@ 'kwargs': { 'check_host_keys': 'ignore', 'compression': True, - 'connect_timeout': 10, + 'connect_timeout': 30, 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, @@ -115,7 +115,7 @@ 'kwargs': { 'check_host_keys': 'ignore', 'compression': True, - 'connect_timeout': 10, + 'connect_timeout': 30, 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, @@ -158,7 +158,7 @@ right: [ { 'kwargs': { - 'connect_timeout': 10, + 'connect_timeout': 30, 'doas_path': null, 'password': null, "python_path": ["/usr/bin/python"], @@ -171,7 +171,7 @@ 'kwargs': { 'check_host_keys': 'ignore', 'compression': True, - 'connect_timeout': 10, + 'connect_timeout': 30, 'hostname': 'cd-normal-normal', 'identities_only': False, 'identity_file': null, @@ -216,7 +216,7 @@ 'kwargs': { 'check_host_keys': 'ignore', 'compression': True, - 'connect_timeout': 10, + 'connect_timeout': 30, 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, @@ -246,7 +246,7 @@ 'kwargs': { 'check_host_keys': 'ignore', 'compression': True, - 'connect_timeout': 10, + 'connect_timeout': 30, 'hostname': 'cd-normal-alias', 'identities_only': False, 'identity_file': null, @@ -289,7 +289,7 @@ right: [ { 'kwargs': { - 'connect_timeout': 10, + 'connect_timeout': 30, 'doas_path': null, 'password': null, "python_path": ["/usr/bin/python"], @@ -302,7 +302,7 @@ 'kwargs': { 'check_host_keys': 'ignore', 'compression': True, - 'connect_timeout': 10, + 'connect_timeout': 30, 'hostname': 'cd-newuser-normal-normal', 'identities_only': False, 'identity_file': null, @@ -348,7 +348,7 @@ 'kwargs': { 'check_host_keys': 'ignore', 'compression': True, - 'connect_timeout': 10, + 'connect_timeout': 30, 'hostname': 'alias-host', 'identities_only': False, 'identity_file': null, @@ -412,7 +412,7 @@ right: [ { 'kwargs': { - 'connect_timeout': 10, + 'connect_timeout': 30, 'doas_path': null, 'password': null, 'python_path': ["/usr/bin/python"], @@ -423,7 +423,7 @@ }, { 'kwargs': { - 'connect_timeout': 10, + 'connect_timeout': 30, 'doas_path': null, 'password': null, 'python_path': ["/usr/bin/python"], diff --git a/tests/ansible/integration/ssh/timeouts.yml b/tests/ansible/integration/ssh/timeouts.yml index 24b1c5bb..f630d943 100644 --- a/tests/ansible/integration/ssh/timeouts.yml +++ b/tests/ansible/integration/ssh/timeouts.yml @@ -5,6 +5,8 @@ tasks: - name: Cause Ansible connection timeout connection: local + environment: + ANSIBLE_SSH_TIMEOUT: 10 command: | ansible -vvv -i "{{MITOGEN_INVENTORY_FILE}}" From 1ed932e8d5bb4c7d4bfcf190e024c782b4299573 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 12 Sep 2022 19:01:38 +0100 Subject: [PATCH 5/8] tests: Eliminate MITOGEN_INVENTORY_FILE Replaced with ansible_inventory_sources. --- .../process/unix_socket_cleanup.yml | 6 ++- .../integration/runner/missing_module.yml | 4 +- tests/ansible/integration/ssh/timeouts.yml | 4 +- tests/ansible/integration/ssh/variables.yml | 48 +++++++++++++++---- .../strategy/mixed_vanilla_mitogen.yml | 8 +++- tests/ansible/run_ansible_playbook.py | 9 ---- 6 files changed, 57 insertions(+), 22 deletions(-) diff --git a/tests/ansible/integration/process/unix_socket_cleanup.yml b/tests/ansible/integration/process/unix_socket_cleanup.yml index 5746e418..625ad7b3 100644 --- a/tests/ansible/integration/process/unix_socket_cleanup.yml +++ b/tests/ansible/integration/process/unix_socket_cleanup.yml @@ -10,7 +10,11 @@ - shell: > ANSIBLE_STRATEGY=mitogen_linear ANSIBLE_SSH_ARGS="" - ansible -m shell -c local -a whoami -i "{{MITOGEN_INVENTORY_FILE}}" test-targets + ansible -m shell -c local -a whoami + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} + test-targets args: chdir: ../.. register: out diff --git a/tests/ansible/integration/runner/missing_module.yml b/tests/ansible/integration/runner/missing_module.yml index baa56b8b..979cdf21 100644 --- a/tests/ansible/integration/runner/missing_module.yml +++ b/tests/ansible/integration/runner/missing_module.yml @@ -7,7 +7,9 @@ connection: local command: | ansible -vvv - -i "{{MITOGEN_INVENTORY_FILE}}" + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} test-targets -m missing_module args: diff --git a/tests/ansible/integration/ssh/timeouts.yml b/tests/ansible/integration/ssh/timeouts.yml index f630d943..d4aba5d2 100644 --- a/tests/ansible/integration/ssh/timeouts.yml +++ b/tests/ansible/integration/ssh/timeouts.yml @@ -9,7 +9,9 @@ ANSIBLE_SSH_TIMEOUT: 10 command: | ansible -vvv - -i "{{MITOGEN_INVENTORY_FILE}}" + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} test-targets -m custom_python_detect_environment -e ansible_user=mitogen__slow_user -e ansible_password=slow_user_password diff --git a/tests/ansible/integration/ssh/variables.yml b/tests/ansible/integration/ssh/variables.yml index f596da63..8e912b2e 100644 --- a/tests/ansible/integration/ssh/variables.yml +++ b/tests/ansible/integration/ssh/variables.yml @@ -18,7 +18,11 @@ ANSIBLE_ANY_ERRORS_FATAL=false ANSIBLE_STRATEGY=mitogen_linear ANSIBLE_SSH_ARGS="" - ansible -m shell -a whoami -i "{{MITOGEN_INVENTORY_FILE}}" test-targets + ansible -m shell -a whoami + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} + test-targets -e ansible_ssh_user=mitogen__has_sudo -e ansible_ssh_pass=has_sudo_password args: @@ -31,7 +35,11 @@ ANSIBLE_ANY_ERRORS_FATAL=false ANSIBLE_STRATEGY=mitogen_linear ANSIBLE_SSH_ARGS="" - ansible -m shell -a whoami -i "{{MITOGEN_INVENTORY_FILE}}" test-targets + ansible -m shell -a whoami + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} + test-targets -e ansible_ssh_user=mitogen__has_sudo -e ansible_ssh_pass=wrong_password args: @@ -52,7 +60,11 @@ ANSIBLE_ANY_ERRORS_FATAL=false ANSIBLE_STRATEGY=mitogen_linear ANSIBLE_SSH_ARGS="" - ansible -m shell -a whoami -i "{{MITOGEN_INVENTORY_FILE}}" test-targets + ansible -m shell -a whoami + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} + test-targets -e ansible_user=mitogen__has_sudo -e ansible_ssh_pass=has_sudo_password args: @@ -65,7 +77,11 @@ ANSIBLE_ANY_ERRORS_FATAL=false ANSIBLE_STRATEGY=mitogen_linear ANSIBLE_SSH_ARGS="" - ansible -m shell -a whoami -i "{{MITOGEN_INVENTORY_FILE}}" test-targets + ansible -m shell -a whoami + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} + test-targets -e ansible_user=mitogen__has_sudo -e ansible_ssh_pass=wrong_password args: @@ -86,7 +102,11 @@ ANSIBLE_ANY_ERRORS_FATAL=false ANSIBLE_STRATEGY=mitogen_linear ANSIBLE_SSH_ARGS="" - ansible -m shell -a whoami -i "{{MITOGEN_INVENTORY_FILE}}" test-targets + ansible -m shell -a whoami + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} + test-targets -e ansible_user=mitogen__has_sudo -e ansible_password=has_sudo_password args: @@ -99,7 +119,11 @@ ANSIBLE_ANY_ERRORS_FATAL=false ANSIBLE_STRATEGY=mitogen_linear ANSIBLE_SSH_ARGS="" - ansible -m shell -a whoami -i "{{MITOGEN_INVENTORY_FILE}}" test-targets + ansible -m shell -a whoami + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} + test-targets -e ansible_user=mitogen__has_sudo -e ansible_password=wrong_password args: @@ -125,7 +149,11 @@ ANSIBLE_ANY_ERRORS_FATAL=false ANSIBLE_STRATEGY=mitogen_linear ANSIBLE_SSH_ARGS="" - ansible -m shell -a whoami -i "{{MITOGEN_INVENTORY_FILE}}" test-targets + ansible -m shell -a whoami + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} + test-targets -e ansible_user=mitogen__has_sudo_pubkey -e ansible_ssh_private_key_file=../data/docker/mitogen__has_sudo_pubkey.key args: @@ -138,7 +166,11 @@ ANSIBLE_ANY_ERRORS_FATAL=false ANSIBLE_STRATEGY=mitogen_linear ANSIBLE_SSH_ARGS="" - ansible -m shell -a whoami -i "{{MITOGEN_INVENTORY_FILE}}" test-targets + ansible -m shell -a whoami + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} + test-targets -e ansible_user=mitogen__has_sudo -e ansible_ssh_private_key_file=/dev/null args: diff --git a/tests/ansible/integration/strategy/mixed_vanilla_mitogen.yml b/tests/ansible/integration/strategy/mixed_vanilla_mitogen.yml index 796cbfef..d183564f 100644 --- a/tests/ansible/integration/strategy/mixed_vanilla_mitogen.yml +++ b/tests/ansible/integration/strategy/mixed_vanilla_mitogen.yml @@ -5,7 +5,9 @@ - connection: local command: | ansible-playbook - -i "{{MITOGEN_INVENTORY_FILE}}" + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} -vvv integration/strategy/_mixed_mitogen_vanilla.yml args: @@ -15,7 +17,9 @@ - connection: local command: | ansible-playbook - -i "{{MITOGEN_INVENTORY_FILE}}" + {% for inv in ansible_inventory_sources %} + -i "{{ inv }}" + {% endfor %} -vvv integration/strategy/_mixed_vanilla_mitogen.yml args: diff --git a/tests/ansible/run_ansible_playbook.py b/tests/ansible/run_ansible_playbook.py index b2b619d2..04c0c9db 100755 --- a/tests/ansible/run_ansible_playbook.py +++ b/tests/ansible/run_ansible_playbook.py @@ -40,15 +40,6 @@ extra = { 'git_basedir': GIT_BASEDIR, } -if '-i' in sys.argv: - extra['MITOGEN_INVENTORY_FILE'] = ( - os.path.abspath(sys.argv[1 + sys.argv.index('-i')]) - ) -else: - extra['MITOGEN_INVENTORY_FILE'] = ( - os.path.join(GIT_BASEDIR, 'tests/ansible/hosts') - ) - if 'ANSIBLE_ARGV' in os.environ: args = eval(os.environ['ANSIBLE_ARGV']) else: From edd2868ef6e599c0bc7178f6f2afe22c454faa54 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 12 Sep 2022 19:20:58 +0100 Subject: [PATCH 6/8] tests: Don't rely on facts when setting become They won't be available if the play is first, and hence no facts have been gather in previous play(s), e.g. due to --start-at-task --- .ci/ansible_tests.py | 6 ++++-- .../regression/issue_776__load_plugins_called_twice.yml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.ci/ansible_tests.py b/.ci/ansible_tests.py index fd0714a7..43d4f4cb 100755 --- a/.ci/ansible_tests.py +++ b/.ci/ansible_tests.py @@ -66,14 +66,16 @@ with ci_lib.Fold('job_setup'): for container in containers ) - for distro, hostnames in distros.items(): + for distro, hostnames in sorted(distros.items(), key=lambda t: t[0]): fp.write('\n[%s]\n' % distro) fp.writelines('%s\n' % name for name in hostnames) - for family, hostnames in families.items(): + for family, hostnames in sorted(families.items(), key=lambda t: t[0]): fp.write('\n[%s]\n' % family) fp.writelines('%s\n' % name for name in hostnames) + fp.write('\n[linux:children]\ntest-targets\n') + ci_lib.dump_file(inventory_path) if not ci_lib.exists_in_path('sshpass'): diff --git a/tests/ansible/regression/issue_776__load_plugins_called_twice.yml b/tests/ansible/regression/issue_776__load_plugins_called_twice.yml index bd57fe12..2eda3944 100755 --- a/tests/ansible/regression/issue_776__load_plugins_called_twice.yml +++ b/tests/ansible/regression/issue_776__load_plugins_called_twice.yml @@ -2,7 +2,7 @@ --- - name: regression/issue_776__load_plugins_called_twice.yml hosts: test-targets - become: "{{ ansible_facts.pkg_mgr not in ['homebrew'] }}" + become: "{{ groups.linux is defined and inventory_hostname in groups.linux }}" gather_facts: yes tags: - issue_776 From 7d79c56cb6ca95bbb141a112c00422d72063f8b4 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 12 Sep 2022 19:25:41 +0100 Subject: [PATCH 7/8] tests: Clarify skipped Poller test reasons --- tests/poller_test.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/tests/poller_test.py b/tests/poller_test.py index 2b0ded51..f915df0a 100644 --- a/tests/poller_test.py +++ b/tests/poller_test.py @@ -394,21 +394,16 @@ class AllMixin(ReceiveStateMixin, """ -class SelectTest(AllMixin, testlib.TestCase): +class CorePollerTest(AllMixin, testlib.TestCase): klass = mitogen.core.Poller -SelectTest = unittest.skipIf( - condition=(not SelectTest.klass.SUPPORTED), - reason='select.select() not supported' -)(SelectTest) - class PollTest(AllMixin, testlib.TestCase): klass = mitogen.parent.PollPoller PollTest = unittest.skipIf( condition=(not PollTest.klass.SUPPORTED), - reason='select.poll() not supported' + reason='select.poll() not available', )(PollTest) @@ -417,7 +412,7 @@ class KqueueTest(AllMixin, testlib.TestCase): KqueueTest = unittest.skipIf( condition=(not KqueueTest.klass.SUPPORTED), - reason='select.kqueue() not supported' + reason='select.kqueue() not available', )(KqueueTest) @@ -426,5 +421,5 @@ class EpollTest(AllMixin, testlib.TestCase): EpollTest = unittest.skipIf( condition=(not EpollTest.klass.SUPPORTED), - reason='select.epoll() not supported' + reason='select.epoll() not available', )(EpollTest) From a3a10cb32e59fa425ea8498dad7ee79420b960ac Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Mon, 12 Sep 2022 19:26:39 +0100 Subject: [PATCH 8/8] tests: Upgrade coverage dependency --- tests/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/requirements.txt b/tests/requirements.txt index 9ed07645..0e9a0f0a 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,5 +1,6 @@ psutil==5.4.8 -coverage==4.5.1 +coverage==5.5; python_version < '3.7' +coverage==6.4.4; python_version >= '3.7' Django==1.6.11 # Last version supporting 2.6. faulthandler==3.2; python_version < '3.3' mock==2.0.0