Skip to content

Commit 067502d

Browse files
committed
updating tests to work with mac
Signed-off-by: Anand Kumar Singh <[email protected]>
1 parent 15e270c commit 067502d

File tree

13 files changed

+105
-85
lines changed

13 files changed

+105
-85
lines changed

scripts/e2e-common.sh

+44-44
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ function unexpectedError() {
2525
echo "Unexpected error occured!!"
2626
failed=1
2727

28-
(( failed )) && fail_test
28+
((failed)) && fail_test
2929
success
30-
}
30+
}
3131

3232
function make_banner() {
33-
local msg="$1$1$1$1 $2 $1$1$1$1"
34-
local border="${msg//[-0-9A-Za-z _.,\/()]/$1}"
35-
echo -e "${border}\n${msg}\n${border}"
33+
local msg="$1$1$1$1 $2 $1$1$1$1"
34+
local border="${msg//[-0-9A-Za-z _.,\/()]/$1}"
35+
echo -e "${border}\n${msg}\n${border}"
3636
}
3737

3838
# Simple header for logging purposes.
@@ -43,22 +43,26 @@ function header() {
4343

4444
function wait_until_pods_running() {
4545
echo -n "Waiting until all pods in namespace $1 are up"
46-
for i in {1..150}; do # timeout after 5 minutes
46+
for i in {1..150}; do # timeout after 5 minutes
4747
local pods="$(oc get pods --no-headers -n $1 2>/dev/null)"
48+
# write it to tempfile
49+
TempFile=$(mktemp)
50+
oc get pods --no-headers -n $1 2>/dev/null >$TempFile
51+
4852
# All pods must be running
4953
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
5054
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
5155
local all_ready=1
52-
while read pod ; do
53-
local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`)
56+
while read pod; do
57+
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
5458
# All containers must be ready
5559
[[ -z ${status[0]} ]] && all_ready=0 && break
5660
[[ -z ${status[1]} ]] && all_ready=0 && break
5761
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
5862
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
5963
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
60-
done <<< $(echo "${pods}" | grep -v Completed)
61-
if (( all_ready )); then
64+
done <${TempFile}
65+
if ((all_ready)); then
6266
echo -e "\nAll pods are up:\n${pods}"
6367
return 0
6468
fi
@@ -79,8 +83,8 @@ function wait_until_object_exist() {
7983
DESCRIPTION="$1 $3/$2"
8084
fi
8185
echo -n "Waiting until ${DESCRIPTION} exist"
82-
for i in {1..150}; do # timeout after 5 minutes
83-
if oc ${oc_ARGS} > /dev/null 2>&1; then
86+
for i in {1..150}; do # timeout after 5 minutes
87+
if oc ${oc_ARGS} >/dev/null 2>&1; then
8488
echo -e "\n${DESCRIPTION} exist"
8589
return 0
8690
fi
@@ -101,8 +105,8 @@ function wait_until_object_doesnt_exist() {
101105
DESCRIPTION="$1 $3/$2"
102106
fi
103107
echo -n "Waiting until ${DESCRIPTION} doesn't exist"
104-
for i in {1..150}; do # timeout after 5 minutes
105-
if ! kubectl ${KUBECTL_ARGS} > /dev/null 2>&1; then
108+
for i in {1..150}; do # timeout after 5 minutes
109+
if ! kubectl ${KUBECTL_ARGS} >/dev/null 2>&1; then
106110
echo -e "\n${DESCRIPTION} dosen't exist"
107111
return 0
108112
fi
@@ -137,7 +141,6 @@ function dump_extra_cluster_state() {
137141
kubectl -n openshift-gitops-operator logs $(get_app_pod argocd-operator openshift-gitops-operator) --all-containers=true
138142
}
139143

140-
141144
# Returns the name of the first pod of the given app.
142145
# Parameters: $1 - app name.
143146
# $2 - namespace (optional).
@@ -161,7 +164,6 @@ function fail_test() {
161164
exit 1
162165
}
163166

164-
165167
function set_test_return_code() {
166168
echo -n "$1"
167169
}
@@ -176,13 +178,13 @@ function success() {
176178
exit 0
177179
}
178180

179-
function build_and_push_catalog_image(){
180-
181+
function build_and_push_catalog_image() {
182+
181183
if [ "$E2E_SKIP_BUILD_TOOL_INSTALLATION" = false ]; then
182-
echo ">> Install operator-sdk & opm"
183-
make operator-sdk opm
184+
echo ">> Install operator-sdk & opm"
185+
make operator-sdk opm
184186
else
185-
echo ">> skipping operator-sdk & olm installation"
187+
echo ">> skipping operator-sdk & olm installation"
186188
fi
187189

188190
echo ">> Building and pushing operator images"
@@ -199,15 +201,15 @@ function build_and_push_catalog_image(){
199201

200202
}
201203

202-
function configure_operator(){
204+
function configure_operator() {
203205
header "Configuring OpenShift Gitops operator"
204206

205207
echo -e "Disabling default catalog sources"
206208
kubectl patch operatorhub.config.openshift.io/cluster -p='{"spec":{"disableAllDefaultSources":true}}' --type=merge
207209
sleep 5
208210

209211
# echo -e "Copying artifacts [catalog source, image content source policy, mapping.txt]..."
210-
cat <<EOF > $TMP_DIR/catalog-source.yaml
212+
cat <<EOF >$TMP_DIR/catalog-source.yaml
211213
apiVersion: operators.coreos.com/v1alpha1
212214
kind: CatalogSource
213215
metadata:
@@ -222,18 +224,17 @@ spec:
222224
interval: 30m
223225
EOF
224226

225-
226227
echo -e "Creating custom catalog source"
227228
kubectl apply -f $TMP_DIR/catalog-source.yaml
228229

229230
echo "Waiting for pods in namespace openshift-marketplace to be ready"
230231
# filtering out old catalog source pod that will be removed shortly
231-
pods=$(kubectl get pods -n openshift-marketplace --sort-by={metadata.creationTimestamp} -o name | \
232-
grep gitops-operator | tail -1)
232+
pods=$(kubectl get pods -n openshift-marketplace --sort-by={metadata.creationTimestamp} -o name |
233+
grep gitops-operator | tail -1)
233234

234235
for pod in ${pods}; do
235-
echo "Waiting for pod $pod in openshift-marketplace to be in ready state"
236-
kubectl wait --for=condition=Ready -n openshift-marketplace $pod --timeout=5m
236+
echo "Waiting for pod $pod in openshift-marketplace to be in ready state"
237+
kubectl wait --for=condition=Ready -n openshift-marketplace $pod --timeout=5m
237238
done
238239
}
239240

@@ -251,29 +252,29 @@ function uninstall_operator_resources() {
251252
oc wait --for=delete $deployment -n openshift-gitops --timeout=5m || fail_test "Failed to delete deployment: $deployment in openshift-gitops namespace"
252253
done
253254

254-
oc delete $(oc get csv -n openshift-gitops-operator -o name|grep gitops) -n openshift-gitops-operator || fail_test "Unable to delete CSV"
255+
oc delete $(oc get csv -n openshift-gitops-operator -o name | grep gitops) -n openshift-gitops-operator || fail_test "Unable to delete CSV"
255256

256257
oc delete -n openshift-gitops-operator installplan $(oc get subscription gitops-operator -n openshift-gitops-operator -o jsonpath='{.status.installplan.name}') || fail_test "Unable to delete installplan"
257258

258259
oc delete subscription gitops-operator -n openshift-gitops-operator --cascade=background || fail_test "Unable to delete subscription"
259260

260261
echo -e ">> Delete arogo resources accross all namespaces"
261262
for res in applications applicationsets appprojects argocds; do
262-
oc delete --ignore-not-found=true ${res}.argoproj.io --all
263+
oc delete --ignore-not-found=true ${res}.argoproj.io --all
263264
done
264265

265266
echo -e ">> Cleanup existing crds"
266267
for res in applications applicationsets appprojects argocds; do
267-
oc delete --ignore-not-found=true crds ${res}.argoproj.io
268+
oc delete --ignore-not-found=true crds ${res}.argoproj.io
268269
done
269270

270271
echo -e ">> Delete \"openshift-gitops\" project"
271272
oc delete --ignore-not-found=true project openshift-gitops
272273
}
273274

274275
function install_operator_resources() {
275-
echo -e ">>Ensure Gitops subscription exists"
276-
oc get subscription gitops-operator -n openshift-gitops-operator 2>/dev/null || \
276+
echo -e ">>Ensure Gitops subscription exists"
277+
oc get subscription gitops-operator -n openshift-gitops-operator 2>/dev/null ||
277278
cat <<EOF | oc apply -f -
278279
apiVersion: operators.coreos.com/v1alpha1
279280
kind: Subscription
@@ -287,24 +288,23 @@ spec:
287288
source: $CATALOG_SOURCE
288289
sourceNamespace: openshift-marketplace
289290
EOF
290-
291-
wait_until_pods_running "openshift-gitops-operator" || fail_test "openshift gitops Operator controller did not come up"
292291

293-
echo ">> Wait for GitopsService creation"
294-
wait_until_object_exist "gitopsservices.pipelines.openshift.io" "cluster" "openshift-gitops" || fail_test "gitops service haven't created yet"
292+
wait_until_pods_running "openshift-gitops-operator" || fail_test "openshift gitops Operator controller did not come up"
293+
294+
echo ">> Wait for GitopsService creation"
295+
wait_until_object_exist "gitopsservices.pipelines.openshift.io" "cluster" "openshift-gitops" || fail_test "gitops service haven't created yet"
295296

296-
wait_until_pods_running "openshift-gitops" || fail_test "argocd controller did not come up"
297+
wait_until_pods_running "openshift-gitops" || fail_test "argocd controller did not come up"
297298

298-
299-
#Make sure that everything is cleaned up in the current namespace.
300-
for res in applications applicationsets appprojects appprojects; do
301-
oc delete --ignore-not-found=true ${res}.argoproj.io --all
302-
done
299+
#Make sure that everything is cleaned up in the current namespace.
300+
for res in applications applicationsets appprojects appprojects; do
301+
oc delete --ignore-not-found=true ${res}.argoproj.io --all
302+
done
303303
}
304304

305305
function get_operator_namespace() {
306306
# TODO: parameterize namespace, operator can run in a namespace different from the namespace where tektonpipelines is installed
307307
local operator_namespace="argocd-operator"
308308
[[ "${TARGET}" == "openshift" ]] && operator_namespace="openshift-gitops"
309309
echo ${operator_namespace}
310-
}
310+
}

test/openshift/e2e/ignore-tests/sequential/1-064_validate_tcp_reset_error/03-wait.yaml

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@ commands:
55
- script: |
66
function wait_until_pods_running() {
77
echo -n "Waiting until all pods in namespace $1 are up"
8-
for i in {1..150}; do # timeout after 5 minutes
8+
for i in {1..150}; do # timeout after 5 minutes
99
local pods="$(oc get pods --no-headers -n $1 2>/dev/null)"
10+
# write it to tempfile
11+
TempFile=$(mktemp)
12+
oc get pods --no-headers -n $1 2>/dev/null >$TempFile
13+
1014
# All pods must be running
1115
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
1216
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
1317
local all_ready=1
14-
while read pod ; do
15-
local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`)
18+
while read pod; do
19+
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
1620
# All containers must be ready
1721
[[ -z ${status[0]} ]] && all_ready=0 && break
1822
[[ -z ${status[1]} ]] && all_ready=0 && break
1923
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
2024
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
2125
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
22-
done <<< $(echo "${pods}" | grep -v Completed)
23-
if (( all_ready )); then
26+
done <${TempFile}
27+
if ((all_ready)); then
2428
echo -e "\nAll pods are up:\n${pods}"
2529
return 0
2630
fi

test/openshift/e2e/parallel/1-008_validate-custom-argocd-namespace/02-wait.yaml

+9-5
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@ commands:
55
- script: |
66
function wait_until_pods_running() {
77
echo -n "Waiting until all pods in namespace $1 are up"
8-
for i in {1..150}; do # timeout after 5 minutes
8+
for i in {1..150}; do # timeout after 5 minutes
99
local pods="$(oc get pods --no-headers -n $1 2>/dev/null)"
10+
# write it to tempfile
11+
TempFile=$(mktemp)
12+
oc get pods --no-headers -n $1 2>/dev/null >$TempFile
13+
1014
# All pods must be running
1115
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
1216
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
1317
local all_ready=1
14-
while read pod ; do
15-
local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`)
18+
while read pod; do
19+
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
1620
# All containers must be ready
1721
[[ -z ${status[0]} ]] && all_ready=0 && break
1822
[[ -z ${status[1]} ]] && all_ready=0 && break
1923
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
2024
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
2125
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
22-
done <<< $(echo "${pods}" | grep -v Completed)
23-
if (( all_ready )); then
26+
done <${TempFile}
27+
if ((all_ready)); then
2428
echo -e "\nAll pods are up:\n${pods}"
2529
return 0
2630
fi

test/openshift/e2e/parallel/1-025-validate-managed-by-change/02-wait.yaml

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ commands:
44
- script: |
55
function wait_until_pods_running() {
66
echo -n "Waiting until all pods in namespace $1 are up"
7-
for i in {1..150}; do # timeout after 5 minutes
7+
for i in {1..150}; do # timeout after 5 minutes
88
local pods="$(oc get pods --no-headers -n $1 2>/dev/null)"
9+
# write it to tempfile
10+
TempFile=$(mktemp)
11+
oc get pods --no-headers -n $1 2>/dev/null >$TempFile
12+
913
# All pods must be running
1014
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
1115
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
1216
local all_ready=1
13-
while read pod ; do
14-
local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`)
17+
while read pod; do
18+
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
1519
# All containers must be ready
1620
[[ -z ${status[0]} ]] && all_ready=0 && break
1721
[[ -z ${status[1]} ]] && all_ready=0 && break
1822
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
1923
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
2024
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
21-
done <<< $(echo "${pods}" | grep -v Completed)
22-
if (( all_ready )); then
25+
done <${TempFile}
26+
if ((all_ready)); then
2327
echo -e "\nAll pods are up:\n${pods}"
2428
return 0
2529
fi
@@ -30,6 +34,6 @@ commands:
3034
echo -e "\n\nERROR: timeout waiting for pods to come up\n${pods}"
3135
return 1
3236
}
33-
37+
3438
wait_until_pods_running "test-1-25-argo1"
3539
wait_until_pods_running "test-1-25-argo2"

