diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-14 20:03:01 +0000 |
commit | a453ac31f3428614cceb99027f8efbdb9258a40b (patch) | |
tree | f61f87408f32a8511cbd91799f9cececb53e0374 /test/integration/targets/ansible-galaxy-collection-scm | |
parent | Initial commit. (diff) | |
download | ansible-a453ac31f3428614cceb99027f8efbdb9258a40b.tar.xz ansible-a453ac31f3428614cceb99027f8efbdb9258a40b.zip |
Adding upstream version 2.10.7+merged+base+2.10.8+dfsg.upstream/2.10.7+merged+base+2.10.8+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'test/integration/targets/ansible-galaxy-collection-scm')
14 files changed, 328 insertions, 0 deletions
diff --git a/test/integration/targets/ansible-galaxy-collection-scm/aliases b/test/integration/targets/ansible-galaxy-collection-scm/aliases new file mode 100644 index 00000000..9c34b360 --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/aliases @@ -0,0 +1,3 @@ +shippable/posix/group4 +skip/aix +skip/python2.6 # ansible-galaxy uses tarfile with features not available until 2.7 diff --git a/test/integration/targets/ansible-galaxy-collection-scm/meta/main.yml b/test/integration/targets/ansible-galaxy-collection-scm/meta/main.yml new file mode 100644 index 00000000..e3dd5fb1 --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: +- setup_remote_tmp_dir diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/download.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/download.yml new file mode 100644 index 00000000..672b849c --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/download.yml @@ -0,0 +1,47 @@ +- name: create test download dir + file: + path: '{{ galaxy_dir }}/download' + state: directory + +- name: download a git repository + command: > + ansible-galaxy collection download + git+https://github.com/ansible-collections/amazon.aws.git,37875c5b4ba5bf3cc43e07edf29f3432fd76def5 + git+https://github.com/AlanCoding/awx.git#awx_collection,750c22a150d04eef1cb625fd4f83cce57949416c + args: + chdir: '{{ galaxy_dir }}/download' + register: download_collection + +- name: check that the amazon.aws collection was downloaded + stat: + path: '{{ galaxy_dir }}/download/collections/amazon-aws-1.0.0.tar.gz' + register: download_collection_amazon_actual + +- name: check that the awx.awx collection was downloaded + stat: + path: '{{ galaxy_dir }}/download/collections/awx-awx-0.0.1-devel.tar.gz' + register: download_collection_awx_actual + +- assert: + that: + - '"Downloading collection ''amazon.aws'' to" in download_collection.stdout' + - '"Downloading collection ''awx.awx'' to" in download_collection.stdout' + - download_collection_amazon_actual.stat.exists + - download_collection_awx_actual.stat.exists + +- name: test the downloaded repository can be installed + command: 'ansible-galaxy collection install -r requirements.yml' + args: + chdir: '{{ galaxy_dir }}/download/collections/' + +- name: list installed collections + command: 'ansible-galaxy collection list' + register: installed_collections + +- assert: + that: + - "'amazon.aws' in installed_collections.stdout" + - "'awx.awx' in installed_collections.stdout" + +- include_tasks: ./empty_installed_collections.yml + when: cleanup diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/empty_installed_collections.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/empty_installed_collections.yml new file mode 100644 index 00000000..f21a6f6b --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/empty_installed_collections.yml @@ -0,0 +1,7 @@ +- name: delete installed collections + file: + state: "{{ item }}" + path: "{{ galaxy_dir }}/ansible_collections" + loop: + - absent + - directory diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/individual_collection_repo.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/individual_collection_repo.yml new file mode 100644 index 00000000..1b761f60 --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/individual_collection_repo.yml @@ -0,0 +1,20 @@ +- name: Clone a git repository + git: + repo: https://github.com/ansible-collections/amazon.aws.git + dest: '{{ galaxy_dir }}/development/amazon.aws/' + +- name: install + command: 'ansible-galaxy collection install git+file://{{galaxy_dir }}/development/amazon.aws/.git' + args: + chdir: '{{ galaxy_dir }}/development' + +- name: list installed collections + command: 'ansible-galaxy collection list' + register: installed_collections + +- assert: + that: + - "'amazon.aws' in installed_collections.stdout" + +- include_tasks: ./empty_installed_collections.yml + when: cleanup diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/main.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/main.yml new file mode 100644 index 00000000..7db7e1d6 --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/main.yml @@ -0,0 +1,41 @@ +--- +- name: set the temp test directory + set_fact: + galaxy_dir: "{{ remote_tmp_dir }}/galaxy" + +- name: Test installing collections from git repositories + environment: + ANSIBLE_COLLECTIONS_PATHS: '{{ galaxy_dir }}' + vars: + cleanup: True + galaxy_dir: "{{ galaxy_dir }}" + block: + + - include_tasks: ./setup.yml + - include_tasks: ./individual_collection_repo.yml + - include_tasks: ./setup_multi_collection_repo.yml + - include_tasks: ./multi_collection_repo_all.yml + - include_tasks: ./scm_dependency.yml + vars: + cleanup: False + - include_tasks: ./reinstalling.yml + - include_tasks: ./multi_collection_repo_individual.yml + - include_tasks: ./setup_recursive_scm_dependency.yml + - include_tasks: ./scm_dependency_deduplication.yml + - include_tasks: ./download.yml + + always: + + - name: Remove the directories for installing collections and git repositories + file: + path: '{{ item }}' + state: absent + loop: + - '{{ galaxy_dir }}/ansible_collections' + - '{{ galaxy_dir }}/development' + + - name: remove git + package: + name: git + state: absent + when: git_install is changed diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/multi_collection_repo_all.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/multi_collection_repo_all.yml new file mode 100644 index 00000000..2992062a --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/multi_collection_repo_all.yml @@ -0,0 +1,14 @@ +- name: Install all collections by default + command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/ansible_test/.git' + +- name: list installed collections + command: 'ansible-galaxy collection list' + register: installed_collections + +- assert: + that: + - "'ansible_test.collection_1' in installed_collections.stdout" + - "'ansible_test.collection_2' in installed_collections.stdout" + +- include_tasks: ./empty_installed_collections.yml + when: cleanup diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/multi_collection_repo_individual.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/multi_collection_repo_individual.yml new file mode 100644 index 00000000..48f6407a --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/multi_collection_repo_individual.yml @@ -0,0 +1,15 @@ +- name: test installing one collection + command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/ansible_test/.git#collection_2' + +- name: list installed collections + command: 'ansible-galaxy collection list' + register: installed_collections + +- assert: + that: + - "'amazon.aws' not in installed_collections.stdout" + - "'ansible_test.collection_1' not in installed_collections.stdout" + - "'ansible_test.collection_2' in installed_collections.stdout" + +- include_tasks: ./empty_installed_collections.yml + when: cleanup diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/reinstalling.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/reinstalling.yml new file mode 100644 index 00000000..c0f6c910 --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/reinstalling.yml @@ -0,0 +1,31 @@ +- name: Rerun installing a collection with a dep + command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/ansible_test/.git#/collection_1/' + register: installed + +- assert: + that: + - "'Skipping' in installed.stdout" + - "'Created' not in installed.stdout" + +- name: Only reinstall the collection + command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/ansible_test/.git#/collection_1/ --force' + register: installed + +- assert: + that: + - "'Created collection for ansible_test.collection_1' in installed.stdout" + - "'Created collection for ansible_test.collection_2' not in installed.stdout" + - "'Skipping' in installed.stdout" + +- name: Reinstall the collection and dependency + command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/ansible_test/.git#/collection_1/ --force-with-deps' + register: installed + +- assert: + that: + - "'Created collection for ansible_test.collection_1' in installed.stdout" + - "'Created collection for ansible_test.collection_2' in installed.stdout" + - "'Skipping' not in installed.stdout" + +- include_tasks: ./empty_installed_collections.yml + when: cleanup diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/scm_dependency.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/scm_dependency.yml new file mode 100644 index 00000000..5a23663e --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/scm_dependency.yml @@ -0,0 +1,14 @@ +- name: test installing one collection that has a SCM dep + command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/ansible_test/.git#/collection_1/' + +- name: list installed collections + command: 'ansible-galaxy collection list' + register: installed_collections + +- assert: + that: + - "'ansible_test.collection_1' in installed_collections.stdout" + - "'ansible_test.collection_2' in installed_collections.stdout" + +- include_tasks: ./empty_installed_collections.yml + when: cleanup diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/scm_dependency_deduplication.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/scm_dependency_deduplication.yml new file mode 100644 index 00000000..bc10f24c --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/scm_dependency_deduplication.yml @@ -0,0 +1,54 @@ +- name: Install all collections in a repo, one of which has a recursive dependency + command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/namespace_1/.git' + register: command + +- assert: + that: + - command.stdout_lines | length == 9 + - command.stdout_lines[0] == "Starting galaxy collection install process" + - command.stdout_lines[1] == "Process install dependency map" + - command.stdout_lines[2] == "Starting collection install process" + - "'namespace_1.collection_1' in command.stdout_lines[3]" + - "'namespace_1.collection_1' in command.stdout_lines[4]" + - "'namespace_1.collection_1' in command.stdout_lines[5]" + - "'namespace_2.collection_2' in command.stdout_lines[6]" + - "'namespace_2.collection_2' in command.stdout_lines[7]" + - "'namespace_2.collection_2' in command.stdout_lines[8]" + +- name: list installed collections + command: 'ansible-galaxy collection list' + register: installed_collections + +- assert: + that: + - "'namespace_1.collection_1' in installed_collections.stdout" + - "'namespace_2.collection_2' in installed_collections.stdout" + +- name: Install a specific collection in a repo with a recursive dependency + command: 'ansible-galaxy collection install git+file://{{ galaxy_dir }}/development/namespace_1/.git#/collection_1/ --force-with-deps' + register: command + +- assert: + that: + - command.stdout_lines | length == 9 + - command.stdout_lines[0] == "Starting galaxy collection install process" + - command.stdout_lines[1] == "Process install dependency map" + - command.stdout_lines[2] == "Starting collection install process" + - "'namespace_1.collection_1' in command.stdout_lines[3]" + - "'namespace_1.collection_1' in command.stdout_lines[4]" + - "'namespace_1.collection_1' in command.stdout_lines[5]" + - "'namespace_2.collection_2' in command.stdout_lines[6]" + - "'namespace_2.collection_2' in command.stdout_lines[7]" + - "'namespace_2.collection_2' in command.stdout_lines[8]" + +- name: list installed collections + command: 'ansible-galaxy collection list' + register: installed_collections + +- assert: + that: + - "'namespace_1.collection_1' in installed_collections.stdout" + - "'namespace_2.collection_2' in installed_collections.stdout" + +- include_tasks: ./empty_installed_collections.yml + when: cleanup diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/setup.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/setup.yml new file mode 100644 index 00000000..f4beb9d6 --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/setup.yml @@ -0,0 +1,19 @@ +- name: ensure git is installed + package: + name: git + when: ansible_distribution != "MacOSX" + register: git_install + +- name: set git global user.email if not already set + shell: git config --global user.email || git config --global user.email "noreply@example.com" + +- name: set git global user.name if not already set + shell: git config --global user.name || git config --global user.name "Ansible Test Runner" + +- name: Create a directory for installing collections and creating git repositories + file: + path: '{{ item }}' + state: directory + loop: + - '{{ galaxy_dir }}/ansible_collections' + - '{{ galaxy_dir }}/development/ansible_test' diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/setup_multi_collection_repo.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/setup_multi_collection_repo.yml new file mode 100644 index 00000000..4a662ca6 --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/setup_multi_collection_repo.yml @@ -0,0 +1,27 @@ +- name: Initialize a git repo + command: 'git init {{ galaxy_dir }}/development/ansible_test' + +- stat: + path: "{{ galaxy_dir }}/development/ansible_test" + +- name: Add a couple collections to the repository + command: 'ansible-galaxy collection init {{ item }}' + args: + chdir: '{{ galaxy_dir }}/development' + loop: + - 'ansible_test.collection_1' + - 'ansible_test.collection_2' + +- name: Add collection_2 as a dependency of collection_1 + lineinfile: + path: '{{ galaxy_dir }}/development/ansible_test/collection_1/galaxy.yml' + regexp: '^dependencies' + line: "dependencies: {'git+file://{{ galaxy_dir }}/development/ansible_test/.git#collection_2/': '*'}" + +- name: Commit the changes + command: '{{ item }}' + args: + chdir: '{{ galaxy_dir }}/development/ansible_test' + loop: + - git add ./ + - git commit -m 'add collections' diff --git a/test/integration/targets/ansible-galaxy-collection-scm/tasks/setup_recursive_scm_dependency.yml b/test/integration/targets/ansible-galaxy-collection-scm/tasks/setup_recursive_scm_dependency.yml new file mode 100644 index 00000000..df0af917 --- /dev/null +++ b/test/integration/targets/ansible-galaxy-collection-scm/tasks/setup_recursive_scm_dependency.yml @@ -0,0 +1,33 @@ +- name: Initialize git repositories + command: 'git init {{ galaxy_dir }}/development/{{ item }}' + loop: + - namespace_1 + - namespace_2 + +- name: Add a couple collections to the repository + command: 'ansible-galaxy collection init {{ item }}' + args: + chdir: '{{ galaxy_dir }}/development' + loop: + - 'namespace_1.collection_1' + - 'namespace_2.collection_2' + +- name: Add collection_2 as a dependency of collection_1 + lineinfile: + path: '{{ galaxy_dir }}/development/namespace_1/collection_1/galaxy.yml' + regexp: '^dependencies' + line: "dependencies: {'git+file://{{ galaxy_dir }}/development/namespace_2/.git#collection_2/': '*'}" + +- name: Add collection_1 as a dependency on collection_2 + lineinfile: + path: '{{ galaxy_dir }}/development/namespace_2/collection_2/galaxy.yml' + regexp: '^dependencies' + line: "dependencies: {'git+file://{{ galaxy_dir }}/development/namespace_1/.git#collection_1/': 'master'}" + +- name: Commit the changes + shell: git add ./; git commit -m 'add collection' + args: + chdir: '{{ galaxy_dir }}/development/{{ item }}' + loop: + - namespace_1 + - namespace_2 |