summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/ansible-galaxy-collection/tasks/upgrade.yml
blob: 893ea8033b59aac240d411cd2790cea513087769 (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
##### Updating collections with a new version constraint

# No deps

- name: reset installation directory
  file:
    state: "{{ item }}"
    path: "{{ galaxy_dir }}/ansible_collections"
  loop:
    - absent
    - directory

- name: install a collection
  command: ansible-galaxy collection install namespace1.name1:0.0.1 {{ galaxy_verbosity }}
  register: result
  failed_when:
    - '"namespace1.name1:0.0.1 was installed successfully" not in result.stdout_lines'

- name: install a new version of the collection without --force
  command: ansible-galaxy collection install namespace1.name1:>0.0.4,<=0.0.5 {{ galaxy_verbosity }}
  register: result

- name: check the MANIFEST.json to verify the version
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
  register: metadata

- assert:
    that:
      - '"namespace1.name1:0.0.5 was installed successfully" in result.stdout_lines'
      - (metadata.content | b64decode | from_json).collection_info.version == '0.0.5'

- name: don't reinstall the collection in the requirement is compatible
  command: ansible-galaxy collection install namespace1.name1:>=0.0.5 {{ galaxy_verbosity }}
  register: result

- assert:
    that: "\"Nothing to do. All requested collections are already installed.\" in result.stdout"

- name: install a pre-release of the collection without --force
  command: ansible-galaxy collection install namespace1.name1:1.1.0-beta.1 {{ galaxy_verbosity }}
  register: result

- name: check the MANIFEST.json to verify the version
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
  register: metadata

- assert:
    that:
      - '"namespace1.name1:1.1.0-beta.1 was installed successfully" in result.stdout_lines'
      - (metadata.content | b64decode | from_json).collection_info.version == '1.1.0-beta.1'

# With deps

- name: reset installation directory
  file:
    state: "{{ item }}"
    path: "{{ galaxy_dir }}/ansible_collections"
  loop:
    - absent
    - directory

- name: install a dep that will need to be upgraded to be compatible with the parent
  command: ansible-galaxy collection install child_dep.child_collection:0.4.0 --no-deps {{ galaxy_verbosity }}
  register: result
  failed_when:
    - '"child_dep.child_collection:0.4.0 was installed successfully" not in result.stdout_lines'

- name: install a dep of the dep that will need to be upgraded to be compatible
  command: ansible-galaxy collection install child_dep.child_dep2:>1.2.2 {{ galaxy_verbosity }}
  register: result
  failed_when:
    - '"child_dep.child_dep2:1.2.3 was installed successfully" not in result.stdout_lines'

- name: install the parent without deps to test dep reconciliation during upgrade
  command: ansible-galaxy collection install parent_dep.parent_collection:0.0.1 {{ galaxy_verbosity }}
  register: result
  failed_when:
    - '"parent_dep.parent_collection:0.0.1 was installed successfully" not in result.stdout_lines'

- name: test upgrading the parent collection and dependencies
  command: ansible-galaxy collection install parent_dep.parent_collection:>=1.0.0,<1.1.0 {{ galaxy_verbosity }}
  register: result

- name: check the MANIFEST.json to verify the versions
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/{{ item.namespace }}/{{ item.name }}/MANIFEST.json'
  register: metadata
  loop:
    - namespace: parent_dep
      name: parent_collection
    - namespace: child_dep
      name: child_collection
    - namespace: child_dep
      name: child_dep2

- assert:
    that:
      - '"parent_dep.parent_collection:1.0.0 was installed successfully" in result.stdout_lines'
      - (metadata.results[0].content | b64decode | from_json).collection_info.version == '1.0.0'
      - '"child_dep.child_collection:0.9.9 was installed successfully" in result.stdout_lines'
      - (metadata.results[1].content | b64decode | from_json).collection_info.version == '0.9.9'
      - '"child_dep.child_dep2:1.2.2 was installed successfully" in result.stdout_lines'
      - (metadata.results[2].content | b64decode | from_json).collection_info.version == '1.2.2'

- name: test upgrading a collection only upgrades dependencies if necessary
  command: ansible-galaxy collection install parent_dep.parent_collection:1.1.0 {{ galaxy_verbosity }}
  register: result

- name: check the MANIFEST.json to verify the versions
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/{{ item.namespace }}/{{ item.name }}/MANIFEST.json'
  register: metadata
  loop:
    - namespace: parent_dep
      name: parent_collection
    - namespace: child_dep
      name: child_collection
    - namespace: child_dep
      name: child_dep2

- assert:
    that:
      - '"parent_dep.parent_collection:1.1.0 was installed successfully" in result.stdout_lines'
      - (metadata.results[0].content | b64decode | from_json).collection_info.version == '1.1.0'
      - "\"'child_dep.child_collection:0.9.9' is already installed, skipping.\" in result.stdout_lines"
      - (metadata.results[1].content | b64decode | from_json).collection_info.version == '0.9.9'
      - "\"'child_dep.child_dep2:1.2.2' is already installed, skipping.\" in result.stdout_lines"
      - (metadata.results[2].content | b64decode | from_json).collection_info.version == '1.2.2'

##### Updating collections with --upgrade

# No deps

- name: reset installation directory
  file:
    state: "{{ item }}"
    path: "{{ galaxy_dir }}/ansible_collections"
  loop:
    - absent
    - directory

- name: install a collection
  command: ansible-galaxy collection install namespace1.name1:0.0.1 {{ galaxy_verbosity }}
  register: result
  failed_when:
    - '"namespace1.name1:0.0.1 was installed successfully" not in result.stdout_lines'

- name: install a new version of the collection with --upgrade
  command: ansible-galaxy collection install namespace1.name1:<=0.0.5 --upgrade {{ galaxy_verbosity }}
  register: result

- name: check the MANIFEST.json to verify the version
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/namespace1/name1/MANIFEST.json'
  register: metadata

- assert:
    that:
      - '"namespace1.name1:0.0.5 was installed successfully" in result.stdout_lines'
      - (metadata.content | b64decode | from_json).collection_info.version == '0.0.5'

- name: upgrade the collection
  command: ansible-galaxy collection install namespace1.name1:<0.0.7 -U {{ galaxy_verbosity }}
  register: result

- assert:
    that: '"namespace1.name1:0.0.6 was installed successfully" in result.stdout_lines'

- name: upgrade the collection to the last version excluding prereleases
  command: ansible-galaxy collection install namespace1.name1 -U {{ galaxy_verbosity }}
  register: result

- assert:
    that: '"namespace1.name1:1.0.9 was installed successfully" in result.stdout_lines'

- name: upgrade the collection to the latest available version including prereleases
  command: ansible-galaxy collection install namespace1.name1 --pre -U {{ galaxy_verbosity }}
  register: result

- assert:
    that: '"namespace1.name1:1.1.0-beta.1 was installed successfully" in result.stdout_lines'

- name: run the same command again
  command: ansible-galaxy collection install namespace1.name1 --pre -U {{ galaxy_verbosity }}
  register: result

- assert:
    that: "\"'namespace1.name1:1.1.0-beta.1' is already installed, skipping.\" in result.stdout"

# With deps

- name: reset installation directory
  file:
    state: "{{ item }}"
    path: "{{ galaxy_dir }}/ansible_collections"
  loop:
    - absent
    - directory

- name: install a parent collection and a particular version of its dependency
  command: ansible-galaxy collection install parent_dep.parent_collection:1.0.0 child_dep.child_collection:0.5.0 {{ galaxy_verbosity }}
  register: result
  failed_when:
    - '"parent_dep.parent_collection:1.0.0 was installed successfully" not in result.stdout_lines'
    - '"child_dep.child_collection:0.5.0 was installed successfully" not in result.stdout_lines'

- name: upgrade the parent and child - the child's new version has a dependency that should be installed
  command: ansible-galaxy collection install parent_dep.parent_collection -U {{ galaxy_verbosity }}
  register: result

- name: check the MANIFEST.json to verify the versions
  slurp:
    path: '{{ galaxy_dir }}/ansible_collections/{{ item.namespace }}/{{ item.name }}/MANIFEST.json'
  register: metadata
  loop:
    - namespace: parent_dep
      name: parent_collection
    - namespace: child_dep
      name: child_collection
    - namespace: child_dep
      name: child_dep2

- assert:
    that:
      - '"parent_dep.parent_collection:2.0.0 was installed successfully" in result.stdout_lines'
      - (metadata.results[0].content | b64decode | from_json).collection_info.version == '2.0.0'
      - '"child_dep.child_collection:1.0.0 was installed successfully" in result.stdout_lines'
      - (metadata.results[1].content | b64decode | from_json).collection_info.version == '1.0.0'
      - '"child_dep.child_dep2:1.2.2 was installed successfully" in result.stdout_lines'
      - (metadata.results[2].content | b64decode | from_json).collection_info.version == '1.2.2'

# Test using a requirements.yml file for upgrade

- name: reset installation directory
  file:
    state: "{{ item }}"
    path: "{{ galaxy_dir }}/ansible_collections"
  loop:
    - absent
    - directory

- name: install upgradeable collections
  command: ansible-galaxy collection install namespace1.name1:1.0.0 parent_dep.parent_collection:0.0.1 {{ galaxy_verbosity }}
  register: result
  failed_when:
    - '"namespace1.name1:1.0.0 was installed successfully" not in result.stdout_lines'
    - '"parent_dep.parent_collection:0.0.1 was installed successfully" not in result.stdout_lines'
    - '"child_dep.child_collection:0.4.0 was installed successfully" not in result.stdout_lines'

- name: create test requirements file with both roles and collections - {{ test_name }}
  copy:
    content: |
      collections:
        - namespace1.name1
        - name: parent_dep.parent_collection
          version: <=2.0.0
      roles:
      - skip.me
    dest: '{{ galaxy_dir }}/ansible_collections/requirements.yml'

- name: upgrade collections with the requirements.yml
  command: ansible-galaxy collection install -r {{ requirements_path }} --upgrade {{ galaxy_verbosity }}
  vars:
    requirements_path: '{{ galaxy_dir }}/ansible_collections/requirements.yml'
  register: result

- assert:
    that:
      - '"namespace1.name1:1.0.9 was installed successfully" in result.stdout_lines'
      - '"parent_dep.parent_collection:2.0.0 was installed successfully" in result.stdout_lines'
      - '"child_dep.child_collection:1.0.0 was installed successfully" in result.stdout_lines'
      - '"child_dep.child_dep2:1.2.2 was installed successfully" in result.stdout_lines'

- name: cleanup
  file:
    state: "{{ item }}"
    path: "{{ galaxy_dir }}/ansible_collections"
  loop:
    - absent
    - directory