Skip to content

Commit addfeac

Browse files
committed
pulp_container_content: Add an integration test
1 parent bb265dd commit addfeac

File tree

1 file changed

+197
-0
lines changed

1 file changed

+197
-0
lines changed

tests/test_container_content.yml

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
---
2+
- name: Test container repositories
3+
gather_facts: false
4+
hosts: localhost
5+
vars:
6+
pulp_url: http://localhost:8080
7+
pulp_username: admin
8+
pulp_password: password
9+
pulp_validate_certs: true
10+
tasks:
11+
- include_role:
12+
name: pulp_repository
13+
vars:
14+
pulp_repository_container_repos:
15+
- name: test_container_repo
16+
upstream_name: pulp/test-fixture-1
17+
url: "https://registry-1.docker.io"
18+
policy: immediate
19+
state: present
20+
- name: test_container_repo2
21+
state: present
22+
23+
- include_role:
24+
name: pulp_container_content
25+
vars:
26+
pulp_container_content:
27+
- repository: test_container_repo2
28+
src_repo: test_container_repo
29+
tags:
30+
- manifest_a
31+
- manifest_b
32+
state: present
33+
34+
- name: Query repository
35+
uri:
36+
url: "{{ pulp_url }}/pulp/api/v3/repositories/container/container/?name={{ 'test_container_repo2' | urlencode | regex_replace('/','%2F') }}"
37+
user: "{{ pulp_username }}"
38+
password: "{{ pulp_password }}"
39+
method: GET
40+
status_code: 200
41+
force_basic_auth: true
42+
register: repo
43+
44+
- name: Query tags
45+
uri:
46+
url: "{{ pulp_url }}/pulp/api/v3/content/container/tags/?repository_version={{ repo.json.results[0].latest_version_href | urlencode | regex_replace('/','%2F') }}"
47+
user: "{{ pulp_username }}"
48+
password: "{{ pulp_password }}"
49+
method: GET
50+
status_code: 200
51+
force_basic_auth: true
52+
register: tags
53+
54+
- name: Assert that tags have been added
55+
assert:
56+
that:
57+
- tags.json.results | map(attribute='name') | sort | list == ['manifest_a', 'manifest_b']
58+
59+
# Test idempotence
60+
- include_role:
61+
name: pulp_container_content
62+
vars:
63+
pulp_container_content:
64+
- repository: test_container_repo2
65+
src_repo: test_container_repo
66+
tags:
67+
- manifest_a
68+
- manifest_b
69+
state: present
70+
71+
- include_role:
72+
name: pulp_container_content
73+
vars:
74+
pulp_container_content:
75+
- repository: test_container_repo2
76+
tags:
77+
- manifest_b
78+
state: absent
79+
80+
- name: Query repository
81+
uri:
82+
url: "{{ pulp_url }}/pulp/api/v3/repositories/container/container/?name={{ 'test_container_repo2' | urlencode | regex_replace('/','%2F') }}"
83+
user: "{{ pulp_username }}"
84+
password: "{{ pulp_password }}"
85+
method: GET
86+
status_code: 200
87+
force_basic_auth: true
88+
register: repo
89+
90+
- name: Query tags
91+
uri:
92+
url: "{{ pulp_url }}/pulp/api/v3/content/container/tags/?repository_version={{ repo.json.results[0].latest_version_href | urlencode | regex_replace('/','%2F') }}"
93+
user: "{{ pulp_username }}"
94+
password: "{{ pulp_password }}"
95+
method: GET
96+
status_code: 200
97+
force_basic_auth: true
98+
register: tags
99+
100+
- name: Assert that manifest_b tag has been removed
101+
assert:
102+
that:
103+
- tags.json.results | map(attribute='name') | list == ['manifest_a']
104+
105+
# Test idempotence
106+
- include_role:
107+
name: pulp_container_content
108+
vars:
109+
pulp_container_content:
110+
- repository: test_container_repo2
111+
tags:
112+
- manifest_b
113+
state: absent
114+
115+
- include_role:
116+
name: pulp_container_content
117+
vars:
118+
pulp_container_content:
119+
- repository: test_container_repo2
120+
tags:
121+
- manifest_a
122+
state: absent
123+
124+
- name: Query repository
125+
uri:
126+
url: "{{ pulp_url }}/pulp/api/v3/repositories/container/container/?name={{ 'test_container_repo2' | urlencode | regex_replace('/','%2F') }}"
127+
user: "{{ pulp_username }}"
128+
password: "{{ pulp_password }}"
129+
method: GET
130+
status_code: 200
131+
force_basic_auth: true
132+
register: repo
133+
134+
- name: Query tags
135+
uri:
136+
url: "{{ pulp_url }}/pulp/api/v3/content/container/tags/?repository_version={{ repo.json.results[0].latest_version_href | urlencode | regex_replace('/','%2F') }}"
137+
user: "{{ pulp_username }}"
138+
password: "{{ pulp_password }}"
139+
method: GET
140+
status_code: 200
141+
force_basic_auth: true
142+
register: tags
143+
144+
- name: Assert that all tags have been removed
145+
assert:
146+
that:
147+
- tags.json.results == []
148+
149+
- include_role:
150+
name: pulp_container_content
151+
vars:
152+
pulp_container_content:
153+
- repository: test_container_repo2
154+
tags:
155+
- manifest_a
156+
state: absent
157+
158+
- include_role:
159+
name: pulp_container_content
160+
vars:
161+
pulp_container_content:
162+
- allow_missing: true
163+
repository: test_container_repo2
164+
src_repo: test_container_repo
165+
tags:
166+
- not-a-valid-tag
167+
state: present
168+
169+
# When allow_missing is false (this is the default), the role should fail
170+
# when provided with a that is not in the source repository.
171+
- block:
172+
- include_role:
173+
name: pulp_container_content
174+
vars:
175+
pulp_container_content:
176+
- repository: test_container_repo2
177+
src_repo: test_container_repo
178+
tags:
179+
- not-a-valid-tag
180+
state: present
181+
rescue:
182+
- set_fact:
183+
failed_task: "{{ ansible_failed_task }}"
184+
always:
185+
- name: Assert that adding a missing tag failed
186+
assert:
187+
that:
188+
- failed_task.name == "Add or remove content units"
189+
190+
- include_role:
191+
name: pulp_repository
192+
vars:
193+
pulp_repository_container_repos:
194+
- name: test_container_repo
195+
state: absent
196+
- name: test_container_repo2
197+
state: absent

0 commit comments

Comments
 (0)