Skip to content

Commit 1c4b195

Browse files
committed
Merge branch 'success-fail-msg-e2e' into 'main'
refactor(e2e): Use functions for success and failure messages See merge request ongresinc/stackgres!1596
2 parents 0877842 + 84fb7f3 commit 1c4b195

89 files changed

Lines changed: 1293 additions & 1900 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

stackgres-k8s/e2e/spec/abstract/backup

Lines changed: 22 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ check_wal_archive() {
1919
try_function wait_until try_check_wal_archive "$NODE"
2020
if "$RESULT"
2121
then
22-
echo "SUCCESS. The WAL is available"
22+
success "The WAL is available"
2323
else
24-
echo "FAIL. The WAL is not available"
25-
return 1
24+
fail "The WAL is not available"
2625
fi
2726
}
2827

@@ -61,20 +60,18 @@ check_automatic_backup() {
6160

6261
if wait_until eval '[ "$(kubectl get sgbackup -n "$CLUSTER_NAMESPACE" -o name | wc -l)" -gt 0 ]'
6362
then
64-
echo "SUCCESS. The automatic backup CR is running"
63+
success "The automatic backup CR is running"
6564
else
66-
echo "FAIL. The automatic backup CR is not running"
67-
return 1
65+
fail "The automatic backup CR is not running"
6866
fi
6967

7068
if wait_until eval '[ "$(kubectl get sgbackup -n "$CLUSTER_NAMESPACE" \
7169
--template "{{ range .items }}{{ .status.process.status }} {{ .status.backupInformation.sourcePod }}{{ print \"\n\" }}{{ end }}" \
7270
| grep "^Completed ${CLUSTER_NAME}-${NODE}$" | wc -l)" -gt 0 ]'
7371
then
74-
echo "SUCCESS. The automatic backup CR has completed"
72+
success "The automatic backup CR has completed"
7573
else
76-
echo "FAIL. The automatic backup CR has failed"
77-
return 1
74+
fail "The automatic backup CR has failed"
7875
fi
7976
}
8077

