Skip to content

Commit 738e6eb

Browse files
committed
MCP: Consolidate common kuttl bash scripts
There is code in the bash scripts that is repeated in multiple kuttl test files. In this commit we consolidate that code into shared functions that can be used by the different tests.
1 parent b6215bd commit 738e6eb

6 files changed

Lines changed: 67 additions & 66 deletions

File tree

test/kuttl/common/shared_funcs.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
#
3+
# Shared assertion functions for kuttl test scripts.
4+
#
5+
# Usage: source ../../common/shared_funcs.sh
6+
# (from test/kuttl/tests/<test-name>/)
7+
8+
NAMESPACE="${NAMESPACE:-openstack-lightspeed}"
9+
CR_NAME="${CR_NAME:-openstack-lightspeed}"
10+
11+
assert_mcp_openstack_enabled() {
12+
local expected="$1"
13+
local mcp_data
14+
mcp_data=$(oc get configmap mcp-config -n "$NAMESPACE" \
15+
-o jsonpath='{.data.config\.yaml}')
16+
local enabled
17+
enabled=$(echo "$mcp_data" | grep -A1 "openstack:" | grep "enabled:" | tr -d ' ')
18+
if [ "$enabled" != "enabled:${expected}" ]; then
19+
echo "ERROR: Expected MCP openstack enabled:${expected}, got ${enabled}"
20+
echo "$mcp_data"
21+
exit 1
22+
fi
23+
}
24+
25+
assert_openstack_ready() {
26+
local expected="$1"
27+
local ready
28+
ready=$(oc get openstacklightspeed "$CR_NAME" -n "$NAMESPACE" \
29+
-o jsonpath='{.status.openStackReady}' 2>/dev/null || true)
30+
if [ "$expected" = "true" ]; then
31+
if [ "$ready" != "true" ]; then
32+
echo "ERROR: Expected openStackReady to be true, got '${ready}'"
33+
exit 1
34+
fi
35+
else
36+
if [ "$ready" = "true" ]; then
37+
echo "ERROR: Expected openStackReady to not be true, got '${ready}'"
38+
exit 1
39+
fi
40+
fi
41+
}
42+
43+
assert_condition_status() {
44+
local condition_type="$1"
45+
local expected_status="$2"
46+
local actual
47+
actual=$(oc get openstacklightspeed "$CR_NAME" -n "$NAMESPACE" \
48+
-o jsonpath="{.status.conditions[?(@.type==\"${condition_type}\")].status}")
49+
if [ "$actual" != "$expected_status" ]; then
50+
echo "ERROR: Expected condition ${condition_type}=${expected_status}, got '${actual}'"
51+
oc get openstacklightspeed "$CR_NAME" -n "$NAMESPACE" -o yaml
52+
exit 1
53+
fi
54+
}

test/kuttl/tests/application-credentials/07-assert-intermediate-state.yaml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,6 @@ commands:
1010
- script: |
1111
#!/bin/bash
1212
set -euo pipefail
13-
14-
# openStackReady is omitempty, so absent means false
15-
READY=$(oc get openstacklightspeed openstack-lightspeed -n openstack-lightspeed \
16-
-o jsonpath='{.status.openStackReady}' 2>/dev/null || true)
17-
if [ "$READY" = "true" ]; then
18-
echo "ERROR: openStackReady should not be true in intermediate state"
19-
exit 1
20-
fi
21-
22-
MCP_CFG=$(oc get configmap mcp-config -n openstack-lightspeed \
23-
-o jsonpath='{.data.config\.yaml}')
24-
ENABLED=$(echo "$MCP_CFG" | grep -A1 "openstack:" | grep "enabled:" | tr -d ' ')
25-
if [ "$ENABLED" != "enabled:false" ]; then
26-
echo "ERROR: MCP config should have openstack disabled in intermediate state"
27-
echo "$MCP_CFG"
28-
exit 1
29-
fi
13+
source ../../common/shared_funcs.sh
14+
assert_openstack_ready false
15+
assert_mcp_openstack_enabled false

