Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Galaxy Collection CI to oci-env #2055

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
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
67 changes: 28 additions & 39 deletions .github/workflows/ci_automation_hub_collection.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,62 +3,51 @@ name: Galaxy Collection CI
on:
pull_request:
branches:
- "*"
- '**'
paths-ignore:
- "CHANGES/**"
- "docs/**"
- "mkdocs.yml"
push:
branches:
- "*"
- '**'
workflow_dispatch:

jobs:
galaxy_collection:
integration:
strategy:
fail-fast: false
matrix:
env:
- TEST_PROFILE: galaxy_collection_standalone
- TEST_PROFILE: galaxy_collection_keycloak
runs-on: ubuntu-latest
steps:
- name: Checkout galaxy_ng
uses: actions/checkout@v4
- uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v4
- uses: actions/setup-python@v4
with:
python-version: "3.10"

- name: Checkout the galaxy collection
uses: actions/checkout@v4
with:
repository: ansible/galaxy_collection
path: galaxy_collection

- name: Build and install the collection
working-directory: galaxy_collection
# Note: COMPOSE_INTERACTIVE_NO_CLI=1 is required for oci-env to work correctly when there's no interactive terminal
- name: Set environment variables
run: |
# The ansible.cfg defined in the collection repository might break the test. We want the same variables for installation and running.
rm -f ansible.cfg
rm -f galaxy.yml
mv .github/files/galaxy.yml.j2 .
ansible all -i localhost, -c local -m template -a "src=galaxy.yml.j2 dest=galaxy.yml" -e collection_namespace=galaxy -e collection_name=galaxy -e collection_version=1.0.0 -e collection_repo=https://github.com/ansible/automation_hub_collection
ansible-galaxy collection build -vvv
ansible-galaxy collection install galaxy-galaxy-1.0.0.tar.gz -vvv
echo "OCI_ENV_PATH=${HOME}/work/galaxy_ng/oci_env" >> $GITHUB_ENV
echo "COMPOSE_INTERACTIVE_NO_CLI=1" >> $GITHUB_ENV
echo "OCI_VERBOSE=1" >> $GITHUB_ENV
echo "GH_DUMP_LOGS=1" >> $GITHUB_ENV

- name: Spin up a standalone galaxy_ng installation
run: |
echo "COMPOSE_PROFILE=standalone" > .compose.env
echo "DEV_SOURCE_PATH=galaxy_ng" >> .compose.env
make docker/all
./compose up -d
pip3 install --upgrade requests pyyaml
python3 dev/common/poll.py
- name: Update apt
run: sudo apt -y update

- name: Test the user playbook
run: ansible-playbook dev/galaxy_collection_plays/user.yml -vvv
- name: Install LDAP requirements
run: sudo apt-get install -y libsasl2-dev python3 libldap2-dev libssl-dev build-essential

- name: Test the content playbook
run: ansible-playbook dev/galaxy_collection_plays/content.yml -vvv

- name: Test the repo playbook
run: ansible-playbook dev/galaxy_collection_plays/repo.yml -vvv
- name: setup oci-env
run: |
git clone https://github.com/pulp/oci_env.git $OCI_ENV_PATH
pip install -e $OCI_ENV_PATH/client/
mkdir $OCI_ENV_PATH/db_backup/

- name: Test the ee playbook
run: ansible-playbook dev/galaxy_collection_plays/ee.yml -vvv
- name: run playbook tests
run: make gh-action/${{ matrix.env.TEST_PROFILE }}
1 change: 1 addition & 0 deletions CHANGES/2421.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Migrate galaxy collection testing to oci-env stack for standalone and keycloak profiles
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ gh-action/community:
gh-action/certified-sync:
python3 dev/oci_env_integration/actions/certified-sync.py

.PHONY: gh-action/galaxy_collection_standalone
gh-action/galaxy_collection_standalone:
python3 dev/oci_env_integration/actions/galaxy_collection_standalone.py

.PHONY: gh-action/galaxy_collection_keycloak
gh-action/galaxy_collection_keycloak:
python3 dev/oci_env_integration/actions/galaxy_collection_keycloak.py

.PHONY: docker/loaddata
docker/loaddata: ## Load initial data from python script
$(call exec_or_run, api, "/bin/bash", "-c", "/entrypoint.sh manage shell < app/dev/common/setup_test_data.py")
Expand Down
10 changes: 5 additions & 5 deletions dev/galaxy_collection_plays/vars.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ah_host: http://localhost:5001
ah_username: iqe_admin
ah_password: redhat
ah_path_prefix: automation-hub
ah_artifact_runner_absolute_path: /home/runner/work/galaxy_ng/galaxy_ng/galaxy_collection/galaxy-galaxy-1.0.0.tar.gz
ah_host: http://localhost:55001
ah_username: admin
ah_password: admin
ah_path_prefix: galaxy
ah_artifact_runner_absolute_path: /src/galaxy_collection_test/galaxy-galaxy-1.0.0.tar.gz
38 changes: 38 additions & 0 deletions dev/oci_env_integration/actions/action_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ class OCIEnvIntegrationTest:
env_file (string, required): oci-env env file to use for the tests. These are all loaded
from dev/oci_env_integration/oci_env_configs
run_tests (boolean, required): if true, integration tests will be run inside this instance
run_playbooks (boolean, required): if true, Galaxy Collection playbook tests will be run
inside this instance
db_restore (string, optional): database backup to restore before running tests These are all
loaded from dev/oci_env_integration/oci_env_configs. When defining this, omit
the file extension (ex: fixture, not fixtur.tar.gz)
Expand Down Expand Up @@ -64,6 +66,7 @@ def __init__(self, envs):
try:
self.set_up_env()
self.run_test()
self.run_playbooks()
except Exception as e:
print(e)
self.failed = True
Expand Down Expand Up @@ -127,6 +130,41 @@ def run_test(self):
f" {pytest_flags} {self.flags}"
)

