@@ -1585,21 +1585,42 @@ class MgmtIfaceCfg(object):
15851585 def update_mgmt_iface (self , iface , key , data ):
15861586 """Handle update management interface config
15871587 """
1588- syslog .syslog (syslog .LOG_DEBUG , 'MgmtIfaceCfg: mgmt iface update' )
1588+ syslog .syslog (syslog .LOG_DEBUG , 'TEST-1 MgmtIfaceCfg: Starting interface update' )
15891589
1590- # Restart management interface service when config was changed
1591- if data != self .iface_config_data .get (key ):
1592- cfg = {key : data }
1593- syslog .syslog (syslog .LOG_INFO , f'MgmtIfaceCfg: Set new interface '
1594- f'config { cfg } for { iface } ' )
1595- try :
1596- run_cmd (['sudo' , 'systemctl' , 'restart' , 'interfaces-config' ], True , True )
1597- except subprocess .CalledProcessError :
1598- syslog .syslog (syslog .LOG_ERR , f'Failed to restart management '
1599- 'interface services' )
1600- return
1590+ existing_data = self .iface_config_data .get (key )
16011591
1592+ # Check if data has changed
1593+ if data != existing_data :
1594+ syslog .syslog (syslog .LOG_INFO , f'TEST-2 MgmtIfaceCfg: Updating config for { iface } with { data } ' )
1595+ # Update the interface configuration
16021596 self .iface_config_data [key ] = data
1597+ elif not data :
1598+ # If new data is empty, remove the key if it exists
1599+ if key in self .iface_config_data :
1600+ self .iface_config_data .pop (key )
1601+ syslog .syslog (syslog .LOG_INFO , f'TEST-3 MgmtIfaceCfg: Removed config for { iface } ' )
1602+
1603+ # This entry is created explicitly by sonic-gnmi, but during delete, this entry is not deleted.
1604+ # This causes the interface.j2 to think static ip is still configured
1605+ subprocess .run (['redis-cli' , '-n' , '4' , 'DEL' , f'MGMT_INTERFACE|{ iface } ' , '' , '' ], check = True )
1606+ else :
1607+ syslog .syslog (syslog .LOG_DEBUG , f'TEST-4 MgmtIfaceCfg: No existing config to remove for { iface } ' )
1608+ # No change; no need to restart services
1609+ return
1610+ else :
1611+ # Data hasn't changed; no need to proceed
1612+ syslog .syslog (syslog .LOG_DEBUG , f'TEST-5 MgmtIfaceCfg: No changes detected for { iface } ' )
1613+ return
1614+
1615+ # Restart services after configuration change
1616+ try :
1617+ syslog .syslog (syslog .LOG_INFO , f'TEST-6 MgmtIfaceCfg: Updated:{ self .iface_config_data } ' )
1618+
1619+ run_cmd (['sudo' , 'systemctl' , 'restart' , 'interfaces-config' ], True , True )
1620+
1621+ syslog .syslog (syslog .LOG_INFO , 'TEST-7 MgmtIfaceCfg: Successfully restarted services' )
1622+ except subprocess .CalledProcessError :
1623+ syslog .syslog (syslog .LOG_ERR , 'TEST-8 MgmtIfaceCfg: Failed to restart management interface services' )
16031624
16041625 def update_mgmt_vrf (self , data ):
16051626 """Handle update management VRF state
0 commit comments