summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-galaxy-collection/tasks/download.yml
blob: b651a73e73eee2f848692185f906f92636e57815 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
---
- name: create test download dir
  file:
    path: '{{ galaxy_dir }}/download'
    state: directory

- name: download collection with multiple dependencies with --no-deps
  command: ansible-galaxy collection download parent_dep.parent_collection:1.0.0 --no-deps -s pulp_v2 {{ galaxy_verbosity }}
  register: download_collection
  args:
    chdir: '{{ galaxy_dir }}/download'

- name: get result of download collection with multiple dependencies
  find:
    path: '{{ galaxy_dir }}/download/collections'
    file_type: file
  register: download_collection_actual

- name: assert download collection with multiple dependencies --no-deps
  assert:
    that:
    - >-
      "Downloading collection 'parent_dep.parent_collection:1.0.0' to '/tmp/"
      in download_collection.stdout
    - >-
      "Downloading collection 'child_dep.child_collection"
      not in download_collection.stdout
    - >-
      "Downloading collection 'child_dep.child_dep2"
      not in download_collection.stdout
    - download_collection_actual.examined == 2
    - download_collection_actual.matched == 2
    - (download_collection_actual.files[0].path | basename) in ['requirements.yml', 'parent_dep-parent_collection-1.0.0.tar.gz']
    - (download_collection_actual.files[1].path | basename) in ['requirements.yml', 'parent_dep-parent_collection-1.0.0.tar.gz']

- name: download collection with multiple dependencies
  command: ansible-galaxy collection download parent_dep.parent_collection:1.0.0 -s pulp_v2 {{ galaxy_verbosity }}
  register: download_collection
  args:
    chdir: '{{ galaxy_dir }}/download'

- name: get result of download collection with multiple dependencies
  find:
    path: '{{ galaxy_dir }}/download/collections'
    file_type: file
  register: download_collection_actual

- name: assert download collection with multiple dependencies
  assert:
    that:
    - '"Downloading collection ''parent_dep.parent_collection:1.0.0'' to" in download_collection.stdout'
    - '"Downloading collection ''child_dep.child_collection:0.9.9'' to" in download_collection.stdout'
    - '"Downloading collection ''child_dep.child_dep2:1.2.2'' to" in download_collection.stdout'
    - download_collection_actual.examined == 4
    - download_collection_actual.matched == 4
    - (download_collection_actual.files[0].path | basename) in ['requirements.yml', 'child_dep-child_dep2-1.2.2.tar.gz', 'child_dep-child_collection-0.9.9.tar.gz', 'parent_dep-parent_collection-1.0.0.tar.gz']
    - (download_collection_actual.files[1].path | basename) in ['requirements.yml', 'child_dep-child_dep2-1.2.2.tar.gz', 'child_dep-child_collection-0.9.9.tar.gz', 'parent_dep-parent_collection-1.0.0.tar.gz']
    - (download_collection_actual.files[2].path | basename) in ['requirements.yml', 'child_dep-child_dep2-1.2.2.tar.gz', 'child_dep-child_collection-0.9.9.tar.gz', 'parent_dep-parent_collection-1.0.0.tar.gz']
    - (download_collection_actual.files[3].path | basename) in ['requirements.yml', 'child_dep-child_dep2-1.2.2.tar.gz', 'child_dep-child_collection-0.9.9.tar.gz', 'parent_dep-parent_collection-1.0.0.tar.gz']

- name: test install of download requirements file
  command: ansible-galaxy collection install -r requirements.yml -p '{{ galaxy_dir }}/download' {{ galaxy_verbosity }}
  args:
    chdir: '{{ galaxy_dir }}/download/collections'
  register: install_download

- name: get result of test install of download requirements file
  slurp:
    path: '{{ galaxy_dir }}/download/ansible_collections/{{ collection.namespace }}/{{ collection.name }}/MANIFEST.json'
  register: install_download_actual
  loop_control:
    loop_var: collection
  loop:
  - namespace: parent_dep
    name: parent_collection
  - namespace: child_dep
    name: child_collection
  - namespace: child_dep
    name: child_dep2

- name: assert test install of download requirements file
  assert:
    that:
    - '"Installing ''parent_dep.parent_collection:1.0.0'' to" in install_download.stdout'
    - '"Installing ''child_dep.child_collection:0.9.9'' to" in install_download.stdout'
    - '"Installing ''child_dep.child_dep2:1.2.2'' to" in install_download.stdout'
    - (install_download_actual.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
    - (install_download_actual.results[1].content | b64decode | from_json).collection_info.version == '0.9.9'
    - (install_download_actual.results[2].content | b64decode | from_json).collection_info.version == '1.2.2'

- name: create test requirements file for download
  copy:
    content: |
      collections:
      - name: namespace1.name1
        version: 1.1.0-beta.1

    dest: '{{ galaxy_dir }}/download/download.yml'

- name: download collection with req to custom dir
  command: ansible-galaxy collection download -r '{{ galaxy_dir }}/download/download.yml' -s galaxy_ng -p '{{ galaxy_dir }}/download/collections-custom' {{ galaxy_verbosity }}
  register: download_req_custom_path

- name: get result of download collection with req to custom dir
  find:
    path: '{{ galaxy_dir }}/download/collections-custom'
    file_type: file
  register: download_req_custom_path_actual

- name: assert download collection with multiple dependencies
  assert:
    that:
    - '"Downloading collection ''namespace1.name1:1.1.0-beta.1'' to" in download_req_custom_path.stdout'
    - download_req_custom_path_actual.examined == 2
    - download_req_custom_path_actual.matched == 2
    - (download_req_custom_path_actual.files[0].path | basename) in ['requirements.yml', 'namespace1-name1-1.1.0-beta.1.tar.gz']
    - (download_req_custom_path_actual.files[1].path | basename) in ['requirements.yml', 'namespace1-name1-1.1.0-beta.1.tar.gz']

# https://github.com/ansible/ansible/issues/68186
- name: create test requirements file without roles and collections
  copy:
    content: |
      collections:
      roles:

    dest: '{{ galaxy_dir }}/download/no_roles_no_collections.yml'

- name: install collection with requirements
  command: ansible-galaxy collection install -r '{{ galaxy_dir }}/download/no_roles_no_collections.yml' {{ galaxy_verbosity }}
  register: install_no_requirements

- name: assert install collection with no roles and no collections in requirements
  assert:
    that:
      - '"Skipping install, no requirements found" in install_no_requirements.stdout'

- name: Test downloading a tar.gz collection artifact
  block:

    - name: get result of build basic collection on current directory
      stat:
        path: '{{ galaxy_dir }}/scratch/ansible_test/my_collection/ansible_test-my_collection-1.0.0.tar.gz'
      register: result

    - name: create default skeleton
      command: ansible-galaxy collection init ansible_test.my_collection {{ galaxy_verbosity }}
      args:
        chdir: '{{ galaxy_dir }}/scratch'
      when: not result.stat.exists

    - name: build the tar.gz
      command:  ansible-galaxy collection build {{ galaxy_verbosity }}
      args:
        chdir: '{{ galaxy_dir }}/scratch/ansible_test/my_collection'
      when: not result.stat.exists

    - name: download a tar.gz file
      command: ansible-galaxy collection download '{{ galaxy_dir }}/scratch/ansible_test/my_collection/ansible_test-my_collection-1.0.0.tar.gz'
      args:
        chdir: '{{ galaxy_dir }}/download'
      register: download_collection

    - name: get result of downloaded tar.gz
      stat:
        path: '{{ galaxy_dir }}/download/collections/ansible_test-my_collection-1.0.0.tar.gz'
      register: download_collection_actual

    - assert:
        that:
        - '"Downloading collection ''ansible_test.my_collection:1.0.0'' to" in download_collection.stdout'
        - download_collection_actual.stat.exists

- name: remove test download dir
  file:
    path: '{{ galaxy_dir }}/download'
    state: absent