Skip to content

Commit

Permalink
Add kuttl tests for the database creation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
amoralej committed Nov 21, 2024
1 parent 8f360f9 commit c836ca7
Show file tree
Hide file tree
Showing 17 changed files with 405 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions tests/kuttl/test-suites/default/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/kuttl/test-suites/default/common/cleanup-watcher.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions tests/kuttl/test-suites/default/config.yaml
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions tests/kuttl/test-suites/default/deps/infra.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/kuttl/test-suites/default/deps/keystone.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: core.openstack.org/v1beta1
kind: OpenStackControlPlane
metadata:
name: openstack
spec:
keystone:
template:
databaseInstance: openstack
secret: osp-secret
42 changes: 42 additions & 0 deletions tests/kuttl/test-suites/default/deps/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/kuttl/test-suites/default/deps/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: watcher-kuttl-default
115 changes: 115 additions & 0 deletions tests/kuttl/test-suites/default/output/kuttl-default-results.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]
}
]
}
50 changes: 50 additions & 0 deletions tests/kuttl/test-suites/default/test/01-assert.yaml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: watcher.openstack.org/v1beta1
kind: Watcher
metadata:
name: watcher-kuttl
namespace: watcher-kuttl-default
spec:
databaseInstance: "openstack"
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit c836ca7

Please sign in to comment.