Skip to content

Commit 4f968b4

Browse files
authored
Merge pull request #40 from stackhpc/more-tests
Add some more tests
2 parents e4f4851 + e21634d commit 4f968b4

File tree

9 files changed

+366
-2
lines changed

9 files changed

+366
-2
lines changed

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- name: Install dependencies
4343
run: |
4444
python -m pip install --upgrade pip
45-
pip install ansible==5.*
45+
pip install ansible==5.* jmespath
4646
ansible-galaxy collection install git+file://$(pwd)
4747
4848
- name: Run Pulp in one

galaxy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ license:
1313
tags:
1414
- pulp
1515
repository: "https://github.com/stackhpc/ansible-collection-pulp"
16+
build_ignore:
17+
- settings

roles/pulp_distribution/tasks/container.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
password: "{{ pulp_password }}"
77
validate_certs: "{{ pulp_validate_certs | bool }}"
88
name: "{{ item.name }}"
9-
base_path: "{{ item.base_path }}"
9+
base_path: "{{ item.base_path | default(omit) }}"
1010
repository: "{{ item.repository | default(omit) }}"
1111
version: "{{ item.version | default(omit) }}"
1212
content_guard: "{{ item.content_guard | default(omit) }}"

roles/pulp_django_user/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ pulp_django_user
33

44
This role creates Django users using the Django admin site.
55

6+
Requirements
7+
------------
8+
9+
The `jmespath` Python module must be installed on the Ansible control host.
10+
611
Role variables
712
--------------
813