test/kuttl/tests/application-credentials/09-assert-mcp-credentials.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,5 @@ commands:
4343
-o jsonpath='{.data.secure\.yaml}' | base64 -d)
4444
echo "$SECURE" | grep -q "application_credential_secret: mock-ac-secret-abcde"
4545
46-
MCP_CFG=$(oc get configmap mcp-config -n openstack-lightspeed \
47-
-o jsonpath='{.data.config\.yaml}')
48-
ENABLED=$(echo "$MCP_CFG" | grep -A1 "openstack:" | grep "enabled:" | tr -d ' ')
49-
if [ "$ENABLED" != "enabled:true" ]; then
50-
echo "ERROR: MCP config does not have openstack enabled"
51-
echo "$MCP_CFG"
52-
exit 1
53-
fi
46+
source ../../common/shared_funcs.sh
47+
assert_mcp_openstack_enabled true

test/kuttl/tests/dynamic-crd-watch-recovery/06-assert-openstack-lightspeed-instance.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,5 @@ commands:
1515
- script: |
1616
#!/bin/bash
1717
set -euo pipefail
18-
MCP_DATA=$(oc get configmap mcp-config -n openstack-lightspeed \
19-
-o jsonpath='{.data.config\.yaml}')
20-
ENABLED=$(echo "$MCP_DATA" | grep -A1 "openstack:" | grep "enabled:" | tr -d ' ')
21-
if [ "$ENABLED" != "enabled:true" ]; then
22-
echo "ERROR: MCP config does not have openstack enabled"
23-
echo "$MCP_DATA"
24-
exit 1
25-
fi
18+
source ../../common/shared_funcs.sh
19+
assert_mcp_openstack_enabled true

test/kuttl/tests/dynamic-crd-watch-recovery/07-assert-openstack-lightspeed-instance.yaml

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,7 @@ commands:
88
- script: |
99
#!/bin/bash
1010
set -euo pipefail
11-
READY=$(oc get openstacklightspeed openstack-lightspeed \
12-
-n openstack-lightspeed \
13-
-o jsonpath='{.status.openStackReady}' 2>/dev/null || true)
14-
if [ "$READY" = "true" ]; then
15-
echo "ERROR: openStackReady is still true"
16-
exit 1
17-
fi
18-
19-
MCP_DATA=$(oc get configmap mcp-config -n openstack-lightspeed \
20-
-o jsonpath='{.data.config\.yaml}')
21-
ENABLED=$(echo "$MCP_DATA" | grep -A1 "openstack:" | grep "enabled:" | tr -d ' ')
22-
if [ "$ENABLED" != "enabled:false" ]; then
23-
echo "ERROR: MCP config does not have openstack disabled"
24-
echo "$MCP_DATA"
25-
exit 1
26-
fi
27-
28-
CONDITION=$(oc get openstacklightspeed openstack-lightspeed \
29-
-n openstack-lightspeed \
30-
-o jsonpath='{.status.conditions[?(@.type=="Ready")].status}')
31-
if [ "$CONDITION" != "True" ]; then
32-
echo "ERROR: Operator is not Ready after CRD removal"
33-
oc get openstacklightspeed openstack-lightspeed -n openstack-lightspeed -o yaml
34-
exit 1
35-
fi
11+
source ../../common/shared_funcs.sh
12+
assert_openstack_ready false
13+
assert_mcp_openstack_enabled false
14+
assert_condition_status Ready True

test/kuttl/tests/dynamic-crd-watch-recovery/10-assert-openstack-lightspeed-instance.yaml

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,5 @@ commands:
1515
- script: |
1616
#!/bin/bash
1717
set -euo pipefail
18-
MCP_DATA=$(oc get configmap mcp-config -n openstack-lightspeed \
19-
-o jsonpath='{.data.config\.yaml}')
20-
ENABLED=$(echo "$MCP_DATA" | grep -A1 "openstack:" | grep "enabled:" | tr -d ' ')
21-
if [ "$ENABLED" != "enabled:true" ]; then
22-
echo "ERROR: MCP config does not have openstack enabled"
23-
echo "$MCP_DATA"
24-
exit 1
25-
fi
18+
source ../../common/shared_funcs.sh
19+
assert_mcp_openstack_enabled true

0 commit comments

Comments
 (0)