Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,24 @@ jobs:
- name: Linting code
run: |
ansible-lint -v --force-color

integration:
runs-on: ubuntu-latest
steps:
# Checks-out the repository under $GITHUB_WORKSPACE, so it's accessible to the job
- uses: actions/checkout@v2

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install ansible==5.*
ansible-galaxy collection install git+file://$(pwd)

- name: Run Pulp in one
run: |
tests/pulp-in-one.sh

# TODO: Use ansible-test to run these.
- name: Running integration tests
run: |
ansible-playbook -v tests/*.yml
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ collections:

See [Ansible Using collections](https://docs.ansible.com/ansible/latest/user_guide/collections_using.html) for more details.

## Testing

The integration tests require a running Pulp server. To run a Pulp in one container for testing:

```
tests/pulp-in-one.sh
```

Then, to run all of the integration tests:

```
ansible-playbook -v tests/*.yml
```

## More information

- [Ansible Collection overview](https://github.com/ansible-collections/overview)
Expand Down
39 changes: 39 additions & 0 deletions tests/pulp-in-one.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Run a Pulp in one container, and reset the admin password to 'password'.
# Use only for testing!

set -eu
set -o pipefail

mkdir -p settings

cat << EOF > settings/settings.py
CONTENT_ORIGIN='http://$(hostname):8080'
ANSIBLE_API_HOSTNAME='http://$(hostname):8080'
ANSIBLE_CONTENT_HOSTNAME='http://$(hostname):8080/pulp/content'
TOKEN_AUTH_DISABLED=True
EOF

# Run Pulp in one container.
docker run \
--detach \
--name pulp \
--volume "$(pwd)/settings":/etc/pulp \
--publish 8080:80 \
pulp/pulp:latest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest is good for starters, let's see how often will it fail ;-)


# Wait for it to come up.
attempts=0
until curl --fail http://localhost:8080/pulp/api/v3/status/ > /dev/null 2>&1; do
sleep 2
attempts=$((attempts + 1))
if [[ $attempts -ge 60 ]]; then
echo "Timed out waiting for pulp"
docker logs pulp
exit 1
fi
done

# Reset the admin password.
docker exec pulp pulpcore-manager reset-admin-password --password password
1 change: 1 addition & 0 deletions tests/roles
185 changes: 185 additions & 0 deletions tests/test_deb_distribution.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
---
- name: Test pulp_distribution
gather_facts: false
hosts: localhost
vars:
pulp_url: http://localhost:8080
pulp_username: admin
pulp_password: password
pulp_validate_certs: true
tasks:
- include_role:
name: pulp_repository
vars:
pulp_repository_deb_repos:
- name: test_deb_repo
url: "https://fixtures.pulpproject.org/debian/"
distributions: "ragnarok"
policy: immediate
state: present

- include_role:
name: pulp_publication
vars:
pulp_publication_deb:
- repository: test_deb_repo
state: present

- include_role:
name: pulp_distribution
vars:
pulp_distribution_deb:
- name: test_deb_distribution
base_path: test_deb_distribution
repository: test_deb_repo
state: present
- name: test_deb_distribution_version_1
base_path: test_deb_distribution_version_1
repository: test_deb_repo
version: 1
state: present

# FIXME: This currently fails due to
# https://github.com/stackhpc/ansible-collection-pulp/issues/34.
# - include_role:
# name: pulp_distribution
# vars:
# pulp_distribution_deb:
# - name: test_deb_distribution_distribution
# base_path: test_deb_distribution_distribution
# distribution: test_deb_distribution
# state: present

- name: Query repository
pulp.squeezer.deb_repository:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
name: test_deb_repo
register: repo_result

- name: Query publication
pulp.squeezer.deb_publication:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
repository: test_deb_repo
version: 1
register: pub_result

- name: Query distribution
pulp.squeezer.deb_distribution:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
name: test_deb_distribution
register: dist_result

- name: Query distribution version 1
pulp.squeezer.deb_distribution:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
name: test_deb_distribution_version_1
register: dist_version_1_result

# FIXME: This currently fails due to
# https://github.com/stackhpc/ansible-collection-pulp/issues/34.
# - name: Query distribution distribution
# pulp.squeezer.deb_distribution:
# pulp_url: "{{ pulp_url }}"
# username: "{{ pulp_username }}"
# password: "{{ pulp_password }}"
# validate_certs: "{{ pulp_validate_certs }}"
# name: test_deb_distribution_distribution
# register: dist_distribution_result

- name: Verify publication creation
assert:
that:
- pub_result.publication.repository == repo_result.repository.pulp_href

- name: Verify distribution creation
assert:
that:
- dist_result.distribution.name == "test_deb_distribution"
- dist_result.distribution.base_path == "test_deb_distribution"
- dist_result.distribution.publication == pub_result.publication.pulp_href

- name: Verify distribution creation
assert:
that:
- dist_version_1_result.distribution.name == "test_deb_distribution_version_1"
- dist_version_1_result.distribution.base_path == "test_deb_distribution_version_1"
- dist_version_1_result.distribution.publication == pub_result.publication.pulp_href

# FIXME: This currently fails due to
# https://github.com/stackhpc/ansible-collection-pulp/issues/34.
# - name: Verify distribution creation
# assert:
# that:
# - dist_distribution_result.distribution.name == "test_deb_distribution_distribution"
# - dist_distribution_result.distribution.base_path == "test_deb_distribution_distribution"
# - dist_distribution_result.distribution.publication == pub_result.publication.pulp_href

- include_role:
name: pulp_distribution
vars:
pulp_distribution_deb:
- name: test_deb_distribution
# FIXME: These should not be required.
repository: test_deb_repo
base_path: foo
state: absent
- name: test_deb_distribution_version_1
# FIXME: These should not be required.
repository: test_deb_repo
base_path: foo
state: absent
- name: test_deb_distribution_distribution
# FIXME: These should not be required.
repository: test_deb_repo
base_path: foo
state: absent

- include_role:
name: pulp_publication
vars:
pulp_publication_deb:
- repository: test_deb_repo
state: absent

- include_role:
name: pulp_repository
vars:
pulp_repository_deb_repos:
- name: test_deb_repo
state: absent

- name: Query distributions
pulp.squeezer.deb_distribution:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
register: deb_distributions

- name: Verify distribution deletion
assert:
that: deb_distributions.distributions | length == 0

- name: Query publications
pulp.squeezer.deb_publication:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
register: deb_publications

- name: Verify publication deletion
assert:
that: deb_publications.publications | length == 0
81 changes: 81 additions & 0 deletions tests/test_deb_repository.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
- name: Test pulp_repository
gather_facts: false
hosts: localhost
vars:
pulp_url: http://localhost:8080
pulp_username: admin
pulp_password: password
pulp_validate_certs: true
tasks:
- include_role:
name: pulp_repository
vars:
pulp_repository_deb_repos:
- name: test_deb_repo
url: "https://fixtures.pulpproject.org/debian/"
distributions: "ragnarok"
policy: immediate
state: present

- name: Query repository
pulp.squeezer.deb_repository:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
name: test_deb_repo
register: repo_result

- name: Verify repository creation
assert:
that:
- repo_result.repository.name == "test_deb_repo"

- name: Query remote
pulp.squeezer.deb_remote:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
name: test_deb_repo-remote
register: remote_result

- name: Verify remote creation
assert:
that:
- remote_result.remote.name == "test_deb_repo-remote"
- remote_result.remote.url == "https://fixtures.pulpproject.org/debian/"
- remote_result.remote.distributions == "ragnarok"
- remote_result.remote.policy == "immediate"

- include_role:
name: pulp_repository
vars:
pulp_repository_deb_repos:
- name: test_deb_repo
state: absent

- name: Query repositories
pulp.squeezer.deb_repository:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
register: deb_repositories

- name: Verify repository deletion
assert:
that: deb_repositories.repositories | length == 0

- name: Query remotes
pulp.squeezer.deb_remote:
pulp_url: "{{ pulp_url }}"
username: "{{ pulp_username }}"
password: "{{ pulp_password }}"
validate_certs: "{{ pulp_validate_certs }}"
register: deb_remotes

- name: Verify remote deletion
assert:
that: deb_remotes.remotes | length == 0
Loading