[write_standby] update write_standby.py script (#11650)
Why I did it The initial value has to be present for the state machines to work. In active-standby dual-tor scenario, or any hardware mux scenario, the value will be updtaed eventually with a delay. However, in active-active dual-tor scenario, there is no other mechanism to initialize the value and get state machines started. So this script will have to write something at start up time. For active-active dualtor, 'active' is a more preferred initial value, the state machine will switch the state to standby soon if link prober found link not in good state. How I did it Update the script to always provide initial values. How to verify it Tested on active-active dual-tor testbed. Signed-off-by: Ying Xie ying.xie@microsoft.com
This commit is contained in:
parent
c953168a87
commit
a3e3530d1d
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import time
|
||||
|
||||
from sonic_py_common import logger as log
|
||||
@ -19,11 +20,13 @@ class MuxStateWriter(object):
|
||||
Class used to write standby mux state to APP DB
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, activeactive, activestandby):
|
||||
self.config_db_connector = None
|
||||
self.appl_db_connector = None
|
||||
self.state_db_connector = None
|
||||
self.asic_db_connector = None
|
||||
self.default_active_active_state = activeactive
|
||||
self.default_active_standby_state = activestandby
|
||||
|
||||
@property
|
||||
def config_db(self):
|
||||
@ -96,14 +99,25 @@ class MuxStateWriter(object):
|
||||
|
||||
return status and value == 'true'
|
||||
|
||||
def get_auto_mux_intfs(self):
|
||||
def get_all_mux_intfs_modes(self):
|
||||
"""
|
||||
Returns a list of all mux cable interfaces that are configured to auto-switch
|
||||
Returns a list of all mux cable interfaces, with suggested modes
|
||||
Setting mux initial modes is crucial to kick off the statemachines,
|
||||
have to set the modes for all mux/gRPC ports.
|
||||
"""
|
||||
intf_modes = {}
|
||||
all_intfs = self.config_db.get_table('MUX_CABLE')
|
||||
auto_intfs = [intf for intf, status in all_intfs.items()
|
||||
if status['state'].lower() == 'auto']
|
||||
return auto_intfs
|
||||
for intf, status in all_intfs.items():
|
||||
state = status['state'].lower()
|
||||
if state in ['active', 'standby']:
|
||||
intf_modes[intf] = state
|
||||
elif state in ['auto', 'manual']:
|
||||
if ('soc_ipv4' in status or 'soc_ipv6' in status or
|
||||
('cable_type' in status and status['cable_type'] == 'active-active')):
|
||||
intf_modes[intf] = self.default_active_active_state
|
||||
else:
|
||||
intf_modes[intf] = self.default_active_standby_state
|
||||
return intf_modes
|
||||
|
||||
def tunnel_exists(self):
|
||||
"""
|
||||
@ -144,19 +158,26 @@ class MuxStateWriter(object):
|
||||
logger.log_warning("Skip setting mux state due to ongoing warmrestart.")
|
||||
return
|
||||
|
||||
intfs = self.get_auto_mux_intfs()
|
||||
state = 'standby'
|
||||
modes = self.get_all_mux_intfs_modes()
|
||||
if self.wait_for_tunnel():
|
||||
logger.log_warning("Applying {} state to interfaces {}".format(state, intfs))
|
||||
logger.log_warning("Applying state to interfaces {}".format(modes))
|
||||
producer_state_table = ProducerStateTable(self.appl_db, 'MUX_CABLE_TABLE')
|
||||
fvs = create_fvs(state=state)
|
||||
|
||||
for intf in intfs:
|
||||
for intf, state in modes.items():
|
||||
fvs = create_fvs(state=state)
|
||||
producer_state_table.set(intf, fvs)
|
||||
else:
|
||||
logger.log_error("Timed out waiting for tunnel {}, mux state will not be written".format(self.tunnel_name))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
mux_writer = MuxStateWriter()
|
||||
parser = argparse.ArgumentParser(description='Write initial mux state')
|
||||
parser.add_argument('-a', '--active_active',
|
||||
help='state: intial state for "auto" and/or "manual" config in active-active mode, default "active"',
|
||||
type=str, required=False, default='active')
|
||||
parser.add_argument('-s', '--active_standby',
|
||||
help='state: intial state for "auto" and/or "manual" config in active-standby mode, default "standby"',
|
||||
type=str, required=False, default='standby')
|
||||
args = parser.parse_args()
|
||||
mux_writer = MuxStateWriter(activeactive=args.active_active, activestandby=args.active_standby)
|
||||
mux_writer.apply_mux_config()
|
||||
|
Loading…
Reference in New Issue
Block a user