From b882b78d354234e83dce33eb7ab7e316461f0f14 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Wed, 18 Apr 2018 15:20:44 +0100 Subject: [PATCH] tests: clean up remaining reg tests Delete some that are impossible to detect, fix up the remainder to detect the condition they describe. --- .../custom_python_detect_environment.py | 1 + .../modules/custom_python_leaky_class_vars.py | 25 +++++++++ tests/ansible/regression/all.yml | 14 ++--- ..._109__target_has_old_ansible_installed.yml | 8 +-- tests/ansible/regression/issue_113.yml | 17 ------ .../issue_113__duplicate_module_imports.yml | 24 ++++++++ ... => issue_118__script_not_marked_exec.yml} | 9 ++- tests/ansible/regression/issue_122.yml | 5 -- .../issue_122__environment_difference.yml | 14 +++++ tests/ansible/regression/issue_131.yml | 56 ------------------- tests/ansible/regression/issue_140.yml | 24 -------- .../regression/issue_140__thread_pileup.yml | 29 ++++++++++ ...ue_152__local_action_wrong_interpreter.yml | 42 +++++++++----- .../issue_152__virtualenv_python_fails.yml | 32 ++++++----- tests/ansible/regression/issue_154.yml | 22 -------- .../issue_154__module_state_leaks.yml | 18 ++++++ tests/ansible/regression/issue_174.yml | 5 -- tests/ansible/regression/issue_177.yml | 7 --- .../issue_177__copy_module_failing.yml | 19 +++++++ 19 files changed, 187 insertions(+), 184 deletions(-) create mode 100644 tests/ansible/lib/modules/custom_python_leaky_class_vars.py delete mode 100644 tests/ansible/regression/issue_113.yml create mode 100644 tests/ansible/regression/issue_113__duplicate_module_imports.yml rename tests/ansible/regression/{issue_118.yml => issue_118__script_not_marked_exec.yml} (51%) delete mode 100644 tests/ansible/regression/issue_122.yml create mode 100644 tests/ansible/regression/issue_122__environment_difference.yml delete mode 100644 tests/ansible/regression/issue_131.yml delete mode 100644 tests/ansible/regression/issue_140.yml create mode 100644 tests/ansible/regression/issue_140__thread_pileup.yml delete mode 100644 tests/ansible/regression/issue_154.yml create mode 100644 tests/ansible/regression/issue_154__module_state_leaks.yml delete mode 100644 tests/ansible/regression/issue_174.yml delete mode 100644 tests/ansible/regression/issue_177.yml create mode 100644 tests/ansible/regression/issue_177__copy_module_failing.yml diff --git a/tests/ansible/lib/modules/custom_python_detect_environment.py b/tests/ansible/lib/modules/custom_python_detect_environment.py index d1136817..4387fd9e 100644 --- a/tests/ansible/lib/modules/custom_python_detect_environment.py +++ b/tests/ansible/lib/modules/custom_python_detect_environment.py @@ -13,6 +13,7 @@ import sys def main(): module = AnsibleModule(argument_spec={}) module.exit_json( + env=dict(os.environ), cwd=os.getcwd(), python_path=sys.path, pid=os.getpid(), diff --git a/tests/ansible/lib/modules/custom_python_leaky_class_vars.py b/tests/ansible/lib/modules/custom_python_leaky_class_vars.py new file mode 100644 index 00000000..1d342329 --- /dev/null +++ b/tests/ansible/lib/modules/custom_python_leaky_class_vars.py @@ -0,0 +1,25 @@ +#!/usr/bin/python +# I am an Ansible new-style Python module. I leak state from each invocation +# into a class variable and a global variable. + +from ansible.module_utils.basic import AnsibleModule + + +leak1 = [] + + +class MyClass: + leak2 = [] + + +def main(): + module = AnsibleModule(argument_spec={'name': {'type': 'str'}}) + leak1.append(module.params['name']) + MyClass.leak2.append(module.params['name']) + module.exit_json( + leak1=leak1, + leak2=MyClass.leak2, + ) + +if __name__ == '__main__': + main() diff --git a/tests/ansible/regression/all.yml b/tests/ansible/regression/all.yml index d449958e..ecb9638c 100644 --- a/tests/ansible/regression/all.yml +++ b/tests/ansible/regression/all.yml @@ -1,11 +1,9 @@ - import_playbook: issue_109__target_has_old_ansible_installed.yml -- import_playbook: issue_113.yml -- import_playbook: issue_118.yml -- import_playbook: issue_122.yml -- import_playbook: issue_131.yml -- import_playbook: issue_140.yml +- import_playbook: issue_113__duplicate_module_imports.yml +- import_playbook: issue_118__script_not_marked_exec.yml +- import_playbook: issue_122__environment_difference.yml +- import_playbook: issue_140__thread_pileup.yml - import_playbook: issue_152__local_action_wrong_interpreter.yml - import_playbook: issue_152__virtualenv_python_fails.yml -- import_playbook: issue_154.yml -- import_playbook: issue_174.yml -- import_playbook: issue_177.yml +- import_playbook: issue_154__module_state_leaks.yml +- import_playbook: issue_177__copy_module_failing.yml 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 acf1521f..3a00f6e1 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 @@ -1,17 +1,15 @@ # issue #109: ensure that any 'ansible' module or package on the remote machine # does not conflict with operation. -- hosts: all +- name: regression/issue_109__target_has_old_ansible_installed.yml + hosts: all + any_errors_fatal: true gather_facts: true become: true become_user: mitogen__user1 tasks: - - name: regression/issue_109__target_has_old_ansible_installed.yml - assert: - that: true # Copy the naughty 'ansible' into place. - - copy: dest: "{{ansible_user_dir}}/ansible.py" src: ansible.py diff --git a/tests/ansible/regression/issue_113.yml b/tests/ansible/regression/issue_113.yml deleted file mode 100644 index d213ba02..00000000 --- a/tests/ansible/regression/issue_113.yml +++ /dev/null @@ -1,17 +0,0 @@ -- hosts: all - tasks: - - - name: Get auth token - uri: - url: "https://httpbin.org/post" - method: POST - body: "client_id=admin-cli&username=admin&\ - password=keycloak_admin_password&grant_type=password" - return_content: true - validate_certs: false - register: r_token - no_log: false - run_once: true - - - assert: - that: r_token.status == 200 diff --git a/tests/ansible/regression/issue_113__duplicate_module_imports.yml b/tests/ansible/regression/issue_113__duplicate_module_imports.yml new file mode 100644 index 00000000..0d3a7e18 --- /dev/null +++ b/tests/ansible/regression/issue_113__duplicate_module_imports.yml @@ -0,0 +1,24 @@ +# issue #113: ensure CookieJar duplicate import issue does not reappear simply +# by exercisizng the uri package. + +- name: regression/issue_113__duplicate_module_imports.yml + any_errors_fatal: true + hosts: all + tasks: + + - name: Get auth token + uri: + url: "http://127.0.0.1:14321/post" + method: POST + body: "client_id=admin-cli&username=admin&\ + password=keycloak_admin_password&grant_type=password" + return_content: true + validate_certs: false + register: out + ignore_errors: true + + - assert: + that: + - out.status == -1 + - out.url == 'http://127.0.0.1:14321/post' + diff --git a/tests/ansible/regression/issue_118.yml b/tests/ansible/regression/issue_118__script_not_marked_exec.yml similarity index 51% rename from tests/ansible/regression/issue_118.yml rename to tests/ansible/regression/issue_118__script_not_marked_exec.yml index 5b920db0..376addf0 100644 --- a/tests/ansible/regression/issue_118.yml +++ b/tests/ansible/regression/issue_118__script_not_marked_exec.yml @@ -1,9 +1,8 @@ # issue #118 repro: chmod +x not happening during script upload -# -- name: saytrue + +- name: regression/issue_118__script_not_marked_exec.yml hosts: all become: True - tasks: - - name: run script saytrue - script: scripts/issue_118_saytrue + + - script: scripts/issue_118_saytrue diff --git a/tests/ansible/regression/issue_122.yml b/tests/ansible/regression/issue_122.yml deleted file mode 100644 index d72ecf96..00000000 --- a/tests/ansible/regression/issue_122.yml +++ /dev/null @@ -1,5 +0,0 @@ -- hosts: all - tasks: - - script: scripts/print_env.sh - register: env - - debug: msg={{env}} diff --git a/tests/ansible/regression/issue_122__environment_difference.yml b/tests/ansible/regression/issue_122__environment_difference.yml new file mode 100644 index 00000000..a7e791c7 --- /dev/null +++ b/tests/ansible/regression/issue_122__environment_difference.yml @@ -0,0 +1,14 @@ +# issue #122: still-undiagnosed environment difference between vanilla and +# Mitogen Ansible. + +# +# TODO: finish me. +# + +- name: regression/issue_122__environment_difference.yml + hosts: all + tasks: + + - script: scripts/print_env.sh + register: env + - debug: msg={{env}} diff --git a/tests/ansible/regression/issue_131.yml b/tests/ansible/regression/issue_131.yml deleted file mode 100644 index a271c46b..00000000 --- a/tests/ansible/regression/issue_131.yml +++ /dev/null @@ -1,56 +0,0 @@ -# Hopeful reproduction for issue #131. -# Run lots of steps (rather than just one) so WorkerProcess and suchlike -# machinery is constantly recreated. - -- hosts: all - tasks: - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" - - shell: "true" diff --git a/tests/ansible/regression/issue_140.yml b/tests/ansible/regression/issue_140.yml deleted file mode 100644 index f9dc2d2b..00000000 --- a/tests/ansible/regression/issue_140.yml +++ /dev/null @@ -1,24 +0,0 @@ -# Reproduction for issue #140. - -- hosts: all - tasks: - - name: Create file tree - connection: local - shell: > - mkdir filetree; - for i in `seq 1 1000` ; do echo $i > filetree/$i ; done - args: - creates: filetree - - - - name: Delete remote file tree - shell: rm -rf /tmp/filetree - - - - name: Trigger nasty process pileup - synchronize: - src: "{{ item.src }}" - dest: "/tmp/filetree" - with_filetree: - - filetree - when: item.state == 'file' diff --git a/tests/ansible/regression/issue_140__thread_pileup.yml b/tests/ansible/regression/issue_140__thread_pileup.yml new file mode 100644 index 00000000..f5fcd804 --- /dev/null +++ b/tests/ansible/regression/issue_140__thread_pileup.yml @@ -0,0 +1,29 @@ +# issue #140: with_filetree use caused unbounded (>500) thread growth in target +# interpreter. No easy hook to check thread count, but doing a 1000 item +# with_items should crash for other reasons (RAM, file descriptor count, ..) + +- name: regression/issue_140__thread_pileup.yml + hosts: all + any_errors_fatal: true + tasks: + + - name: Create file tree + connection: local + shell: > + mkdir filetree; + for i in `seq 1 1000` ; do echo $i > filetree/$i ; done + args: + creates: filetree + + + - name: Delete remote file tree + shell: rm -rf /tmp/filetree + + + - name: Trigger nasty process pileup + synchronize: + src: "{{ item.src }}" + dest: "/tmp/filetree" + with_filetree: + - filetree + when: item.state == 'file' 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 e4b0adbc..df200469 100644 --- a/tests/ansible/regression/issue_152__local_action_wrong_interpreter.yml +++ b/tests/ansible/regression/issue_152__local_action_wrong_interpreter.yml @@ -1,19 +1,31 @@ # issue #152 (b): local connections were not receiving -# ansible_python_interpreter treatment, breaking virtualenvs. +# ansible_python_interpreter treatment, breaking virtualenvs. Verify this is +# fixed by writing out a wrapper script that sets an environment variable we +# can test for. -# To test: -# - Ensure system Python does not have boto3 installed. -# - Run /path/to/venv/ansible-playbook ... with the virtualenv deactivated. -# Observe success. -# - Run ansible-playbook ... with the virtualenv activated. Observe success. - -- hosts: all +- name: regression/issue_152__local_action_wrong_interpreter.yml + hosts: all + connection: local + any_errors_fatal: true tasks: - - name: regression/issue_152__local_action_wrong_interpreter.yml - connection: local - become: true - shell: pip uninstall boto3 - ignore_errors: true - - cloudformation_facts: - connection: local + - copy: + dest: /tmp/issue_152_interpreter.sh + mode: u+x + content: | + #!/bin/bash + export CUSTOM_INTERPRETER=1 + exec python2.7 "$@" + + - custom_python_detect_environment: + vars: + ansible_python_interpreter: /tmp/issue_152_interpreter.sh + register: out + + - assert: + that: + - out.env.CUSTOM_INTERPRETER == "1" + + - file: + path: /tmp/issue_152_interpreter.sh + state: absent diff --git a/tests/ansible/regression/issue_152__virtualenv_python_fails.yml b/tests/ansible/regression/issue_152__virtualenv_python_fails.yml index e6c60c99..9e9a9beb 100644 --- a/tests/ansible/regression/issue_152__virtualenv_python_fails.yml +++ b/tests/ansible/regression/issue_152__virtualenv_python_fails.yml @@ -1,19 +1,21 @@ -- hosts: all +- name: regression/issue_152__virtualenv_python_fails.yml + any_errors_fatal: true + hosts: all tasks: - - name: Make virtualenv - pip: - virtualenv: /tmp/issue_151_virtualenv - name: psycopg2 - - name: Use virtualenv for the Python interpeter - set_fact: ansible_python_interpreter=/tmp/issue_151_virtualenv/bin/python + # Can't use pip module because you can't fricking just create a virtualenv, + # must call it directly. + - shell: virtualenv /tmp/issue_152_virtualenv - - name: Ensure the app DB user exists - postgresql_user: - db: postgres - login_host: localhost - login_user: "{{ansible_user_id}}" - login_password: "x" - name: fakeuser - state: present + - custom_python_detect_environment: + vars: + ansible_python_interpreter: /tmp/issue_152_virtualenv/bin/python + register: out + - assert: + that: + - out.sys_executable == "/tmp/issue_152_virtualenv/bin/python" + + - file: + path: /tmp/issue_152_virtualenv + state: absent diff --git a/tests/ansible/regression/issue_154.yml b/tests/ansible/regression/issue_154.yml deleted file mode 100644 index 28c476e7..00000000 --- a/tests/ansible/regression/issue_154.yml +++ /dev/null @@ -1,22 +0,0 @@ -- hosts: all - become: true - vars: - repo_baseurl: "http://myurl.com" - default_repos: - - repo: demo-repo1 - description: Base software packages - url: "{{repo_baseurl}}/repo1" - - repo: demo-repo2 - description: Misc packages - url: "{{repo_baseurl}}/repo2" - tasks: - - name: Create multiple yum repos - yum_repository: - name: '{{item.repo}}' - http_caching: packages - gpgcheck: no - description: '{{item.description}}' - state: present - baseurl: '{{item.url}}' - enabled: yes - with_items: '{{ default_repos }}' diff --git a/tests/ansible/regression/issue_154__module_state_leaks.yml b/tests/ansible/regression/issue_154__module_state_leaks.yml new file mode 100644 index 00000000..471d92de --- /dev/null +++ b/tests/ansible/regression/issue_154__module_state_leaks.yml @@ -0,0 +1,18 @@ +# issue #154: yum_repository module leaks state via a class variable, so it +# must be reinitialized or cleared out somehow on each invocation. + +- name: regression/issue_154__module_state_leaks.yml + any_errors_fatal: true + hosts: all + tasks: + + - custom_python_leaky_class_vars: + name: David + with_sequence: start=0 end=3 + register: out + + - assert: + that: + - out.results[item|int].leak1 == ["David"] + - out.results[item|int].leak2 == ["David"] + with_sequence: start=0 end=3 diff --git a/tests/ansible/regression/issue_174.yml b/tests/ansible/regression/issue_174.yml deleted file mode 100644 index c64cc70f..00000000 --- a/tests/ansible/regression/issue_174.yml +++ /dev/null @@ -1,5 +0,0 @@ -- hosts: all - tasks: - - name: add nginx ppa - become: yes - apt_repository: repo='ppa:nginx/stable' update_cache=yes diff --git a/tests/ansible/regression/issue_177.yml b/tests/ansible/regression/issue_177.yml deleted file mode 100644 index 5137b73d..00000000 --- a/tests/ansible/regression/issue_177.yml +++ /dev/null @@ -1,7 +0,0 @@ -- hosts: all - tasks: - - name: copy repo configs - copy: src=/etc/{{ item }} dest=/tmp/{{item}} mode=0644 - with_items: - - passwd - - hosts diff --git a/tests/ansible/regression/issue_177__copy_module_failing.yml b/tests/ansible/regression/issue_177__copy_module_failing.yml new file mode 100644 index 00000000..2b192d91 --- /dev/null +++ b/tests/ansible/regression/issue_177__copy_module_failing.yml @@ -0,0 +1,19 @@ +- name: regression/issue_177__copy_module_failing.yml + any_errors_fatal: true + hosts: all + tasks: + + - copy: + src: /etc/{{item}} + dest: /tmp/{{item}} + mode: 0644 + with_items: + - passwd + - hosts + + - file: + path: /tmp/{{item}} + state: absent + with_items: + - passwd + - hosts