PMK-6388: fix bash exit status reporting #400
Open
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ISSUE(S):
https://platform9.atlassian.net/browse/PMK-6388
SUMMARY
Root cause: Error was not reported back correctly.
2023-09-06T17:49:09.0543Z DEBUG Running command https_proxy=http://qcwebproxylb.juniper.net:3128 bash "-c" "grep host_id /etc/pf9/host_id.conf | cut -d '=' -f2"stdout:stderr:grep: /etc/pf9/host_id.conf: No such file or directory
In scenarios when "file is not found", it's expected to receive a non nil error.
When piping commands, the status code reported by
grep
is overwritten by that ofcut
Which leads to a nil
err
& despite of having error handling it fails to gracefully handle it and later panics with nil pointer dereference due to emptyhostID
insideAuthorizeHost
function.Suggested fix:
use
&&
instead of|
operator to achieve same behavior with correct exit status.ISSUE TYPE
IMPACTED FEATURES/COMPONENTS:
prepNode
RELATED ISSUE(S):
DEPENDS ON:
TESTING DONE
Automated
Manual
Reviewers
Summary by Bito
Fixed a bug in command pipeline error handling by replacing the pipe operator (|) with logical AND (&&) when reading host_id from /etc/pf9/host_id.conf. This change ensures proper error reporting from grep commands and prevents potential nil pointer dereference panics.Unit tests added: False
Estimated effort to review (1-5, lower is better): 1