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
2 changes: 1 addition & 1 deletion .github/workflows/jsonschema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
persist-credentials: false

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ matrix.python-version }}

Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
# You can add custom targets above or below the include line

include Makefile-common

CLUSTERGROUP_LABEL ?= group-one
.PHONY: import-default-spoke
import-default-spoke: ## Import the default spoke cluster for this pattern, set VP_SPOKECONFIG and VP_HUBCONFIG env vars
@$(ANSIBLE_RUN) -e clustergroup_label=$(CLUSTERGROUP_LABEL) rhvp.cluster_utils.import_spoke_cluster
4 changes: 4 additions & 0 deletions Makefile-common
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ validate-schema: ## validates values files against schema in common/clustergroup
.PHONY: argo-healthcheck
argo-healthcheck: ## Checks if all argo applications are synced
@$(ANSIBLE_RUN) rhvp.cluster_utils.argo_healthcheck

.PHONY: run-ci-tests
run-ci-tests: ## To run ci-tests, set any needed env vars
@$(ANSIBLE_RUN) rhvp.cluster_utils.run_ci_tests
14 changes: 14 additions & 0 deletions pattern.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@ function version {
echo "$1" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
}

# We need this check mostly for CI testing, we do not want to run container in container
function is_container() {
[ -n "${KUBERNETES_SERVICE_HOST:-}" ] && return 0
[ -f /.dockerenv ] && return 0
[ -f /run/.containerenv ] && return 0
return 1
}

if is_container; then
echo "Already running in a container"
exec "$@"
fi

if [ -z "${PATTERN_UTILITY_CONTAINER:-}" ]; then
PATTERN_UTILITY_CONTAINER="quay.io/validatedpatterns/utility-container"
fi
Expand Down Expand Up @@ -115,6 +128,7 @@ podman run -it --rm --pull=newer \
-e TOKEN_SECRET \
-e UUID_FILE \
-e VALUES_SECRET \
-e 'VP_*' \
"${PKI_HOST_MOUNT_ARGS[@]}" \
-v "$(pwd -P)":"$(pwd -P)" \
-v "${HOME}":"${HOME}" \
Expand Down
42 changes: 42 additions & 0 deletions tests/ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# CI Tests

The requirements.txt file is just a placeholder to show the installed packages in the utility container:
[utility-container requirements.txt](https://github.com/validatedpatterns/utility-container/blob/main/requirements.txt)

## The ci will run pytest based on file pattern

pytest -lv test\_\<TARGET_CLUSTERGROUP>.py --junit-xml .results/test\_\<TARGET_CLUSTERGROUP>.xml

## To run upstream tests locally

Set the env variables pointing to the clusters needed to run the tests on:\
`VP_HUBCONFIG` (`VP_SPOKECONFIG` if applicable) pointing to the kubconfig of hub (and spoke) clusters\
(all VP\_\* env var will be available inside the container)\
`TARGET_CLUSTERGROUP` if its different from the default (values-global.yaml main.clusterGroupName)\
Test logs and junit-xml will be saved in ci/.results/\
Run from root repository:

```bash
./pattern.sh make run-ci-tests
```

## Writing additional tests

The openshift_dyn_client fixture will return a DynamicClient which can be used inside test functions.\
It requires only an env variable param to use it as a kubeconfig.

```python
@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG"],
indirect=True,
)
```

If your tests requires additional python packages, you might want to either run them fully locally in a venv or similar.\
Or if you want to use the pattern framework (make/Ansible wrappers) you need to use your own util container

```bash
PATTERN_UTILITY_CONTAINER="your_utility container" ./pattern.sh make run-ci-tests

```
1 change: 1 addition & 0 deletions tests/ci/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.1.0"
1 change: 1 addition & 0 deletions tests/ci/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from validatedpatterns_tests.interop.conftest_openshift import * # noqa: F401,F403
15 changes: 15 additions & 0 deletions tests/ci/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ansible-core==2.18.*
ansible-runner
awxkit
kubernetes
openshift
boto3>=1.21
botocore>=1.24
awscli>=1.22
azure-cli>=2.34
gcloud
humanize
pytz
pytest
junitparser
vp-qe-test-common @ git+https://github.com/validatedpatterns/vp-qe-test-common.git@v1
106 changes: 106 additions & 0 deletions tests/ci/test_hub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import pytest
from validatedpatterns_tests.interop import application, components, subscription


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG"],
indirect=True,
)
def test_subscription_status_hub(openshift_dyn_client):
expected_subs = {
"openshift-gitops-operator": ["openshift-gitops-operator"],
"advanced-cluster-management": ["open-cluster-management"],
"multicluster-engine": ["multicluster-engine"],
}
subscription.assert_subscription_status(openshift_dyn_client, expected_subs)


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_SPOKECONFIG"],
indirect=True,
)
def test_subscription_status_spoke(openshift_dyn_client):
expected_subs = {
"openshift-gitops-operator": ["openshift-gitops-operator"],
}

