platform: fix reversed bytes.Contains arguments in CheckMachine's systemd state check - #920
Draft
AdityaShome wants to merge 2 commits into
Draft
platform: fix reversed bytes.Contains arguments in CheckMachine's systemd state check#920AdityaShome wants to merge 2 commits into
AdityaShome wants to merge 2 commits into
Conversation
…ck and add a test for it Signed-off-by: AdityaShome <shomeaditya65@gmail.com>
There was a problem hiding this comment.
Pull request overview
Fixes the systemd readiness-state parsing in CheckMachine by extracting it into a helper that correctly classifies systemctl is-system-running output, and adds a focused unit test to cover known states plus empty output.
Changes:
- Extracted
systemctl is-system-runningoutput parsing intosystemRunningState, replacing the priorbytes.Containssubstring checks. - Changed polling behavior so empty/unrecognized output stops retrying immediately (matching the existing “degraded stops retrying” behavior).
- Added
TestSystemRunningStatewith subtests, including the empty-output case.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| platform/platform.go | Introduces systemRunningState and uses it in CheckMachine to avoid reversed/unsafe substring matching. |
| platform/platform_test.go | Adds unit tests for state classification, including empty output handling. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+344
to
+346
| // systemRunningState classifies `systemctl is-system-running` output. keep | ||
| // is true while still on the way to "running"; anything else, including | ||
| // empty output, means stop retrying. |
Author
There was a problem hiding this comment.
keep=true doesn't actually mean retries continue. util.Retry stops on any nil return, which happens both when keep=false and when keep=true with state=="running" (success case). Retries only continue when keep=true and err != nil.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
CheckMachinecheckssystemctl is-system-runningoutput against a list of known states, but bothbytes.Contains(b, subslice)calls had their arguments backwards checking "is the state a substring of this literal" instead of "is the state one of these known values." It happened to work today because every real state name is a substring of the literal, but empty SSH output was silently treated as "still starting" instead of as an anomaly.This PR extracts the check into a small
systemRunningStatehelper. Empty or unrecognized output now stops polling immediately, same as "degraded", instead of being silently accepted.How to use
No behavior change for real systemd states check that
platform/platform.go's diff is small and thatsystemRunningStatecovers the same four states the old literal did. Run the test below to see the empty-output case is now handled.Testing done
Not applicable Go source change in
mantle, not an OS image/ebuild change.