Skip to content

Commit f288041

Browse files
authored
Add retry port-forward connection and logic to wait until request is populated (#1411)
* Add retry port-forward connection * merge other changes * more small fixes * add sleep
1 parent 2174e9a commit f288041

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

turbinia/e2e/run-e2e-gke.sh

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# - have a GCP disk created that matches the $DISK variable name
1111

1212
set -o posix
13-
set -e
1413

1514
RELEASE="test"
1615
DISK="disk-1"
@@ -59,8 +58,18 @@ echo "Starting GKE e2e test for Turbinia..."
5958
# Forward k8s services
6059
echo "Forwarding Turbinia API k8s $RELEASE service"
6160
kubectl --namespace default port-forward service/$RELEASE-turbinia 8000:8000 > /dev/null 2>&1 &
62-
# Give time before submitting request to service
63-
sleep 5
61+
62+
# Ensure connection is stable before running test
63+
turbinia-client status summary
64+
if [ $? != "0" ]
65+
then
66+
echo "Connection to the Turbinia service failed. Retrying k8s port-forward..."
67+
kubectl --namespace default port-forward service/$RELEASE-turbinia 8000:8000 > /dev/null 2>&1 &
68+
sleep 5
69+
fi
70+
71+
# Exit on any failures after this point
72+
set -e
6473

6574
# List Turbinia config
6675
echo "Listing Turbinia config..."
@@ -70,16 +79,24 @@ turbinia-client config list
7079
echo "Running Turbinia: turbinia-client submit googleclouddisk --project $GCP_PROJECT --zone $GCP_ZONE --disk_name $DISK --request_id $REQUEST_ID"
7180
turbinia-client submit googleclouddisk --project $GCP_PROJECT --zone $GCP_ZONE --disk_name $DISK --request_id $REQUEST_ID
7281

73-
# Wait until request is complete
74-
sleep 5
82+
# Wait until request is received
83+
req=$(turbinia-client status request $REQUEST_ID -j)
84+
while [[ -z "$req" ]]
85+
do
86+
echo "Request $REQUEST_ID is still populating. Sleeping for 5 seconds..."
87+
sleep 5
88+
req=$(turbinia-client status request $REQUEST_ID -j)
89+
done
90+
91+
# Wait until request is complete
7592
req_status=$(turbinia-client status request $REQUEST_ID -j | jq -r '.status')
76-
while [ $req_status = "running" ]
93+
while [[ $req_status = "running" ]]
7794
do
7895
req_status=$(turbinia-client status request $REQUEST_ID -j | jq -r '.status')
7996
if [[ $req_status = "running" ]]
8097
then
81-
echo "Turbinia request $REQUEST_ID is still running. Sleeping for 10 seconds..."
82-
sleep 10
98+
echo "Turbinia request $REQUEST_ID is still running. Sleeping for 180 seconds..."
99+
sleep 180
83100
fi
84101
done
85102

@@ -92,31 +109,31 @@ length=$(echo $task_status | jq '. | length')
92109
# Check if there is a failed Turbinia Task
93110
if [[ $length > 0 ]]
94111
then
95-
echo "A failed Task for Turbinia Request $req has been detected."
112+
echo "A failed Task for Turbinia Request $REQUEST_ID has been detected"
96113
echo "Listing failed Tasks..."
97114
# Grab the Task ID
98115
tasks=$(echo $task_status | jq -r '.[] | .id')
99116
FAILED=1
100-
for t in $tasks
117+
for task in $tasks
101118
do
102-
echo "Failed Task ID: $t"
103-
turbinia-client status task $t
119+
echo "Failed Task ID: $task"
120+
turbinia-client status task $task
104121
done
105122
# Grab Turbinia worker logs from the server pod
106123
server=$(kubectl get pods -o name | grep turbinia-server)
107124
workers=$(echo $task_status | jq -r '.[] | .worker_name')
108-
for w in $workers
125+
for worker in $workers
109126
do
110-
wlogs=$(kubectl exec $server -- find /mnt/turbiniavolume/logs -path "*$w*")
127+
wlogs=$(kubectl exec $server -- find /mnt/turbiniavolume/logs -path "*$worker*")
111128
if [ -n $wlogs ] && [ -n $server ]
112129
then
113-
echo "Grabbing logs for Turbinia worker $w"
130+
echo "Grabbing logs for Turbinia worker $worker"
114131
kubectl exec $server -- cat $wlogs
115132
fi
116133
done
117134
# If no failed Tasks were detected
118135
else
119-
echo "No failed Tasks detected for Turbinia request $req"
136+
echo "No failed Tasks detected for Turbinia request $REQUEST_ID"
120137
fi
121138

122139
# Restore previous Turbinia config
@@ -137,4 +154,4 @@ echo "Turbinia integration tests succeeded!"
137154
echo -n "Ended at "
138155
date -Iseconds
139156

140-
exit 0
157+
exit 0

0 commit comments

Comments
 (0)