[test] Fix test_sub_port_intf assuming exactly one VRF in ASIC_DB#4340
Merged
prsunny merged 2 commits intosonic-net:masterfrom Mar 17, 2026
Merged
[test] Fix test_sub_port_intf assuming exactly one VRF in ASIC_DB#4340prsunny merged 2 commits intosonic-net:masterfrom
prsunny merged 2 commits intosonic-net:masterfrom
Conversation
The test_sub_port_intf tests assume there is exactly one virtual router (the default VRF) in ASIC_DB at startup. This assumption breaks when other features (VRFs, VNETs, loopback-action, or prior tests) create additional virtual routers, causing get_default_vrf_oid() to fail with: AssertionError: Wrong # of default vrfs: 2, expected #: 1. This has been an open issue since July 2022 (sonic-net#2365) and continues to block unrelated PRs across repos. Fix: - Query SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID from the switch object in ASIC_DB to reliably identify the default VRF, regardless of how many virtual routers exist. - Track initial_vrf_count at setup and use relative counts for wait_for_n_keys assertions instead of hardcoded 1/2 values. Fixes: sonic-net#2365 Signed-off-by: Rustiqly <rustiqly@users.noreply.github.com>
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
Updates the VS sub-port interface tests to stop assuming there is exactly one VRF object in ASIC_DB, which has been causing deterministic failures when other features/tests create additional VRFs.
Changes:
- Resolve the default VRF by reading
SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_IDfrom the ASIC switch object (with a fallback path). - Capture
initial_vrf_countduring test DB setup. - Replace hardcoded VRF key-count expectations with
initial_vrf_count-based expectations in relevant test flows.
You can also share your feedback on Copilot code review. Take the survey.
Comment on lines
+398
to
409
| tbl = swsscommon.Table(self.asic_db.db_connection, ASIC_SWITCH_TABLE) | ||
| switch_keys = tbl.getKeys() | ||
| assert len(switch_keys) >= 1, "No switch entry in ASIC_DB" | ||
| (status, fvs) = tbl.get(switch_keys[0]) | ||
| assert status, "Failed to read switch entry from ASIC_DB" | ||
| for fv in fvs: | ||
| if fv[0] == "SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID": | ||
| return fv[1] | ||
| # Fallback: if the attribute is absent, use legacy behaviour | ||
| oids = self.get_oids(ASIC_VIRTUAL_ROUTER_TABLE) | ||
| assert len(oids) == 1, "Wrong # of default vrfs: %d, expected #: 1." % (len(oids)) | ||
| assert len(oids) >= 1, "No virtual routers found in ASIC_DB" | ||
| return oids[0] |
Collaborator
|
@prabhataravind for viz |
Collaborator
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
prajjwal-arista
pushed a commit
to prajjwal-arista/sonic-swss
that referenced
this pull request
Mar 18, 2026
…nic-net#4340) The test_sub_port_intf tests assume there is exactly one virtual router (the default VRF) in ASIC_DB at startup. This assumption breaks when other features (VRFs, VNETs, loopback-action, or prior tests) create additional virtual routers, causing get_default_vrf_oid() to fail with: AssertionError: Wrong # of default vrfs: 2, expected #: 1. This has been an open issue since July 2022 (sonic-net#2365) and continues to block unrelated PRs across repos. Fix: - Query SAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_ID from the switch object in ASIC_DB to reliably identify the default VRF, regardless of how many virtual routers exist. - Track initial_vrf_count at setup and use relative counts for wait_for_n_keys assertions instead of hardcoded 1/2 values. Fixes: sonic-net#2365 Signed-off-by: Rustiqly <rustiqly@users.noreply.github.com>
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
Fix
test_sub_port_intftests that have been consistently failing since July 2022 (#2365).Summary
get_default_vrf_oid()asserts exactly one virtual router exists in ASIC_DB. This fails when other features (VRFs, VNETs, loopback-action) or prior tests create additional virtual routers:This blocks unrelated PRs across repos (sairedis, swss, etc.) because the vstest harness runs these tests.
Changes
get_default_vrf_oid(): QuerySAI_SWITCH_ATTR_DEFAULT_VIRTUAL_ROUTER_IDfrom the switch object in ASIC_DB to reliably identify the default VRF, regardless of how many virtual routers exist.connect_dbs(): Trackinitial_vrf_countat setup time.wait_for_n_keyscalls: Replace hardcoded1/2withself.initial_vrf_count/self.initial_vrf_count + 1.Motivation
Fixes: #2365