test/openshift/e2e/parallel/1-030_validate_reencrypt/02-wait.yaml

+10-6
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ commands:
44
- script: |
55
function wait_until_pods_running() {
66
echo -n "Waiting until all pods in namespace $1 are up"
7-
for i in {1..150}; do # timeout after 5 minutes
7+
for i in {1..150}; do # timeout after 5 minutes
88
local pods="$(oc get pods --no-headers -n $1 2>/dev/null)"
9+
# write it to tempfile
10+
TempFile=$(mktemp)
11+
oc get pods --no-headers -n $1 2>/dev/null >$TempFile
12+
913
# All pods must be running
1014
local not_running=$(echo "${pods}" | grep -v Running | grep -v Completed | wc -l)
1115
if [[ -n "${pods}" && ${not_running} -eq 0 ]]; then
1216
local all_ready=1
13-
while read pod ; do
14-
local status=(`echo -n ${pod} | cut -f2 -d' ' | tr '/' ' '`)
17+
while read pod; do
18+
local status=($(echo ${pod} | cut -f2 -d' ' | tr '/' ' '))
1519
# All containers must be ready
1620
[[ -z ${status[0]} ]] && all_ready=0 && break
1721
[[ -z ${status[1]} ]] && all_ready=0 && break
1822
[[ ${status[0]} -lt 1 ]] && all_ready=0 && break
1923
[[ ${status[1]} -lt 1 ]] && all_ready=0 && break
2024
[[ ${status[0]} -ne ${status[1]} ]] && all_ready=0 && break
21-
done <<< $(echo "${pods}" | grep -v Completed)
22-
if (( all_ready )); then
25+
done <${TempFile}
26+
if ((all_ready)); then
2327
echo -e "\nAll pods are up:\n${pods}"
2428
return 0
2529
fi
@@ -30,5 +34,5 @@ commands:
3034
echo -e "\n\nERROR: timeout waiting for pods to come up\n${pods}"
3135
return 1
3236
}
33-
37+
3438
wait_until_pods_running "test-1-30-argo1"

