Skip to content

Commit 9d3194c

Browse files
zjswhhhqiluo-msft
authored andcommitted
Avoid write_standby in warm restart context (#11283)
Avoid write_standby in warm restart context. sign-off: Jing Zhang [email protected] 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.
1 parent 0bf0133 commit 9d3194c

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

files/scripts/write_standby.py

+29-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import time
44

55
from sonic_py_common import logger as log
6-
from swsscommon.swsscommon import ConfigDBConnector, DBConnector, FieldValuePairs, ProducerStateTable, SonicV2Connector
7-
from swsscommon.swsscommon import APPL_DB
6+
from swsscommon.swsscommon import ConfigDBConnector, DBConnector, FieldValuePairs, ProducerStateTable, SonicV2Connector, Table
7+
from swsscommon.swsscommon import APPL_DB, STATE_DB
88

99
logger = log.Logger('write_standby')
1010

@@ -22,6 +22,7 @@ class MuxStateWriter(object):
2222
def __init__(self):
2323
self.config_db_connector = None
2424
self.appl_db_connector = None
25+
self.state_db_connector = None
2526
self.asic_db_connector = None
2627

2728
@property
@@ -45,6 +46,16 @@ def appl_db(self):
4546
if self.appl_db_connector is None:
4647
self.appl_db_connector = DBConnector(APPL_DB, REDIS_SOCK_PATH, True)
4748
return self.appl_db_connector
49+
50+
@property
51+
def state_db(self):
52+
"""
53+
Returns the state DB connector.
54+
Intializes the connector during the first call
55+
"""
56+
if self.state_db_connector is None:
57+
self.state_db_connector = DBConnector(STATE_DB, REDIS_SOCK_PATH, True)
58+
return self.state_db_connector
4859

4960
@property
5061
def asic_db(self):
@@ -75,6 +86,16 @@ def is_dualtor(self):
7586

7687
return 'subtype' in metadata and 'dualtor' in metadata['subtype'].lower()
7788

89+
@property
90+
def is_warmrestart(self):
91+
"""
92+
Checks if a warmrestart is going on
93+
"""
94+
tbl = Table(self.state_db, 'WARM_RESTART_ENABLE_TABLE')
95+
(status, value) = tbl.hget('system', 'enable')
96+
97+
return status and value == 'true'
98+
7899
def get_auto_mux_intfs(self):
79100
"""
80101
Returns a list of all mux cable interfaces that are configured to auto-switch
@@ -117,6 +138,12 @@ def apply_mux_config(self):
117138
if not self.is_dualtor:
118139
# If not running on a dual ToR system, take no action
119140
return
141+
142+
if self.is_warmrestart:
143+
# If in warmrestart context, take no action
144+
logger.log_warning("Skip setting mux state due to ongoing warmrestart.")
145+
return
146+
120147
intfs = self.get_auto_mux_intfs()
121148
state = 'standby'
122149
if self.wait_for_tunnel():

0 commit comments

Comments
 (0)