diff options
author | Lee Garrett <lgarrett@rocketjump.eu> | 2022-09-13 16:39:18 +0200 |
---|---|---|
committer | Lee Garrett <lgarrett@rocketjump.eu> | 2022-09-13 16:39:18 +0200 |
commit | dfc95dfc10415e8ba138e2c042c39632c9251abb (patch) | |
tree | f0d4aac54ea7f6ef3ffb1b61d4a316fab0d2602c /test/integration/targets | |
parent | 5883937d823fe68e35dbedf2a9d45ecaf6636470 (diff) | |
download | debian-ansible-core-dfc95dfc10415e8ba138e2c042c39632c9251abb.zip |
New upstream version 2.13.4
Diffstat (limited to 'test/integration/targets')
15 files changed, 302 insertions, 2 deletions
diff --git a/test/integration/targets/ansible-galaxy-collection/library/setup_collections.py b/test/integration/targets/ansible-galaxy-collection/library/setup_collections.py index 58ec9b2a..35b18dec 100644 --- a/test/integration/targets/ansible-galaxy-collection/library/setup_collections.py +++ b/test/integration/targets/ansible-galaxy-collection/library/setup_collections.py @@ -87,6 +87,10 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils._text import to_bytes from functools import partial from multiprocessing import dummy as threading +from multiprocessing import TimeoutError + + +COLLECTIONS_BUILD_AND_PUBLISH_TIMEOUT = 120 def publish_collection(module, collection): @@ -241,7 +245,14 @@ def run_module(): pool = threading.Pool(4) publish_func = partial(publish_collection, module) - result['results'] = pool.map(publish_func, module.params['collections']) + try: + result['results'] = pool.map_async( + publish_func, module.params['collections'], + ).get(timeout=COLLECTIONS_BUILD_AND_PUBLISH_TIMEOUT) + except TimeoutError as timeout_err: + module.fail_json( + 'Timed out waiting for collections to be provisioned.', + ) failed = bool(sum( r['build']['rc'] + r['publish']['rc'] for r in result['results'] diff --git a/test/integration/targets/ansible-galaxy-collection/tasks/install.yml b/test/integration/targets/ansible-galaxy-collection/tasks/install.yml index 0068e76d..a55b64d8 100644 --- a/test/integration/targets/ansible-galaxy-collection/tasks/install.yml +++ b/test/integration/targets/ansible-galaxy-collection/tasks/install.yml @@ -423,6 +423,15 @@ - (install_req_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0' - (install_req_actual.results[1].content | b64decode | from_json).collection_info.version == '1.0.0' +- name: Test deviations on -r and --role-file without collection or role sub command + command: '{{ cmd }}' + loop: + - ansible-galaxy install -vr '{{ galaxy_dir }}/ansible_collections/requirements.yaml' -s '{{ test_name }}' -vv + - ansible-galaxy install --role-file '{{ galaxy_dir }}/ansible_collections/requirements.yaml' -s '{{ test_name }}' -vvv + - ansible-galaxy install --role-file='{{ galaxy_dir }}/ansible_collections/requirements.yaml' -s '{{ test_name }}' -vvv + loop_control: + loop_var: cmd + - name: uninstall collections for next requirements file test file: path: '{{ galaxy_dir }}/ansible_collections/{{ collection }}/name' diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/aliases b/test/integration/targets/ansible-test-sanity-ansible-doc/aliases new file mode 100644 index 00000000..7741d444 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/aliases @@ -0,0 +1,4 @@ +shippable/posix/group3 # runs in the distro test containers +shippable/generic/group1 # runs in the default test container +context/controller +needs/target/collection diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/a/b/lookup2.py b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/a/b/lookup2.py new file mode 100644 index 00000000..5cd2cf0f --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/a/b/lookup2.py @@ -0,0 +1,28 @@ +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = """ + name: lookup2 + author: Ansible Core Team + short_description: hello test lookup + description: + - Hello test lookup. + options: {} +""" + +EXAMPLES = """ +- minimal: +""" + +RETURN = """ +""" + +from ansible.plugins.lookup import LookupBase + + +class LookupModule(LookupBase): + + def run(self, terms, variables=None, **kwargs): + return [] diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/lookup1.py b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/lookup1.py new file mode 100644 index 00000000..e274f19f --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/lookup/lookup1.py @@ -0,0 +1,28 @@ +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +DOCUMENTATION = """ + name: lookup1 + author: Ansible Core Team + short_description: hello test lookup + description: + - Hello test lookup. + options: {} +""" + +EXAMPLES = """ +- minimal: +""" + +RETURN = """ +""" + +from ansible.plugins.lookup import LookupBase + + +class LookupModule(LookupBase): + + def run(self, terms, variables=None, **kwargs): + return [] diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/a/b/module2.py b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/a/b/module2.py new file mode 100644 index 00000000..6fafa193 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/a/b/module2.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +module: module2 +short_description: Hello test module +description: Hello test module. +options: {} +author: + - Ansible Core Team +''' + +EXAMPLES = ''' +- minimal: +''' + +RETURN = '''''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec={}, + ) + + module.exit_json() + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/module1.py b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/module1.py new file mode 100644 index 00000000..8847f5b8 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/ansible_collections/ns/col/plugins/modules/module1.py @@ -0,0 +1,34 @@ +#!/usr/bin/python +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +DOCUMENTATION = ''' +module: module1 +short_description: Hello test module +description: Hello test module. +options: {} +author: + - Ansible Core Team +''' + +EXAMPLES = ''' +- minimal: +''' + +RETURN = '''''' + +from ansible.module_utils.basic import AnsibleModule + + +def main(): + module = AnsibleModule( + argument_spec={}, + ) + + module.exit_json() + + +if __name__ == '__main__': + main() diff --git a/test/integration/targets/ansible-test-sanity-ansible-doc/runme.sh b/test/integration/targets/ansible-test-sanity-ansible-doc/runme.sh new file mode 100755 index 00000000..ee1a8823 --- /dev/null +++ b/test/integration/targets/ansible-test-sanity-ansible-doc/runme.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -eu + +source ../collection/setup.sh + +set -x + +ansible-test sanity --test ansible-doc --color "${@}" diff --git a/test/integration/targets/apt/tasks/apt.yml b/test/integration/targets/apt/tasks/apt.yml index 5b1a24a3..d273eda7 100644 --- a/test/integration/targets/apt/tasks/apt.yml +++ b/test/integration/targets/apt/tasks/apt.yml @@ -83,12 +83,26 @@ - apt_install_fnmatch is changed - apt_uninstall_fnmatch is changed +- name: Test update_cache 1 (check mode) + apt: + update_cache: true + cache_valid_time: 10 + register: apt_update_cache_1_check_mode + check_mode: true + - name: Test update_cache 1 apt: update_cache: true cache_valid_time: 10 register: apt_update_cache_1 +- name: Test update_cache 2 (check mode) + apt: + update_cache: true + cache_valid_time: 10 + register: apt_update_cache_2_check_mode + check_mode: true + - name: Test update_cache 2 apt: update_cache: true @@ -98,7 +112,9 @@ - name: verify update_cache assert: that: + - apt_update_cache_1_check_mode is changed - apt_update_cache_1 is changed + - apt_update_cache_2_check_mode is not changed - apt_update_cache_2 is not changed - name: uninstall apt bindings with apt again diff --git a/test/integration/targets/apt/tasks/repo.yml b/test/integration/targets/apt/tasks/repo.yml index 1705cb3e..e4e39aa3 100644 --- a/test/integration/targets/apt/tasks/repo.yml +++ b/test/integration/targets/apt/tasks/repo.yml @@ -40,6 +40,17 @@ state: absent allow_unauthenticated: yes +- name: Try to install non-existent version + apt: + name: foo=99 + state: present + ignore_errors: true + register: apt_result + +- name: Check if install failed + assert: + that: + - apt_result is failed # https://github.com/ansible/ansible/issues/30638 - block: @@ -56,6 +67,7 @@ assert: that: - "apt_result is not changed" + - "apt_result is failed" - apt: name: foo=1.0.0 @@ -122,12 +134,58 @@ - item.item.3 is none or "Inst foo [1.0.0] (" + item.item.3 + " localhost [all])" in item.stdout_lines loop: '{{ apt_result.results }}' + - name: Pin foo=1.0.0 + copy: + content: |- + Package: foo + Pin: version 1.0.0 + Pin-Priority: 1000 + dest: /etc/apt/preferences.d/foo + + - name: Run pinning version test matrix + apt: + name: foo{{ item.0 }} + default_release: '{{ item.1 }}' + state: '{{ item.2 | ternary("latest","present") }}' + check_mode: true + ignore_errors: true + register: apt_result + loop: + # [filter, release, state_latest, expected] # expected=null for no change. expected=False to assert an error + - ["", null, false, null] + - ["", null, true, null] + - ["=1.0.0", null, false, null] + - ["=1.0.0", null, true, null] + - ["=1.0.1", null, false, "1.0.1"] + #- ["=1.0.*", null, false, null] # legacy behavior. should not upgrade without state=latest + - ["=1.0.*", null, true, "1.0.1"] + - [">=1.0.0", null, false, null] + - [">=1.0.0", null, true, null] + - [">=1.0.1", null, false, False] + - ["", "testing", false, null] + - ["", "testing", true, null] + - ["=2.0.0", null, false, "2.0.0"] + - [">=2.0.0", "testing", false, False] + + - name: Validate pinning version test matrix + assert: + that: + - (item.item.3 != False) or (item.item.3 == False and item is failed) + - (item.item.3 is string) == (item.stdout is defined) + - item.item.3 is not string or "Inst foo [1.0.0] (" + item.item.3 + " localhost [all])" in item.stdout_lines + loop: '{{ apt_result.results }}' + always: - name: Uninstall foo apt: name: foo state: absent + - name: Unpin foo + file: + path: /etc/apt/preferences.d/foo + state: absent + # https://github.com/ansible/ansible/issues/35900 - block: - name: Disable ubuntu repos so system packages are not upgraded and do not change testing env @@ -138,6 +196,42 @@ name: foobar=1.0.0 allow_unauthenticated: yes + - name: mark foobar as auto for next test + shell: apt-mark auto foobar + + - name: Install foobar (marked as manual) (check mode) + apt: + name: foobar=1.0.1 + allow_unauthenticated: yes + check_mode: yes + register: manual_foobar_install_check_mode + + - name: check foobar was not marked as manually installed by check mode + shell: apt-mark showmanual | grep foobar + ignore_errors: yes + register: showmanual + + - assert: + that: + - manual_foobar_install_check_mode.changed + - "'foobar' not in showmanual.stdout" + + - name: Install foobar (marked as manual) + apt: + name: foobar=1.0.1 + allow_unauthenticated: yes + register: manual_foobar_install + + - name: check foobar was marked as manually installed + shell: apt-mark showmanual | grep foobar + ignore_errors: yes + register: showmanual + + - assert: + that: + - manual_foobar_install.changed + - "'foobar' in showmanual.stdout" + - name: Upgrade foobar to a version which does not depend on foo, autoremove should remove foo apt: upgrade: dist diff --git a/test/integration/targets/connection_paramiko_ssh/aliases b/test/integration/targets/connection_paramiko_ssh/aliases index aa7fd949..c5793217 100644 --- a/test/integration/targets/connection_paramiko_ssh/aliases +++ b/test/integration/targets/connection_paramiko_ssh/aliases @@ -2,4 +2,5 @@ needs/ssh shippable/posix/group3 needs/target/setup_paramiko needs/target/connection +skip/freebsd/13.0 # bcrypt 4+ requires a newer version of rust than is available destructive # potentially installs/uninstalls OS packages via setup_paramiko diff --git a/test/integration/targets/file/tasks/main.yml b/test/integration/targets/file/tasks/main.yml index a74cbc28..4ad19e06 100644 --- a/test/integration/targets/file/tasks/main.yml +++ b/test/integration/targets/file/tasks/main.yml @@ -151,8 +151,10 @@ attributes_supported: yes when: - attribute_A_set is success + - attribute_A_set.stdout_lines - "'A' in attribute_A_set.stdout_lines[0].split()[0]" - attribute_A_unset is success + - attribute_A_unset.stdout_lines - "'A' not in attribute_A_unset.stdout_lines[0].split()[0]" - name: explicitly set file attribute "A" diff --git a/test/integration/targets/incidental_inventory_aws_ec2/playbooks/setup.yml b/test/integration/targets/incidental_inventory_aws_ec2/playbooks/setup.yml index 8a9b8893..d12d300f 100644 --- a/test/integration/targets/incidental_inventory_aws_ec2/playbooks/setup.yml +++ b/test/integration/targets/incidental_inventory_aws_ec2/playbooks/setup.yml @@ -14,7 +14,7 @@ owner-id: '125523088429' virtualization-type: hvm root-device-type: ebs - name: 'Fedora-Atomic-27*' + name: 'Fedora-Cloud-Base-*' <<: *aws_connection_info register: fedora_images diff --git a/test/integration/targets/wait_for/files/write_utf16.py b/test/integration/targets/wait_for/files/write_utf16.py new file mode 100644 index 00000000..6079ed33 --- /dev/null +++ b/test/integration/targets/wait_for/files/write_utf16.py @@ -0,0 +1,20 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import sys + +# utf16 encoded bytes +# to ensure wait_for doesn't have any encoding errors +data = ( + b'\xff\xfep\x00r\x00e\x00m\x00i\x00\xe8\x00r\x00e\x00 \x00i\x00s\x00 ' + b'\x00f\x00i\x00r\x00s\x00t\x00\n\x00p\x00r\x00e\x00m\x00i\x00e\x00' + b'\x00\x03r\x00e\x00 \x00i\x00s\x00 \x00s\x00l\x00i\x00g\x00h\x00t\x00' + b'l\x00y\x00 \x00d\x00i\x00f\x00f\x00e\x00r\x00e\x00n\x00t\x00\n\x00\x1a' + b'\x048\x04@\x048\x04;\x04;\x048\x04F\x040\x04 \x00i\x00s\x00 \x00C\x00y' + b'\x00r\x00i\x00l\x00l\x00i\x00c\x00\n\x00\x01\xd8\x00\xdc \x00a\x00m' + b'\x00 \x00D\x00e\x00s\x00e\x00r\x00e\x00t\x00\n\x00\n' + b'completed\n' +) + +with open(sys.argv[1], 'wb') as f: + f.write(data) diff --git a/test/integration/targets/wait_for/tasks/main.yml b/test/integration/targets/wait_for/tasks/main.yml index c524f990..f71ddbda 100644 --- a/test/integration/targets/wait_for/tasks/main.yml +++ b/test/integration/targets/wait_for/tasks/main.yml @@ -104,6 +104,16 @@ - waitfor['match_groupdict']['foo'] == 'data' - waitfor['match_groups'] == ['data', '123'] +- name: write non-ascii file + script: write_utf16.py "{{remote_tmp_dir}}/utf16.txt" + args: + executable: '{{ ansible_facts.python.executable }}' + +- name: test non-ascii file + wait_for: + path: "{{remote_tmp_dir}}/utf16.txt" + search_regex: completed + - name: test wait for port timeout wait_for: port: 12121 |