From 047458a8b301c23a4b8197ce68b0a3b07b7f3f09 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Mon, 2 Apr 2018 08:05:37 +0100 Subject: [PATCH] "examples": start adding structure to regression tests. --- ansible_mitogen/planner.py | 3 ++ examples/playbook/.gitignore | 4 +-- examples/playbook/Makefile | 4 +-- ... => action__low_level_execute_command.yml} | 4 --- examples/playbook/ansible.cfg | 3 +- examples/playbook/async_polling.yml | 4 --- examples/playbook/issue_109.yml | 3 -- examples/playbook/issue_113.yml | 3 -- examples/playbook/issue_118.yml | 2 -- examples/playbook/issue_122.yml | 1 - examples/playbook/issue_131.yml | 5 ---- examples/playbook/issue_140.yml | 5 ---- examples/playbook/issue_152.yml | 3 -- examples/playbook/issue_152b.yml | 3 -- examples/playbook/issue_154.yml | 3 -- examples/playbook/issue_174.yml | 4 --- examples/playbook/issue_177.yml | 4 --- examples/playbook/modules/bin_bash_module.sh | 5 ---- ...ule.sh => custom_bash_old_style_module.sh} | 4 +-- ...ule.sh => custom_bash_want_json_module.sh} | 0 ..._json.c => custom_binary_producing_json.c} | 0 ..._junk.c => custom_binary_producing_junk.c} | 0 .../modules/custom_binary_single_null | Bin 0 -> 1 bytes ...n.py => custom_python_json_args_module.py} | 0 ...e.py => custom_python_new_style_module.py} | 0 ...e.py => custom_python_want_json_module.py} | 0 examples/playbook/modules/single_null_binary | Bin 2 -> 0 bytes examples/playbook/non_python_modules.yml | 6 ---- examples/playbook/playbook__become_flags.yml | 27 ++++++++++++++++++ ...egate_to.yml => playbook__delegate_to.yml} | 4 --- ...ironment.yml => playbook__environment.yml} | 4 --- examples/playbook/runner.yml | 9 ++++++ ...yml => runner__builtin_command_module.yml} | 5 +--- .../runner__custom_bash_old_style_module.yml | 5 ++++ .../runner__custom_bash_want_json_module.yml | 5 ++++ .../runner__custom_binary_producing_json.yml | 5 ++++ .../runner__custom_binary_producing_junk.yml | 6 ++++ .../runner__custom_binary_single_null.yml | 6 ++++ ...runner__custom_python_json_args_module.yml | 5 ++++ ...runner__custom_python_new_style_module.yml | 5 ++++ ...runner__custom_python_want_json_module.yml | 5 ++++ 41 files changed, 90 insertions(+), 74 deletions(-) rename examples/playbook/{low_level_execute_command.yml => action__low_level_execute_command.yml} (96%) delete mode 100755 examples/playbook/modules/bin_bash_module.sh rename examples/playbook/modules/{old_style_module.sh => custom_bash_old_style_module.sh} (76%) rename examples/playbook/modules/{want_json_module.sh => custom_bash_want_json_module.sh} (100%) rename examples/playbook/modules/{binary_producing_json.c => custom_binary_producing_json.c} (100%) rename examples/playbook/modules/{binary_producing_junk.c => custom_binary_producing_junk.c} (100%) create mode 100644 examples/playbook/modules/custom_binary_single_null rename examples/playbook/modules/{json_args_python.py => custom_python_json_args_module.py} (100%) mode change 100644 => 100755 rename examples/playbook/modules/{python_new_style_module.py => custom_python_new_style_module.py} (100%) rename examples/playbook/modules/{python_want_json_module.py => custom_python_want_json_module.py} (100%) delete mode 100755 examples/playbook/modules/single_null_binary delete mode 100644 examples/playbook/non_python_modules.yml create mode 100644 examples/playbook/playbook__become_flags.yml rename examples/playbook/{delegate_to.yml => playbook__delegate_to.yml} (98%) rename examples/playbook/{environment.yml => playbook__environment.yml} (89%) create mode 100644 examples/playbook/runner.yml rename examples/playbook/{run_hostname_100_times.yml => runner__builtin_command_module.yml} (53%) create mode 100644 examples/playbook/runner__custom_bash_old_style_module.yml create mode 100644 examples/playbook/runner__custom_bash_want_json_module.yml create mode 100644 examples/playbook/runner__custom_binary_producing_json.yml create mode 100644 examples/playbook/runner__custom_binary_producing_junk.yml create mode 100644 examples/playbook/runner__custom_binary_single_null.yml create mode 100644 examples/playbook/runner__custom_python_json_args_module.yml create mode 100644 examples/playbook/runner__custom_python_new_style_module.yml create mode 100644 examples/playbook/runner__custom_python_want_json_module.yml diff --git a/ansible_mitogen/planner.py b/ansible_mitogen/planner.py index 8fcd639c..b940fbbb 100644 --- a/ansible_mitogen/planner.py +++ b/ansible_mitogen/planner.py @@ -185,6 +185,9 @@ class ScriptPlanner(BinaryPlanner): detection and rewrite. """ def _rewrite_interpreter(self, interpreter, task_vars, templar): + if interpreter is None: + return None + key = u'ansible_%s_interpreter' % os.path.basename(interpreter).strip() try: return templar.template(task_vars[key].strip()) diff --git a/examples/playbook/.gitignore b/examples/playbook/.gitignore index 5d172bda..14f1a005 100644 --- a/examples/playbook/.gitignore +++ b/examples/playbook/.gitignore @@ -1,2 +1,2 @@ -modules/binary_producing_junk -modules/binary_producing_json +modules/custom_binary_producing_junk +modules/custom_binary_producing_json diff --git a/examples/playbook/Makefile b/examples/playbook/Makefile index 8c9e4480..f37789ee 100644 --- a/examples/playbook/Makefile +++ b/examples/playbook/Makefile @@ -1,4 +1,4 @@ all: \ - modules/binary_producing_junk \ - modules/binary_producing_json + modules/custom_binary_producing_junk \ + modules/custom_binary_producing_json diff --git a/examples/playbook/low_level_execute_command.yml b/examples/playbook/action__low_level_execute_command.yml similarity index 96% rename from examples/playbook/low_level_execute_command.yml rename to examples/playbook/action__low_level_execute_command.yml index 10fb8d79..419af489 100644 --- a/examples/playbook/low_level_execute_command.yml +++ b/examples/playbook/action__low_level_execute_command.yml @@ -1,11 +1,7 @@ ---- - # Verify the behaviour of _low_level_execute_command(). - hosts: all - gather_facts: false tasks: - # "echo -en" to test we actually hit bash shell too. - name: Run raw module without sudo raw: 'echo -en $((1 + 1))' diff --git a/examples/playbook/ansible.cfg b/examples/playbook/ansible.cfg index 479e42ab..2b3c6193 100644 --- a/examples/playbook/ansible.cfg +++ b/examples/playbook/ansible.cfg @@ -1,7 +1,8 @@ [defaults] inventory = hosts +gathering = explicit strategy_plugins = ../../ansible_mitogen/plugins/strategy -strategy = mitogen_linear +#strategy = mitogen_linear library = modules retry_files_enabled = False forks = 50 diff --git a/examples/playbook/async_polling.yml b/examples/playbook/async_polling.yml index f4dcd96d..20aa211c 100644 --- a/examples/playbook/async_polling.yml +++ b/examples/playbook/async_polling.yml @@ -1,9 +1,5 @@ ---- - - hosts: all - gather_facts: false tasks: - - name: simulate long running op (3 sec), wait for up to 5 sec, poll every 1 sec command: /bin/sleep 2 async: 4 diff --git a/examples/playbook/issue_109.yml b/examples/playbook/issue_109.yml index 15e66c21..b47a225f 100644 --- a/examples/playbook/issue_109.yml +++ b/examples/playbook/issue_109.yml @@ -1,8 +1,5 @@ ---- - # Reproduction for issue #109. - hosts: all roles: - issue_109 - gather_facts: no diff --git a/examples/playbook/issue_113.yml b/examples/playbook/issue_113.yml index 870cd44a..d213ba02 100644 --- a/examples/playbook/issue_113.yml +++ b/examples/playbook/issue_113.yml @@ -1,7 +1,4 @@ ---- - - hosts: all - gather_facts: false tasks: - name: Get auth token diff --git a/examples/playbook/issue_118.yml b/examples/playbook/issue_118.yml index 0e2b6751..5b920db0 100644 --- a/examples/playbook/issue_118.yml +++ b/examples/playbook/issue_118.yml @@ -1,5 +1,3 @@ ---- - # issue #118 repro: chmod +x not happening during script upload # - name: saytrue diff --git a/examples/playbook/issue_122.yml b/examples/playbook/issue_122.yml index 4bba6ad6..d72ecf96 100644 --- a/examples/playbook/issue_122.yml +++ b/examples/playbook/issue_122.yml @@ -1,4 +1,3 @@ - - hosts: all tasks: - script: scripts/print_env.sh diff --git a/examples/playbook/issue_131.yml b/examples/playbook/issue_131.yml index 9c3aa0f4..a271c46b 100644 --- a/examples/playbook/issue_131.yml +++ b/examples/playbook/issue_131.yml @@ -1,13 +1,9 @@ ---- - # Hopeful reproduction for issue #131. # Run lots of steps (rather than just one) so WorkerProcess and suchlike # machinery is constantly recreated. - hosts: all - gather_facts: no tasks: - - shell: "true" - shell: "true" - shell: "true" @@ -58,4 +54,3 @@ - shell: "true" - shell: "true" - shell: "true" - diff --git a/examples/playbook/issue_140.yml b/examples/playbook/issue_140.yml index e540bcea..f9dc2d2b 100644 --- a/examples/playbook/issue_140.yml +++ b/examples/playbook/issue_140.yml @@ -1,11 +1,7 @@ ---- - # Reproduction for issue #140. - hosts: all - gather_facts: no tasks: - - name: Create file tree connection: local shell: > @@ -26,4 +22,3 @@ with_filetree: - filetree when: item.state == 'file' - diff --git a/examples/playbook/issue_152.yml b/examples/playbook/issue_152.yml index af7d257a..dff424b1 100644 --- a/examples/playbook/issue_152.yml +++ b/examples/playbook/issue_152.yml @@ -1,8 +1,5 @@ - - - hosts: all tasks: - - name: Make virtualenv pip: virtualenv: /tmp/issue_151_virtualenv diff --git a/examples/playbook/issue_152b.yml b/examples/playbook/issue_152b.yml index 617de96a..962f1d6f 100644 --- a/examples/playbook/issue_152b.yml +++ b/examples/playbook/issue_152b.yml @@ -1,4 +1,3 @@ - # issue #152 (b): local connections were not receiving # ansible_python_interpreter treatment, breaking virtualenvs. @@ -9,7 +8,5 @@ # - Run ansible-playbook ... with the virtualenv activated. Observe success. - hosts: all - gather_facts: false tasks: - - local_action: cloudformation_facts diff --git a/examples/playbook/issue_154.yml b/examples/playbook/issue_154.yml index d262abb3..28c476e7 100644 --- a/examples/playbook/issue_154.yml +++ b/examples/playbook/issue_154.yml @@ -1,6 +1,4 @@ - - hosts: all - gather_facts: no become: true vars: repo_baseurl: "http://myurl.com" @@ -11,7 +9,6 @@ - repo: demo-repo2 description: Misc packages url: "{{repo_baseurl}}/repo2" - tasks: - name: Create multiple yum repos yum_repository: diff --git a/examples/playbook/issue_174.yml b/examples/playbook/issue_174.yml index b68fdb24..c64cc70f 100644 --- a/examples/playbook/issue_174.yml +++ b/examples/playbook/issue_174.yml @@ -1,9 +1,5 @@ ---- - - hosts: all - gather_facts: false tasks: - name: add nginx ppa become: yes apt_repository: repo='ppa:nginx/stable' update_cache=yes - diff --git a/examples/playbook/issue_177.yml b/examples/playbook/issue_177.yml index ec7e3338..5137b73d 100644 --- a/examples/playbook/issue_177.yml +++ b/examples/playbook/issue_177.yml @@ -1,11 +1,7 @@ - - - hosts: all - gather_facts: false tasks: - name: copy repo configs copy: src=/etc/{{ item }} dest=/tmp/{{item}} mode=0644 with_items: - passwd - hosts - diff --git a/examples/playbook/modules/bin_bash_module.sh b/examples/playbook/modules/bin_bash_module.sh deleted file mode 100755 index 01abff0c..00000000 --- a/examples/playbook/modules/bin_bash_module.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -exec >/tmp/derp -echo "$1" -cat "$1" - diff --git a/examples/playbook/modules/old_style_module.sh b/examples/playbook/modules/custom_bash_old_style_module.sh similarity index 76% rename from examples/playbook/modules/old_style_module.sh rename to examples/playbook/modules/custom_bash_old_style_module.sh index 47e6afbd..144789cb 100755 --- a/examples/playbook/modules/old_style_module.sh +++ b/examples/playbook/modules/custom_bash_old_style_module.sh @@ -4,13 +4,13 @@ INPUT=$1 [ ! -r "$INPUT" ] && { - echo "Usage: $0 " >&2 + echo "Usage: $0 " >&2 exit 1 } echo "{" echo " \"changed\": false," echo " \"msg\": \"Here is my input\"," -echo " \"filname\": \"$INPUT\"," +echo " \"filename\": \"$INPUT\"," echo " \"input\": [\"$(cat $INPUT | tr \" \' )\"]" echo "}" diff --git a/examples/playbook/modules/want_json_module.sh b/examples/playbook/modules/custom_bash_want_json_module.sh similarity index 100% rename from examples/playbook/modules/want_json_module.sh rename to examples/playbook/modules/custom_bash_want_json_module.sh diff --git a/examples/playbook/modules/binary_producing_json.c b/examples/playbook/modules/custom_binary_producing_json.c similarity index 100% rename from examples/playbook/modules/binary_producing_json.c rename to examples/playbook/modules/custom_binary_producing_json.c diff --git a/examples/playbook/modules/binary_producing_junk.c b/examples/playbook/modules/custom_binary_producing_junk.c similarity index 100% rename from examples/playbook/modules/binary_producing_junk.c rename to examples/playbook/modules/custom_binary_producing_junk.c diff --git a/examples/playbook/modules/custom_binary_single_null b/examples/playbook/modules/custom_binary_single_null new file mode 100644 index 0000000000000000000000000000000000000000..f76dd238ade08917e6712764a16a22005a50573d GIT binary patch literal 1 IcmZPo000310RR91 literal 0 HcmV?d00001 diff --git a/examples/playbook/modules/json_args_python.py b/examples/playbook/modules/custom_python_json_args_module.py old mode 100644 new mode 100755 similarity index 100% rename from examples/playbook/modules/json_args_python.py rename to examples/playbook/modules/custom_python_json_args_module.py diff --git a/examples/playbook/modules/python_new_style_module.py b/examples/playbook/modules/custom_python_new_style_module.py similarity index 100% rename from examples/playbook/modules/python_new_style_module.py rename to examples/playbook/modules/custom_python_new_style_module.py diff --git a/examples/playbook/modules/python_want_json_module.py b/examples/playbook/modules/custom_python_want_json_module.py similarity index 100% rename from examples/playbook/modules/python_want_json_module.py rename to examples/playbook/modules/custom_python_want_json_module.py diff --git a/examples/playbook/modules/single_null_binary b/examples/playbook/modules/single_null_binary deleted file mode 100755 index 1f2a4f5ef3df7f7456d91c961da36fc58904f2f1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2 JcmZSJ0ssIE01E&B diff --git a/examples/playbook/non_python_modules.yml b/examples/playbook/non_python_modules.yml deleted file mode 100644 index 5fb6cc75..00000000 --- a/examples/playbook/non_python_modules.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- - -- hosts: all - gather_facts: false - tasks: - - bin_bash_module: diff --git a/examples/playbook/playbook__become_flags.yml b/examples/playbook/playbook__become_flags.yml new file mode 100644 index 00000000..74ebf059 --- /dev/null +++ b/examples/playbook/playbook__become_flags.yml @@ -0,0 +1,27 @@ +# This must be run with FOO=2 set in the environment. + +# +# Test sudo_flags respects -E. +# + +- hosts: all + tasks: + - name: "without -E" + become: true + shell: "echo $FOO" + register: out + + - assert: + that: "out.stdout == ''" + +- hosts: all + become_flags: -E + tasks: + - name: "with -E" + become: true + shell: "set" + register: out2 + + - debug: msg={{out2}} + - assert: + that: "out2.stdout == '2'" diff --git a/examples/playbook/delegate_to.yml b/examples/playbook/playbook__delegate_to.yml similarity index 98% rename from examples/playbook/delegate_to.yml rename to examples/playbook/playbook__delegate_to.yml index b4f85112..dae2afd8 100644 --- a/examples/playbook/delegate_to.yml +++ b/examples/playbook/playbook__delegate_to.yml @@ -1,9 +1,5 @@ ---- - - hosts: all - gather_facts: false tasks: - # # delegate_to, no sudo # diff --git a/examples/playbook/environment.yml b/examples/playbook/playbook__environment.yml similarity index 89% rename from examples/playbook/environment.yml rename to examples/playbook/playbook__environment.yml index c24bf083..fd70174f 100644 --- a/examples/playbook/environment.yml +++ b/examples/playbook/playbook__environment.yml @@ -1,10 +1,7 @@ ---- # Ensure environment: is preserved during call. - hosts: all - gather_facts: false tasks: - - shell: echo $SOME_ENV environment: SOME_ENV: 123 @@ -14,4 +11,3 @@ - assert: that: "result.stdout == '123'" - diff --git a/examples/playbook/runner.yml b/examples/playbook/runner.yml new file mode 100644 index 00000000..fb8baa64 --- /dev/null +++ b/examples/playbook/runner.yml @@ -0,0 +1,9 @@ +- import_playbook: runner__builtin_command_module.yml +- import_playbook: runner__custom_bash_old_style_module.yml +- import_playbook: runner__custom_bash_want_json_module.yml +- import_playbook: runner__custom_binary_producing_json.yml +- import_playbook: runner__custom_binary_producing_junk.yml +- import_playbook: runner__custom_binary_single_null.yml +- import_playbook: runner__custom_python_json_args_module.yml +- import_playbook: runner__custom_python_new_style_module.yml +- import_playbook: runner__custom_python_want_json_module.yml diff --git a/examples/playbook/run_hostname_100_times.yml b/examples/playbook/runner__builtin_command_module.yml similarity index 53% rename from examples/playbook/run_hostname_100_times.yml rename to examples/playbook/runner__builtin_command_module.yml index 22c74138..c0b0c6e2 100644 --- a/examples/playbook/run_hostname_100_times.yml +++ b/examples/playbook/runner__builtin_command_module.yml @@ -1,8 +1,5 @@ ---- - - hosts: all - gather_facts: false tasks: - name: "Run hostname" command: hostname - with_sequence: start=1 end=100 + with_sequence: start=1 end={{end|default(100)}} diff --git a/examples/playbook/runner__custom_bash_old_style_module.yml b/examples/playbook/runner__custom_bash_old_style_module.yml new file mode 100644 index 00000000..f7ebefa8 --- /dev/null +++ b/examples/playbook/runner__custom_bash_old_style_module.yml @@ -0,0 +1,5 @@ +- hosts: all + tasks: + - custom_bash_old_style_module: + foo: true + with_sequence: start=1 end={{end|default(100)}} diff --git a/examples/playbook/runner__custom_bash_want_json_module.yml b/examples/playbook/runner__custom_bash_want_json_module.yml new file mode 100644 index 00000000..bcf49b50 --- /dev/null +++ b/examples/playbook/runner__custom_bash_want_json_module.yml @@ -0,0 +1,5 @@ +- hosts: all + tasks: + - custom_bash_want_json_module: + foo: true + with_sequence: start=1 end={{end|default(100)}} diff --git a/examples/playbook/runner__custom_binary_producing_json.yml b/examples/playbook/runner__custom_binary_producing_json.yml new file mode 100644 index 00000000..bc0ced40 --- /dev/null +++ b/examples/playbook/runner__custom_binary_producing_json.yml @@ -0,0 +1,5 @@ +- hosts: all + tasks: + - custom_binary_producing_json: + foo: true + with_sequence: start=1 end={{end|default(100)}} diff --git a/examples/playbook/runner__custom_binary_producing_junk.yml b/examples/playbook/runner__custom_binary_producing_junk.yml new file mode 100644 index 00000000..b806752d --- /dev/null +++ b/examples/playbook/runner__custom_binary_producing_junk.yml @@ -0,0 +1,6 @@ +- hosts: all + tasks: + - custom_binary_producing_junk: + foo: true + with_sequence: start=1 end={{end|default(100)}} + ignore_errors: true diff --git a/examples/playbook/runner__custom_binary_single_null.yml b/examples/playbook/runner__custom_binary_single_null.yml new file mode 100644 index 00000000..a830e5fe --- /dev/null +++ b/examples/playbook/runner__custom_binary_single_null.yml @@ -0,0 +1,6 @@ +- hosts: all + tasks: + - custom_binary_single_null: + foo: true + with_sequence: start=1 end={{end|default(100)}} + ignore_errors: true diff --git a/examples/playbook/runner__custom_python_json_args_module.yml b/examples/playbook/runner__custom_python_json_args_module.yml new file mode 100644 index 00000000..f281184a --- /dev/null +++ b/examples/playbook/runner__custom_python_json_args_module.yml @@ -0,0 +1,5 @@ +- hosts: all + tasks: + - custom_python_json_args_module: + foo: true + with_sequence: start=1 end={{end|default(100)}} diff --git a/examples/playbook/runner__custom_python_new_style_module.yml b/examples/playbook/runner__custom_python_new_style_module.yml new file mode 100644 index 00000000..1a2421d3 --- /dev/null +++ b/examples/playbook/runner__custom_python_new_style_module.yml @@ -0,0 +1,5 @@ +- hosts: all + tasks: + - custom_python_new_style_module: + foo: true + with_sequence: start=1 end={{end|default(100)}} diff --git a/examples/playbook/runner__custom_python_want_json_module.yml b/examples/playbook/runner__custom_python_want_json_module.yml new file mode 100644 index 00000000..b149808f --- /dev/null +++ b/examples/playbook/runner__custom_python_want_json_module.yml @@ -0,0 +1,5 @@ +- hosts: all + tasks: + - custom_python_want_json_module: + foo: true + with_sequence: start=1 end={{end|default(100)}}