Skip to content

Commit

Permalink
add kuttl tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzeek committed Dec 4, 2023
1 parent 8ce2cc6 commit b7945c9
Show file tree
Hide file tree
Showing 11 changed files with 248 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/kuttl/common/scripts/check_db_account.sh
Original file line number Diff line number Diff line change
@@ -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
114 changes: 114 additions & 0 deletions tests/kuttl/tests/account_create/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/kuttl/tests/account_create/01-deploy_galera.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/kuttl/tests/account_create/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
apiVersion: batch/v1
kind: Job
metadata:
name: kuttldb-accounttest-db-create
status:
succeeded: 1
9 changes: 9 additions & 0 deletions tests/kuttl/tests/account_create/02-create-database.yaml
Original file line number Diff line number Diff line change
@@ -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
25 changes: 25 additions & 0 deletions tests/kuttl/tests/account_create/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
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
- message: MariaDB / Galera server ready
reason: Ready
status: "True"
type: MariaDBServerReady
22 changes: 22 additions & 0 deletions tests/kuttl/tests/account_create/03-create-account.yaml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/kuttl/tests/account_create/04-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions tests/kuttl/tests/account_create/05-drop-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
oc delete -n $NAMESPACE mariadbaccounts/kuttldb-some-db-account
6 changes: 6 additions & 0 deletions tests/kuttl/tests/account_create/06-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions tests/kuttl/tests/account_create/07-teardown.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b7945c9

Please sign in to comment.