subscription.assert_subscription_status(openshift_dyn_client, expected_subs)


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG", "VP_SPOKECONFIG"],
indirect=True,
)
def test_site_reachable(openshift_dyn_client):

components.assert_site_reachable(openshift_dyn_client)


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG"],
indirect=True,
)
def test_pod_status_hub(openshift_dyn_client):
projects = [
"patterns-operator",
"open-cluster-management",
"open-cluster-management-hub",
"vp-gitops",
"vault",
"hello-world",
"config-demo",
"external-secrets",
]

components.assert_pod_status(openshift_dyn_client, projects, skip_check=[])


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_SPOKECONFIG"],
indirect=True,
)
def test_pod_status_spoke(openshift_dyn_client):
projects = [
"open-cluster-management-agent",
"open-cluster-management-agent-addon",
"vp-gitops",
"hello-world",
"config-demo",
"external-secrets",
]

components.assert_pod_status(openshift_dyn_client, projects, skip_check=[])


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG"],
indirect=True,
)
def test_managed_clusters(openshift_dyn_client):
components.assert_managed_clusters(openshift_dyn_client, ["group-one"])


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG", "VP_SPOKECONFIG"],
indirect=True,
)
def test_argocd_reachable(openshift_dyn_client):
components.assert_argocd_reachable(openshift_dyn_client)


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG", "VP_SPOKECONFIG"],
indirect=True,
)
def test_argocd_applications_health(openshift_dyn_client):
projects = ["vp-gitops", "multicloud-gitops-hub"]

application.assert_argocd_applications(openshift_dyn_client, projects)
51 changes: 51 additions & 0 deletions tests/ci/test_standalone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pytest
from validatedpatterns_tests.interop import components, subscription


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG"],
indirect=True,
)
def test_subscription_status_standalone(openshift_dyn_client):
expected_subs = {
"openshift-gitops-operator": ["openshift-gitops-operator"],
}

subscription.assert_subscription_status(openshift_dyn_client, expected_subs)


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG"],
indirect=True,
)
def test_site_reachable_hub(openshift_dyn_client):
components.assert_site_reachable(openshift_dyn_client)


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG"],
indirect=True,
)
def test_argocd_reachable_standalone(openshift_dyn_client):
components.assert_argocd_reachable(openshift_dyn_client)


@pytest.mark.parametrize(
"openshift_dyn_client",
["VP_HUBCONFIG"],
indirect=True,
)
def test_pod_status_standalone(openshift_dyn_client):
projects = [
"patterns-operator",
"vp-gitops",
"vault",
"hello-world",
"config-demo",
"external-secrets",
# "non-existing"
]
components.assert_pod_status(openshift_dyn_client, projects, skip_check=[])
2 changes: 1 addition & 1 deletion values-global.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ global:
syncPolicy: Automatic
installPlanApproval: Automatic
main:
clusterGroupName: hub
variant: hub
multiSourceConfig:
enabled: true
clusterGroupChartVersion: "0.9.*"
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading