Skip to content

Commit

Permalink
Add kuttl tests for dbsync execution
Browse files Browse the repository at this point in the history
It checks the dbsync job is properly executed and conditions and hash
created.

And apply some fixes to be able to run kuttl tests easily when running
the operator locally instead of in a container.
  • Loading branch information
amoralej authored and openshift-merge-bot[bot] committed Dec 20, 2024
1 parent 74a3456 commit 20ecc51
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -449,9 +449,9 @@ SKIP_CERT ?=false
.PHONY: run-with-webhook
run-with-webhook: export METRICS_PORT?=33080
run-with-webhook: export HEALTH_PORT?=33081
run-with-webhook: export WATCHER_API_IMAGE_URL_DEFAULT=quay.io/podified-main-centos9/openstack-watcher-api:current-podified
run-with-webhook: export WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT=quay.io/podified-main-centos9/openstack-watcher-decision-engine:current-podified
run-with-webhook: export WATCHER_APPLIER_IMAGE_URL_DEFAULT=quay.io/podified-main-centos9/openstack-watcher-applier:current-podified
run-with-webhook: export WATCHER_API_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-watcher-api:current-podified
run-with-webhook: export WATCHER_DECISION_ENGINE_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-watcher-decision-engine:current-podified
run-with-webhook: export WATCHER_APPLIER_IMAGE_URL_DEFAULT=quay.io/podified-antelope-centos9/openstack-watcher-applier:current-podified
run-with-webhook: manifests generate fmt vet ## Run a controller from your host.
/bin/bash hack/clean_local_webhook.sh
/bin/bash hack/run_with_local_webhook.sh
Expand Down
33 changes: 33 additions & 0 deletions tests/kuttl/test-suites/default/watcher/01-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ spec:
apiContainerImageURL: "quay.io/podified-antelope-centos9/openstack-watcher-api:current-podified"
decisionengineContainerImageURL: "quay.io/podified-antelope-centos9/openstack-watcher-decision-engine:current-podified"
applierContainerImageURL: "quay.io/podified-antelope-centos9/openstack-watcher-applier:current-podified"
databaseAccount: watcher
databaseInstance: openstack
passwordSelectors:
service: WatcherPassword
preserveJobs: false
rabbitMqClusterName: rabbitmq
secret: osp-secret
serviceUser: watcher
status:
conditions:
- message: Setup complete
Expand All @@ -19,6 +27,10 @@ status:
reason: Ready
status: "True"
type: DBReady
- message: DBsync completed
reason: Ready
status: "True"
type: DBSyncReady
- message: Input data complete
reason: Ready
status: "True"
Expand All @@ -43,6 +55,10 @@ status:
reason: Ready
status: "True"
type: ServiceAccountReady
- message: Service config create completed
reason: Ready
status: "True"
type: ServiceConfigReady
- message: WatcherRabbitMQTransportURL successfully created
reason: Ready
status: "True"
Expand Down Expand Up @@ -140,6 +156,18 @@ subjects:
name: watcher-watcher-kuttl
namespace: watcher-kuttl-default
---
apiVersion: batch/v1
kind: Job
metadata:
labels:
service: watcher
name: watcher-kuttl-db-sync
---
apiVersion: v1
kind: Secret
metadata:
name: watcher-kuttl-config-data
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
namespaced: true
Expand All @@ -149,13 +177,18 @@ commands:
oc exec -n watcher-kuttl-default openstackclient -- openstack service list -f value -c Name -c Type |[ $(grep -c ^watcher) == 1 ]
SERVICEID=$(oc exec -n watcher-kuttl-default openstackclient -- openstack service list -f value -c Name -c Type -c ID | grep watcher| awk '{print $1}')
[ $(oc get -n watcher-kuttl-default keystoneservice watcher -o jsonpath={.status.serviceID}) == $SERVICEID ]
[ -n "$(oc get -n watcher-kuttl-default watcher watcher-kuttl -o jsonpath={.status.hash.dbsync})" ]
---
# Check for Container Image environment variables
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
commands:
- script: |
set -euxo pipefail
# If we are running the container locally, skip this test
if [ "$(oc get pods -n openstack-operators -o name -l openstack.org/operator-name=watcher)" == "" ]; then
exit 0
fi
env_variables=$(oc set env $(oc get pods -n openstack-operators -o name -l openstack.org/operator-name=watcher) -n openstack-operators --list)
counter=0
for i in ${env_variables}; do
Expand Down
21 changes: 21 additions & 0 deletions tests/kuttl/test-suites/default/watcher/04-assert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ status:
reason: Ready
status: "True"
type: DBReady
- message: DBsync completed
reason: Ready
status: "True"
type: DBSyncReady
- message: Input data complete
reason: Ready
status: "True"
Expand All @@ -45,6 +49,10 @@ status:
reason: Ready
status: "True"
type: ServiceAccountReady
- message: Service config create completed
reason: Ready
status: "True"
type: ServiceConfigReady
- message: WatcherRabbitMQTransportURL successfully created
reason: Ready
status: "True"
Expand Down Expand Up @@ -128,3 +136,16 @@ spec:
serviceName: watcher
serviceType: infra-optim
serviceUser: watcher
---
apiVersion: batch/v1
kind: Job
metadata:
labels:
service: watcher
name: watcher-kuttl-db-sync
---
apiVersion: v1
kind: Secret
metadata:
name: watcher-kuttl-config-data
---
12 changes: 12 additions & 0 deletions tests/kuttl/test-suites/default/watcher/05-errors.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ kind: Secret
metadata:
name: watcher-db-secret
---
apiVersion: batch/v1
kind: Job
metadata:
labels:
service: watcher
name: watcher-kuttl-db-sync
---
apiVersion: v1
kind: Secret
metadata:
name: watcher-kuttl-config-data
---
apiVersion: watcher.openstack.org/v1beta1
kind: Watcher
metadata:
Expand Down

0 comments on commit 20ecc51

Please sign in to comment.