From c836ca77cc453de4fc541359f291de582bec2e0c Mon Sep 17 00:00:00 2001 From: Alfredo Moralejo Date: Thu, 21 Nov 2024 18:22:48 +0100 Subject: [PATCH] Add kuttl tests for the database creation This patch is: - Adding the base kuttl tests structure - Adding some make targets to run and cleanup kuttl tests - Creating kuttl tests for the database creation including with and without precreating a MariaDBAccount. This will be used for a kuttl job that will be added later. --- Makefile | 31 +++++ .../kuttl/test-suites/default/03-assert.yaml | 11 ++ .../default/common/cleanup-watcher.yaml | 7 ++ tests/kuttl/test-suites/default/config.yaml | 14 +++ .../kuttl/test-suites/default/deps/infra.yaml | 39 ++++++ .../test-suites/default/deps/keystone.yaml | 9 ++ .../default/deps/kustomization.yaml | 42 +++++++ .../test-suites/default/deps/namespace.yaml | 4 + .../default/output/kuttl-default-results.json | 115 ++++++++++++++++++ .../default/test/00-cleanup-watcher.yaml | 1 + .../test-suites/default/test/01-assert.yaml | 50 ++++++++ .../default/test/01-deploy-with-defaults.yaml | 7 ++ .../default/test/02-cleanup-watcher.yaml | 1 + .../test/03-precreate-mariadbaccount.yaml | 9 ++ .../test-suites/default/test/04-assert.yaml | 56 +++++++++ .../04-deploy-with-precreated-account.yaml | 8 ++ .../default/test/05-cleanup-watcher.yaml | 1 + 17 files changed, 405 insertions(+) create mode 100644 tests/kuttl/test-suites/default/03-assert.yaml create mode 100644 tests/kuttl/test-suites/default/common/cleanup-watcher.yaml create mode 100644 tests/kuttl/test-suites/default/config.yaml create mode 100644 tests/kuttl/test-suites/default/deps/infra.yaml create mode 100644 tests/kuttl/test-suites/default/deps/keystone.yaml create mode 100644 tests/kuttl/test-suites/default/deps/kustomization.yaml create mode 100644 tests/kuttl/test-suites/default/deps/namespace.yaml create mode 100644 tests/kuttl/test-suites/default/output/kuttl-default-results.json create mode 120000 tests/kuttl/test-suites/default/test/00-cleanup-watcher.yaml create mode 100644 tests/kuttl/test-suites/default/test/01-assert.yaml create mode 100644 tests/kuttl/test-suites/default/test/01-deploy-with-defaults.yaml create mode 120000 tests/kuttl/test-suites/default/test/02-cleanup-watcher.yaml create mode 100644 tests/kuttl/test-suites/default/test/03-precreate-mariadbaccount.yaml create mode 100644 tests/kuttl/test-suites/default/test/04-assert.yaml create mode 100644 tests/kuttl/test-suites/default/test/04-deploy-with-precreated-account.yaml create mode 120000 tests/kuttl/test-suites/default/test/05-cleanup-watcher.yaml diff --git a/Makefile b/Makefile index 8754679..0ac565d 100644 --- a/Makefile +++ b/Makefile @@ -396,3 +396,34 @@ watcher_cleanup: export CATALOG_IMG=${CATALOG_IMAGE} watcher_cleanup: ## Cleaning watcher operator via olm bash ci/olm.sh oc delete -f ci/olm.yaml + +KUTTL_SUITE ?= default +KUTTL_NAMESPACE ?= watcher-kuttl-$(KUTTL_SUITE) +KUTTL_SUITE_DIR ?= tests/kuttl/test-suites/$(KUTTL_SUITE) + +.PHONY: kuttl-test-prep +kuttl-test-prep: + oc apply -k $(KUTTL_SUITE_DIR)/deps/ --timeout=120s + oc wait -n $(KUTTL_NAMESPACE) openstackcontrolplane openstack --for condition=Ready --timeout=300s + +.PHONY: kuttl-test-run +kuttl-test-run: + oc kuttl test --v 1 --start-kind=false --config $(KUTTL_SUITE_DIR)/config.yaml + +.PHONY: kuttl-test +kuttl-test: kuttl-test-prep kuttl-test-run + +.PHONY: kuttl-test-cleanup +kuttl-test-cleanup: + # only cleanup if the $(KUTTL_NAMESPACE) exists + $(eval namespace_exists=$(shell oc get namespace $(KUTTL_NAMESPACE) --ignore-not-found -o name)) + # We need to order the deletion. Simply deleting the namespace will + # result in errors in mariadb- and keystone-operator and then + # finalizer removal get stuck blocking the namespace deletion. + if [ "${namespace_exists}" != "" ]; then \ + oc delete --wait=true --all=true -n $(KUTTL_NAMESPACE) --timeout=120s Nova; \ + oc delete --wait=true --all=true -n $(KUTTL_NAMESPACE) --timeout=120s OpenStackControlPlane; \ + oc delete --wait=true namespace $(KUTTL_NAMESPACE); \ + else \ + echo "Namespce already cleaned up. Nothing to do"; \ +fi diff --git a/tests/kuttl/test-suites/default/03-assert.yaml b/tests/kuttl/test-suites/default/03-assert.yaml new file mode 100644 index 0000000..fbd3c04 --- /dev/null +++ b/tests/kuttl/test-suites/default/03-assert.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Secret +metadata: + name: watcher-db-secret + namespace: watcher-kuttl-default +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + name: watcher-precreated + namespace: watcher-kuttl-default diff --git a/tests/kuttl/test-suites/default/common/cleanup-watcher.yaml b/tests/kuttl/test-suites/default/common/cleanup-watcher.yaml new file mode 100644 index 0000000..31bb5ab --- /dev/null +++ b/tests/kuttl/test-suites/default/common/cleanup-watcher.yaml @@ -0,0 +1,7 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +delete: +- apiVersion: watcher.openstack.org/v1beta1 + kind: Watcher + name: watcher-kuttl + namespace: watcher-kuttl-default diff --git a/tests/kuttl/test-suites/default/config.yaml b/tests/kuttl/test-suites/default/config.yaml new file mode 100644 index 0000000..65e3755 --- /dev/null +++ b/tests/kuttl/test-suites/default/config.yaml @@ -0,0 +1,14 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestSuite +reportFormat: JSON +reportName: kuttl-default-results +namespace: watcher-kuttl-default +# we could set this lower, but the initial image pull can take a while +timeout: 300 +parallel: 1 +skipDelete: true +testDirs: + - tests/kuttl/test-suites/default/ +suppress: + - events +artifactsDir: tests/kuttl/test-suites/default/output diff --git a/tests/kuttl/test-suites/default/deps/infra.yaml b/tests/kuttl/test-suites/default/deps/infra.yaml new file mode 100644 index 0000000..eb2aa78 --- /dev/null +++ b/tests/kuttl/test-suites/default/deps/infra.yaml @@ -0,0 +1,39 @@ +apiVersion: core.openstack.org/v1beta1 +kind: OpenStackControlPlane +metadata: + name: openstack +spec: + storageClass: crc-csi-hostpath-provisioner + mariadb: + enabled: false + galera: + enabled: true + templates: + openstack: + storageRequest: 500M + storageClass: crc-csi-hostpath-provisioner + openstack-cell1: + storageRequest: 500M + storageClass: crc-csi-hostpath-provisioner + rabbitmq: + templates: + rabbitmq: + replicas: 1 + rabbitmq-cell1: + replicas: 1 + memcached: + templates: + memcached: + replicas: 1 + nova: + enabled: false + placement: + enabled: false + neutron: + enabled: false + keystone: + enabled: true + cinder: + enabled: false + telemetry: + enabled: false diff --git a/tests/kuttl/test-suites/default/deps/keystone.yaml b/tests/kuttl/test-suites/default/deps/keystone.yaml new file mode 100644 index 0000000..97f568e --- /dev/null +++ b/tests/kuttl/test-suites/default/deps/keystone.yaml @@ -0,0 +1,9 @@ +apiVersion: core.openstack.org/v1beta1 +kind: OpenStackControlPlane +metadata: + name: openstack +spec: + keystone: + template: + databaseInstance: openstack + secret: osp-secret diff --git a/tests/kuttl/test-suites/default/deps/kustomization.yaml b/tests/kuttl/test-suites/default/deps/kustomization.yaml new file mode 100644 index 0000000..30d1d12 --- /dev/null +++ b/tests/kuttl/test-suites/default/deps/kustomization.yaml @@ -0,0 +1,42 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization +namespace: watcher-kuttl-default + +secretGenerator: +- literals: + - AdminPassword=password + - DbRootPassword=password + - DatabasePassword=password + - WatcherPassword=password + - KeystoneDatabasePassword=password + - PlacementPassword=password + - PlacementDatabasePassword=password + - GlancePassword=password + - GlanceDatabasePassword=password + - NeutronPassword=password + - NeutronDatabasePassword=password + - NovaPassword=password + - NovaAPIDatabasePassword=password + - NovaCell0DatabasePassword=password + - NovaCell1DatabasePassword=password + - MetadataSecret=42 + name: osp-secret +generatorOptions: + disableNameSuffixHash: true + labels: + type: osp-secret + +resources: +- namespace.yaml +- infra.yaml + +patches: +- patch: |- + apiVersion: core.openstack.org/v1beta1 + kind: OpenStackControlPlane + metadata: + name: openstack + spec: + secret: osp-secret +- path: infra.yaml +- path: keystone.yaml diff --git a/tests/kuttl/test-suites/default/deps/namespace.yaml b/tests/kuttl/test-suites/default/deps/namespace.yaml new file mode 100644 index 0000000..3be094c --- /dev/null +++ b/tests/kuttl/test-suites/default/deps/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: watcher-kuttl-default diff --git a/tests/kuttl/test-suites/default/output/kuttl-default-results.json b/tests/kuttl/test-suites/default/output/kuttl-default-results.json new file mode 100644 index 0000000..68348c1 --- /dev/null +++ b/tests/kuttl/test-suites/default/output/kuttl-default-results.json @@ -0,0 +1,115 @@ +{ + "name": "", + "tests": 10, + "failures": 0, + "time": "47.541", + "testsuite": [ + { + "tests": 10, + "failures": 0, + "timestamp": "2024-11-21T18:21:24.571977938+01:00", + "time": "46.872", + "name": "tests/kuttl/test-suites/default/", + "testsuite": [ + { + "tests": 1, + "failures": 0, + "timestamp": "2024-11-21T18:21:24.572187427+01:00", + "time": "0.267", + "name": "common", + "testcase": [ + { + "classname": "common", + "name": "setup", + "timestamp": "2024-11-21T18:21:24.572188221+01:00", + "time": "0.267" + } + ] + }, + { + "tests": 1, + "failures": 0, + "timestamp": "2024-11-21T18:21:24.83901661+01:00", + "time": "0.132", + "name": "output", + "testcase": [ + { + "classname": "output", + "name": "setup", + "timestamp": "2024-11-21T18:21:24.839019114+01:00", + "time": "0.132" + } + ] + }, + { + "tests": 7, + "failures": 0, + "timestamp": "2024-11-21T18:21:24.973647553+01:00", + "time": "46.203", + "name": "test", + "testcase": [ + { + "classname": "test", + "name": "setup", + "timestamp": "2024-11-21T18:21:24.973649109+01:00", + "time": "0.133" + }, + { + "classname": "test", + "name": "step 0-cleanup-watcher", + "timestamp": "2024-11-21T18:21:25.107142603+01:00", + "time": "1.084" + }, + { + "classname": "test", + "name": "step 1-deploy-with-defaults", + "timestamp": "2024-11-21T18:21:26.190709294+01:00", + "time": "21.358", + "assertions": 4 + }, + { + "classname": "test", + "name": "step 2-cleanup-watcher", + "timestamp": "2024-11-21T18:21:47.548998243+01:00", + "time": "0.948" + }, + { + "classname": "test", + "name": "step 3-precreate-mariadbaccount", + "timestamp": "2024-11-21T18:21:48.4972392+01:00", + "time": "0.407" + }, + { + "classname": "test", + "name": "step 4-deploy-with-precreated-account", + "timestamp": "2024-11-21T18:21:48.904623313+01:00", + "time": "21.326", + "assertions": 4 + }, + { + "classname": "test", + "name": "step 5-cleanup-watcher", + "timestamp": "2024-11-21T18:22:10.230458338+01:00", + "time": "0.946" + } + ] + }, + { + "tests": 1, + "failures": 0, + "timestamp": "2024-11-21T18:22:11.176668323+01:00", + "time": "0.267", + "name": "deps", + "testcase": [ + { + "classname": "deps", + "name": "setup", + "timestamp": "2024-11-21T18:22:11.176670376+01:00", + "time": "0.267" + } + ] + } + ] + } + ] + } diff --git a/tests/kuttl/test-suites/default/test/00-cleanup-watcher.yaml b/tests/kuttl/test-suites/default/test/00-cleanup-watcher.yaml new file mode 120000 index 0000000..92ed6e0 --- /dev/null +++ b/tests/kuttl/test-suites/default/test/00-cleanup-watcher.yaml @@ -0,0 +1 @@ +../common/cleanup-watcher.yaml \ No newline at end of file diff --git a/tests/kuttl/test-suites/default/test/01-assert.yaml b/tests/kuttl/test-suites/default/test/01-assert.yaml new file mode 100644 index 0000000..9426536 --- /dev/null +++ b/tests/kuttl/test-suites/default/test/01-assert.yaml @@ -0,0 +1,50 @@ +apiVersion: watcher.openstack.org/v1beta1 +kind: Watcher +metadata: + finalizers: + - openstack.org/watcher + name: watcher-kuttl + namespace: watcher-kuttl-default +status: + conditions: + - message: Setup complete + reason: Ready + status: "True" + type: Ready + - message: DB create completed + reason: Ready + status: "True" + type: DBReady + - message: MariaDBAccount creation complete + reason: Ready + status: "True" + type: MariaDBAccountReady +--- +apiVersion: v1 +kind: Secret +metadata: + name: watcher-db-secret + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + name: watcher + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher + - openstack.org/mariadbaccount + labels: + mariaDBDatabaseName: watcher +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBDatabase +metadata: + name: watcher + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher + - openstack.org/mariadbdatabase + - openstack.org/mariadbaccount-watcher diff --git a/tests/kuttl/test-suites/default/test/01-deploy-with-defaults.yaml b/tests/kuttl/test-suites/default/test/01-deploy-with-defaults.yaml new file mode 100644 index 0000000..3b969ba --- /dev/null +++ b/tests/kuttl/test-suites/default/test/01-deploy-with-defaults.yaml @@ -0,0 +1,7 @@ +apiVersion: watcher.openstack.org/v1beta1 +kind: Watcher +metadata: + name: watcher-kuttl + namespace: watcher-kuttl-default +spec: + databaseInstance: "openstack" diff --git a/tests/kuttl/test-suites/default/test/02-cleanup-watcher.yaml b/tests/kuttl/test-suites/default/test/02-cleanup-watcher.yaml new file mode 120000 index 0000000..92ed6e0 --- /dev/null +++ b/tests/kuttl/test-suites/default/test/02-cleanup-watcher.yaml @@ -0,0 +1 @@ +../common/cleanup-watcher.yaml \ No newline at end of file diff --git a/tests/kuttl/test-suites/default/test/03-precreate-mariadbaccount.yaml b/tests/kuttl/test-suites/default/test/03-precreate-mariadbaccount.yaml new file mode 100644 index 0000000..cb94f3b --- /dev/null +++ b/tests/kuttl/test-suites/default/test/03-precreate-mariadbaccount.yaml @@ -0,0 +1,9 @@ +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + name: watcher-precreated + namespace: watcher-kuttl-default +spec: + requireTLS: false + secret: watcher-db-secret + userName: watcher_test diff --git a/tests/kuttl/test-suites/default/test/04-assert.yaml b/tests/kuttl/test-suites/default/test/04-assert.yaml new file mode 100644 index 0000000..3a4c03a --- /dev/null +++ b/tests/kuttl/test-suites/default/test/04-assert.yaml @@ -0,0 +1,56 @@ +apiVersion: watcher.openstack.org/v1beta1 +kind: Watcher +metadata: + finalizers: + - openstack.org/watcher + name: watcher-kuttl + namespace: watcher-kuttl-default +spec: + databaseAccount: watcher-precreated + databaseInstance: openstack + passwordSelectors: + service: WatcherPassword + secret: osp-secret +status: + conditions: + - message: Setup complete + reason: Ready + status: "True" + type: Ready + - message: DB create completed + reason: Ready + status: "True" + type: DBReady + - message: MariaDBAccount creation complete + reason: Ready + status: "True" + type: MariaDBAccountReady +--- +apiVersion: v1 +kind: Secret +metadata: + name: watcher-db-secret + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + name: watcher-precreated + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher + - openstack.org/mariadbaccount + labels: + mariaDBDatabaseName: watcher +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBDatabase +metadata: + name: watcher + namespace: watcher-kuttl-default + finalizers: + - openstack.org/watcher + - openstack.org/mariadbdatabase + - openstack.org/mariadbaccount-watcher-precreated diff --git a/tests/kuttl/test-suites/default/test/04-deploy-with-precreated-account.yaml b/tests/kuttl/test-suites/default/test/04-deploy-with-precreated-account.yaml new file mode 100644 index 0000000..6cda9cf --- /dev/null +++ b/tests/kuttl/test-suites/default/test/04-deploy-with-precreated-account.yaml @@ -0,0 +1,8 @@ +apiVersion: watcher.openstack.org/v1beta1 +kind: Watcher +metadata: + name: watcher-kuttl + namespace: watcher-kuttl-default +spec: + databaseInstance: "openstack" + databaseAccount: watcher-precreated diff --git a/tests/kuttl/test-suites/default/test/05-cleanup-watcher.yaml b/tests/kuttl/test-suites/default/test/05-cleanup-watcher.yaml new file mode 120000 index 0000000..92ed6e0 --- /dev/null +++ b/tests/kuttl/test-suites/default/test/05-cleanup-watcher.yaml @@ -0,0 +1 @@ +../common/cleanup-watcher.yaml \ No newline at end of file