test/openshift/e2e/parallel/1-043_validate_log_level_format/03-check-loglevel.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ commands:
66
set -e
77
set -o pipefail
88
for wl in deployment/argocd-server deployment/argocd-repo-server statefulset/argocd-application-controller; do
9-
wlCommand=$(oc get -n $NAMESPACE $wl -o jsonpath='{.spec.template.spec.containers[0].command}'| jq -r '.[]' )
9+
wlCommand=$(oc get -n $NAMESPACE $wl -o jsonpath='{.spec.template.spec.containers[0].command}')
1010
level="debug"
1111
format="json"
12-
if ! echo "$wlCommand" | grep -qPz -- "--loglevel\\n$level(\$|\\n)"; then
12+
if ! echo "$wlCommand" | grep -e "\"--loglevel\",\"${level}\""; then
1313
echo "logLevel was not set correctly for $wl"
1414
echo "CWD: $wlCommand"
1515
exit 1
1616
fi
17-
if ! echo "$wlCommand" | grep -qPz -- "--logformat\\n$format(\$|\\n)"; then
17+
if ! echo "$wlCommand" | grep -e "\"--logformat\",\"${format}\""; then
1818
echo "logFormat was not set correctly for $wl"
1919
echo "CWD: $wlCommand"
2020
exit 1

test/openshift/e2e/parallel/1-049_validate_parallelism_limit/02-check-deployment.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ commands:
55
set -e
66
set -o pipefail
77
expected=10
8-
wlCommand=$(oc get -n $NAMESPACE statefulset/argocd-application-controller -o jsonpath='{.spec.template.spec.containers[0].command}'| jq -r '.[]' )
9-
if ! echo "$wlCommand" | grep -qPz -- "--kubectl-parallelism-limit\\n${expected}(\$|\\n)"; then
8+
wlCommand=$(oc get -n $NAMESPACE statefulset/argocd-application-controller -o jsonpath='{.spec.template.spec.containers[0].command}')
9+
if ! echo "$wlCommand" | grep -e "\"--kubectl-parallelism-limit\",\"${expected}\""; then
1010
echo "Incorrect or missing --kubectl-parallelism-limit detected."
1111
echo "$wlCommand"
1212
exit 1

0 commit comments

Comments
 (0)