def install_galaxy_collection(self, env):
self.exec_cmd(
env,
"exec git clone https://github.com/ansible/galaxy_collection /src/galaxy_collection_test" # noqa E501
)

# The ansible.cfg defined in the collection repository might break the test.
# We want the same variables for installation and running.
self.exec_cmd(env, "exec rm -f /src/galaxy_collection_test/ansible.cfg")
self.exec_cmd(env, "exec rm -f /src/galaxy_collection_test/galaxy.yml")
self.exec_cmd(env, "exec mv /src/galaxy_collection_test/.github/files/galaxy.yml.j2 /src/galaxy_collection_test/") # noqa E501
self.exec_cmd(
env,
'exec ansible all -i localhost, -c local -m template -a "src=/src/galaxy_collection_test/galaxy.yml.j2 dest=/src/galaxy_collection_test/galaxy.yml" -e collection_namespace=galaxy -e collection_name=galaxy -e collection_version=1.0.0 -e collection_repo=https://github.com/ansible/automation_hub_collection' # noqa E501
)
self.exec_cmd(env, "exec ansible-galaxy collection build --output-path /src/galaxy_collection_test/ /src/galaxy_collection_test/ -vvv") # noqa E501
self.exec_cmd(env, "exec ansible-galaxy collection install /src/galaxy_collection_test/galaxy-galaxy-1.0.0.tar.gz -vvv --force") # noqa E501

def run_playbooks(self):
for env in self.envs:
if self.envs[env]["run_playbooks"]:
if wait_time := self.envs[env].get("wait_before_tests", 20):
print(f"waiting {wait_time} seconds")
time.sleep(wait_time)

self.install_galaxy_collection(env)

if len(self.envs[env]["playbooks"]) > 0:
for playbook in self.envs[env]["playbooks"]:
print(f"testing the {playbook} playbook")
self.exec_cmd(
env,
f"exec ansible-playbook src/galaxy_ng/dev/galaxy_collection_plays/{playbook} -vvv" # noqa E501
)

def dump_logs(self):
if not self.do_dump_logs:
return
Expand Down
1 change: 1 addition & 0 deletions dev/oci_env_integration/actions/certified-sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"env_file": "standalone.compose.env",
"run_tests": True,
"run_playbooks": False,
"db_restore": None,
"pytest_flags": '-m sync'
},
Expand Down
1 change: 1 addition & 0 deletions dev/oci_env_integration/actions/community.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"env_file": "community.compose.env",
"run_tests": True,
"run_playbooks": False,
"db_restore": None,
}
]
Expand Down
22 changes: 22 additions & 0 deletions dev/oci_env_integration/actions/galaxy_collection_keycloak.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import action_lib

env = action_lib.OCIEnvIntegrationTest(
envs=[
{
"env_file": "keycloak.compose.env",
"run_tests": False,
"run_playbooks": True,
"playbooks": [
"user.yml",
"content.yml",
"repo.yml",
"ee.yml",
],
"db_restore": None,

# the keycloak profile performs some setup after the service
# comes online
"wait_before_tests": 120
}
]
)
22 changes: 22 additions & 0 deletions dev/oci_env_integration/actions/galaxy_collection_standalone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import action_lib

env = action_lib.OCIEnvIntegrationTest(
envs=[
{
"env_file": "standalone.compose.env",
"run_tests": False,
"run_playbooks": True,
"playbooks": [
"user.yml",
"content.yml",
"repo.yml",
"ee.yml",
],
"db_restore": None,

# the keycloak profile performs some setup after the service
# comes online
# "wait_before_tests": 120
}
]
)
1 change: 1 addition & 0 deletions dev/oci_env_integration/actions/insights.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"env_file": "insights.compose.env",
"run_tests": True,
"run_playbooks": False,
"db_restore": None,

# The minio client can take a long time to install
Expand Down
1 change: 1 addition & 0 deletions dev/oci_env_integration/actions/iqe_rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"env_file": "standalone.compose.env",
"run_tests": True,
"run_playbooks": False,
"db_restore": None,
"pytest_flags": "-m iqe_rbac_test"
}
Expand Down
1 change: 1 addition & 0 deletions dev/oci_env_integration/actions/keycloak.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"env_file": "keycloak.compose.env",
"run_tests": True,
"run_playbooks": False,
"db_restore": None,

# the keycloak profile performs some setup after the service
Expand Down
1 change: 1 addition & 0 deletions dev/oci_env_integration/actions/ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"env_file": "ldap.compose.env",
"run_tests": True,
"run_playbooks": False,
"db_restore": None,
}
]
Expand Down
1 change: 1 addition & 0 deletions dev/oci_env_integration/actions/rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"env_file": "standalone.compose.env",
"run_tests": True,
"run_playbooks": False,
"db_restore": None,
"pytest_flags": "-m rbac_roles"
}
Expand Down
1 change: 1 addition & 0 deletions dev/oci_env_integration/actions/standalone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"env_file": "standalone.compose.env",
"run_tests": True,
"run_playbooks": False,
"db_restore": None,
}
]
Expand Down
1 change: 1 addition & 0 deletions dev/oci_env_integration/actions/x_repo_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{
"env_file": "standalone.compose.env",
"run_tests": True,
"run_playbooks": False,
"db_restore": None,
"pytest_flags": "-m x_repo_search"
}
Expand Down
Loading