Skip to content

Commit

Permalink
Enhance Kuttl tests coverage
Browse files Browse the repository at this point in the history
This patch enhances Kuttl coverage by adding the following tests:
	* Scale up all Designate services
	* Scale down all Designate services
	* Scale up again all Designate services
	* Scale down to 0 all Designate services

The tests will assert the Bind9 & Mdns predictable IPs and generated
pools.yaml file were changed accordingly (except for the scale down to
0)
  • Loading branch information
omersch381 committed Feb 4, 2025
1 parent b8784e9 commit 4d52b98
Show file tree
Hide file tree
Showing 17 changed files with 537 additions and 79 deletions.
94 changes: 94 additions & 0 deletions tests/kuttl/common/validate-pools-yaml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash
#
# This is a base script which will verify the pools.yaml generated file.
#
# Get the ConfigMap content
NUM_OF_SERVICES=$1
EXPECTED_IPS_NUM=$((NUM_OF_SERVICES * 2))
config_content=$(oc get -n $NAMESPACE configmap designate-pools-yaml-config-map -o jsonpath='{.data.pools-yaml-content}')

# Validate pools.yaml config map YAML structure
if ! yq eval '.' <<< "$config_content" &> /dev/null; then
echo "Invalid YAML structure"
exit 1
fi

# Assert pool's name
if [ "$(echo "$config_content" | yq eval '.[0].name' -)" != "default" ]; then
echo "Pool name is not 'default'"
exit 1
fi

# Assert pool's NS records
if [ "$(echo "$config_content" | yq eval '.[0].ns_records[0].hostname' -)" != "ns1.example.com." ]; then
echo "First NS record hostname is incorrect"
exit 1
fi
if [ "$(echo "$config_content" | yq eval '.[0].ns_records[1].hostname' -)" != "ns2.example.com." ]; then
echo "Second NS record hostname is incorrect"
exit 1
fi

# Check nameserver IPs
nameserver_ips=$(echo "$config_content" | yq eval '.[0].nameservers[].host' -)
for ip in $nameserver_ips; do
if [[ ! $ip =~ ^172\.28\.0\.[0-9]+$ ]]; then
echo "Invalid nameserver IP format: $ip"
exit 1
fi
done

# Check master IPs
master_ips=$(echo "$config_content" | yq eval '.[0].targets[].masters[].host' -)
for ip in $master_ips; do
if [[ ! $ip =~ ^172\.28\.0\.[0-9]+$ ]]; then
echo "Invalid master IP format: $ip"
exit 1
fi
done

# Check target.option IPs
target_ips=$(echo "$config_content" | yq eval '.[0].targets[].options.host' -)
rndc_ips=$(echo "$config_content" | yq eval '.[0].targets[].options.rndc_host' -)
for ip in $target_ips $rndc_ips; do
if [[ ! $ip =~ ^172\.28\.0\.[0-9]+$ ]]; then
echo "Invalid target/rndc IP format: $ip"
exit 1
fi
done

