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 5, 2023
1 parent 4571187 commit 6edfb49
Show file tree
Hide file tree
Showing 13 changed files with 273 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
9 changes: 9 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,9 @@
apiVersion: mariadb.openstack.org/v1beta1
kind: Galera
metadata:
name: openstack
spec:
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
27 changes: 27 additions & 0 deletions tests/kuttl/tests/account_create/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
apiVersion: mariadb.openstack.org/v1beta1
kind: MariaDBAccount
metadata:
labels:
mariaDBDatabaseName: kuttldb-accounttest
name: kuttldb-some-db-account
status:
conditions:
- message: 'MariaDBAccount secret is missing or incomplete: Secret openstack/some-db-secret not found'
reason: SecretMissing
severity: Info
status: "False"
type: Ready
- message: 'MariaDBAccount secret is missing or incomplete: Secret openstack/some-db-secret not found'
reason: SecretMissing
severity: Info
status: "False"
type: MariaDBAccountReady
- message: MariaDBDatabase ready
reason: Ready
status: "True"
type: MariaDBDatabaseReady
- message: MariaDB / Galera server ready
reason: Ready
status: "True"
type: MariaDBServerReady
9 changes: 9 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,9 @@
apiVersion: mariadb.openstack.org/v1beta1
kind: MariaDBAccount
metadata:
labels:
mariaDBDatabaseName: kuttldb-accounttest
name: kuttldb-some-db-account
spec:
userName: someuser
secret: some-db-secret
25 changes: 25 additions & 0 deletions tests/kuttl/tests/account_create/04-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
7 changes: 7 additions & 0 deletions tests/kuttl/tests/account_create/04-create-secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
data:
DatabasePassword: ZGJzZWNyZXQx
kind: Secret
metadata:
name: some-db-secret
type: Opaque
6 changes: 6 additions & 0 deletions tests/kuttl/tests/account_create/05-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/06-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/07-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
17 changes: 17 additions & 0 deletions tests/kuttl/tests/account_create/08-teardown.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: kuttl.dev/v1beta
kind: TestStep
delete:
- apiVersion: mariadb.openstack.org/v1beta1
kind: Galera
name: openstack
- apiVersion: mariadb.openstack.org/v1beta1
kind: MariaDBDatabase
- apiVersion: mariadb.openstack.org/v1beta1
kind: MariaDBAccount
- apiVersion: v1
kind: Secret
name: some-db-secret
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 6edfb49

Please sign in to comment.