Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions scripts/ci_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ set -o pipefail
SECRETS_BASE_PATH="${SECRETS_BASE_PATH:-/var/run/secrets}"
JOB_NAME="assisted-chat-eval-test"

if [[ -n $ASSISTED_CHAT_TEST ]]; then
echo "The variable ASSISTED_CHAT_TEST was proided with the value ${ASSISTED_CHAT_TEST}, using it to create the IMAGE and TAG variables for the template"
else
IMAGE="quay.io/redhat-user-workloads/assisted-installer-tenant/assisted-chat-test-image-saas-main/assisted-chat-test-image-saas-main"
echo "The variable ASSISTED_CHAT_TEST was not provieded, downloading the latest image from ${IMAGE}"
ASSISTED_CHAT_TEST="${IMAGE}:latest"
fi

if ! oc get secret -n "$NAMESPACE" assisted-chat-ssl-ci &>/dev/null; then
echo "Creating assisted-chat-ssl-ci secret in namespace $NAMESPACE"
oc create secret generic -n "$NAMESPACE" assisted-chat-ssl-ci --from-file=client_id="${SECRETS_BASE_PATH}/sso-ci/client_id" \
Expand Down Expand Up @@ -39,21 +47,15 @@ while [ $ELAPSED -lt $TIMEOUT ]; do
JOB_FAILED=$(oc get job "$JOB_NAME" -n "$NAMESPACE" -o=jsonpath='{.status.failed}' 2>/dev/null)

if [[ "$JOB_SUCCEEDED" -gt 0 ]]; then
echo "Pod ${POD_NAME} is successfully completed, exiting"
oc logs -n "$NAMESPACE" "$POD_NAME"
echo "The evaluation test were successful. The logs of the tests are stored in the directory artifacts/eval-test/gather-extra/artifacts/pods/ in the logs of the pod ${POD_NAME}."
exit 0
fi

if [[ "$JOB_FAILED" -gt 0 ]]; then
echo "Pod ${POD_NAME} is Failed, exiting"
oc logs -n "$NAMESPACE" "$POD_NAME"
ASSISTED_CHAT_POD=$(oc get pods -n "$NAMESPACE" | tr -s ' ' | cut -d ' ' -f1 | grep -v assisted-chat-eval-test | grep assisted-chat)
echo "oc logs -n \"$NAMESPACE\" \"$ASSISTED_CHAT_POD\""
oc logs -n "$NAMESPACE" "$ASSISTED_CHAT_POD"
echo "The evaluation tests failed, you can see the logs of the pods under the directory artifacts/eval-test/gather-extra/artifacts/pods/."
echo "oc events"
oc events -n "$NAMESPACE"
echo "oc describe pod -n \"$NAMESPACE\" \"$ASSISTED_CHAT_POD\""
oc describe pod -n "$NAMESPACE" "$ASSISTED_CHAT_POD"
exit "$(oc get pod "$POD_NAME" -n "$NAMESPACE" -o=jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}')"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

❓ Verification inconclusive

Exit code retrieval can be empty; provide a safe fallback.

Avoid “numeric argument required” if the jsonpath yields empty.

-        exit "$(oc get pod "$POD_NAME" -n "$NAMESPACE" -o=jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}')"
+        EC="$(oc get pod "$POD_NAME" -n "$NAMESPACE" -o=jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}' 2>/dev/null || true)"
+        [[ -n "${EC:-}" ]] || EC=1
+        exit "$EC"

Use a safe fallback exit code to prevent “numeric argument required”
Shell’s exit "" fails when the JSONPath returns empty; capture the exit code with a default of 1:

-        exit "$(oc get pod "$POD_NAME" -n "$NAMESPACE" -o=jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}')"
+        EC="$(oc get pod "$POD_NAME" -n "$NAMESPACE" -o=jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}' 2>/dev/null || true)"
+        [[ -n "${EC}" ]] || EC=1
+        exit "$EC"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
exit "$(oc get pod "$POD_NAME" -n "$NAMESPACE" -o=jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}')"
EC="$(oc get pod "$POD_NAME" -n "$NAMESPACE" -o=jsonpath='{.status.containerStatuses[0].lastState.terminated.exitCode}' 2>/dev/null || true)"
[[ -n "${EC}" ]] || EC=1
exit "$EC"
🤖 Prompt for AI Agents
In scripts/ci_test.sh around line 82, the script directly exits with the command
substitution which can produce an empty string and cause “numeric argument
required”; capture the pod container exit code into a variable by running the oc
jsonpath command and then exit using that variable with a safe default of 1
(e.g. use shell parameter expansion so if the captured value is empty the script
exits with 1).

fi

Expand All @@ -62,7 +64,6 @@ while [ $ELAPSED -lt $TIMEOUT ]; do
ELAPSED=$((ELAPSED + 1))
done

oc logs -n "$NAMESPACE" "$POD_NAME"

echo "Timeout reached. Pod $POD_NAME did not become ready in time."
echo "Timeout reached. Pod $POD_NAME did not become ready in time. PLease check the logs of the pods under the directory artifacts/eval-test/gather-extra/artifacts/pods/."
exit 1
24 changes: 12 additions & 12 deletions scripts/deploy_template.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ SECRETS_BASE_PATH="${SECRETS_BASE_PATH:-/var/run/secrets}"
#$ASSISTED_CHAT_IMG is not in repo/image:tag format but rather in repo/<image name>@sha256:<digest>
#The template needs the tag, and it references the image by <image name>:<tag> so splitting the variable by ":" works for now

echo "$ASSISTED_CHAT_IMG"
IMAGE=$(echo "$ASSISTED_CHAT_IMG" | cut -d ":" -f1)
TAG=$(echo "$ASSISTED_CHAT_IMG" | cut -d ":" -f2)
if [[ -n $ASSISTED_CHAT_IMG ]]; then
echo "The variable ASSISTED_CHAT_IMG was proided with the value ${ASSISTED_CHAT_IMG}, using it to create the IMAGE and TAG variables for the template"
IMAGE=$(echo "$ASSISTED_CHAT_IMG" | cut -d ":" -f1)
TAG=$(echo "$ASSISTED_CHAT_IMG" | cut -d ":" -f2)
else
IMAGE="quay.io/redhat-services-prod/assisted-installer-tenant/saas/assisted-chat"
echo "The variable ASSISTED_CHAT_IMG was not provieded, downloading the latest image from ${IMAGE}"
TAG="latest"
fi

# What secrets have we got?
ls -laR "$SECRETS_BASE_PATH"
Expand Down Expand Up @@ -81,13 +87,7 @@ oc process \
oc apply -n "$NAMESPACE" -f -

sleep 5
if ! oc rollout status -n $NAMESPACE deployment/assisted-chat --timeout=300s; then
echo "Deploying assisted-chat failed"
ASSISTED_CHAT_POD=$(oc get pods -n "$NAMESPACE" | tr -s ' ' | cut -d ' ' -f1 | grep assisted-chat)
echo "The logs of the pod ${ASSISTED_CHAT_POD}"
oc logs -n $NAMESPACE "$ASSISTED_CHAT_POD"
echo "The events in the namespace '${NAMESPACE}'"
oc events -n $NAMESPACE
echo "oc describe pod ${ASSISTED_CHAT_POD}"
oc describe pod $ASSISTED_CHAT_POD
if ! oc rollout status -n $NAMESPACE deployment/assisted-chat --timeout=300s; then
echo "Deploying assisted-chat failed, the logs of the pods are in artifacts/eval-test/gather-extra/artifacts/pods/ directory."
exit 1
fi