blob: 484d8aec28a01b4068a455c2c3fb1a576a95ea9e (
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
|
---
- name: Generate a test ID
set_fact:
test_id: "{{ lookup('password', '/dev/null chars=ascii_letters length=16') }}"
when: test_id is not defined
- name: Generate names
set_fact:
project_name1: "AWX-Collection-tests-project-project1-{{ test_id }}"
project_name2: "AWX-Collection-tests-project-project2-{{ test_id }}"
project_name3: "AWX-Collection-tests-project-project3-{{ test_id }}"
jt1: "AWX-Collection-tests-project-jt1-{{ test_id }}"
scm_cred_name: "AWX-Collection-tests-project-scm-cred-{{ test_id }}"
org_name: "AWX-Collection-tests-project-org-{{ test_id }}"
cred_name: "AWX-Collection-tests-project-cred-{{ test_id }}"
- block:
- name: Create an SCM Credential
credential:
name: "{{ scm_cred_name }}"
organization: Default
credential_type: Source Control
register: result
- assert:
that:
- result is changed
- name: Create a git project without credentials and wait
project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples
wait: true
register: result
- assert:
that:
- result is changed
- name: Create a git project without credentials and wait with exists
project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples
wait: true
state: exists
register: result
- assert:
that:
- result is not changed
- name: Create a git project and wait with short request timeout.
project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples
wait: true
state: exists
request_timeout: .001
register: result
ignore_errors: true
- assert:
that:
- result is failed
- "'timed out' in result.msg"
- name: Delete a git project without credentials and wait
project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples
wait: true
state: absent
register: result
- assert:
that:
- result is changed
- name: Create a git project without credentials and wait with exists
project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples
wait: true
state: exists
register: result
- assert:
that:
- result is changed
- name: Recreate the project to validate not changed
project:
name: "{{ project_name1 }}"
organization: Default
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples
wait: false
register: result
ignore_errors: true
- assert:
that:
- result is not changed
- name: Create organizations
organization:
name: "{{ org_name }}"
register: result
- assert:
that:
- result is changed
- name: Create credential
credential:
credential_type: Source Control
name: "{{ cred_name }}"
organization: "{{ org_name }}"
register: result
- assert:
that:
- result is changed
- name: Create a new test project in check_mode
project:
name: "{{ project_name2 }}"
organization: "{{ org_name }}"
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples
scm_credential: "{{ cred_name }}"
check_mode: true
- name: "Copy project from {{ project_name1 }}"
project:
name: "{{ project_name2 }}"
copy_from: "{{ project_name1 }}"
organization: "{{ org_name }}"
scm_type: git
scm_credential: "{{ cred_name }}"
state: present
register: result
# If this fails it may be because the check_mode task actually already created
# the project, or it could be because the module actually failed somehow
- assert:
that:
- result.copied
- name: Check module fails with correct msg when given non-existing org as param
project:
name: "{{ project_name2 }}"
organization: Non_Existing_Org
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples
scm_credential: "{{ cred_name }}"
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'Non_Existing_Org' in result.msg"
- "result.total_results == 0"
- name: Check module fails with correct msg when given non-existing credential as param
project:
name: "{{ project_name2 }}"
organization: "{{ org_name }}"
scm_type: git
scm_url: https://github.com/ansible/ansible-tower-samples
scm_credential: Non_Existing_Credential
register: result
ignore_errors: true
- assert:
that:
- "result is failed"
- "result is not changed"
- "'Non_Existing_Credential' in result.msg"
- "result.total_results == 0"
- name: Create a git project using a branch and allowing branch override
project:
name: "{{ project_name3 }}"
organization: Default
scm_type: git
scm_branch: empty_branch
scm_url: https://github.com/ansible/test-playbooks
allow_override: true
register: result
- assert:
that:
- result is changed
- name: Update the project and wait. Verify not changed as no change made to repo and refspec not changed
project:
name: "{{ project_name3 }}"
organization: Default
scm_type: git
scm_branch: empty_branch
scm_url: https://github.com/ansible/test-playbooks
allow_override: true
wait: true
update_project: true
register: result
- assert:
that:
- result is not changed
- name: Create a job template that overrides the project scm_branch
job_template:
name: "{{ jt1 }}"
project: "{{ project_name3 }}"
inventory: "Demo Inventory"
scm_branch: master
playbook: debug.yml
- name: Launch "{{ jt1 }}"
job_launch:
job_template: "{{ jt1 }}"
register: result
- assert:
that:
- result is changed
- name: "wait for job {{ result.id }}"
job_wait:
job_id: "{{ result.id }}"
register: job
- assert:
that:
- job is successful
- name: Rename an inventory
project:
name: "{{ project_name3 }}"
new_name: "{{ project_name3 }}a"
organization: Default
state: present
register: result
- assert:
that:
- result.changed
- name: Set project to remote archive and test that it updates correctly.
project:
name: "{{ project_name3 }}"
organization: Default
scm_type: archive
scm_url: https://github.com/ansible/ansible-tower-samples/archive/refs/tags/1.0.0.tar.gz
wait: true
update_project: true
register: result
- assert:
that:
- result is changed
always:
- name: Delete the test job_template
job_template:
name: "{{ jt1 }}"
project: "{{ project_name3 }}"
inventory: "Demo Inventory"
state: absent
- name: Delete the test project 3
project:
name: "{{ project_name3 }}"
organization: Default
state: absent
- name: Delete the test project 3a
project:
name: "{{ project_name3 }}a"
organization: Default
state: absent
- name: Delete the test project 2
project:
name: "{{ project_name2 }}"
organization: "{{ org_name }}"
state: absent
- name: Delete the SCM Credential
credential:
name: "{{ scm_cred_name }}"
organization: Default
credential_type: Source Control
state: absent
register: result
- assert:
that:
- result is changed
- name: Delete the test project 1
project:
name: "{{ project_name1 }}"
organization: Default
state: absent
register: result
- assert:
that:
- result is changed
- name: Delete credential
credential:
credential_type: Source Control
name: "{{ cred_name }}"
organization: "{{ org_name }}"
state: absent
register: result
- assert:
that:
- result is changed
- name: Delete the organization
organization:
name: "{{ org_name }}"
state: absent
register: result
- assert:
that:
- result is changed
|