From b7fb882d3067f260cb180f48aea0391aeee9055d Mon Sep 17 00:00:00 2001 From: zhangjing Date: Wed, 29 Jun 2022 00:57:04 +0000 Subject: [PATCH 1/2] check warmrestart context --- files/scripts/write_standby.py | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/files/scripts/write_standby.py b/files/scripts/write_standby.py index 53cf5265ec..8b4edbbd28 100755 --- a/files/scripts/write_standby.py +++ b/files/scripts/write_standby.py @@ -3,8 +3,8 @@ import time from sonic_py_common import logger as log -from swsscommon.swsscommon import ConfigDBConnector, DBConnector, FieldValuePairs, ProducerStateTable, SonicV2Connector -from swsscommon.swsscommon import APPL_DB +from swsscommon.swsscommon import ConfigDBConnector, DBConnector, FieldValuePairs, ProducerStateTable, SonicV2Connector, Table +from swsscommon.swsscommon import APPL_DB, STATE_DB logger = log.Logger('write_standby') @@ -22,6 +22,7 @@ class MuxStateWriter(object): def __init__(self): self.config_db_connector = None self.appl_db_connector = None + self.state_db_connector = None self.asic_db_connector = None @property @@ -45,6 +46,16 @@ def appl_db(self): if self.appl_db_connector is None: self.appl_db_connector = DBConnector(APPL_DB, REDIS_SOCK_PATH, True) 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 def asic_db(self): @@ -75,6 +86,16 @@ def is_dualtor(self): 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): """ Returns a list of all mux cable interfaces that are configured to auto-switch @@ -117,6 +138,12 @@ def apply_mux_config(self): if not self.is_dualtor: # If not running on a dual ToR system, take no action return + + if self.is_warmrestart: + # If in warmrestart context, take no action + logger.log_warning("Taking no action due to ongoing warmrestart.") + return + intfs = self.get_auto_mux_intfs() state = 'standby' if self.wait_for_tunnel(): From 18b0cbfa6a417e0959b5df5cb5733cd8b924b4b6 Mon Sep 17 00:00:00 2001 From: zhangjing Date: Wed, 29 Jun 2022 03:21:24 +0000 Subject: [PATCH 2/2] update log wording --- files/scripts/write_standby.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/scripts/write_standby.py b/files/scripts/write_standby.py index 8b4edbbd28..3a41fe58bb 100755 --- a/files/scripts/write_standby.py +++ b/files/scripts/write_standby.py @@ -141,7 +141,7 @@ def apply_mux_config(self): if self.is_warmrestart: # If in warmrestart context, take no action - logger.log_warning("Taking no action due to ongoing warmrestart.") + logger.log_warning("Skip setting mux state due to ongoing warmrestart.") return intfs = self.get_auto_mux_intfs()