Skip to content

Commit 8f18aa0

Browse files
authored
chore(ci): fix rsync interference & droute re-enable (#2414)
* Fix droute might interfere between PR check and nightly * Reporting in function * Fix status * rsync with retries * Re-enable droute fail on error * Fix metedata var * Add condition * Resolve review comments
1 parent 6816e51 commit 8f18aa0

File tree

1 file changed

+67
-40
lines changed

1 file changed

+67
-40
lines changed

.ibm/pipelines/utils.sh

+67-40
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ droute_send() {
3939
if [[ "${OPENSHIFT_CI}" != "true" ]]; then return 0; fi
4040
temp_kubeconfig=$(mktemp) # Create temporary KUBECONFIG to open second `oc` session
4141
( # Open subshell
42-
set +e
42+
if [ -n "${PULL_NUMBER:-}" ]; then
43+
set +e
44+
fi
4345
export KUBECONFIG="$temp_kubeconfig"
4446
local droute_version="1.2.2"
4547
local release_name=$1
@@ -93,26 +95,42 @@ droute_send() {
9395
.targets.reportportal.processing.tfa.auto_finalization_threshold = ($auto_finalization_treshold | tonumber)
9496
' data_router/data_router_metadata_template.json > "${ARTIFACT_DIR}/${project}/${metadata_output}"
9597

96-
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
97115

98116
# "Install" Data Router
99117
oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "
100-
curl -fsSLk -o /tmp/droute-linux-amd64 'https://${DATA_ROUTER_NEXUS_HOSTNAME}/nexus/repository/dno-raw/droute-client/${droute_version}/droute-linux-amd64' \
101-
&& chmod +x /tmp/droute-linux-amd64 \
102-
&& /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"
103121

104122
# Send test results through DataRouter and save the request ID.
105123
local max_attempts=5
106124
local wait_seconds=1
107125
for ((i = 1; i <= max_attempts; i++)); do
108126
echo "Attempt ${i} of ${max_attempts} to send test results through Data Router."
109127
if output=$(oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "
110-
/tmp/droute-linux-amd64 send --metadata ${temp_droute}/${metadata_output} \
111-
--url '${DATA_ROUTER_URL}' \
112-
--username '${DATA_ROUTER_USERNAME}' \
113-
--password '${DATA_ROUTER_PASSWORD}' \
114-
--results '${temp_droute}/${JUNIT_RESULTS}' \
115-
--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
116134
if DATA_ROUTER_REQUEST_ID=$(echo "$output" | grep "request:" | awk '{print $2}') &&
117135
[ -n "$DATA_ROUTER_REQUEST_ID" ]; then
118136
echo "Test results successfully sent through Data Router."
@@ -140,40 +158,15 @@ droute_send() {
140158
for ((i = 1; i <= max_attempts; i++)); do
141159
# Get DataRouter request information.
142160
DATA_ROUTER_REQUEST_OUTPUT=$(oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "
143-
/tmp/droute-linux-amd64 request get \
161+
${temp_droute}/droute-linux-amd64 request get \
144162
--url ${DATA_ROUTER_URL} \
145163
--username ${DATA_ROUTER_USERNAME} \
146164
--password ${DATA_ROUTER_PASSWORD} \
147165
${DATA_ROUTER_REQUEST_ID}")
148166
# Try to extract the ReportPortal launch URL from the request. This fails if it doesn't contain the launch URL.
149167
REPORTPORTAL_LAUNCH_URL=$(echo "$DATA_ROUTER_REQUEST_OUTPUT" | yq e '.targets[0].events[] | select(.component == "reportportal-connector") | .message | fromjson | .[0].launch_url' -)
150-
if [[ $? -eq 0 ]]; then
151-
if [[ "$release_name" == *rbac* ]]; then
152-
RUN_TYPE="rbac-nightly"
153-
else
154-
RUN_TYPE="nightly"
155-
fi
156-
if [[ ${PIPESTATUS[0]} -eq 0 ]]; then
157-
RUN_STATUS_EMOJI=":done-circle-check:"
158-
RUN_STATUS="passed"
159-
else
160-
RUN_STATUS_EMOJI=":failed:"
161-
RUN_STATUS="failed"
162-
fi
163-
jq -n \
164-
--arg run_status "$RUN_STATUS" \
165-
--arg run_type "$RUN_TYPE" \
166-
--arg reportportal_launch_url "$REPORTPORTAL_LAUNCH_URL" \
167-
--arg job_name "$JOB_NAME" \
168-
--arg run_status_emoji "$RUN_STATUS_EMOJI" \
169-
'{
170-
"RUN_STATUS": $run_status,
171-
"RUN_TYPE": $run_type,
172-
"REPORTPORTAL_LAUNCH_URL": $reportportal_launch_url,
173-
"JOB_NAME": $job_name,
174-
"RUN_STATUS_EMOJI": $run_status_emoji
175-
}' > /tmp/data_router_slack_message.json
176-
curl -X POST -H 'Content-type: application/json' --data @/tmp/data_router_slack_message.json $SLACK_DATA_ROUTER_WEBHOOK_URL
168+
if [[ -n "$REPORTPORTAL_LAUNCH_URL" ]]; then
169+
reportportal_slack_alert $release_name $REPORTPORTAL_LAUNCH_URL
177170
return 0
178171
else
179172
echo "Attempt ${i} of ${max_attempts}: ReportPortal launch URL not ready yet."
@@ -183,12 +176,46 @@ droute_send() {
183176
set -e
184177
fi
185178
oc exec -n "${droute_project}" "${droute_pod_name}" -- /bin/bash -c "rm -rf ${temp_droute}/*"
186-
set -e
179+
if [ -n "${PULL_NUMBER:-}" ]; then
180+
set -e
181+
fi
187182
) # Close subshell
188183
rm -f "$temp_kubeconfig" # Destroy temporary KUBECONFIG
189184
oc whoami --show-server
190185
}
191186

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
217+
}
218+
192219
# Merge the base YAML value file with the differences file for Kubernetes
193220
yq_merge_value_files() {
194221
local base_file=$1

0 commit comments

Comments
 (0)