Avoid write_standby in warm restart context (#11283)
Avoid write_standby in warm restart context. sign-off: Jing Zhang zhangjing@microsoft.com Why I did it In warm restart context, we should avoid mux state change. How I did it Check warm restart flag before applying changes to app db. How to verify it Ran write_standby in table missing, key missing, field missing scenarios. Did a warm restart, app db changes were skipped. Saw this in syslog: WARNING write_standby: Taking no action due to ongoing warmrestart.
This commit is contained in:
parent
859b4793d2
commit
5d03b5d0df
@ -3,8 +3,8 @@
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from sonic_py_common import logger as log
|
from sonic_py_common import logger as log
|
||||||
from swsscommon.swsscommon import ConfigDBConnector, DBConnector, FieldValuePairs, ProducerStateTable, SonicV2Connector
|
from swsscommon.swsscommon import ConfigDBConnector, DBConnector, FieldValuePairs, ProducerStateTable, SonicV2Connector, Table
|
||||||
from swsscommon.swsscommon import APPL_DB
|
from swsscommon.swsscommon import APPL_DB, STATE_DB
|
||||||
|
|
||||||
logger = log.Logger('write_standby')
|
logger = log.Logger('write_standby')
|
||||||
|
|
||||||
@ -22,6 +22,7 @@ class MuxStateWriter(object):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.config_db_connector = None
|
self.config_db_connector = None
|
||||||
self.appl_db_connector = None
|
self.appl_db_connector = None
|
||||||
|
self.state_db_connector = None
|
||||||
self.asic_db_connector = None
|
self.asic_db_connector = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -46,6 +47,16 @@ class MuxStateWriter(object):
|
|||||||
self.appl_db_connector = DBConnector(APPL_DB, REDIS_SOCK_PATH, True)
|
self.appl_db_connector = DBConnector(APPL_DB, REDIS_SOCK_PATH, True)
|
||||||
return self.appl_db_connector
|
return self.appl_db_connector
|
||||||
|
|
||||||
|
@property
|
||||||
|
def state_db(self):
|
||||||
|
"""
|
||||||
|
Returns the state DB connector.
|
||||||
|
Intializes the connector during the first call
|
||||||
|
"""
|
||||||
|
if self.state_db_connector is None:
|
||||||
|
self.state_db_connector = DBConnector(STATE_DB, REDIS_SOCK_PATH, True)
|
||||||
|
return self.state_db_connector
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def asic_db(self):
|
def asic_db(self):
|
||||||
"""
|
"""
|
||||||
@ -75,6 +86,16 @@ class MuxStateWriter(object):
|
|||||||
|
|
||||||
return 'subtype' in metadata and 'dualtor' in metadata['subtype'].lower()
|
return 'subtype' in metadata and 'dualtor' in metadata['subtype'].lower()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def is_warmrestart(self):
|
||||||
|
"""
|
||||||
|
Checks if a warmrestart is going on
|
||||||
|
"""
|
||||||
|
tbl = Table(self.state_db, 'WARM_RESTART_ENABLE_TABLE')
|
||||||
|
(status, value) = tbl.hget('system', 'enable')
|
||||||
|
|
||||||
|
return status and value == 'true'
|
||||||
|
|
||||||
def get_auto_mux_intfs(self):
|
def get_auto_mux_intfs(self):
|
||||||
"""
|
"""
|
||||||
Returns a list of all mux cable interfaces that are configured to auto-switch
|
Returns a list of all mux cable interfaces that are configured to auto-switch
|
||||||
@ -117,6 +138,12 @@ class MuxStateWriter(object):
|
|||||||
if not self.is_dualtor:
|
if not self.is_dualtor:
|
||||||
# If not running on a dual ToR system, take no action
|
# If not running on a dual ToR system, take no action
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if self.is_warmrestart:
|
||||||
|
# If in warmrestart context, take no action
|
||||||
|
logger.log_warning("Skip setting mux state due to ongoing warmrestart.")
|
||||||
|
return
|
||||||
|
|
||||||
intfs = self.get_auto_mux_intfs()
|
intfs = self.get_auto_mux_intfs()
|
||||||
state = 'standby'
|
state = 'standby'
|
||||||
if self.wait_for_tunnel():
|
if self.wait_for_tunnel():
|
||||||
|
Reference in New Issue
Block a user