@@ -92,8 +89,7 @@ check_timelines(){
9289

9390
if [ "$EXPECTED_TIMELINE" != "$ACTUAL_TIMELINE" ]
9491
then
95-
echo "FAIL. Timeline of $(echo "$BACKUP_LINE" | cut -d ' ' -f 1) with walFile $(echo "$BACKUP_LINE" | cut -d ' ' -f 3) is incorrect. Actual timeline: $ACTUAL_TIMELINE"
96-
return 1
92+
fail "Timeline of $(echo "$BACKUP_LINE" | cut -d ' ' -f 1) with walFile $(echo "$BACKUP_LINE" | cut -d ' ' -f 3) is incorrect. Actual timeline: $ACTUAL_TIMELINE"
9793
else
9894
echo "Backup $(echo "$BACKUP_LINE" | cut -d ' ' -f 1) timeline is correct"
9995
fi
@@ -114,8 +110,7 @@ check_control_data(){
114110

115111
if [ "$EXPECTED_CONTROL_DATA_LENGTH" != "$ACTUAL_CONTROL_DATA_LENGTH" ]
116112
then
117-
echo "FAIL. Backup $BACKUP_NAME has invalid controlData. Expected $EXPECTED_CONTROL_DATA_LENGTH fields, found $ACTUAL_CONTROL_DATA_LENGTH"
118-
return 1
113+
fail "Backup $BACKUP_NAME has invalid controlData. Expected $EXPECTED_CONTROL_DATA_LENGTH fields, found $ACTUAL_CONTROL_DATA_LENGTH"
119114
else
120115
echo "Backup $BACKUP_NAME has valid controlData"
121116
fi
@@ -127,10 +122,9 @@ check_automatic_backup_cr() {
127122

128123
if wait_until is_automatic_backup_cr_completed "$NODE"
129124
then
130-
echo "SUCCESS. The full backup is available"
125+
success "The full backup is available"
131126
else
132-
echo "FAIL. The full backup is not available"
133-
return 1
127+
fail "The full backup is not available"
134128
fi
135129
}
136130

@@ -145,10 +139,9 @@ is_automatic_backup_cr_completed() {
145139
if [ "$(kubectl exec -n "$CLUSTER_NAMESPACE" "${CLUSTER_NAME}-${NODE}" -c patroni -- \
146140
exec-with-env backup -- wal-g backup-list 2>/dev/null | grep "^$BACKUP_NAME " | wc -l)" -gt 0 ]
147141
then
148-
echo "SUCCESS. The automatic backup is available"
142+
success "The automatic backup is available"
149143
else
150-
echo "FAIL. The automatic backup is not available"
151-
return 1
144+
fail "The automatic backup is not available"
152145
fi
153146
}
154147

@@ -159,10 +152,9 @@ wait_backup_is_completed() {
159152
--template "{{ .status.process.status }} {{ .status.backupInformation.sourcePod }}" \
160153
| grep "^Completed ${CLUSTER_NAME}-${NODE}$" | wc -l)" -gt 0 ]'
161154
then
162-
echo "SUCCESS. The manual backup CR has complete"
155+
success "The manual backup CR has complete"
163156
else
164-
echo "FAIL. The manual backup CR has failed"
165-
return 1
157+
fail "The manual backup CR has failed"
166158
fi
167159
}
168160

@@ -189,10 +181,9 @@ check_is_managed_lifecycle_value() {
189181

190182
if [ "$ACTUAL_MANAGED_LYFECYCLE" != "$EXPECTED_MANAGED_LYFECYCLE" ]
191183
then
192-
echo "FAIL. Backup /status/process/managedLifecycle expected to be $EXPECTED_MANAGED_LYFECYCLE but was $ACTUAL_MANAGED_LYFECYCLE"
193-
return 1
184+
fail "Backup /status/process/managedLifecycle expected to be $EXPECTED_MANAGED_LYFECYCLE but was $ACTUAL_MANAGED_LYFECYCLE"
194185
else
195-
echo "SUCCESS. Backup /status/process/managedLifecycle was $EXPECTED_MANAGED_LYFECYCLE"
186+
success "Backup /status/process/managedLifecycle was $EXPECTED_MANAGED_LYFECYCLE"
196187
fi
197188
}
198189

@@ -203,10 +194,9 @@ check_backup_retention() {
203194
--template "{{ range .items }}{{ .status.process.status }} {{ .status.backupInformation.sourcePod }}{{ print \"\n\" }}{{ end }}" \
204195
| grep "^Completed ${CLUSTER_NAME}-${NODE}$" | wc -l)" -ge 2 ]'
205196
then
206-
echo "SUCCESS. The maximum retainable backups are available"
197+
success "The maximum retainable backups are available"
207198
else
208-
echo "FAIL. The maximum retainable backups are not available"
209-
return 1
199+
fail "The maximum retainable backups are not available"
210200
fi
211201

212202
local BACKUP_NAME
@@ -223,19 +213,18 @@ check_backup_retention() {
223213

224214
if wait_until -t "$((E2E_TIMEOUT * 2))" eval '! kubectl get sgbackup -n "$CLUSTER_NAMESPACE" "$BACKUP_NAME" > /dev/null 2>&1'
225215
then
226-
echo "SUCCESS. The backup retention has been honored. Old backups $BACKUP_NAME deleted"
216+
success "The backup retention has been honored. Old backups $BACKUP_NAME deleted"
227217
else
228-
echo "FAIL. The backup retention has not been honored. Old backups $BACKUP_NAME not deleted"
218+
fail_no_return "The backup retention has not been honored. Old backups $BACKUP_NAME not deleted"
229219
kubectl get sgbackup -n "$CLUSTER_NAMESPACE"
230220
return 1
231221
fi
232222

233223
if wait_until eval '[ "$(get_completed_backup_count)" = "2" ]'
234224
then
235-
echo "SUCCESS. The backup retention has been honored. Remaining backups are 2"
225+
success "The backup retention has been honored. Remaining backups are 2"
236226
else
237-
echo "FAIL. The backup retention has not been honored. Remaining backups are $(get_completed_backup_count)"
238-
return 1
227+
fail "The backup retention has not been honored. Remaining backups are $(get_completed_backup_count)"
239228
fi
240229
}
241230

stackgres-k8s/e2e/spec/abstract/dbops-major-version-upgrade

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,9 @@ EOF
172172
EOF
173173
)" >/dev/null 2>&1
174174
then
175-
echo "FAILED. Changed SGCluster postgres version directly."
176-
return 1
175+
fail "Changed SGCluster postgres version directly."
177176
else
178-
echo "SUCCESS. Could not change SGCluster postgres version directly."
177+
success "Could not change SGCluster postgres version directly."
179178
fi
180179
}
181180