tests/files/ca.pem

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIEuTCCA6GgAwIBAgIQQBrEZCGzEyEDDrvkEhrFHTANBgkqhkiG9w0BAQsFADCB
3+
vTELMAkGA1UEBhMCVVMxFzAVBgNVBAoT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XMFUWCWltYWdlL2dpZjAhMB8wBwYFKw4DAhoEFI/l0xqGrI2Oa8PPgGrUSBgs
20+
exkuMCUWI2h0dHA6Ly9sb2dvLnZlcmlzaWduLmNvbS92c2xvZ28uZ2lmMB0GA1Ud
21+
DgQWBBS2d/ppSEefUxLVwuoHMnYH0ZcHGTANBgkqhkiG9w0BAQsFAAOCAQEASvj4
22+
sAPmLGd75JR3Y8xuTPl9Dg3cyLk1uXBPY/ok+myDjEedO2Pzmvl2MpWRsXe8rJq+
23+
seQxIcaBlVZaDrHC1LGmWazxY8u4TB1ZkErvkBYoH1quEPuBUDgMbMzxPcP1Y+Oz
24+
4yHJJDnp/RVmRvQbEdBNc6N9Rvk97ahfYtTxP/jgdFcrGJ2BtMQo2pSXpXDrrB2+
25+
BxHw1dvd5Yzw1TKwg+ZX4o+/vqGqvz0dtdQ46tewXDpPaj+PwGZsY6rp2aQW9IHR
26+
lRQOfc2VNNnSj3BzgXucfr2YYdhFh5iQxeuGMMY1v/D/w1WIg0vvBZIGcfK4mJO3
27+
7M2CYfE45k+XmCpajQ==
28+
-----END CERTIFICATE-----
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
- name: Test container distribution
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+
21+
- include_role:
22+
name: pulp_distribution
23+
vars:
24+
pulp_distribution_container:
25+
- name: test_container_distribution
26+
base_path: test_container_distribution
27+
repository: test_container_repo
28+
state: present
29+
- name: test_container_distribution_version_1
30+
base_path: test_container_distribution_version_1
31+
repository: test_container_repo
32+
version: 1
33+
state: present
34+
35+
- name: Query repository
36+
pulp.squeezer.container_repository:
37+
pulp_url: "{{ pulp_url }}"
38+
username: "{{ pulp_username }}"
39+
password: "{{ pulp_password }}"
40+
validate_certs: "{{ pulp_validate_certs }}"
41+
name: test_container_repo
42+
register: repo_result
43+
44+
- name: Query distribution
45+
pulp.squeezer.container_distribution:
46+
pulp_url: "{{ pulp_url }}"
47+
username: "{{ pulp_username }}"
48+
password: "{{ pulp_password }}"
49+
validate_certs: "{{ pulp_validate_certs }}"
50+
name: test_container_distribution
51+
register: dist_result
52+
53+
- name: Query distribution version 1
54+
pulp.squeezer.container_distribution:
55+
pulp_url: "{{ pulp_url }}"
56+
username: "{{ pulp_username }}"
57+
password: "{{ pulp_password }}"
58+
validate_certs: "{{ pulp_validate_certs }}"
59+
name: test_container_distribution_version_1
60+
register: dist_version_1_result
61+
62+
- name: Verify distribution creation
63+
assert:
64+
that:
65+
- dist_result.distribution.name == "test_container_distribution"
66+
- dist_result.distribution.base_path == "test_container_distribution"
67+
- dist_result.distribution.repository == repo_result.repository.pulp_href
68+
- dist_result.distribution.repository_version is none
69+
70+
- name: Verify distribution creation
71+
assert:
72+
that:
73+
- dist_version_1_result.distribution.name == "test_container_distribution_version_1"
74+
- dist_version_1_result.distribution.base_path == "test_container_distribution_version_1"
75+
- dist_version_1_result.distribution.repository is none
76+
- dist_version_1_result.distribution.repository_version == repo_result.repository.latest_version_href
77+
78+
- include_role:
79+
name: pulp_distribution
80+
vars:
81+
pulp_distribution_container:
82+
- name: test_container_distribution
83+
state: absent
84+
- name: test_container_distribution_version_1
85+
state: absent
86+
87+
- include_role:
88+
name: pulp_repository
89+
vars:
90+
pulp_repository_container_repos:
91+
- name: test_container_repo
92+
state: absent
93+
94+
- name: Query distributions
95+
pulp.squeezer.container_distribution:
96+
pulp_url: "{{ pulp_url }}"
97+
username: "{{ pulp_username }}"
98+
password: "{{ pulp_password }}"
99+
validate_certs: "{{ pulp_validate_certs }}"
100+
register: container_distributions
101+
102+
- name: Verify distribution deletion
103+
assert:
104+
that: container_distributions.distributions | length == 0
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
21+
- name: Query repository
22+
pulp.squeezer.container_repository:
23+
pulp_url: "{{ pulp_url }}"
24+
username: "{{ pulp_username }}"
25+
password: "{{ pulp_password }}"
26+
validate_certs: "{{ pulp_validate_certs }}"
27+
name: test_container_repo
28+
register: repo_result
29+
30+
- name: Verify repository creation
31+
assert:
32+
that:
33+
- repo_result.repository.name == "test_container_repo"
34+
35+
- name: Query remote
36+
pulp.squeezer.container_remote:
37+
pulp_url: "{{ pulp_url }}"
38+
username: "{{ pulp_username }}"
39+
password: "{{ pulp_password }}"
40+
validate_certs: "{{ pulp_validate_certs }}"
41+
name: test_container_repo-remote
42+
register: remote_result
43+
44+
- name: Verify remote creation
45+
assert:
46+
that:
47+
- remote_result.remote.name == "test_container_repo-remote"
48+
- remote_result.remote.url == "https://registry-1.docker.io"
49+
- remote_result.remote.upstream_name == "pulp/test-fixture-1"
50+
- remote_result.remote.policy == "immediate"
51+
52+
- include_role:
53+
name: pulp_repository
54+
vars:
55+
pulp_repository_container_repos:
56+
- name: test_container_repo
57+
state: absent
58+
59+
- name: Query repositories
60+
pulp.squeezer.container_repository:
61+
pulp_url: "{{ pulp_url }}"
62+
username: "{{ pulp_username }}"
63+
password: "{{ pulp_password }}"
64+
validate_certs: "{{ pulp_validate_certs }}"
65+
register: container_repositories
66+
67+
- name: Verify repository deletion
68+
assert:
69+
that: container_repositories.repositories | length == 0
70+
71+
- name: Query remotes
72+
pulp.squeezer.container_remote:
73+
pulp_url: "{{ pulp_url }}"
74+
username: "{{ pulp_username }}"
75+
password: "{{ pulp_password }}"
76+
validate_certs: "{{ pulp_validate_certs }}"
77+
register: container_remotes
78+
79+
- name: Verify remote deletion
80+
assert:
81+
that: container_remotes.remotes | length == 0

