Skip to content

Commit 9df4061

Browse files
committed
Adding tests for new roles
1 parent c92ae90 commit 9df4061

File tree

10 files changed

+435
-35
lines changed

10 files changed

+435
-35
lines changed

roles/pulp_content_guard/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Role variables
1616
* `description`
1717
* `ca_certificate`
1818
* `state` (Default is `present`. Setting this value to `absent` will delete the content guard if it exists)
19-
* `pulp_content_guard_rbac`: List of groups to create/update/delete. Default is an empty list. Each item is a dict containing:
19+
* `pulp_content_guard_rbac`: List of RBAC content guards to create/update/delete. Default is an empty list. Each item is a dict containing:
2020
* `name` (Required)
2121
* `roles` List of dict containing:
2222
* `role` (role name)

roles/pulp_content_guard/tasks/rbac/add_or_remove_group_roles.yml

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,30 @@
77

88
- name: Get RBAC content guard list
99
uri:
10-
url: "{{ pulp_rbac_cg_url }}"
10+
url: "{{ pulp_rbac_cg_url }}?name={{ content_guard.name }}"
1111
user: "{{ pulp_username }}"
1212
password: "{{ pulp_password }}"
1313
method: GET
1414
status_code: 200
1515
force_basic_auth: true
16-
no_log: true
17-
register: rbac_cg_list_result
18-
19-
- name: Get current roles associated with content guard
20-
vars:
21-
url_query: "[?name=='{{ content_guard.name }}'].pulp_href"
22-
set_fact:
23-
given_cg_href: "{{ rbac_cg_list_result.json.results | json_query(url_query) | first | default([]) }}"
16+
register: rbac_cg_result
2417

2518
- name: Get role list
2619
uri:
27-
url: "{{ pulp_url }}{{ given_cg_href }}list_roles/"
20+
url: "{{ pulp_url }}{{ (rbac_cg_result.json.results | first).pulp_href }}list_roles/"
2821
user: "{{ pulp_username }}"
2922
password: "{{ pulp_password }}"
3023
method: GET
3124
status_code: 200
3225
force_basic_auth: true
33-
no_log: true
3426
register: role_list_result
3527

3628
- name: Remove unused roles
3729
vars:
3830
rolenames: "{{ content_guard.roles | default([]) | map(attribute='role') | list }}"
3931
url_query: "[?name=='{{ content_guard.name }}'].pulp_href"
4032
uri:
41-
url: "{{ pulp_url }}{{ rbac_cg_list_result.json.results | json_query(url_query) | first }}remove_role/"
33+
url: "{{ pulp_url }}{{ (rbac_cg_result.json.results | first).pulp_href }}remove_role/"
4234
user: "{{ pulp_username }}"
4335
password: "{{ pulp_password }}"
4436
force_basic_auth: true
@@ -48,10 +40,7 @@
4840
role: "{{ item.role }}"
4941
groups: "{{ item.groups }}"
5042
body_format: form-urlencoded
51-
# debug:
52-
# msg: "{{ item.role }}"
5343
loop: "{{ role_list_result.json.roles }}"
54-
# no_log: true
5544
register: result
5645
when:
5746
- item.role not in rolenames

roles/pulp_content_guard/tasks/rbac/add_or_remove_groups_from_role.yml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
current_groups: "{{ role_list_result.json.roles | json_query(role_query) | first | default([]) }}"
88

99
- name: Add new group to role
10-
vars:
11-
url_query: "[?name=='{{ content_guard.name }}'].pulp_href"
1210
uri:
13-
url: "{{ pulp_url }}{{ rbac_cg_list_result.json.results | json_query(url_query) | first }}add_role/"
11+
url: "{{ pulp_url }}{{ (rbac_cg_result.json.results | first).pulp_href }}add_role/"
1412
user: "{{ pulp_username }}"
1513
password: "{{ pulp_password }}"
1614
force_basic_auth: true
@@ -20,17 +18,14 @@
2018
role: "{{ rbac_cg_new_role.role }}"
2119
groups: "{{ item }}"
2220
body_format: form-urlencoded
23-
# no_log: true
2421
register: result
2522
loop: "{{ rbac_cg_new_role.groups | default([], true) }}"
2623
when: item not in current_groups
2724
changed_when: result.status == 201
2825

2926
- name: Remove old group from role
30-
vars:
31-
url_query: "[?name=='{{ content_guard.name }}'].pulp_href"
3227
uri:
33-
url: "{{ pulp_url }}{{ rbac_cg_list_result.json.results | json_query(url_query) | first }}remove_role/"
28+
url: "{{ pulp_url }}{{ (rbac_cg_result.json.results | first).pulp_href }}remove_role/"
3429
user: "{{ pulp_username }}"
3530
password: "{{ pulp_password }}"
3631
force_basic_auth: true
@@ -40,7 +35,6 @@
4035
role: "{{ rbac_cg_new_role.role }}"
4136
groups: "{{ item }}"
4237
body_format: form-urlencoded
43-
# no_log: true
4438
register: result
4539
loop: "{{ current_groups }}"
4640
when: item not in (rbac_cg_new_role.groups | default([]))

roles/pulp_content_guard/tasks/rbac/rbac.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
method: GET
99
status_code: 200
1010
force_basic_auth: true
11-
no_log: true
1211
register: rbac_cg_list_result
1312

1413
- name: Initialise remove_rbac_cg
@@ -36,7 +35,6 @@
3635
description: "{{ item.description | default(omit) }}"
3736
body_format: form-urlencoded
3837
loop: "{{ pulp_content_guard_rbac | default([], true) }}"
39-
# no_log: true
4038
register: result
4139
when:
4240
- item.name not in rbaccgnames
@@ -58,7 +56,6 @@
5856
description: "{{ item.description | default(omit) }}"
5957
body_format: form-urlencoded
6058
loop: "{{ pulp_content_guard_rbac | default([], true) }}"
61-
# no_log: true
6259
register: result
6360
when:
6461
- item.name in rbaccgnames
@@ -96,6 +93,5 @@
9693
status_code: 204
9794
body_format: form-urlencoded
9895
loop: "{{ hrefs | default([]) }}"
99-
no_log: true
10096
register: result
10197
changed_when: result.status == 204

roles/pulp_group/tasks/main.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
method: GET
99
status_code: 200
1010
force_basic_auth: true
11-
no_log: true
1211
register: groups_list_result
1312

1413
- name: Set fact remove_groups
@@ -31,7 +30,6 @@
3130
name: "{{ item.name }}"
3231
body_format: form-urlencoded
3332
loop: "{{ pulp_groups | default([], true) }}"
34-
# no_log: true
3533
register: result
3634
when:
3735
- item.name not in groupnames
@@ -58,6 +56,5 @@
5856
status_code: 204
5957
body_format: form-urlencoded
6058
loop: "{{ hrefs | default([]) }}"
61-
no_log: true
6259
register: result
6360
changed_when: result.status == 204

roles/pulp_user/tasks/main.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
method: GET
99
status_code: 200
1010
force_basic_auth: true
11-
no_log: true
1211
register: users_list_result
1312

1413
- name: Set fact remove_users
@@ -39,7 +38,6 @@
3938
loop: "{{ pulp_users | default([], true) }}"
4039
loop_control:
4140
label: "{{ item.username }}"
42-
# no_log: true
4341
register: result
4442
when:
4543
- item.username not in usernames
@@ -68,7 +66,6 @@
6866
loop: "{{ pulp_users | default([], true) }}"
6967
loop_control:
7068
label: "{{ item.username }}"
71-
no_log: true
7269
register: result
7370
when:
7471
- item.username in usernames
@@ -107,6 +104,5 @@
107104
status_code: 204
108105
body_format: form-urlencoded
109106
loop: "{{ hrefs | default([]) }}"
110-
no_log: true
111107
register: result
112108
changed_when: result.status == 204

