Skip to content

Commit d8b392c

Browse files
committed
chore(ci): fix rsync interference & droute re-enable (#2414)
1 parent f7e04c3 commit d8b392c

File tree

1 file changed

+84
-11
lines changed

1 file changed

+84
-11
lines changed

.ibm/pipelines/utils.sh

+84-11
Original file line numberDiff line numberDiff line change
@@ -95,26 +95,42 @@ droute_send() {
9595
.targets.reportportal.processing.tfa.auto_finalization_threshold = ($auto_finalization_treshold | tonumber)
9696
' data_router/data_router_metadata_template.json > "${ARTIFACT_DIR}/${project}/${metadata_output}"
9797

98-
oc rsync --progress=true --include="${metadata_output}" --include="${JUNIT_RESULTS}" --exclude="*" -n "${droute_project}" "${ARTIFACT_DIR}/${project}/" "${droute_project}/${droute_pod_name}:${temp_droute}/"
98+
# Send test by rsync to bastion pod.
99+
local max_attempts=5
100+
local wait_seconds=4
101+
for ((i = 1; i <= max_attempts; i++)); do
102+
echo "Attempt ${i} of ${max_attempts} to rsync test resuls to bastion pod."
103+
if output=$(oc rsync --progress=true --include="${metadata_output}" --include="${JUNIT_RESULTS}" --exclude="*" -n "${droute_project}" "${ARTIFACT_DIR}/${project}/" "${droute_project}/${droute_pod_name}:${temp_droute}/" 2>&1); then
104+
echo "$output"
105+
break
106+
fi
107+
if ((i == max_attempts)); then
108+
echo "Failed to rsync test results after ${max_attempts} attempts."
109+
echo "Last rsync error details:"
110+
echo "${output}"
111+
echo "Troubleshooting steps:"
112+
echo "1. Restart $droute_pod_name in $droute_project project/namespace"
113+
fi
114+
done
99115

100116
# "Install" Data Router
101117
oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "
102-
curl -fsSLk -o /tmp/droute-linux-amd64 'https://${DATA_ROUTER_NEXUS_HOSTNAME}/nexus/repository/dno-raw/droute-client/${droute_version}/droute-linux-amd64' \
103-
&& chmod +x /tmp/droute-linux-amd64 \
104-
&& /tmp/droute-linux-amd64 version"
118+
curl -fsSLk -o ${temp_droute}/droute-linux-amd64 'https://${DATA_ROUTER_NEXUS_HOSTNAME}/nexus/repository/dno-raw/droute-client/${droute_version}/droute-linux-amd64' \
119+
&& chmod +x ${temp_droute}/droute-linux-amd64 \
120+
&& ${temp_droute}/droute-linux-amd64 version"
105121

106122
# Send test results through DataRouter and save the request ID.
107123
local max_attempts=5
108124
local wait_seconds=1
109125
for ((i = 1; i <= max_attempts; i++)); do
110126
echo "Attempt ${i} of ${max_attempts} to send test results through Data Router."
111127
if output=$(oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "
112-
/tmp/droute-linux-amd64 send --metadata ${temp_droute}/${metadata_output} \
113-
--url '${DATA_ROUTER_URL}' \
114-
--username '${DATA_ROUTER_USERNAME}' \
115-
--password '${DATA_ROUTER_PASSWORD}' \
116-
--results '${temp_droute}/${JUNIT_RESULTS}' \
117-
--verbose" 2>&1); then
128+
${temp_droute}/droute-linux-amd64 send --metadata ${temp_droute}/${metadata_output} \
129+
--url '${DATA_ROUTER_URL}' \
130+
--username '${DATA_ROUTER_USERNAME}' \
131+
--password '${DATA_ROUTER_PASSWORD}' \
132+
--results '${temp_droute}/${JUNIT_RESULTS}' \
133+
--verbose" 2>&1); then
118134
if DATA_ROUTER_REQUEST_ID=$(echo "$output" | grep "request:" | awk '{print $2}') &&
119135
[ -n "$DATA_ROUTER_REQUEST_ID" ]; then
120136
echo "Test results successfully sent through Data Router."
@@ -133,12 +149,69 @@ droute_send() {
133149
echo "3. Ask for help at Slack: #forum-dno-datarouter"
134150
fi
135151
done
136-
152+
153+
# shellcheck disable=SC2317
154+
if [[ "$JOB_NAME" == *periodic-* ]]; then
155+
local max_attempts=30
156+
local wait_seconds=2
157+
set +e
158+
for ((i = 1; i <= max_attempts; i++)); do
159+
# Get DataRouter request information.
160+
DATA_ROUTER_REQUEST_OUTPUT=$(oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "
161+
${temp_droute}/droute-linux-amd64 request get \
162+
--url ${DATA_ROUTER_URL} \
163+
--username ${DATA_ROUTER_USERNAME} \
164+
--password ${DATA_ROUTER_PASSWORD} \
165+
${DATA_ROUTER_REQUEST_ID}")
166+
# Try to extract the ReportPortal launch URL from the request. This fails if it doesn't contain the launch URL.
167+
REPORTPORTAL_LAUNCH_URL=$(echo "$DATA_ROUTER_REQUEST_OUTPUT" | yq e '.targets[0].events[] | select(.component == "reportportal-connector") | .message | fromjson | .[0].launch_url' -)
168+
if [[ -n "$REPORTPORTAL_LAUNCH_URL" ]]; then
169+
reportportal_slack_alert $release_name $REPORTPORTAL_LAUNCH_URL
170+
return 0
171+
else
172+
echo "Attempt ${i} of ${max_attempts}: ReportPortal launch URL not ready yet."
173+
sleep "${wait_seconds}"
174+
fi
175+
done
176+
set -e
177+
fi
137178
oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "rm -rf ${temp_droute}/*"
138179
if [ -n "${PULL_NUMBER:-}" ]; then
139180
set -e
140181
fi
141182
) # Close subshell
142183
rm -f "$temp_kubeconfig" # Destroy temporary KUBECONFIG
143184
oc whoami --show-server
185+
}
186+
187+
reportportal_slack_alert() {
188+
local release_name=$1
189+
local reportportal_launch_url=$2
190+
191+
if [[ "$release_name" == *rbac* ]]; then
192+
RUN_TYPE="rbac-nightly"
193+
else
194+
RUN_TYPE="nightly"
195+
fi
196+
if [[ ${RESULT} -eq 0 ]]; then
197+
RUN_STATUS_EMOJI=":done-circle-check:"
198+
RUN_STATUS="passed"
199+
else
200+
RUN_STATUS_EMOJI=":failed:"
201+
RUN_STATUS="failed"
202+
fi
203+
jq -n \
204+
--arg run_status "$RUN_STATUS" \
205+
--arg run_type "$RUN_TYPE" \
206+
--arg reportportal_launch_url "$reportportal_launch_url" \
207+
--arg job_name "$JOB_NAME" \
208+
--arg run_status_emoji "$RUN_STATUS_EMOJI" \
209+
'{
210+
"RUN_STATUS": $run_status,
211+
"RUN_TYPE": $run_type,
212+
"REPORTPORTAL_LAUNCH_URL": $reportportal_launch_url,
213+
"JOB_NAME": $job_name,
214+
"RUN_STATUS_EMOJI": $run_status_emoji
215+
}' > /tmp/data_router_slack_message.json
216+
curl -X POST -H 'Content-type: application/json' --data @/tmp/data_router_slack_message.json $SLACK_DATA_ROUTER_WEBHOOK_URL
144217
}

0 commit comments

Comments
 (0)