From 1079429c9c3f5b18e329335456da36784a36d954 Mon Sep 17 00:00:00 2001 From: Alfredo Moralejo Date: Wed, 18 Dec 2024 18:44:43 +0100 Subject: [PATCH] Add kuttl tests for dbsync execution 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. --- Makefile | 6 ++-- .../default/watcher/01-assert.yaml | 33 +++++++++++++++++++ .../default/watcher/04-assert.yaml | 21 ++++++++++++ .../default/watcher/05-errors.yaml | 12 +++++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index a33e74a..2a608d7 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/tests/kuttl/test-suites/default/watcher/01-assert.yaml b/tests/kuttl/test-suites/default/watcher/01-assert.yaml index e209f7a..74adc1b 100644 --- a/tests/kuttl/test-suites/default/watcher/01-assert.yaml +++ b/tests/kuttl/test-suites/default/watcher/01-assert.yaml @@ -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 @@ -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" @@ -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" @@ -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 @@ -149,6 +177,7 @@ 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 @@ -156,6 +185,10 @@ 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 diff --git a/tests/kuttl/test-suites/default/watcher/04-assert.yaml b/tests/kuttl/test-suites/default/watcher/04-assert.yaml index 4108869..4b9a836 100644 --- a/tests/kuttl/test-suites/default/watcher/04-assert.yaml +++ b/tests/kuttl/test-suites/default/watcher/04-assert.yaml @@ -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" @@ -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" @@ -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 +--- diff --git a/tests/kuttl/test-suites/default/watcher/05-errors.yaml b/tests/kuttl/test-suites/default/watcher/05-errors.yaml index 6e7479a..0544f6b 100644 --- a/tests/kuttl/test-suites/default/watcher/05-errors.yaml +++ b/tests/kuttl/test-suites/default/watcher/05-errors.yaml @@ -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: