[dut_basic_facts]: resolve real release (YYYYMM) from build_version on unstamped images#26383
Merged
StormLiangMS merged 1 commit intoJul 22, 2026
Conversation
…n unstamped images The `release` fact from dut_basic_facts is consumed by the conditional_mark plugin. On images without /etc/sonic/sonic_release (all VS/KVM and self-built images) the release was guessed from build_version, but the fallback only recognized 201811, 201911 and master. Every other release (202012 ... 202605) collapsed to "unknown" -- even though build_version starts with the release, e.g. "202605.1166406-...". As a result, release-based conditional_mark skips such as `release in ['202605', ...]` silently never fired on VS. Extract the resolution into a pure, unit-testable helper `guess_release_from_build_version()` that keeps an already-stamped release, otherwise extracts a leading YYYYMM token (also resolving old date-stamped images like 20181130.31 -> 201811), maps master, and defaults to unknown. Add colocated pytest coverage (62 cases) for the regex and edge cases. Signed-off-by: Deepak Singhal <deepsinghal@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: bcef2f79-ca22-49b5-b7ca-6c86a46e39d0 Signed-off-by: Deepak Singhal <deepsinghal@microsoft.com>
Collaborator
|
/azp run |
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
|
Azure Pipelines: Successfully started running 1 pipeline(s). |
Collaborator
|
Cherry-pick PR to 202605: #26445 |
12 tasks
Collaborator
|
This PR has backport request label(s) for branch(es): 202605, but is missing required test information. Please make sure you tick the tested branch(es) in the Tested branch section and provide test evidence (e.g., 202605: <test result>) in the Test result section as well in your PR description. ---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:
On images without
/etc/sonic/sonic_release(all VS/KVM and self-built images), thereleasefact produced byansible/library/dut_basic_facts.pyis guessed frombuild_version. The old fallback only recognized201811,201911, andmaster, so every other release (202012…202605) collapsed to"unknown"— even thoughbuild_versionstarts with the release token (e.g.202605.1166406-...).Because the
releasefact is what theconditional_markplugin evaluates, release-based skips such asrelease in ['202605', ...]silently never matched on VS, so tests intended to be skipped there ran anyway. This surfaced while triaging the CI failure on #26270. This PR fixes the fallback soreleaseresolves to the realYYYYMMrelease on unstamped/VS images.Type of change
Back port request
Approach
What is the motivation for this PR?
Make
release-basedconditional_markconditions work correctly on VS/KVM (and any self-built) images. Today they can never match becausereleaseresolves to"unknown"on those images, which makes release-gated skips a silent no-op on VS.How did you do it?
Extracted the release resolution into a pure, dependency-free helper
ansible/module_utils/sonic_release_utils.py::guess_release_from_build_version(): an already-stampedrelease(real HW) is returned unchanged; otherwise a leadingYYYYMMtoken is extracted viare.match(r'(20\d{4})', ...)(202605.1166406-...->202605; old date-stamped20181130.31->201811);masterinbuild_version->master; anything else ->unknown.ansible/library/dut_basic_facts.pynow imports and calls the helper (mirroring the existingparse_utilsimport guard), replacing the hard-coded 201811/201911/master ladder.How did you verify/test it?
Added
ansible/module_utils/test_sonic_release_utils.py— 62 parametrized cases covering all modern releases, old date-stamped images,master, precedence of an already-stamped release, unparseable ->unknown, build-number-not-confused, and a regression guard that202605no longer collapses tounknown:python3 -m pytest --noconftest ansible/module_utils/test_sonic_release_utils.py-> 62 passed.flake8 --max-line-length=120clean;py_compileOK.Any platform specific information?
Only affects the
releasefact derivation for images lacking/etc/sonic/sonic_release(VS/KVM, self-built). Real-HW images that stampreleaseare unchanged. Old-release exclusion lists are unaffected; the intended effect is that current-release skips now correctly fire on VS.Supported testbed topology if it's a new test case?
N/A (framework fix).
Documentation
No.