Skip to content

fix(conftest): always regenerate pre-test config snapshot from live CONFIG_DB#24660

Open
rookie-who wants to merge 1 commit into
sonic-net:masterfrom
rookie-who:fix/config-db-check-stale-snapshot
Open

fix(conftest): always regenerate pre-test config snapshot from live CONFIG_DB#24660
rookie-who wants to merge 1 commit into
sonic-net:masterfrom
rookie-who:fix/config-db-check-stale-snapshot

Conversation

@rookie-who
Copy link
Copy Markdown
Contributor

Description

The config_db_check sanity checker in conftest.py uses running_golden_config.json as the pre-test CONFIG_DB baseline. Previously, this file was only generated if it didn't already exist on the DUT (created once during test_pretest), which meant it could become stale across test runs.

Daemon-written fields get added to CONFIG_DB at runtime after config reload / load_minigraph:

  • BGP_NEIGHBOR|*/admin_status: up — written by bgpcfgd when default_bgp_status: down is set in DEVICE_METADATA
  • DEVICE_METADATA|localhost/zebra_nexthop: disabled — written by zebra config logic

When the cached pre-test snapshot was created before these daemons finished writing, the post-test snapshot includes these fields but the pre-test snapshot does not, causing a spurious config_db_check_failed: True.

Fix

Always regenerate running_golden_config.json from live CONFIG_DB (sonic-cfggen -d --print-data) before each test. This ensures the pre-test baseline reflects the fully-converged state including all daemon-injected fields.

Affected tests

Fixes flaky config_db_check failures observed in:

  • override_config_table/test_override_config_table.py::test_load_minigraph_with_golden_config
  • Potentially other tests that trigger config reload with daemon-injected CONFIG_DB fields

Risk

Low — this only changes when the snapshot file is regenerated (always vs. only-if-missing). The snapshot content is identical when daemons have converged. This also benefits the recovery system (recover.py) which uses the same file for config_reload(config_source="running_golden_config"), ensuring recovery uses an up-to-date baseline.

…ONFIG_DB

The config_db_check sanity checker uses running_golden_config.json as
the pre-test baseline. Previously, this file was only generated if it
didn't already exist on the DUT, which meant it could become stale.

Daemon-written fields like BGP_NEIGHBOR admin_status (from bgpcfgd when
default_bgp_status is set) and DEVICE_METADATA zebra_nexthop get added
to CONFIG_DB at runtime but may not be in a cached snapshot. This causes
spurious config_db_check failures when the post-test snapshot includes
these daemon-injected fields but the stale pre-test snapshot does not.

Fix by always regenerating the snapshot from live CONFIG_DB via
sonic-cfggen before each test. This ensures the pre-test baseline
reflects the fully-converged state including all daemon-written fields.

Fixes flaky failures in tests like:
  test_load_minigraph_with_golden_config (override_config_table)

Signed-off-by: rookie-who <rookie-who@users.noreply.github.com>
@mssonicbld
Copy link
Copy Markdown
Collaborator

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 1 pipeline(s).

@rookie-who rookie-who marked this pull request as ready for review May 15, 2026 18:44
@vaibhavhd vaibhavhd requested a review from rimunagala May 15, 2026 18:47
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.

2 participants