Fix flaky YANG validation: apply empty patch from file, not stdin pipe#25486
Open
sakshamkhurana21 wants to merge 1 commit into
Open
Conversation
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses intermittent flakiness in YANG validation probes by avoiding config apply-patch /dev/stdin (which can be read as empty under load) and instead applying an empty JSON patch from a file on disk.
Changes:
- Updated YANG validation helpers to write an empty patch (
[]) to/tmpand apply it viaconfig apply-patch <file>. - Applied the same change in both the generic YANG validation helper and the
MultiAsicSonicHost.yang_validate()path.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| tests/common/helpers/yang_utils.py | Switches YANG validation probe from stdin pipe to file-based empty patch application. |
| tests/common/devices/multi_asic.py | Switches Multi-ASIC YANG validation probe from stdin pipe to file-based empty patch application. |
Comment on lines
5
to
9
| YANG_EMPTY_PATCH_FILE = "/tmp/yang_validation_empty_patch.json" | ||
|
|
||
|
|
||
| def run_yang_validation(duthost, stage="validation"): | ||
| """ |
Signed-off-by: sakshamkhurana <sakkhurana@microsoft.com>
4f9c432 to
acd8220
Compare
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Collaborator
|
This PR has backport request for branch(es): 202605. ---Powered by SONiC BuildBot
|
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 of PR
Summary:
Tests that run YANG validation (e.g.
pc/test_lag_member_forwarding) intermittently fail/error withFailed to apply patch due to: Expecting value: line 1 column 1 (char 0). The empty-patch YANG probe pipes its payload viaecho '[]' | sudo config apply-patch /dev/stdin. On the DUT,generic_config_updater/main.pydoesjson.loads(open(path).read())on/dev/stdinas its first operation, with no empty-input guard. Under load the pipe is read back empty (0 bytes) before the data lands, sojson.loads('')raises the error above, before YANG validation even runs. This replaces the pipe with a durable file (config apply-patch <file>), matching the existing race-free convention intests/common/gu_utils.py(apply_patch).Fixes # (no linked issue; flaky-test fix)
Type of change
Back port request
Approach
What is the motivation for this PR?
Intermittent
Expecting value: line 1 column 1 (char 0)failures in the YANG-validation step cause flaky PR failures. It surfaces both in the test body (config_reload->MultiAsicSonicHost.yang_validate) and in teardown (conftest->yang_utils.run_yang_validation). The root cause is reading an empty/dev/stdinpipe, not an actual config/YANG problem.How did you do it?
Replaced
echo '[]' | sudo config apply-patch /dev/stdinwith a durable file at both probe sites (tests/common/devices/multi_asic.py::yang_validateandtests/common/helpers/yang_utils.py::run_yang_validation): copy[]to/tmp/yang_validation_empty_patch.json, runsudo config apply-patch <file>, then remove it. A file on disk always contains[], so the empty-read race is structurally impossible. This mirrors thegu_utils.apply_patchpattern already used throughout the repo.How did you verify/test it?
printf '' | sudo config apply-patch /dev/stdin) yields the exact error (rc=2,Expecting value: line 1 column 1 (char 0)); the file-based form returnsrc=0 Patch applied successfully./dev/stdin.test_lag_member_forwarding_packets[vlab-03]with the patched framework: green; all probes read the file.flake8clean (120-char CI limit).Any platform specific information?
None
Supported testbed topology if it's a new test case?
N/A
Documentation
No documentation changes required.