tests/test_content_guard.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
- name: Test content guards
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_content_guard
13+
vars:
14+
pulp_content_guard_x509_cert_guards:
15+
- name: test_cert_guard
16+
description: foo
17+
ca_certificate: "{{ lookup('file', 'files/ca.pem') }}"
18+
state: present
19+
20+
- name: Query content guard
21+
pulp.squeezer.x509_cert_guard:
22+
pulp_url: "{{ pulp_url }}"
23+
username: "{{ pulp_username }}"
24+
password: "{{ pulp_password }}"
25+
validate_certs: "{{ pulp_validate_certs }}"
26+
name: test_cert_guard
27+
register: cg_result
28+
29+
- name: Verify cert guard creation
30+
assert:
31+
that:
32+
- cg_result.content_guard.name == "test_cert_guard"
33+
- cg_result.content_guard.description == "foo"
34+
- cg_result.content_guard.ca_certificate == lookup('file', 'files/ca.pem')
35+
36+
- include_role:
37+
name: pulp_content_guard
38+
vars:
39+
pulp_content_guard_x509_cert_guards:
40+
- name: test_cert_guard
41+
state: absent
42+
43+
- name: Query content guards
44+
pulp.squeezer.x509_cert_guard:
45+
pulp_url: "{{ pulp_url }}"
46+
username: "{{ pulp_username }}"
47+
password: "{{ pulp_password }}"
48+
validate_certs: "{{ pulp_validate_certs }}"
49+
register: cert_guards
50+
51+
- name: Verify cert guard deletion
52+
assert:
53+
that: cert_guards.content_guards | length == 0

tests/test_django_user.yml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
- name: Test django users
3+
gather_facts: false
4+
hosts: localhost
5+
vars:
6+
pulp_url: http://localhost:8080
7+
pulp_admin_username: admin
8+
pulp_admin_password: password
9+
pulp_validate_certs: true
10+
tasks:
11+
- name: Query groups
12+
uri:
13+
url: "{{ pulp_url }}/pulp/api/v3/groups/"
14+
user: "{{ pulp_admin_username }}"
15+
password: "{{ pulp_admin_password }}"
16+
method: GET
17+
body_format: json
18+
status_code: 200
19+
force_basic_auth: true
20+
register: groups_result
21+
22+
- name: Create groups
23+
uri:
24+
url: "{{ pulp_url }}/pulp/api/v3/groups/"
25+
user: "{{ pulp_admin_username }}"
26+
password: "{{ pulp_admin_password }}"
27+
method: POST
28+
body:
29+
name: "{{ item }}"
30+
body_format: json
31+
status_code: 201
32+
force_basic_auth: true
33+
loop:
34+
- test_group1
35+
- test_group2
36+
when: item not in groups_result.json.results | map(attribute='name') | list
37+
38+
- include_role:
39+
name: pulp_django_user
40+
vars:
41+
pulp_django_users:
42+
- username: test_user
43+
password: correct horse battery staple
44+
groups:
45+
- test_group1
46+
47+
- name: Query user
48+
uri:
49+
url: "{{ pulp_url }}/pulp/api/v3/users/?username=test_user"
50+
user: "{{ pulp_admin_username }}"
51+
password: "{{ pulp_admin_password }}"
52+
method: GET
53+
status_code: 200
54+
force_basic_auth: true
55+
register: user_result
56+
57+
- name: Verify django user creation
58+
assert:
59+
that:
60+
- user_result.json.count == 1
61+
- user_result.json.results[0].username == "test_user"
62+
- user_result.json.results[0].groups | length == 1
63+
- user_result.json.results[0].groups[0].name == "test_group1"
64+
65+
# Update group membership.
66+
- include_role:
67+
name: pulp_django_user
68+
vars:
69+
pulp_django_users:
70+
- username: test_user
71+
password: correct horse battery staple
72+
groups:
73+
- test_group2
74+
75+
- name: Query user
76+
uri:
77+
url: "{{ pulp_url }}/pulp/api/v3/users/?username=test_user"
78+
user: "{{ pulp_admin_username }}"
79+
password: "{{ pulp_admin_password }}"
80+
method: GET
81+
status_code: 200
82+
force_basic_auth: true
83+
register: user_result
84+
85+
- name: Verify django user group update
86+
assert:
87+
that:
88+
- user_result.json.count == 1
89+
- user_result.json.results[0].username == "test_user"
90+
- user_result.json.results[0].groups | length == 1
91+
- user_result.json.results[0].groups[0].name == "test_group2"

0 commit comments

Comments
 (0)