diff options
author | Martin Krizek <martin.krizek@gmail.com> | 2021-10-20 19:22:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-20 12:22:29 -0500 |
commit | 7621784b947adb497a24725259318506a102d1a4 (patch) | |
tree | 5194910123e52b4f36e90a0d5d8a00decab0a31d /test | |
parent | 835fe7182872422f59dfd0c94a0fdbb3b2da5bc7 (diff) | |
download | ansible-7621784b947adb497a24725259318506a102d1a4.tar.gz |
Require Jinja2 3.0.0 (#75881)
* Require Jinja2 3.0.0
ci_complete
* Fix sanity
* Remove Jinja min/max tests
* ansible-test changes
* ci_complete
* More cleanup
ci_complete
* Revert _count_newlines_from_end :( and other stuff
* Fix sanity
* It's using host_vars ...
* Unused import
* Remove overridden groupby filter
* environmentfilter -> pass_environment
* Explain preserve_trailing_newlines
* Add changelog
* ci_complete
* Deprecated ANSIBLE_JINJA2_NATIVE_WARNING
* native_helpers.py cleanup
* More cleanup in the find intgration test
Diffstat (limited to 'test')
33 files changed, 41 insertions, 324 deletions
diff --git a/test/integration/targets/ansible-vault/single_vault_as_string.yml b/test/integration/targets/ansible-vault/single_vault_as_string.yml index ca147b0b3b..2d523a0b85 100644 --- a/test/integration/targets/ansible-vault/single_vault_as_string.yml +++ b/test/integration/targets/ansible-vault/single_vault_as_string.yml @@ -81,8 +81,6 @@ - assert: that: - vaulted_value|map('upper')|list == ['F', 'O', 'O', ' ', 'B', 'A', 'R'] - when: lookup('pipe', ansible_python.executable ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.7', '>=') - - assert: that: @@ -90,23 +88,19 @@ - vaulted_value|select('equalto', 'o')|list == ['o', 'o'] - vaulted_value|title == 'Foo Bar' - vaulted_value is equalto('foo bar') - when: lookup('pipe', ansible_python.executable ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.8', '>=') - assert: that: - vaulted_value|string|tojson == '"foo bar"' - vaulted_value|truncate(4) == 'foo bar' - when: lookup('pipe', ansible_python.executable ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.9', '>=') - assert: that: - vaulted_value|wordwrap(4) == 'foo\nbar' - when: lookup('pipe', ansible_python.executable ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.11', '>=') - assert: that: - vaulted_value|wordcount == 2 - when: lookup('pipe', ansible_python.executable ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.11.2', '>=') - ping: data: !vault | diff --git a/test/integration/targets/collections/test_bypass_host_loop.yml b/test/integration/targets/collections/test_bypass_host_loop.yml index e95262b87b..71f48d5e30 100644 --- a/test/integration/targets/collections/test_bypass_host_loop.yml +++ b/test/integration/targets/collections/test_bypass_host_loop.yml @@ -5,9 +5,6 @@ collections: - testns.testcoll tasks: - - meta: end_host - when: lookup('pipe', ansible_playbook_python ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.7', '<') - - bypass_host_loop: register: bypass diff --git a/test/integration/targets/filter_core/tasks/main.yml b/test/integration/targets/filter_core/tasks/main.yml index 5a5d813fd4..05622d84b0 100644 --- a/test/integration/targets/filter_core/tasks/main.yml +++ b/test/integration/targets/filter_core/tasks/main.yml @@ -79,8 +79,6 @@ - "31 == ['x','y']|map('extract',{'x':42,'y':31})|list|last" - "'local' == ['localhost']|map('extract',hostvars,'ansible_connection')|list|first" - "'local' == ['localhost']|map('extract',hostvars,['ansible_connection'])|list|first" - # map was added to jinja2 in version 2.7 - when: lookup('pipe', ansible_python.executable ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.7', '>=') - name: Test extract filter with defaults vars: diff --git a/test/integration/targets/filter_mathstuff/runme.sh b/test/integration/targets/filter_mathstuff/runme.sh index 3650300315..5a474cf558 100755 --- a/test/integration/targets/filter_mathstuff/runme.sh +++ b/test/integration/targets/filter_mathstuff/runme.sh @@ -5,13 +5,3 @@ set -eux export ANSIBLE_ROLES_PATH=../ ansible-playbook runme.yml "$@" - -source virtualenv.sh - -# Install Jinja < 2.10 since we want to test the fallback to Ansible's custom -# unique filter. Jinja < 2.10 does not have do_unique so we will trigger the -# fallback. -pip install 'jinja2 < 2.10' - -# Run the playbook again in the venv with Jinja < 2.10 -ansible-playbook runme.yml "$@" diff --git a/test/integration/targets/filter_urls/runme.sh b/test/integration/targets/filter_urls/runme.sh deleted file mode 100755 index f6460acb33..0000000000 --- a/test/integration/targets/filter_urls/runme.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash - -set -eux - -export ANSIBLE_ROLES_PATH=../ - -ansible-playbook runme.yml "$@" - -source virtualenv.sh - -# This is necessary for installing Jinja 2.6. We need this because Jinja 2.6 -# won't install with newer setuptools, and because setuptools 45+ won't work -# with Python 2. -pip install 'setuptools<45' - -# Install Jinja 2.6 since we want to test the fallback to Ansible's custom -# urlencode functions. Jinja 2.6 does not have urlencode so we will trigger the -# fallback. -pip install 'jinja2 >= 2.6, < 2.7' - -# Run the playbook again in the venv with Jinja 2.6 -ansible-playbook runme.yml "$@" diff --git a/test/integration/targets/filter_urls/runme.yml b/test/integration/targets/filter_urls/runme.yml deleted file mode 100644 index 527a03e357..0000000000 --- a/test/integration/targets/filter_urls/runme.yml +++ /dev/null @@ -1,4 +0,0 @@ -- hosts: localhost - gather_facts: false - roles: - - { role: filter_urls } diff --git a/test/integration/targets/filter_urls/tasks/main.yml b/test/integration/targets/filter_urls/tasks/main.yml index 935ed479fd..c062326c54 100644 --- a/test/integration/targets/filter_urls/tasks/main.yml +++ b/test/integration/targets/filter_urls/tasks/main.yml @@ -1,10 +1,3 @@ -- name: Get Jinja2 version - shell: "{{ ansible_python_interpreter }} -c 'import jinja2; print(jinja2.__version__)'" - register: jinja2_version - -- name: Print Jinja2 version - debug: var=jinja2_version.stdout - - name: Test urldecode filter set_fact: urldecoded_string: key="@{}é&%£ foo bar '(;\<>""°) diff --git a/test/integration/targets/find/tasks/main.yml b/test/integration/targets/find/tasks/main.yml index 366ef31253..e90f0846a6 100644 --- a/test/integration/targets/find/tasks/main.yml +++ b/test/integration/targets/find/tasks/main.yml @@ -259,16 +259,10 @@ use_regex: true exclude: .*\.ogg register: find_test3 -# Note that currently sane ways of doing this with map() or -# selectattr() aren't available in centos6 era jinja2 ... + - set_fact: - find_test3_list: >- - [ {% for f in find_test3.files %} - {{ f.path }} - {% if not loop.last %},{% endif %} - {% endfor %} - ] -- debug: var=find_test3_list + find_test3_list: "{{ find_test3.files|map(attribute='path') }}" + - name: assert we skipped the ogg file assert: that: @@ -303,12 +297,7 @@ register: result - set_fact: - astest_list: >- - [ {% for f in result.files %} - {{ f.path }} - {% if not loop.last %},{% endif %} - {% endfor %} - ] + astest_list: "{{ result.files|map(attribute='path') }}" - name: assert we only find the old file assert: @@ -323,12 +312,7 @@ register: result - set_fact: - astest_list: >- - [ {% for f in result.files %} - {{ f.path }} - {% if not loop.last %},{% endif %} - {% endfor %} - ] + astest_list: "{{ result.files|map(attribute='path') }}" - name: assert we only find the current file assert: @@ -348,12 +332,7 @@ register: result - set_fact: - astest_list: >- - [ {% for f in result.files %} - {{ f.path }} - {% if not loop.last %},{% endif %} - {% endfor %} - ] + astest_list: "{{ result.files|map(attribute='path') }}" - name: assert we only find the hello world file assert: @@ -372,12 +351,7 @@ register: result - set_fact: - astest_list: >- - [ {% for f in result.files %} - {{ f.path }} - {% if not loop.last %},{% endif %} - {% endfor %} - ] + astest_list: "{{ result.files|map(attribute='path') }}" - name: assert we do not find the hello world file and a checksum is present assert: diff --git a/test/integration/targets/git/tasks/archive.yml b/test/integration/targets/git/tasks/archive.yml index 18b9dff350..952154dcac 100644 --- a/test/integration/targets/git/tasks/archive.yml +++ b/test/integration/targets/git/tasks/archive.yml @@ -11,14 +11,9 @@ register: git_archive with_items: "{{ git_archive_extensions[ansible_os_family ~ ansible_distribution_major_version | default('default') ] | default(git_archive_extensions.default) }}" -# The map filter was added in Jinja2 2.7, which is newer than the version on RHEL/CentOS 6, -# so we skip this validation on those hosts - name: ARCHIVE | Assert that archives were downloaded assert: that: (git_archive.results | map(attribute='changed') | unique | list)[0] - when: - - "ansible_os_family == 'RedHat'" - - ansible_distribution_major_version is version('7', '>=') - name: ARCHIVE | Check if archive file is created or not stat: @@ -53,14 +48,9 @@ register: git_archive with_items: "{{ git_archive_extensions[ansible_os_family ~ ansible_distribution_major_version | default('default') ] | default(git_archive_extensions.default) }}" -# The map filter was added in Jinja2 2.7, which is newer than the version on RHEL/CentOS 6, -# so we skip this validation on those hosts - name: ARCHIVE | Assert that archives were downloaded assert: that: (git_archive.results | map(attribute='changed') | unique | list)[0] - when: - - "ansible_os_family == 'RedHat'" - - ansible_distribution_major_version is version('7', '>=') - name: ARCHIVE | Check if archive file is created or not stat: @@ -82,14 +72,11 @@ register: archive_content with_items: "{{ git_archive_extensions[ansible_os_family ~ ansible_distribution_major_version | default('default') ] | default(git_archive_extensions.default) }}" -# Does not work on RedHat6 (jinja2 too old?) - name: ARCHIVE | Ensure archive content is correct assert: that: - item.stdout_lines | sort | first == 'defaults/' with_items: "{{ archive_content.results }}" - when: - - ansible_os_family ~ ansible_distribution_major_version != 'RedHat6' - name: ARCHIVE | Clear checkout_dir file: diff --git a/test/integration/targets/groupby_filter/aliases b/test/integration/targets/groupby_filter/aliases index 58201272a0..90ea9e1281 100644 --- a/test/integration/targets/groupby_filter/aliases +++ b/test/integration/targets/groupby_filter/aliases @@ -1,3 +1,2 @@ shippable/posix/group2 -needs/file/test/lib/ansible_test/_data/requirements/constraints.txt context/controller diff --git a/test/integration/targets/groupby_filter/requirements.txt b/test/integration/targets/groupby_filter/requirements.txt deleted file mode 100644 index fdd9ec5c23..0000000000 --- a/test/integration/targets/groupby_filter/requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -# pip 7.1 added support for constraints, which are required by ansible-test to install most python requirements -# see https://github.com/pypa/pip/blame/e648e00dc0226ade30ade99591b245b0c98e86c9/NEWS.rst#L1258 -pip >= 7.1, < 10 ; python_version < '2.7' # pip 10+ drops support for python 2.6 (sanity_ok) -pip >= 7.1 ; python_version >= '2.7' # sanity_ok diff --git a/test/integration/targets/groupby_filter/runme.sh b/test/integration/targets/groupby_filter/runme.sh deleted file mode 100755 index 09b47d55b0..0000000000 --- a/test/integration/targets/groupby_filter/runme.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -set -eux - -source virtualenv.sh - -# Update pip in the venv to a version that supports constraints -pip install --requirement requirements.txt - -pip install -U jinja2==2.9.4 --constraint "../../../lib/ansible_test/_data/requirements/constraints.txt" - -ansible-playbook -i ../../inventory test_jinja2_groupby.yml -v "$@" - -pip install -U "jinja2<2.9.0" --constraint "../../../lib/ansible_test/_data/requirements/constraints.txt" - -ansible-playbook -i ../../inventory test_jinja2_groupby.yml -v "$@" diff --git a/test/integration/targets/groupby_filter/tasks/main.yml b/test/integration/targets/groupby_filter/tasks/main.yml new file mode 100644 index 0000000000..45c868764c --- /dev/null +++ b/test/integration/targets/groupby_filter/tasks/main.yml @@ -0,0 +1,16 @@ +- set_fact: + result: "{{ fruits | groupby('enjoy') }}" + vars: + fruits: + - name: apple + enjoy: yes + - name: orange + enjoy: no + - name: strawberry + enjoy: yes + +- assert: + that: + - result == expected + vars: + expected: [[false, [{"enjoy": false, "name": "orange"}]], [true, [{"enjoy": true, "name": "apple"}, {"enjoy": true, "name": "strawberry"}]]] diff --git a/test/integration/targets/groupby_filter/test_jinja2_groupby.yml b/test/integration/targets/groupby_filter/test_jinja2_groupby.yml deleted file mode 100644 index 3cd02959ca..0000000000 --- a/test/integration/targets/groupby_filter/test_jinja2_groupby.yml +++ /dev/null @@ -1,29 +0,0 @@ ---- -- name: Test jinja2 groupby - hosts: localhost - gather_facts: True - connection: local - vars: - fruits: - - name: apple - enjoy: yes - - name: orange - enjoy: no - - name: strawberry - enjoy: yes - expected: [[false, [{"enjoy": false, "name": "orange"}]], [true, [{"enjoy": true, "name": "apple"}, {"enjoy": true, "name": "strawberry"}]]] - tasks: - - name: show python interpreter - debug: - msg: "{{ ansible_python['executable'] }}" - - - name: show jinja2 version - debug: - msg: "{{ lookup('pipe', '{{ ansible_python[\"executable\"] }} -c \"import jinja2; print(jinja2.__version__)\"') }}" - - - set_fact: - result: "{{ fruits | groupby('enjoy') }}" - - - assert: - that: - - result == expected diff --git a/test/integration/targets/jinja2_native_types/nested_undefined.yml b/test/integration/targets/jinja2_native_types/nested_undefined.yml index c808ffb73c..b60a871f92 100644 --- a/test/integration/targets/jinja2_native_types/nested_undefined.yml +++ b/test/integration/targets/jinja2_native_types/nested_undefined.yml @@ -21,4 +21,3 @@ - assert: that: - "\"'nested_and_undefined' is undefined\" in result.msg" - when: lookup('pipe', ansible_python_interpreter ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.10', '>=') diff --git a/test/integration/targets/jinja2_native_types/runtests.yml b/test/integration/targets/jinja2_native_types/runtests.yml index efcdb7a572..422ef57bba 100644 --- a/test/integration/targets/jinja2_native_types/runtests.yml +++ b/test/integration/targets/jinja2_native_types/runtests.yml @@ -31,20 +31,10 @@ s_false: "False" yaml_none: ~ tasks: - - name: check jinja version - command: "{{ ansible_python_interpreter }} -c 'import jinja2; print(jinja2.__version__)'" - register: jinja2_version - - - name: make sure jinja is the right version - set_fact: - is_native: "{{ jinja2_version.stdout is version('2.10', '>=') }}" - - - block: - - import_tasks: test_casting.yml - - import_tasks: test_concatentation.yml - - import_tasks: test_bool.yml - - import_tasks: test_dunder.yml - - import_tasks: test_types.yml - - import_tasks: test_none.yml - - import_tasks: test_template.yml - when: is_native + - import_tasks: test_casting.yml + - import_tasks: test_concatentation.yml + - import_tasks: test_bool.yml + - import_tasks: test_dunder.yml + - import_tasks: test_types.yml + - import_tasks: test_none.yml + - import_tasks: test_template.yml diff --git a/test/integration/targets/roles_arg_spec/test_complex_role_fails.yml b/test/integration/targets/roles_arg_spec/test_complex_role_fails.yml index a04785fb12..e44950a134 100644 --- a/test/integration/targets/roles_arg_spec/test_complex_role_fails.yml +++ b/test/integration/targets/roles_arg_spec/test_complex_role_fails.yml @@ -38,16 +38,6 @@ ] tasks: - # This test play requires jinja >= 2.7 - - name: get the jinja2 version - shell: python -c 'import jinja2; print(jinja2.__version__)' - register: jinja2_version - delegate_to: localhost - changed_when: false - - - debug: - msg: "Jinja version: {{ jinja2_version.stdout }}" - - name: include_role test1 since it has a arg_spec.yml block: - include_role: @@ -174,7 +164,3 @@ - ansible_failed_result.validate_args_context.name == "test1" - ansible_failed_result.validate_args_context.type == "role" - "ansible_failed_result.validate_args_context.path is search('roles_arg_spec/roles/test1')" - - # skip this task if jinja isnt >= 2.7, aka centos6 - when: - - jinja2_version.stdout is version('2.7', '>=') diff --git a/test/integration/targets/template/72615.yml b/test/integration/targets/template/72615.yml index 9a6eb941b4..153cfd67ac 100644 --- a/test/integration/targets/template/72615.yml +++ b/test/integration/targets/template/72615.yml @@ -16,11 +16,3 @@ - "'top-level-foo' not in template_result" - "'template-level-foo' in template_result" - "'template-nested-level-foo' in template_result" - when: lookup('pipe', ansible_python_interpreter ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.9', '>=') - - - assert: - that: - - "'top-level-foo' in template_result" - - "'template-level-foo' not in template_result" - - "'template-nested-level-foo' not in template_result" - when: lookup('pipe', ansible_python_interpreter ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.9', '<') diff --git a/test/integration/targets/template/tasks/main.yml b/test/integration/targets/template/tasks/main.yml index f8848ef5b4..67d07b146b 100644 --- a/test/integration/targets/template/tasks/main.yml +++ b/test/integration/targets/template/tasks/main.yml @@ -199,11 +199,6 @@ # VERIFY lstrip_blocks -- name: Check support for lstrip_blocks in Jinja2 - shell: "{{ ansible_python.executable }} -c 'import jinja2; jinja2.defaults.LSTRIP_BLOCKS'" - register: lstrip_block_support - ignore_errors: True - - name: Render a template with "lstrip_blocks" set to False template: src: lstrip_blocks.j2 @@ -229,24 +224,15 @@ register: lstrip_blocks_true_result ignore_errors: True -- name: Verify exception is thrown if Jinja2 does not support lstrip_blocks but lstrip_blocks is used - assert: - that: - - "lstrip_blocks_true_result.failed" - - 'lstrip_blocks_true_result.msg is search(">=2.7")' - when: "lstrip_block_support is failed" - - name: Get checksum of known good lstrip_blocks_true.expected stat: path: "{{role_path}}/files/lstrip_blocks_true.expected" register: lstrip_blocks_true_good - when: "lstrip_block_support is successful" - name: Verify templated lstrip_blocks_true matches known good using checksum assert: that: - "lstrip_blocks_true_result.checksum == lstrip_blocks_true_good.stat.checksum" - when: "lstrip_block_support is successful" # VERIFY CONTENTS diff --git a/test/integration/targets/template_jinja2_latest/aliases b/test/integration/targets/template_jinja2_latest/aliases deleted file mode 100644 index b9c19e3d84..0000000000 --- a/test/integration/targets/template_jinja2_latest/aliases +++ /dev/null @@ -1,5 +0,0 @@ -needs/root -shippable/posix/group2 -needs/target/template -context/controller -needs/file/test/lib/ansible_test/_data/requirements/constraints.txt diff --git a/test/integration/targets/template_jinja2_latest/main.yml b/test/integration/targets/template_jinja2_latest/main.yml deleted file mode 100644 index aa7d64330c..0000000000 --- a/test/integration/targets/template_jinja2_latest/main.yml +++ /dev/null @@ -1,4 +0,0 @@ -- hosts: testhost - gather_facts: True - roles: - - { role: template } diff --git a/test/integration/targets/template_jinja2_latest/pip-requirements.txt b/test/integration/targets/template_jinja2_latest/pip-requirements.txt deleted file mode 100644 index fdd9ec5c23..0000000000 --- a/test/integration/targets/template_jinja2_latest/pip-requirements.txt +++ /dev/null @@ -1,4 +0,0 @@ -# pip 7.1 added support for constraints, which are required by ansible-test to install most python requirements -# see https://github.com/pypa/pip/blame/e648e00dc0226ade30ade99591b245b0c98e86c9/NEWS.rst#L1258 -pip >= 7.1, < 10 ; python_version < '2.7' # pip 10+ drops support for python 2.6 (sanity_ok) -pip >= 7.1 ; python_version >= '2.7' # sanity_ok diff --git a/test/integration/targets/template_jinja2_latest/requirements.txt b/test/integration/targets/template_jinja2_latest/requirements.txt deleted file mode 100644 index 49a806fb66..0000000000 --- a/test/integration/targets/template_jinja2_latest/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -jinja2 < 2.11 ; python_version < '2.7' # jinja2 2.11 and later require python 2.7 or later -jinja2 ; python_version >= '2.7' diff --git a/test/integration/targets/template_jinja2_latest/runme.sh b/test/integration/targets/template_jinja2_latest/runme.sh deleted file mode 100755 index d6ef693ef5..0000000000 --- a/test/integration/targets/template_jinja2_latest/runme.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash - -set -eux - -source virtualenv.sh - -pip install --requirement pip-requirements.txt - -pip install -U -r requirements.txt --constraint "../../../lib/ansible_test/_data/requirements/constraints.txt" - -ANSIBLE_ROLES_PATH=../ -export ANSIBLE_ROLES_PATH - -ansible-playbook -i ../../inventory main.yml -v "$@" diff --git a/test/integration/targets/template_jinja2_non_native/46169.yml b/test/integration/targets/template_jinja2_non_native/46169.yml index efb443eae0..4dc3dc01a3 100644 --- a/test/integration/targets/template_jinja2_non_native/46169.yml +++ b/test/integration/targets/template_jinja2_non_native/46169.yml @@ -29,4 +29,3 @@ - assert: that: - native_lookup | type_debug == 'dict' - when: lookup('pipe', ansible_python_interpreter ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.10', '>=') diff --git a/test/integration/targets/test_mathstuff/tasks/main.yml b/test/integration/targets/test_mathstuff/tasks/main.yml index dd379ce263..b5109ce395 100644 --- a/test/integration/targets/test_mathstuff/tasks/main.yml +++ b/test/integration/targets/test_mathstuff/tasks/main.yml @@ -1,8 +1,3 @@ -- name: Get Jinja2 version - set_fact: - jinja2_version: >- - {{ lookup('pipe', '{{ ansible_playbook_python }} -c "import jinja2; print(jinja2.__version__)"') }} - - name: Assert subset tests work assert: that: @@ -28,11 +23,5 @@ that: - "'bad' is not nan" - "1.1 | float is not nan" - -# Jinja2 versions prior to 2.10 will traceback when using: 'nan' | float -- name: Assert nan tests work (Jinja2 2.10+) - assert: - that: - "'nan' | float is isnan" # old name - "'nan' | float is nan" - when: jinja2_version is version('2.10', '>=') diff --git a/test/integration/targets/unarchive/tasks/test_include.yml b/test/integration/targets/unarchive/tasks/test_include.yml index 04842e0ecd..ea3a01cf2e 100644 --- a/test/integration/targets/unarchive/tasks/test_include.yml +++ b/test/integration/targets/unarchive/tasks/test_include.yml @@ -24,17 +24,12 @@ paths: "{{ remote_tmp_dir }}/include-zip" register: unarchive_dir02 -# The map filter was added in Jinja2 2.7, which is newer than the version on RHEL/CentOS 6, -# so we skip this validation on those hosts - name: Verify that zip extraction included only one file assert: that: - file_names == ['FOO-UNAR.TXT'] vars: file_names: "{{ unarchive_dir02.files | map(attribute='path') | map('basename') }}" - when: - - "ansible_facts.os_family == 'RedHat'" - - ansible_facts.distribution_major_version is version('7', '>=') - name: Unpack tar file include one file unarchive: diff --git a/test/integration/targets/undefined/tasks/main.yml b/test/integration/targets/undefined/tasks/main.yml index bbd8284585..e50841ef80 100644 --- a/test/integration/targets/undefined/tasks/main.yml +++ b/test/integration/targets/undefined/tasks/main.yml @@ -1,5 +1,4 @@ -- when: lookup('pipe', ansible_playbook_python ~ ' -c "import jinja2; print(jinja2.__version__)"') is version('2.7', '>=') - block: +- block: - set_fact: names: '{{ things|map(attribute="name") }}' vars: diff --git a/test/lib/ansible_test/_data/requirements/ansible.txt b/test/lib/ansible_test/_data/requirements/ansible.txt index 40cf83a647..a732a5951d 100644 --- a/test/lib/ansible_test/_data/requirements/ansible.txt +++ b/test/lib/ansible_test/_data/requirements/ansible.txt @@ -3,7 +3,7 @@ # packages. Thus, this should be the loosest set possible (only required # packages, not optional ones, and with the widest range of versions that could # be suitable) -jinja2 +jinja2 >= 3.0.0 PyYAML cryptography packaging diff --git a/test/lib/ansible_test/_internal/ansible_util.py b/test/lib/ansible_test/_internal/ansible_util.py index 5c689bed48..385416bd77 100644 --- a/test/lib/ansible_test/_internal/ansible_util.py +++ b/test/lib/ansible_test/_internal/ansible_util.py @@ -96,7 +96,6 @@ def ansible_environment(args, color=True, ansible_config=None): # type: (Common ANSIBLE_CONFIG=ansible_config, ANSIBLE_LIBRARY='/dev/null', ANSIBLE_DEVEL_WARNING='false', # Don't show warnings that CI is running devel - ANSIBLE_JINJA2_NATIVE_WARNING='false', # Don't show warnings in CI for old Jinja for native PYTHONPATH=get_ansible_python_path(args), PAGER='/bin/cat', PATH=path, diff --git a/test/lib/ansible_test/_util/target/setup/bootstrap.sh b/test/lib/ansible_test/_util/target/setup/bootstrap.sh index 2d31945e75..a015df0d61 100644 --- a/test/lib/ansible_test/_util/target/setup/bootstrap.sh +++ b/test/lib/ansible_test/_util/target/setup/bootstrap.sh @@ -147,20 +147,18 @@ bootstrap_remote_freebsd() ;; esac + # Jinja2 is not installed with an OS package since the provided version is too old. # PyYAML is never installed with an OS package since it does not include libyaml support. - # Instead, ansible-test will install it using pip. + # Instead, ansible-test will install them using pip. if [ "${have_os_packages}" ]; then - jinja2_pkg="py${python_package_version}-Jinja2" cryptography_pkg="py${python_package_version}-cryptography" else - jinja2_pkg="" cryptography_pkg="" fi packages=" ${packages} libyaml - ${jinja2_pkg} ${cryptography_pkg} " fi @@ -238,10 +236,11 @@ bootstrap_remote_rhel_8() ${py_pkg_prefix}-devel " + # Jinja2 is not installed with an OS package since the provided version is too old. + # Instead, ansible-test will install it using pip. if [ "${controller}" ]; then packages=" ${packages} - ${py_pkg_prefix}-jinja2 ${py_pkg_prefix}-cryptography " fi diff --git a/test/units/plugins/filter/test_mathstuff.py b/test/units/plugins/filter/test_mathstuff.py index d44a714669..f79387142a 100644 --- a/test/units/plugins/filter/test_mathstuff.py +++ b/test/units/plugins/filter/test_mathstuff.py @@ -62,26 +62,6 @@ class TestSymmetricDifference: assert sorted(ms.symmetric_difference(env, tuple(dataset1), tuple(dataset2))) == expected[2] -class TestMin: - def test_min(self): - assert ms.min(env, (1, 2)) == 1 - assert ms.min(env, (2, 1)) == 1 - assert ms.min(env, ('p', 'a', 'w', 'b', 'p')) == 'a' - assert ms.min(env, ({'key': 'a'}, {'key': 'b'}, {'key': 'c'}), attribute='key') == {'key': 'a'} - assert ms.min(env, ({'key': 1}, {'key': 2}, {'key': 3}), attribute='key') == {'key': 1} - assert ms.min(env, ('a', 'A', 'b', 'B'), case_sensitive=True) == 'A' - - -class TestMax: - def test_max(self): - assert ms.max(env, (1, 2)) == 2 - assert ms.max(env, (2, 1)) == 2 - assert ms.max(env, ('p', 'a', 'w', 'b', 'p')) == 'w' - assert ms.max(env, ({'key': 'a'}, {'key': 'b'}, {'key': 'c'}), attribute='key') == {'key': 'c'} - assert ms.max(env, ({'key': 1}, {'key': 2}, {'key': 3}), attribute='key') == {'key': 3} - assert ms.max(env, ('a', 'A', 'b', 'B'), case_sensitive=True) == 'b' - - class TestLogarithm: def test_log_non_number(self): # Message changed in python3.6 diff --git a/test/units/template/test_vars.py b/test/units/template/test_vars.py index 74e6783925..dbfba2ea28 100644 --- a/test/units/template/test_vars.py +++ b/test/units/template/test_vars.py @@ -29,53 +29,13 @@ class TestVars(unittest.TestCase): def setUp(self): self.mock_templar = MagicMock(name='mock_templar') - def test(self): - ajvars = AnsibleJ2Vars(None, None) - print(ajvars) - - def test_globals_empty_2_8(self): - ajvars = AnsibleJ2Vars(self.mock_templar, {}) - res28 = self._dict_jinja28(ajvars) - self.assertIsInstance(res28, dict) - - def test_globals_empty_2_9(self): + def test_globals_empty(self): ajvars = AnsibleJ2Vars(self.mock_templar, {}) - res29 = self._dict_jinja29(ajvars) - self.assertIsInstance(res29, dict) + res = dict(ajvars) + self.assertIsInstance(res, dict) - def _assert_globals(self, res): + def test_globals(self): + res = dict(AnsibleJ2Vars(self.mock_templar, {'foo': 'bar', 'blip': [1, 2, 3]})) self.assertIsInstance(res, dict) self.assertIn('foo', res) self.assertEqual(res['foo'], 'bar') - - def test_globals_2_8(self): - ajvars = AnsibleJ2Vars(self.mock_templar, {'foo': 'bar', 'blip': [1, 2, 3]}) - res28 = self._dict_jinja28(ajvars) - self._assert_globals(res28) - - def test_globals_2_9(self): - ajvars = AnsibleJ2Vars(self.mock_templar, {'foo': 'bar', 'blip': [1, 2, 3]}) - res29 = self._dict_jinja29(ajvars) - self._assert_globals(res29) - - def _dicts(self, ajvars): - print(ajvars) - res28 = self._dict_jinja28(ajvars) - res29 = self._dict_jinja29(ajvars) - # res28_other = self._dict_jinja28(ajvars, {'other_key': 'other_value'}) - # other = {'other_key': 'other_value'} - # res29_other = self._dict_jinja29(ajvars, *other) - print('res28: %s' % res28) - print('res29: %s' % res29) - # print('res28_other: %s' % res28_other) - # print('res29_other: %s' % res29_other) - # return (res28, res29, res28_other, res29_other) - # assert ajvars == res28 - # assert ajvars == res29 - return (res28, res29) - - def _dict_jinja28(self, *args, **kwargs): - return dict(*args, **kwargs) - - def _dict_jinja29(self, the_vars): - return dict(the_vars) |