From 29fa113c0811ae354b604b61ee85d73e1d4ca524 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Mon, 27 Nov 2023 13:11:18 -0500 Subject: [PATCH] add kuttl tests --- .../kuttl/common/scripts/check_db_account.sh | 32 +++++ .../kuttl/tests/account_create/01-assert.yaml | 114 ++++++++++++++++++ .../account_create/01-deploy_galera.yaml | 10 ++ .../kuttl/tests/account_create/02-assert.yaml | 7 ++ .../account_create/02-create-database.yaml | 9 ++ .../kuttl/tests/account_create/03-assert.yaml | 21 ++++ .../account_create/03-create-account.yaml | 22 ++++ .../kuttl/tests/account_create/04-assert.yaml | 6 + .../tests/account_create/05-drop-account.yaml | 5 + .../kuttl/tests/account_create/06-assert.yaml | 6 + .../tests/account_create/07-teardown.yaml | 12 ++ 11 files changed, 244 insertions(+) create mode 100755 tests/kuttl/common/scripts/check_db_account.sh create mode 100644 tests/kuttl/tests/account_create/01-assert.yaml create mode 100644 tests/kuttl/tests/account_create/01-deploy_galera.yaml create mode 100644 tests/kuttl/tests/account_create/02-assert.yaml create mode 100644 tests/kuttl/tests/account_create/02-create-database.yaml create mode 100644 tests/kuttl/tests/account_create/03-assert.yaml create mode 100644 tests/kuttl/tests/account_create/03-create-account.yaml create mode 100644 tests/kuttl/tests/account_create/04-assert.yaml create mode 100644 tests/kuttl/tests/account_create/05-drop-account.yaml create mode 100644 tests/kuttl/tests/account_create/06-assert.yaml create mode 100644 tests/kuttl/tests/account_create/07-teardown.yaml diff --git a/tests/kuttl/common/scripts/check_db_account.sh b/tests/kuttl/common/scripts/check_db_account.sh new file mode 100755 index 00000000..7adfc51c --- /dev/null +++ b/tests/kuttl/common/scripts/check_db_account.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +set -x + +galera="$1" +dbname="$2" +username="$3" +password="$4" + + +found=0 +not_found=1 + +if [ "$5" = "--reverse" ];then + # sometimes we want to check that a user does not exist + found=1 + not_found=0 +fi + +found_username=$(oc rsh -n ${NAMESPACE} -c galera ${galera} /bin/sh -c 'mysql -uroot -p${DB_ROOT_PASSWORD} -Nse "select user from mysql.user"' | grep -o -w ${username}) + +# username was not found, exit +if [ -z "$found_username" ]; then + exit $not_found +fi + +# username was found. if we wanted it to be found, then check the login also. +if [ "$found" = "0" ]; then + oc rsh -n ${NAMESPACE} -c galera ${galera} /bin/sh -c "mysql -u${username} -p${password} -Nse 'select database();' ${dbname}" || exit -1 +fi + +exit $found diff --git a/tests/kuttl/tests/account_create/01-assert.yaml b/tests/kuttl/tests/account_create/01-assert.yaml new file mode 100644 index 00000000..3b721bbd --- /dev/null +++ b/tests/kuttl/tests/account_create/01-assert.yaml @@ -0,0 +1,114 @@ +# +# Check for: +# +# - 1 MariaDB CR +# - 1 Pod for MariaDB CR +# + +apiVersion: mariadb.openstack.org/v1beta1 +kind: Galera +metadata: + name: openstack +spec: + replicas: 1 + secret: osp-secret + storageRequest: 500M +status: + bootstrapped: true + conditions: + - message: Setup complete + reason: Ready + status: "True" + type: Ready + - message: Deployment completed + reason: Ready + status: "True" + type: DeploymentReady + - message: Exposing service completed + reason: Ready + status: "True" + type: ExposeServiceReady + - message: RoleBinding created + reason: Ready + status: "True" + type: RoleBindingReady + - message: Role created + reason: Ready + status: "True" + type: RoleReady + - message: ServiceAccount created + reason: Ready + status: "True" + type: ServiceAccountReady + - message: Service config create completed + reason: Ready + status: "True" + type: ServiceConfigReady +--- +apiVersion: apps/v1 +kind: StatefulSet +metadata: + name: openstack-galera +spec: + replicas: 1 + selector: + matchLabels: + app: galera + cr: galera-openstack + galera/name: openstack + serviceName: openstack-galera + template: + metadata: + labels: + app: galera + cr: galera-openstack + galera/name: openstack + spec: + containers: + - command: + - /usr/bin/dumb-init + - -- + - /usr/local/bin/kolla_start + name: galera + ports: + - containerPort: 3306 + name: mysql + protocol: TCP + - containerPort: 4567 + name: galera + protocol: TCP + serviceAccount: galera-openstack + serviceAccountName: galera-openstack +status: + availableReplicas: 1 + readyReplicas: 1 + replicas: 1 +--- +apiVersion: v1 +kind: Pod +metadata: + name: openstack-galera-0 +--- +apiVersion: v1 +kind: Service +metadata: + name: openstack-galera +spec: + ports: + - name: mysql + port: 3306 + protocol: TCP + targetPort: 3306 + selector: + app: galera + cr: galera-openstack +--- +apiVersion: v1 +kind: Endpoints +metadata: + name: openstack-galera +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: openstack-config-data diff --git a/tests/kuttl/tests/account_create/01-deploy_galera.yaml b/tests/kuttl/tests/account_create/01-deploy_galera.yaml new file mode 100644 index 00000000..d61b68a4 --- /dev/null +++ b/tests/kuttl/tests/account_create/01-deploy_galera.yaml @@ -0,0 +1,10 @@ +apiVersion: mariadb.openstack.org/v1beta1 +kind: Galera +metadata: + name: openstack +spec: + containerImage: quay.io/podified-antelope-centos9/openstack-mariadb:current-podified + secret: osp-secret + storageClass: local-storage + storageRequest: 500M + replicas: 1 diff --git a/tests/kuttl/tests/account_create/02-assert.yaml b/tests/kuttl/tests/account_create/02-assert.yaml new file mode 100644 index 00000000..a58f68ab --- /dev/null +++ b/tests/kuttl/tests/account_create/02-assert.yaml @@ -0,0 +1,7 @@ +--- +apiVersion: batch/v1 +kind: Job +metadata: + name: kuttldb-accounttest-db-create +status: + succeeded: 1 diff --git a/tests/kuttl/tests/account_create/02-create-database.yaml b/tests/kuttl/tests/account_create/02-create-database.yaml new file mode 100644 index 00000000..45a80ff2 --- /dev/null +++ b/tests/kuttl/tests/account_create/02-create-database.yaml @@ -0,0 +1,9 @@ +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBDatabase +metadata: + name: kuttldb-accounttest + labels: + dbName: openstack +spec: + secret: osp-secret + name: kuttldb_accounttest diff --git a/tests/kuttl/tests/account_create/03-assert.yaml b/tests/kuttl/tests/account_create/03-assert.yaml new file mode 100644 index 00000000..22b2b7cb --- /dev/null +++ b/tests/kuttl/tests/account_create/03-assert.yaml @@ -0,0 +1,21 @@ +--- +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + labels: + mariaDBDatabaseName: kuttldb-accounttest + name: kuttldb-some-db-account +status: + conditions: + - message: Setup complete + reason: Ready + status: "True" + type: Ready + - message: MariaDBAccount creation complete + reason: Ready + status: "True" + type: MariaDBAccountReady + - message: MariaDBDatabase ready + reason: Ready + status: "True" + type: MariaDBDatabaseReady diff --git a/tests/kuttl/tests/account_create/03-create-account.yaml b/tests/kuttl/tests/account_create/03-create-account.yaml new file mode 100644 index 00000000..b74d3322 --- /dev/null +++ b/tests/kuttl/tests/account_create/03-create-account.yaml @@ -0,0 +1,22 @@ +--- + +apiVersion: mariadb.openstack.org/v1beta1 +kind: MariaDBAccount +metadata: + labels: + mariaDBDatabaseName: kuttldb-accounttest + name: kuttldb-some-db-account +spec: + userName: someuser + secret: some-db-secret + +--- + +apiVersion: v1 +data: + # dbsecret1 + DatabasePassword: ZGJzZWNyZXQx +kind: Secret +metadata: + name: some-db-secret +type: Opaque diff --git a/tests/kuttl/tests/account_create/04-assert.yaml b/tests/kuttl/tests/account_create/04-assert.yaml new file mode 100644 index 00000000..8f81e9fe --- /dev/null +++ b/tests/kuttl/tests/account_create/04-assert.yaml @@ -0,0 +1,6 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + ${MARIADB_KUTTL_DIR:-tests/kuttl/tests}/../common/scripts/check_db_account.sh openstack-galera-0 kuttldb_accounttest someuser dbsecret1 diff --git a/tests/kuttl/tests/account_create/05-drop-account.yaml b/tests/kuttl/tests/account_create/05-drop-account.yaml new file mode 100644 index 00000000..83450f12 --- /dev/null +++ b/tests/kuttl/tests/account_create/05-drop-account.yaml @@ -0,0 +1,5 @@ +apiVersion: kuttl.dev/v1beta1 +kind: TestStep +commands: + - script: | + oc delete -n $NAMESPACE mariadbaccounts/kuttldb-some-db-account diff --git a/tests/kuttl/tests/account_create/06-assert.yaml b/tests/kuttl/tests/account_create/06-assert.yaml new file mode 100644 index 00000000..25bc2004 --- /dev/null +++ b/tests/kuttl/tests/account_create/06-assert.yaml @@ -0,0 +1,6 @@ +--- +apiVersion: kuttl.dev/v1beta1 +kind: TestAssert +commands: + - script: | + ${MARIADB_KUTTL_DIR:-tests/kuttl/tests}/../common/scripts/check_db_account.sh openstack-galera-0 kuttldb_accounttest someuser dbsecret1 --reverse diff --git a/tests/kuttl/tests/account_create/07-teardown.yaml b/tests/kuttl/tests/account_create/07-teardown.yaml new file mode 100644 index 00000000..5184bca7 --- /dev/null +++ b/tests/kuttl/tests/account_create/07-teardown.yaml @@ -0,0 +1,12 @@ +apiVersion: kuttl.dev/v1beta +kind: TestStep +delete: +- apiVersion: mariadb.openstack.org/v1beta1 + kind: Galera + name: openstack +- apiVersion: mariadb.openstack.org/v1beta1 + kind: MariaDBDatabase +commands: + - script: | + oc delete -n $NAMESPACE pvc mysql-db-openstack-galera-0 + for i in `oc get pv | awk '/'$NAMESPACE'\/mysql-db-openstack-galera/ {print $1}'`; do oc patch pv $i -p '{"spec":{"claimRef": null}}'; done