# Count total unique IPs
all_ips=$(echo "$config_content" | yq eval '
.[0].nameservers[].host,
.[0].targets[].masters[].host,
.[0].targets[].options.host,
.[0].targets[].options.rndc_host' - | sort -u)
unique_ip_count=$(echo "$all_ips" | wc -l)
if [ "$unique_ip_count" -ne $EXPECTED_IPS_NUM ]; then
echo "Expected $EXPECTED_IPS_NUM unique IPs, found $unique_ip_count"
exit 1
fi

# Verify port numbers
nameserver_ports=$(echo "$config_content" | yq eval '.[0].nameservers[].port' -)
for port in $nameserver_ports; do
if [ "$port" -ne 53 ]; then
echo "Invalid nameserver port: $port"
exit 1
fi
done
master_ports=$(echo "$config_content" | yq eval '.[0].targets[].masters[].port' -)
for port in $master_ports; do
if [ "$port" -ne 5354 ]; then
echo "Invalid master port: $port"
exit 1
fi
done
rndc_ports=$(echo "$config_content" | yq eval '.[0].targets[].options.rndc_port' -)
for port in $rndc_ports; do
if [ "$port" -ne 953 ]; then
echo "Invalid rndc port: $port"
exit 1
fi
done
echo "pools.yaml generated file was verified successfully"
31 changes: 31 additions & 0 deletions tests/kuttl/common/validate-predictable-ips.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
#
# This is a base script which will verify Bind9 & Mdns predictable IPs.
#
# Check Bind9 predictable IPs configmap
NUM_OF_SERVICES=$1
bind_ips=$(oc get -n $NAMESPACE configmap designate-bind-ip-map -o json | jq -r '.data | values[]')
if [ $(echo "$bind_ips" | wc -l) -ne ${NUM_OF_SERVICES} ]; then
echo "Expected ${NUM_OF_SERVICES} bind addresses, found $(echo "$bind_ips" | wc -l)"
exit 1
fi
for ip in $bind_ips; do
if [[ ! $ip =~ ^172\.28\.0\.[0-9]+$ ]]; then
echo "Invalid bind IP format: $ip"
exit 1
fi
done

# Check Mdns predictable IPs configmap
mdns_ips=$(oc get -n $NAMESPACE configmap designate-mdns-ip-map -o json | jq -r '.data | values[]')
if [ $(echo "$mdns_ips" | wc -l) -ne ${NUM_OF_SERVICES} ]; then
echo "Expected ${NUM_OF_SERVICES} mdns addresses, found $(echo "$mdns_ips" | wc -l)"
exit 1
fi
for ip in $mdns_ips; do
if [[ ! $ip =~ ^172\.28\.0\.[0-9]+$ ]]; then
echo "Invalid mdns IP format: $ip"
exit 1
fi
done
echo "Bind9 & Mdns predictable IPs were verified successfully"
83 changes: 81 additions & 2 deletions tests/kuttl/tests/designate_scale/02-assert.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Check for:
#
# - 1 DesignateAPI CR
# - 3 Pods for DesignateAPI CR
# - Designate CR with all services scaled to 3 replicas
# - 3 Pods for each Designate service
#

apiVersion: designate.openstack.org/v1beta1
Expand All @@ -14,8 +14,26 @@ metadata:
spec:
designateAPI:
replicas: 3
designateBackendbind9:
replicas: 3
designateCentral:
replicas: 3
designateMdns:
replicas: 3
designateProducer:
replicas: 3
designateUnbound:
replicas: 3
designateWorker:
replicas: 3
status:
designateAPIReadyCount: 3
designateBackendbind9ReadyCount: 3
designateCentralReadyCount: 3
designateMdnsReadyCount: 3
designateProducerReadyCount: 3
designateUnboundReadyCount: 3
designateWorkerReadyCount: 3
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -25,3 +43,64 @@ spec:
replicas: 3
status:
availableReplicas: 3
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: designate-backendbind9
spec:
replicas: 3
status:
availableReplicas: 3
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: designate-central
spec:
replicas: 3
status:
availableReplicas: 3
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: designate-mdns
spec:
replicas: 3
status:
availableReplicas: 3
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: designate-producer
spec:
replicas: 3
status:
availableReplicas: 3
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: designate-unbound
spec:
replicas: 3
status:
availableReplicas: 3
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: designate-worker
spec:
replicas: 3
status:
availableReplicas: 3
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
commands:
- script: |
../../common/validate-predictable-ips.sh 3
../../common/validate-pools-yaml.sh 3
6 changes: 6 additions & 0 deletions tests/kuttl/tests/designate_scale/02-scale-designate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
SVC_REPLICA_COUNT=3
for svc in API Backendbind9 Central Mdns Producer Unbound Worker; do oc patch designate -n $NAMESPACE designate --type='json' -p='[{"op": "replace", "path": "/spec/designate'"${svc}"'/replicas", "value":'"${SVC_REPLICA_COUNT}"'}]'; done
5 changes: 0 additions & 5 deletions tests/kuttl/tests/designate_scale/02-scale-designateapi.yaml

This file was deleted.

83 changes: 81 additions & 2 deletions tests/kuttl/tests/designate_scale/03-assert.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#
# Check for:
#
# - 1 DesignateAPI CR
# - 1 Pods for DesignateAPI CR
# - Designate CR with all services scaled down to 1 replica
# - 1 Pod for each Designate service
#

apiVersion: designate.openstack.org/v1beta1
Expand All @@ -14,8 +14,26 @@ metadata:
spec:
designateAPI:
replicas: 1
designateBackendbind9:
replicas: 1
designateCentral:
replicas: 1
designateMdns:
replicas: 1
designateProducer:
replicas: 1
designateUnbound:
replicas: 1
designateWorker:
replicas: 1
status:
designateAPIReadyCount: 1
designateBackendbind9ReadyCount: 1
designateCentralReadyCount: 1
designateMdnsReadyCount: 1
designateProducerReadyCount: 1
designateUnboundReadyCount: 1
designateWorkerReadyCount: 1
---
apiVersion: apps/v1
kind: Deployment
Expand All @@ -25,3 +43,64 @@ spec:
replicas: 1
status:
availableReplicas: 1
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: designate-backendbind9
spec:
replicas: 1
status:
availableReplicas: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: designate-central
spec:
replicas: 1
status:
availableReplicas: 1
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: designate-mdns
spec:
replicas: 1
status:
availableReplicas: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: designate-producer
spec:
replicas: 1
status:
availableReplicas: 1
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: designate-unbound
spec:
replicas: 1
status:
availableReplicas: 1
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: designate-worker
spec:
replicas: 1
status:
availableReplicas: 1
---
apiVersion: kuttl.dev/v1beta1
kind: TestAssert
commands:
- script: |
../../common/validate-predictable-ips.sh 1
../../common/validate-pools-yaml.sh 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
SVC_REPLICA_COUNT=1
for svc in API Backendbind9 Central Mdns Producer Unbound Worker; do oc patch designate -n $NAMESPACE designate --type='json' -p='[{"op": "replace", "path": "/spec/designate'"${svc}"'/replicas", "value":'"${SVC_REPLICA_COUNT}"'}]'; done

This file was deleted.

Loading

0 comments on commit 4d52b98

Please sign in to comment.