Skip to content

hostcfgd: fix mgmtVrfEnabled state caching causing unnecessary interface restarts#400

Open
xhinhellhx wants to merge 1 commit into
sonic-net:masterfrom
xhinhellhx:bugfix/management-teardown
Open

hostcfgd: fix mgmtVrfEnabled state caching causing unnecessary interface restarts#400
xhinhellhx wants to merge 1 commit into
sonic-net:masterfrom
xhinhellhx:bugfix/management-teardown

Conversation

@xhinhellhx

Copy link
Copy Markdown

Problem Summary

Executing config load -y repeatedly on a SONiC switch causes unexpected SSH session teardowns. The management interface would be reconfigured on every configuration load even when no actual configuration changes were made.

Symptoms

  • SSH sessions to the switch device are terminated unexpectedly during config load -y operations
  • The interfaces-config service restarts unnecessarily on every config load
  • Management connectivity instability during configuration operations

Root Cause

The MgmtIfaceCfg.load() method in hostcfgd was incorrectly retrieving the mgmtVrfEnabled value from the top level of the mgmt_vrf dictionary:

self.mgmt_vrf_enabled = mgmt_vrf.get('mgmtVrfEnabled', '')

However, the actual data structure passed from HostConfigDaemon.load() is a full table dict keyed by row name, following the YANG model for sonic-mgmt_vrf. This means the correct way to read the value is:

mgmt_vrf.get('vrf_global', {}).get('mgmtVrfEnabled', '')

Impact

The internal cache (self.mgmt_vrf_enabled) was always initialized to '' (empty string)
update_mgmt_vrf() would compare the actual value ('true' or 'false') against ''
This resulted in a "state change" detection interfaces-config service would be restarted on every config load, disrupting network connectivity.

Full changes description

  • Fixed the retrieval logic in MgmtIfaceCfg.load() to properly access the nested vrf_global row
  • Added a regression test (test_mgmtvrf_no_restart_on_same_state) that verifies:
    • Correct initialization of mgmt_vrf_enabled from the nested structure;
    • No service restart is triggered when the VRF state hasn't changed;
  • Updated the existing test (test_mgmtvrf_route_check_failed) to use the correct nested dictionary structure.

Evidence (system logs)

1. hostcfgd detects VRF state change and restarts interfaces-config

2026 Jun 19 13:01:39.121253 device-**** DEBUG hostcfgd: MgmtIfaceCfg: mgmt vrf state update
2026 Jun 19 13:01:39.121312 device-**** INFO hostcfgd: Set mgmt vrf state true

2. interfaces-config service is stopped (causing network disruption)

2026 Jun 19 13:01:39.150709 device-****INFO systemd[1]: interfaces-config.service: Deactivated successfully.
2026 Jun 19 13:01:39.151148 device-**** INFO systemd[1]: Stopped interfaces-config.service - Update interfaces configuration.
2026 Jun 19 13:01:39.151354 device-**** INFO systemd[1]: Stopping interfaces-config.service - Update interfaces configuration...

3. Management interface goes down (eth0)

2026 Jun 19 13:01:40.783461 device-**** INFO bgp#pimd[45]: [W6DJA-XRCK3] PIM INTERFACE DOWN: on interface mgmt: link down
2026 Jun 19 13:01:41.549599 device-**** INFO kernel: [ 4758.942832] igb 0000:02:00.0 eth0: igb: eth0 NIC Link is Up 1000 Mbps Full Duplex

4. Network services restart causing connectivity loss

2026 Jun 19 13:01:40.390748 device-**** INFO systemd[1]: Stopping networking.service - Network initialization...
2026 Jun 19 13:01:40.952964 device-**** INFO systemd[1]: networking.service: Deactivated successfully.
2026 Jun 19 13:01:40.953374 device-**** INFO systemd[1]: Stopped networking.service - Network initialization.
2026 Jun 19 13:01:40.983539 device-**** INFO systemd[1]: Starting networking.service - Network initialization...

…obal` table

The `MgmtIfaceCfg.load()` method was incorrectly reading `mgmtVrfEnabled`
directly from the top level of the `mgmt_vrf` dict, but the actual data
structure from ConfigDB is a full table dict keyed by row name
(e.g., `{'vrf_global': {'mgmtVrfEnabled': 'true'}}`).

This caused the internal cache to always be initialized to `''` (empty
string), `making update_mgmt_vrf()` detect a state change on
`config load` and unnecessarily restart the interfaces-config service.

The issue was discovered during repetitive execution of `config load -y`,
which caused unexpected SSH session teardowns as the networking stack
was being reconfigured unnecessarily.

Change the retrieval to access the nested `vrf_global` row following
the `sonic-mgmt_vrf` YANG model leaf path:
`/sonic-mgmt_vrf:sonic-mgmt_vrf/MGMT_VRF_CONFIG/vrf_global/mgmtVrfEnabled`

Signed-off-by: Andrew Bezzubtsev <xhinhellhx.sb@icloud.com>
@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 25, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: xhinhellhx / name: Andrew Bezzubtsev (4a8a652)

@mssonicbld

Copy link
Copy Markdown

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown

Hi, there are workflow run(s) waiting for approval, you may be first-time contributor. I will notify maintainers to help approve once PR is approved. Thanks!

---Powered by SONiC BuildBot

@xhinhellhx

Copy link
Copy Markdown
Author

Guys, no volunteers to review that? :)

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