Skip to content

[test] Fix test_sub_port_intf assuming exactly one VRF in ASIC_DB#4340

Merged
prsunny merged 2 commits intosonic-net:masterfrom
rustiqly:fix-sub-port-intf-vrf-assert
Mar 17, 2026
Merged

[test] Fix test_sub_port_intf assuming exactly one VRF in ASIC_DB#4340
prsunny merged 2 commits intosonic-net:masterfrom
rustiqly:fix-sub-port-intf-vrf-assert

Conversation

@rustiqly
Copy link
Copy Markdown
Contributor

Description of PR

Fix test_sub_port_intf tests 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:

AssertionError: Wrong # of default vrfs: 2, expected #: 1.
assert 2 == 1
  +  where 2 = len(('oid:0x3000000000022', 'oid:0x30000000006c0'))

This blocks unrelated PRs across repos (sairedis, swss, etc.) because the vstest harness runs these tests.

Changes

  1. get_default_vrf_oid(): 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.
  2. connect_dbs(): Track initial_vrf_count at setup time.
  3. wait_for_n_keys calls: Replace hardcoded 1/2 with self.initial_vrf_count / self.initial_vrf_count + 1.

Motivation

Fixes: #2365

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>
@rustiqly rustiqly requested a review from prsunny as a code owner March 14, 2026 17:07
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_ID from the ASIC switch object (with a fallback path).
  • Capture initial_vrf_count during 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]
Copy link
Copy Markdown
Collaborator

@prsunny prsunny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good fix, lgtm

@prsunny
Copy link
Copy Markdown
Collaborator

prsunny commented Mar 16, 2026

@prabhataravind for viz

@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@prsunny prsunny merged commit 99dd8ff into sonic-net:master Mar 17, 2026
19 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[VS] All subport tests are consistently failing

4 participants