@@ -188,10 +187,9 @@ check_major_version_upgrade() {
188187
-p '[{"op":"replace","path":"/spec/metadata","value":{"annotations":{"allResources":{"'"$(random_string)"'": "'"$(random_string)"'"}}}}]' \
189188
>/dev/null 2>&1
190189
then
191-
echo "FAILED. Cluster has been updated while locked."
192-
return 1
190+
fail "Cluster has been updated while locked."
193191
else
194-
echo "SUCCESS. Cluster has not been updated while locked."
192+
success "Cluster has not been updated while locked."
195193
fi
196194

197195
assert_dbops_completion "$DBOPS_NAME" "$CLUSTER_NAMESPACE" "$((E2E_TIMEOUT * 2))"
@@ -200,19 +198,17 @@ check_major_version_upgrade() {
200198
-l "stackgres.io/dbops-name=$DBOPS_NAME,stackgres.io/db-ops=true" \
201199
-o name 2>/dev/null | wc -l)" = 1 ]
202200
then
203-
echo "SUCCESS. major version upgrade job was not removed after completion."
201+
success "major version upgrade job was not removed after completion."
204202
else
205-
echo "FAILED. major version upgrade job was removed after completion."
206-
return 1
203+
fail "major version upgrade job was removed after completion."
207204
fi
208205

209206
if [ "$(kubectl get -n "$CLUSTER_NAMESPACE" sgcluster "$CLUSTER_NAME" \
210207
--template '{{ .spec.postgres.version }}')" = "$E2E_MAJOR_TARGET_POSTGRES_VERSION" ]
211208
then
212-
echo "SUCCESS. cluster postgres version has been updated."
209+
success "cluster postgres version has been updated."
213210
else
214-
echo "FAILED. cluster postgres version has not been updated."
215-
return 1
211+
fail "cluster postgres version has not been updated."
216212
fi
217213

218214
wait_until run_query -i 0 -q "SELECT 1;"
@@ -230,10 +226,9 @@ check_major_version_upgrade_check() {
230226
-p '[{"op":"replace","path":"/spec/metadata","value":{"annotations":{"allResources":{"'"$(random_string)"'": "'"$(random_string)"'"}}}}]' \
231227
>/dev/null 2>&1
232228
then
233-
echo "FAILED. Cluster has been updated while locked."
234-
return 1
229+
fail "Cluster has been updated while locked."
235230
else
236-
echo "SUCCESS. Cluster has not been updated while locked."
231+
success "Cluster has not been updated while locked."
237232
fi
238233

239234
assert_dbops_completion "$DBOPS_NAME" "$CLUSTER_NAMESPACE" "$((E2E_TIMEOUT * 2))"
@@ -242,19 +237,17 @@ check_major_version_upgrade_check() {
242237
-l "stackgres.io/dbops-name=$DBOPS_NAME,stackgres.io/db-ops=true" \
243238
-o name 2>/dev/null | wc -l)" = 1 ]
244239
then
245-
echo "SUCCESS. major version upgrade job was not removed after completion."
240+
success "major version upgrade job was not removed after completion."
246241
else
247-
echo "FAILED. major version upgrade job was removed after completion."
248-
return 1
242+
fail "major version upgrade job was removed after completion."
249243
fi
250244

251245
if [ "$(kubectl get -n "$CLUSTER_NAMESPACE" sgcluster "$CLUSTER_NAME" \
252246
--template '{{ .spec.postgres.version }}')" = "$E2E_MAJOR_SOURCE_POSTGRES_VERSION" ]
253247
then
254-
echo "SUCCESS. cluster postgres version has not been updated."
248+
success "cluster postgres version has not been updated."
255249
else
256-
echo "FAILED. cluster postgres version has been updated."
257-
return 1
250+
fail "cluster postgres version has been updated."
258251
fi
259252

260253
wait_until run_query -i 0 -q "SELECT 1;"

stackgres-k8s/e2e/spec/abstract/dbops-minor-version-upgrade

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,9 @@ reset_cluster() {
3939
EOF
4040
)" >/dev/null 2>&1
4141
then
42-
echo "FAILED. Changed SGCluster postgres version directly."
43-
return 1
42+
fail "Changed SGCluster postgres version directly."
4443
else
45-
echo "SUCCESS. Could not change SGCluster postgres version directly."
44+
success "Could not change SGCluster postgres version directly."
4645
fi
4746
}
4847

@@ -64,10 +63,9 @@ check_restart() {
6463
-p '[{"op":"replace","path":"/spec/metadata","value":{"annotations":{"allResources":{"'"$(random_string)"'": "'"$(random_string)"'"}}}}]' \
6564
>/dev/null 2>&1
6665
then
67-
echo "FAILED. Cluster has been updated while locked."
68-
return 1
66+
fail "Cluster has been updated while locked."
6967
else
70-
echo "SUCCESS. Cluster has not been updated while locked."
68+
success "Cluster has not been updated while locked."
7169
fi
7270

7371
assert_dbops_completion "$DBOPS_NAME" "$CLUSTER_NAMESPACE" "$((E2E_TIMEOUT * 2))"
@@ -77,10 +75,9 @@ check_restart() {
7775
INITIAL_INSTANCES="$(printf '%s' "$INITIAL_INSTANCES" | jq '.status.restart.initialInstances | length')"
7876
if printf '%s %s' "$RESTARTED_PODS" "$NOT_RESTARTED_PODS" | wc -w | grep -q "^$INITIAL_INSTANCES$"
7977
then
80-
echo "SUCCESS. Instances after minor version upgrade match the initial instances in status ($INITIAL_INSTANCES)"
78+
success "Instances after minor version upgrade match the initial instances in status ($INITIAL_INSTANCES)"
8179
else
82-
echo "FAILED. Instances after minor version upgrade ($(printf '%s %s' "$RESTARTED_PODS" "$NOT_RESTARTED_PODS" | wc -w)) do not match the initial instances in status ($INITIAL_INSTANCES)"
83-
return 1
80+
fail "Instances after minor version upgrade ($(printf '%s %s' "$RESTARTED_PODS" "$NOT_RESTARTED_PODS" | wc -w)) do not match the initial instances in status ($INITIAL_INSTANCES)"
8481
fi
8582

8683
local DBOPS_CREATION_TIMESTAMP
@@ -94,10 +91,9 @@ check_restart() {
9491
POD_CREATION_TIMESTAMP="$(date -d "$POD_CREATION_TIMESTAMP" +%s)"
9592
if [ "$POD_CREATION_TIMESTAMP" -lt "$DBOPS_CREATION_TIMESTAMP" ]
9693
then
97-
echo "FAILED. Pod $POD was not restarted"
98-
return 1
94+
fail "Pod $POD was not restarted"
9995
else
100-
echo "SUCCESS. Pod $POD was restarted"
96+
success "Pod $POD was restarted"
10197
fi
10298
done
10399
for POD in $NOT_RESTARTED_PODS
@@ -106,41 +102,37 @@ check_restart() {
106102
POD_CREATION_TIMESTAMP="$(date -d "$POD_CREATION_TIMESTAMP" +%s)"
107103
if [ "$POD_CREATION_TIMESTAMP" -lt "$DBOPS_CREATION_TIMESTAMP" ]
108104
then
109-
echo "SUCCESS. Pod $POD was not restarted"
105+
success "Pod $POD was not restarted"
110106
else
111-
echo "FAILED. Pod $POD was restarted"
112-
return 1
107+
fail "Pod $POD was restarted"
113108
fi
114109
done
115110

116111
if [ "$(kubectl get -n "$CLUSTER_NAMESPACE" job \
117112
-l "app=StackGresDbOps,stackgres.io/dbops-name=$DBOPS_NAME,stackgres.io/db-ops=true" \
118113
-o name 2>/dev/null | wc -l)" = 1 ]
119114
then
120-
echo "SUCCESS. minor version upgrade job was not removed after completion."
115+
success "minor version upgrade job was not removed after completion."
121116
else
122-
echo "FAILED. minor version upgrade job was removed after completion."
123-
return 1
117+
fail "minor version upgrade job was removed after completion."
124118
fi
125119

126120
local FINAL_DBOPS_JOB_NAME
127121
FINAL_DBOPS_JOB_NAME="$(kubectl get job -n "$CLUSTER_NAMESPACE" \
128122
-l "app=StackGresDbOps,stackgres.io/dbops-name=$DBOPS_NAME,stackgres.io/db-ops=true" -o name)"
129123
if [ "$DBOPS_JOB_NAME" = "$FINAL_DBOPS_JOB_NAME" ]
130124
then
131-
echo "SUCCESS. minor version upgrade Job was not re-created."
125+
success "minor version upgrade Job was not re-created."
132126
else
133-
echo "FAILED. minor version upgrade Job was re-created. Was $DBOPS_JOB_NAME but ended being $FINAL_DBOPS_JOB_NAME."
134-
return 1
127+
fail "minor version upgrade Job was re-created. Was $DBOPS_JOB_NAME but ended being $FINAL_DBOPS_JOB_NAME."
135128
fi
136129

137130
if [ "$(kubectl get -n "$CLUSTER_NAMESPACE" sgcluster "$CLUSTER_NAME" \
138131
--template '{{ .spec.postgres.version }}')" = "$E2E_MINOR_TARGET_POSTGRES_VERSION" ]
139132
then
140-
echo "SUCCESS. cluster postgres version has been updated."
133+
success "cluster postgres version has been updated."
141134
else
142-
echo "FAILED. cluster postgres version has not been updated."
143-
return 1
135+
fail "cluster postgres version has not been updated."
144136
fi
145137

146138
if [ "$SKIP_CHECK_DATA" != true ]

0 commit comments

Comments
 (0)