diff options
author | Lee Garrett <lgarrett@rocketjump.eu> | 2022-03-29 17:09:09 +0200 |
---|---|---|
committer | Lee Garrett <lgarrett@rocketjump.eu> | 2022-03-29 17:09:09 +0200 |
commit | 71ed02a1e802462d5d9b5f7e0fad42307a175278 (patch) | |
tree | 843d2684d305cf5f12bb9c9d5a3da49c0a9dcc5f /test | |
parent | 37d585600d2e2d1c64e33ffaaadce57e4c8407bd (diff) | |
download | debian-ansible-core-71ed02a1e802462d5d9b5f7e0fad42307a175278.zip |
New upstream version 2.12.4
Diffstat (limited to 'test')
14 files changed, 126 insertions, 5 deletions
diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml b/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml index 8bf39577..815a67f5 100644 --- a/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml +++ b/test/integration/targets/ansible-galaxy-collection/tasks/verify.yml @@ -275,6 +275,16 @@ - name: append a newline to a module to modify the checksum shell: "echo '' >> {{ module_path }}" +- name: create a new module file + file: + path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/test_new_file.py' + state: touch + +- name: create a new directory + file: + path: '{{ galaxy_dir }}/ansible_collections/ansible_test/verify/plugins/modules/test_new_dir' + state: directory + - name: verify modified collection locally-only (should fail) command: ansible-galaxy collection verify --offline ansible_test.verify register: verify @@ -287,3 +297,5 @@ - verify.rc != 0 - "'Collection ansible_test.verify contains modified content in the following files:' in verify.stdout" - "'plugins/modules/test_module.py' in verify.stdout" + - "'plugins/modules/test_new_file.py' in verify.stdout" + - "'plugins/modules/test_new_dir' in verify.stdout" diff --git a/test/integration/targets/collections/ansiballz_dupe/collections/ansible_collections/duplicate/name/plugins/modules/ping.py b/test/integration/targets/collections/ansiballz_dupe/collections/ansible_collections/duplicate/name/plugins/modules/ping.py new file mode 100644 index 00000000..d0fdba76 --- /dev/null +++ b/test/integration/targets/collections/ansiballz_dupe/collections/ansible_collections/duplicate/name/plugins/modules/ping.py @@ -0,0 +1,3 @@ +#!/usr/bin/python +from ansible.module_utils.basic import AnsibleModule +AnsibleModule({}).exit_json(ping='duplicate.name.pong') diff --git a/test/integration/targets/collections/ansiballz_dupe/test_ansiballz_cache_dupe_shortname.yml b/test/integration/targets/collections/ansiballz_dupe/test_ansiballz_cache_dupe_shortname.yml new file mode 100644 index 00000000..25526246 --- /dev/null +++ b/test/integration/targets/collections/ansiballz_dupe/test_ansiballz_cache_dupe_shortname.yml @@ -0,0 +1,15 @@ +- hosts: localhost + gather_facts: false + tasks: + - ping: + register: result1 + + - ping: + collections: + - duplicate.name + register: result2 + + - assert: + that: + - result1.ping == 'pong' + - result2.ping == 'duplicate.name.pong' diff --git a/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testredirect/meta/runtime.yml b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testredirect/meta/runtime.yml index da8e4901..2dcf456e 100644 --- a/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testredirect/meta/runtime.yml +++ b/test/integration/targets/collections/collection_root_user/ansible_collections/testns/testredirect/meta/runtime.yml @@ -2,3 +2,20 @@ plugin_routing: modules: ping: redirect: testns.testcoll.ping + filter: + multi_redirect_filter: + redirect: testns.testredirect.redirect_filter1 + deprecation: + warning_text: deprecation1 + redirect_filter1: + redirect: redirect_filter2 + deprecation: + warning_text: deprecation2 + redirect_filter2: + redirect: testns.testcoll.testfilter + deprecation: + warning_text: deprecation3 + dead_end: + redirect: bad_redirect + recursive_redirect: + redirect: recursive_redirect diff --git a/test/integration/targets/collections/runme.sh b/test/integration/targets/collections/runme.sh index 5a5261bb..5f11abeb 100755 --- a/test/integration/targets/collections/runme.sh +++ b/test/integration/targets/collections/runme.sh @@ -65,6 +65,16 @@ else ansible-playbook -i "${INVENTORY_PATH}" collection_root_user/ansible_collections/testns/testcoll/playbooks/default_collection_playbook.yml "$@" fi +# test redirects and warnings for filter redirects +echo "testing redirect and deprecation display" +ANSIBLE_DEPRECATION_WARNINGS=yes ansible localhost -m debug -a msg='{{ "data" | testns.testredirect.multi_redirect_filter }}' -vvvvv 2>&1 | tee out.txt +cat out.txt + +test "$(grep out.txt -ce 'deprecation1' -ce 'deprecation2' -ce 'deprecation3')" == 3 +grep out.txt -e 'redirecting (type: filter) testns.testredirect.multi_redirect_filter to testns.testredirect.redirect_filter1' +grep out.txt -e 'redirecting (type: filter) testns.testredirect.redirect_filter1 to testns.testredirect.redirect_filter2' +grep out.txt -e 'redirecting (type: filter) testns.testredirect.redirect_filter2 to testns.testcoll.testfilter' + echo "--- validating collections support in playbooks/roles" # run test playbooks ansible-playbook -i "${INVENTORY_PATH}" -v "${TEST_PLAYBOOK}" "$@" @@ -100,6 +110,9 @@ ansible-playbook inventory_test.yml -i a.statichost.yml -i redirected.statichost # test plugin loader redirect_list ansible-playbook test_redirect_list.yml -v "$@" +# test ansiballz cache dupe +ansible-playbook ansiballz_dupe/test_ansiballz_cache_dupe_shortname.yml -v "$@" + # test adjacent with --playbook-dir export ANSIBLE_COLLECTIONS_PATH='' ANSIBLE_INVENTORY_ANY_UNPARSED_IS_FAILED=1 ansible-inventory --list --export --playbook-dir=. -v "$@" diff --git a/test/integration/targets/collections/test_collection_meta.yml b/test/integration/targets/collections/test_collection_meta.yml index 22a00b21..b682d220 100644 --- a/test/integration/targets/collections/test_collection_meta.yml +++ b/test/integration/targets/collections/test_collection_meta.yml @@ -21,6 +21,25 @@ # redirect filter - assert: that: ('yes' | formerly_core_filter) == True + # redirect filter (multiple levels) + - assert: + that: ('data' | testns.testredirect.multi_redirect_filter) == 'data_via_testfilter_from_userdir' + # invalid filter redirect + - debug: msg="{{ 'data' | testns.testredirect.dead_end }}" + ignore_errors: yes + register: redirect_failure + - assert: + that: + - redirect_failure is failed + - '"no filter named ''testns.testredirect.dead_end''" in (redirect_failure.msg | lower)' + # recursive filter redirect + - debug: msg="{{ 'data' | testns.testredirect.recursive_redirect }}" + ignore_errors: yes + register: redirect_failure + - assert: + that: + - redirect_failure is failed + - '"recursive collection redirect found for ''testns.testredirect.recursive_redirect''" in redirect_failure.msg' # legacy filter should mask redirected - assert: that: ('' | formerly_core_masked_filter) == 'hello from overridden formerly_core_masked_filter' diff --git a/test/integration/targets/lookup_first_found/files/vars file spaces.yml b/test/integration/targets/lookup_first_found/files/vars file spaces.yml new file mode 100644 index 00000000..790bc26c --- /dev/null +++ b/test/integration/targets/lookup_first_found/files/vars file spaces.yml @@ -0,0 +1 @@ +foo: 1 diff --git a/test/integration/targets/lookup_first_found/tasks/main.yml b/test/integration/targets/lookup_first_found/tasks/main.yml index e85f4f27..9aeaf1d1 100644 --- a/test/integration/targets/lookup_first_found/tasks/main.yml +++ b/test/integration/targets/lookup_first_found/tasks/main.yml @@ -84,3 +84,13 @@ assert: that: - "hatethisformat == '/etc/hosts'" + +- name: test spaces in names + include_vars: "{{ item }}" + with_first_found: + - files: + - "{{ role_path + '/files/vars file spaces.yml' }}" + +- assert: + that: + - foo is defined diff --git a/test/integration/targets/setup_pexpect/tasks/main.yml b/test/integration/targets/setup_pexpect/tasks/main.yml index 690fe441..84b7bd1c 100644 --- a/test/integration/targets/setup_pexpect/tasks/main.yml +++ b/test/integration/targets/setup_pexpect/tasks/main.yml @@ -3,8 +3,17 @@ src: constraints.txt dest: "{{ remote_tmp_dir }}/pexpect-constraints.txt" +- name: Install pexpect with --user + pip: + name: pexpect + extra_args: '--user --constraint "{{ remote_tmp_dir }}/pexpect-constraints.txt"' + state: present + ignore_errors: yes # fails when inside a virtual environment + register: pip_user + - name: Install pexpect pip: name: pexpect extra_args: '--constraint "{{ remote_tmp_dir }}/pexpect-constraints.txt"' state: present + when: pip_user is failed diff --git a/test/lib/ansible_test/_internal/commands/integration/__init__.py b/test/lib/ansible_test/_internal/commands/integration/__init__.py index 839b24ae..a9a49aa1 100644 --- a/test/lib/ansible_test/_internal/commands/integration/__init__.py +++ b/test/lib/ansible_test/_internal/commands/integration/__init__.py @@ -92,6 +92,7 @@ from ...data import ( ) from ...host_configs import ( + InventoryConfig, OriginConfig, ) @@ -183,6 +184,18 @@ def check_inventory(args, inventory_path): # type: (IntegrationConfig, str) -> display.warning('Use of "ansible_ssh_private_key_file" in inventory with the --docker or --remote option is unsupported and will likely fail.') +def get_inventory_absolute_path(args: IntegrationConfig, target: InventoryConfig) -> str: + """Return the absolute inventory path used for the given integration configuration or target inventory config (if provided).""" + path = target.path or os.path.basename(get_inventory_relative_path(args)) + + if args.host_path: + path = os.path.join(data_context().content.root, path) # post-delegation, path is relative to the content root + else: + path = os.path.join(data_context().content.root, data_context().content.integration_path, path) + + return path + + def get_inventory_relative_path(args): # type: (IntegrationConfig) -> str """Return the inventory path used for the given integration configuration relative to the content root.""" inventory_names = { diff --git a/test/lib/ansible_test/_internal/commands/integration/network.py b/test/lib/ansible_test/_internal/commands/integration/network.py index f9953144..778384f4 100644 --- a/test/lib/ansible_test/_internal/commands/integration/network.py +++ b/test/lib/ansible_test/_internal/commands/integration/network.py @@ -23,6 +23,7 @@ from ...config import ( from . import ( command_integration_filter, command_integration_filtered, + get_inventory_absolute_path, get_inventory_relative_path, check_inventory, delegate_inventory, @@ -46,8 +47,11 @@ def command_network_integration(args): # type: (NetworkIntegrationConfig) -> No template_path = os.path.join(ANSIBLE_TEST_CONFIG_ROOT, os.path.basename(inventory_relative_path)) + '.template' if issubclass(args.target_type, NetworkInventoryConfig): - inventory_path = os.path.join(data_context().content.root, data_context().content.integration_path, - args.only_target(NetworkInventoryConfig).path or os.path.basename(inventory_relative_path)) + target = args.only_target(NetworkInventoryConfig) + inventory_path = get_inventory_absolute_path(args, target) + + if args.delegate or not target.path: + target.path = inventory_relative_path else: inventory_path = os.path.join(data_context().content.root, inventory_relative_path) diff --git a/test/lib/ansible_test/_internal/commands/integration/windows.py b/test/lib/ansible_test/_internal/commands/integration/windows.py index f6b44942..d14ae11b 100644 --- a/test/lib/ansible_test/_internal/commands/integration/windows.py +++ b/test/lib/ansible_test/_internal/commands/integration/windows.py @@ -34,6 +34,7 @@ from ...host_configs import ( from . import ( command_integration_filter, command_integration_filtered, + get_inventory_absolute_path, get_inventory_relative_path, check_inventory, delegate_inventory, @@ -52,8 +53,11 @@ def command_windows_integration(args): # type: (WindowsIntegrationConfig) -> No template_path = os.path.join(ANSIBLE_TEST_CONFIG_ROOT, os.path.basename(inventory_relative_path)) + '.template' if issubclass(args.target_type, WindowsInventoryConfig): - inventory_path = os.path.join(data_context().content.root, data_context().content.integration_path, - args.only_target(WindowsInventoryConfig).path or os.path.basename(inventory_relative_path)) + target = args.only_target(WindowsInventoryConfig) + inventory_path = get_inventory_absolute_path(args, target) + + if args.delegate or not target.path: + target.path = inventory_relative_path else: inventory_path = os.path.join(data_context().content.root, inventory_relative_path) diff --git a/test/sanity/ignore.txt b/test/sanity/ignore.txt index 058331e1..1dba93b0 100644 --- a/test/sanity/ignore.txt +++ b/test/sanity/ignore.txt @@ -101,7 +101,6 @@ lib/ansible/modules/stat.py validate-modules:undocumented-parameter lib/ansible/modules/systemd.py validate-modules:parameter-invalid lib/ansible/modules/systemd.py validate-modules:return-syntax-error lib/ansible/modules/sysvinit.py validate-modules:return-syntax-error -lib/ansible/modules/unarchive.py validate-modules:nonexistent-parameter-documented lib/ansible/modules/uri.py pylint:disallowed-name lib/ansible/modules/uri.py validate-modules:doc-required-mismatch lib/ansible/modules/user.py validate-modules:doc-default-does-not-match-spec diff --git a/test/units/modules/test_unarchive.py b/test/units/modules/test_unarchive.py index c3300372..3e7a58c9 100644 --- a/test/units/modules/test_unarchive.py +++ b/test/units/modules/test_unarchive.py @@ -52,6 +52,7 @@ class TestCaseZipArchive: "extra_opts": "", "exclude": "", "include": "", + "io_buffer_size": 65536, } z = ZipArchive( @@ -74,6 +75,7 @@ class TestCaseTgzArchive: "extra_opts": "", "exclude": "", "include": "", + "io_buffer_size": 65536, } fake_ansible_module.check_mode = False |