Skip to content

Commit 6990dd2

Browse files
authored
Merge pull request #33 from stackhpc/testing
Add integration testing
2 parents 5dccd72 + 32ba370 commit 6990dd2

File tree

8 files changed

+604
-0
lines changed

8 files changed

+604
-0
lines changed

.github/workflows/pull_request.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,24 @@ jobs:
3232
- name: Linting code
3333
run: |
3434
ansible-lint -v --force-color
35+
36+
integration:
37+
runs-on: ubuntu-latest
38+
steps:
39+
# Checks-out the repository under $GITHUB_WORKSPACE, so it's accessible to the job
40+
- uses: actions/checkout@v2
41+
42+
- name: Install dependencies
43+
run: |
44+
python -m pip install --upgrade pip
45+
pip install ansible==5.*
46+
ansible-galaxy collection install git+file://$(pwd)
47+
48+
- name: Run Pulp in one
49+
run: |
50+
tests/pulp-in-one.sh
51+
52+
# TODO: Use ansible-test to run these.
53+
- name: Running integration tests
54+
run: |
55+
ansible-playbook -v tests/*.yml

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,20 @@ collections:
2929
3030
See [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for more details.
3131
32+
## Testing
33+
34+
The integration tests require a running Pulp server. To run a Pulp in one container for testing:
35+
36+
```
37+
tests/pulp-in-one.sh
38+
```
39+
40+
Then, to run all of the integration tests:
41+
42+
```
43+
ansible-playbook -v tests/*.yml
44+
```
45+
3246
## More information
3347

3448
- [Ansible Collection overview](https://github.com/ansible-collections/overview)

tests/pulp-in-one.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Run a Pulp in one container, and reset the admin password to 'password'.
4+
# Use only for testing!
5+
6+
set -eu
7+
set -o pipefail
8+
9+
mkdir -p settings
10+
11+
cat << EOF > settings/settings.py
12+
CONTENT_ORIGIN='http://$(hostname):8080'
13+
ANSIBLE_API_HOSTNAME='http://$(hostname):8080'
14+
ANSIBLE_CONTENT_HOSTNAME='http://$(hostname):8080/pulp/content'
15+
TOKEN_AUTH_DISABLED=True
16+
EOF
17+
18+
# Run Pulp in one container.
19+
docker run \
20+
--detach \
21+
--name pulp \
22+
--volume "$(pwd)/settings":/etc/pulp \
23+
--publish 8080:80 \
24+
pulp/pulp:latest
25+
26+
# Wait for it to come up.
27+
attempts=0
28+
until curl --fail http://localhost:8080/pulp/api/v3/status/ > /dev/null 2>&1; do
29+
sleep 2
30+
attempts=$((attempts + 1))
31+
if [[ $attempts -ge 60 ]]; then
32+
echo "Timed out waiting for pulp"
33+
docker logs pulp
34+
exit 1
35+
fi
36+
done
37+
38+
# Reset the admin password.
39+
docker exec pulp pulpcore-manager reset-admin-password --password password

tests/roles

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../roles

tests/test_deb_distribution.yml

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
---
2+
- name: Test pulp_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_deb_repos:
15+
- name: test_deb_repo
16+
url: "https://fixtures.pulpproject.org/debian/"
17+
distributions: "ragnarok"
18+
policy: immediate
19+
state: present
20+
21+
- include_role:
22+
name: pulp_publication
23+
vars:
24+
pulp_publication_deb:
25+
- repository: test_deb_repo
26+
state: present
27+
28+
- include_role:
29+
name: pulp_distribution
30+
vars:
31+
pulp_distribution_deb:
32+
- name: test_deb_distribution
33+
base_path: test_deb_distribution
34+
repository: test_deb_repo
35+
state: present
36+
- name: test_deb_distribution_version_1
37+
base_path: test_deb_distribution_version_1
38+
repository: test_deb_repo
39+
version: 1
40+
state: present
41+
42+
# FIXME: This currently fails due to
43+
# https://github.com/stackhpc/ansible-collection-pulp/issues/34.
44+
# - include_role:
45+
# name: pulp_distribution
46+
# vars:
47+
# pulp_distribution_deb:
48+
# - name: test_deb_distribution_distribution
49+
# base_path: test_deb_distribution_distribution
50+
# distribution: test_deb_distribution
51+
# state: present
52+
53+
- name: Query repository
54+
pulp.squeezer.deb_repository:
55+
pulp_url: "{{ pulp_url }}"
56+
username: "{{ pulp_username }}"
57+
password: "{{ pulp_password }}"
58+
validate_certs: "{{ pulp_validate_certs }}"
59+
name: test_deb_repo
60+
register: repo_result
61+
62+
- name: Query publication
63+
pulp.squeezer.deb_publication:
64+
pulp_url: "{{ pulp_url }}"
65+
username: "{{ pulp_username }}"
66+
password: "{{ pulp_password }}"
67+
validate_certs: "{{ pulp_validate_certs }}"
68+
repository: test_deb_repo
69+
version: 1
70+
register: pub_result
71+
72+
- name: Query distribution
73+
pulp.squeezer.deb_distribution:
74+
pulp_url: "{{ pulp_url }}"
75+
username: "{{ pulp_username }}"
76+
password: "{{ pulp_password }}"
77+
validate_certs: "{{ pulp_validate_certs }}"
78+
name: test_deb_distribution
79+
register: dist_result
80+
81+
- name: Query distribution version 1
82+
pulp.squeezer.deb_distribution:
83+
pulp_url: "{{ pulp_url }}"
84+
username: "{{ pulp_username }}"
85+
password: "{{ pulp_password }}"
86+
validate_certs: "{{ pulp_validate_certs }}"
87+
name: test_deb_distribution_version_1
88+
register: dist_version_1_result
89+
90+
# FIXME: This currently fails due to
91+
# https://github.com/stackhpc/ansible-collection-pulp/issues/34.
92+
# - name: Query distribution distribution
93+
# pulp.squeezer.deb_distribution:
94+
# pulp_url: "{{ pulp_url }}"
95+
# username: "{{ pulp_username }}"
96+
# password: "{{ pulp_password }}"
97+
# validate_certs: "{{ pulp_validate_certs }}"
98+
# name: test_deb_distribution_distribution
99+
# register: dist_distribution_result
100+
101+
- name: Verify publication creation
102+
assert:
103+
that:
104+
- pub_result.publication.repository == repo_result.repository.pulp_href
105+
106+
- name: Verify distribution creation
107+
assert:
108+
that:
109+
- dist_result.distribution.name == "test_deb_distribution"
110+
- dist_result.distribution.base_path == "test_deb_distribution"
111+
- dist_result.distribution.publication == pub_result.publication.pulp_href
112+
113+
- name: Verify distribution creation
114+
assert:
115+
that:
116+
- dist_version_1_result.distribution.name == "test_deb_distribution_version_1"
117+
- dist_version_1_result.distribution.base_path == "test_deb_distribution_version_1"
118+
- dist_version_1_result.distribution.publication == pub_result.publication.pulp_href
119+
120+
# FIXME: This currently fails due to
121+
# https://github.com/stackhpc/ansible-collection-pulp/issues/34.
122+
# - name: Verify distribution creation
123+
# assert:
124+
# that:
125+
# - dist_distribution_result.distribution.name == "test_deb_distribution_distribution"
126+
# - dist_distribution_result.distribution.base_path == "test_deb_distribution_distribution"
127+
# - dist_distribution_result.distribution.publication == pub_result.publication.pulp_href
128+
129+
- include_role:
130+
name: pulp_distribution
131+
vars:
132+
pulp_distribution_deb:
133+
- name: test_deb_distribution
134+
# FIXME: These should not be required.
135+
repository: test_deb_repo
136+
base_path: foo
137+
state: absent
138+
- name: test_deb_distribution_version_1
139+
# FIXME: These should not be required.
140+
repository: test_deb_repo
141+
base_path: foo
142+
state: absent
143+
- name: test_deb_distribution_distribution
144+
# FIXME: These should not be required.
145+
repository: test_deb_repo
146+
base_path: foo
147+
state: absent
148+
149+
- include_role:
150+
name: pulp_publication
151+
vars:
152+
pulp_publication_deb:
153+
- repository: test_deb_repo
154+
state: absent
155+
156+
- include_role:
157+
name: pulp_repository
158+
vars:
159+
pulp_repository_deb_repos:
160+
- name: test_deb_repo
161+
state: absent
162+
163+
- name: Query distributions
164+
pulp.squeezer.deb_distribution:
165+
pulp_url: "{{ pulp_url }}"
166+
username: "{{ pulp_username }}"
167+
password: "{{ pulp_password }}"
168+
validate_certs: "{{ pulp_validate_certs }}"
169+
register: deb_distributions
170+
171+
- name: Verify distribution deletion
172+
assert:
173+
that: deb_distributions.distributions | length == 0
174+
175+
- name: Query publications
176+
pulp.squeezer.deb_publication:
177+
pulp_url: "{{ pulp_url }}"
178+
username: "{{ pulp_username }}"
179+
password: "{{ pulp_password }}"
180+
validate_certs: "{{ pulp_validate_certs }}"
181+
register: deb_publications
182+
183+
- name: Verify publication deletion
184+
assert:
185+
that: deb_publications.publications | length == 0

tests/test_deb_repository.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
- name: Test pulp_repository
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_deb_repos:
15+
- name: test_deb_repo
16+
url: "https://fixtures.pulpproject.org/debian/"
17+
distributions: "ragnarok"
18+
policy: immediate
19+
state: present
20+
21+
- name: Query repository
22+
pulp.squeezer.deb_repository:
23+
pulp_url: "{{ pulp_url }}"
24+
username: "{{ pulp_username }}"
25+
password: "{{ pulp_password }}"
26+
validate_certs: "{{ pulp_validate_certs }}"
27+
name: test_deb_repo
28+
register: repo_result
29+
30+
- name: Verify repository creation
31+
assert:
32+
that:
33+
- repo_result.repository.name == "test_deb_repo"
34+
35+
- name: Query remote
36+
pulp.squeezer.deb_remote:
37+
pulp_url: "{{ pulp_url }}"
38+
username: "{{ pulp_username }}"
39+
password: "{{ pulp_password }}"
40+
validate_certs: "{{ pulp_validate_certs }}"
41+
name: test_deb_repo-remote
42+
register: remote_result
43+
44+
- name: Verify remote creation
45+
assert:
46+
that:
47+
- remote_result.remote.name == "test_deb_repo-remote"
48+
- remote_result.remote.url == "https://fixtures.pulpproject.org/debian/"
49+
- remote_result.remote.distributions == "ragnarok"
50+
- remote_result.remote.policy == "immediate"
51+
52+
- include_role:
53+
name: pulp_repository
54+
vars:
55+
pulp_repository_deb_repos:
56+
- name: test_deb_repo
57+
state: absent
58+
59+
- name: Query repositories
60+
pulp.squeezer.deb_repository:
61+
pulp_url: "{{ pulp_url }}"
62+
username: "{{ pulp_username }}"
63+
password: "{{ pulp_password }}"
64+
validate_certs: "{{ pulp_validate_certs }}"
65+
register: deb_repositories
66+
67+
- name: Verify repository deletion
68+
assert:
69+
that: deb_repositories.repositories | length == 0
70+
71+
- name: Query remotes
72+
pulp.squeezer.deb_remote:
73+
pulp_url: "{{ pulp_url }}"
74+
username: "{{ pulp_username }}"
75+
password: "{{ pulp_password }}"
76+
validate_certs: "{{ pulp_validate_certs }}"
77+
register: deb_remotes
78+
79+
- name: Verify remote deletion
80+
assert:
81+
that: deb_remotes.remotes | length == 0

0 commit comments

Comments
 (0)