Fixing the lexical error Hello-world test#2509
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughThe Changesrun_curl response parsing
Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4fabd917-9871-463f-91d8-71e5570d176b
📒 Files selected for processing (1)
tests/e2e/collections/ansible_collections/e2e/tests/roles/run_curl/tasks/main.yml
4b694b7 to
e654414
Compare
| echo "BODY_BASE64: $response"; | ||
| exit 0; | ||
| else | ||
| echo "BODY_BASE64: $response"; |
There was a problem hiding this comment.
Picky: only the exit 0 / exit 1 needs to be within the if/else clauses. Move the echo to before the if, as it is identical in both cases.
There was a problem hiding this comment.
I have not changed the if/else block much here. I am leaving the original way as it is.
| fi | ||
| ' | ||
| tmp_file=$(mktemp); | ||
| code=$(curl -s -w "%{http_code}" -o "$tmp_file" "{{ run_curl_address }}"); |
There was a problem hiding this comment.
I like the single call to curl. That's a good improvement.
| ' | ||
| tmp_file=$(mktemp); | ||
| code=$(curl -s -w "%{http_code}" -o "$tmp_file" "{{ run_curl_address }}"); | ||
| response=$(base64 < "$tmp_file" | tr -d "\n"); |
There was a problem hiding this comment.
This is the crux of the PR, but I'm not convinced it is really required. The PR description mentions nested double quotes, but I see no nesting in the provided example.
Also, the contents of the example don't seem to match what I'd expect as a response from the backend service (it contanis user information in a json, whereas I'd expect a plain message such as Hello, stranger. I am Supreme Cipher (1360c152dd3c).).
Which task is throwing that error? Is it really failing on a curl call?
There was a problem hiding this comment.
It is corrected without base64
| - name: Debug the curl command output | ||
| ansible.builtin.debug: | ||
| msg: "{{ curl_result.stdout }}" | ||
| msg: "{{ (curl_result.stdout | regex_search('BODY_BASE64: (.*)', '\\1') | first) | b64decode }}" |
There was a problem hiding this comment.
This is the only place where you're decoding it from base64. Is run_curl used elsewhere? Could other tests depend / parse the actual output. If so, they'd need to do the decoding, too.
There was a problem hiding this comment.
It is corrected without base64
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 97126738-8060-4333-8e5b-e36378fe907c
📒 Files selected for processing (1)
tests/e2e/collections/ansible_collections/e2e/tests/roles/run_curl/tasks/main.yml
hash-d
left a comment
There was a problem hiding this comment.
lgtm; I worked with Ram and the full suite still runs fine after the changes.
| kubeconfig: "{{ kubeconfig }}" | ||
| pod: curl | ||
| command: >- | ||
| command: > |
There was a problem hiding this comment.
Apparently, this is the main thing that fixes this issue, though we're not sure what the mechanism for that is
| exit 1; | ||
| fi | ||
| response=$(curl -s -w "\n%{http_code}" "{{ run_curl_address }}"); | ||
| code=$(echo "$response" | tail -n 1); |
There was a problem hiding this comment.
Having a single call to curl is definitely an improvement, and not using a tmpfile for that is good, too.
While I was running the E2E tests, I had the follwing error for hello-world module.
Description
Fixes a critical runtime failure in the
run_curlrole where the task fails with anUnknown error(lexical error: invalid character inside string).The failure occurs because ansible task definition contain end of line character in sh location. As of now it has been noticed in s390x.
Changes
Key Changes
curl -s -w "\n%{http_code}" "{{ run_curl_address }}"): Reduces traffic by making exactly one request to the backend. The API response text is captured alongside the 3-digit HTTP status code, which is appended to a brand-new line at the very bottom.tail -n 1): Pipes the combined response string and isolates only the final line to extract the HTTP status code.sed "$ d"): Trims the appended status code line from the stream, safely preserving the original API message body (including any native trailing text or newlines).[ "$code" = "200" ]): Switches the conditional check to a robust string comparison. This protects the shell executor from crashing if network drops cause the status code to return empty.>) to preserve intended script indentation and readability without breaking the Kubernetes command processor array.Testing Triaged
lexical error.Summary by CodeRabbit
BODY: <body>on success and on failure.