tests/test_content_guard_rbac.yml

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
---
2+
- name: Test content guard rbac
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+
12+
- name: Query pulp status
13+
uri:
14+
url: "{{ pulp_url }}/pulp/api/v3/status/"
15+
user: "{{ pulp_username }}"
16+
password: "{{ pulp_password }}"
17+
method: GET
18+
body_format: json
19+
status_code: 200
20+
force_basic_auth: true
21+
register: status_result
22+
23+
- name: Exit if version < 3.17
24+
meta: end_play
25+
vars:
26+
query: "[?component=='core'].version"
27+
when: status_result.json.versions | json_query(query) | first is version('3.17', '<')
28+
29+
- name: Query groups
30+
uri:
31+
url: "{{ pulp_url }}/pulp/api/v3/groups/"
32+
user: "{{ pulp_username }}"
33+
password: "{{ pulp_password }}"
34+
method: GET
35+
body_format: json
36+
status_code: 200
37+
force_basic_auth: true
38+
register: groups_result
39+
40+
- name: Create groups
41+
uri:
42+
url: "{{ pulp_url }}/pulp/api/v3/groups/"
43+
user: "{{ pulp_username }}"
44+
password: "{{ pulp_password }}"
45+
method: POST
46+
body:
47+
name: "{{ item }}"
48+
body_format: json
49+
status_code: 201
50+
force_basic_auth: true
51+
loop:
52+
- test_group1
53+
- test_group2
54+
when: item not in groups_result.json.results | map(attribute='name') | list
55+
56+
- include_role:
57+
name: pulp_content_guard
58+
vars:
59+
pulp_content_guard_rbac:
60+
- name: test-rbac_cg-1
61+
roles:
62+
- role: core.rbaccontentguard_downloader
63+
groups:
64+
- test_group1
65+
- test_group2
66+
state: present
67+
- name: test-rbac_cg-2
68+
roles:
69+
- role: core.rbaccontentguard_downloader
70+
groups:
71+
- test_group1
72+
- test_group2
73+
state: present
74+
75+
- name: Query rbac content guard list
76+
uri:
77+
url: "{{ pulp_url }}/pulp/api/v3/contentguards/core/rbac/"
78+
user: "{{ pulp_username }}"
79+
password: "{{ pulp_password }}"
80+
method: GET
81+
status_code: 200
82+
force_basic_auth: true
83+
register: rbac_cg_list
84+
85+
- name: Evaluate results for test-rbac_cg-1
86+
vars:
87+
query: "[?name=='test-rbac_cg-1']"
88+
assert:
89+
that:
90+
- rbac_cg_list.json.results | json_query(query) | length == 1
91+
- (rbac_cg_list.json.results | json_query(query) | first).name == 'test-rbac_cg-1'
92+
- (rbac_cg_list.json.results | json_query(query) | first).groups | length == 2
93+
- (rbac_cg_list.json.results | json_query(query) | first).groups[0].name in ['test_group1', 'test_group2']
94+
- (rbac_cg_list.json.results | json_query(query) | first).groups[1].name in ['test_group1', 'test_group2']
95+
- >
96+
(rbac_cg_list.json.results | json_query(query) | first).groups[0].name !=
97+
(rbac_cg_list.json.results | json_query(query) | first).groups[1].name
98+
99+
- name: Evaluate results for test-rbac_cg-2
100+
vars:
101+
query: "[?name=='test-rbac_cg-2']"
102+
assert:
103+
that:
104+
- rbac_cg_list.json.results | json_query(query) | length == 1
105+
- (rbac_cg_list.json.results | json_query(query) | first).name == 'test-rbac_cg-2'
106+
- (rbac_cg_list.json.results | json_query(query) | first).groups | length == 2
107+
- (rbac_cg_list.json.results | json_query(query) | first).groups[0].name in ['test_group1', 'test_group2']
108+
- (rbac_cg_list.json.results | json_query(query) | first).groups[1].name in ['test_group1', 'test_group2']
109+
- >
110+
(rbac_cg_list.json.results | json_query(query) | first).groups[0].name !=
111+
(rbac_cg_list.json.results | json_query(query) | first).groups[1].name
112+
113+
# update content guards
114+
- include_role:
115+
name: pulp_content_guard
116+
vars:
117+
pulp_content_guard_rbac:
118+
- name: test-rbac_cg-1
119+
roles:
120+
- role: core.rbaccontentguard_downloader
121+
groups:
122+
- test_group1
123+
state: present
124+
- name: test-rbac_cg-2
125+
state: absent
126+
127+
- name: Query rbac content guard list
128+
uri:
129+
url: "{{ pulp_url }}/pulp/api/v3/contentguards/core/rbac/"
130+
user: "{{ pulp_username }}"
131+
password: "{{ pulp_password }}"
132+
method: GET
133+
status_code: 200
134+
force_basic_auth: true
135+
register: rbac_cg_list
136+
137+
- name: Evaluate results for test-rbac_cg-1
138+
vars:
139+
query: "[?name=='test-rbac_cg-1']"
140+
assert:
141+
that:
142+
- rbac_cg_list.json.results | json_query(query) | length == 1
143+
- (rbac_cg_list.json.results | json_query(query) | first).name == 'test-rbac_cg-1'
144+
- (rbac_cg_list.json.results | json_query(query) | first).groups | length == 1
145+
- (rbac_cg_list.json.results | json_query(query) | first).groups[0].name == 'test_group1'
146+
147+
148+
- name: Evaluate results for test-rbac_cg-2
149+
vars:
150+
query: "[?name=='test-rbac_cg-2']"
151+
assert:
152+
that:
153+
- rbac_cg_list.json.results | json_query(query) | length == 0
154+
155+
- name: Cleanup
156+
include_role:
157+
name: pulp_content_guard
158+
vars:
159+
pulp_content_guard_rbac:
160+
- name: test-rbac_cg-1
161+
state: absent
162+
- name: test-rbac_cg-2
163+
state: absent
File renamed without changes.

0 commit comments

Comments
 (0)