Skip to content

Commit 4ad9eee

Browse files
yxiecaskbarista
authored andcommitted
[write_standby] update write_standby.py script (sonic-net#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 [email protected]
1 parent a88ba29 commit 4ad9eee

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

files/scripts/write_standby.py

+33-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import argparse
34
import time
45

56
from sonic_py_common import logger as log
@@ -19,11 +20,13 @@ class MuxStateWriter(object):
1920
Class used to write standby mux state to APP DB
2021
"""
2122

22-
def __init__(self):
23+
def __init__(self, activeactive, activestandby):
2324
self.config_db_connector = None
2425
self.appl_db_connector = None
2526
self.state_db_connector = None
2627
self.asic_db_connector = None
28+
self.default_active_active_state = activeactive
29+
self.default_active_standby_state = activestandby
2730

2831
@property
2932
def config_db(self):
@@ -96,14 +99,25 @@ def is_warmrestart(self):
9699

97100
return status and value == 'true'
98101

99-
def get_auto_mux_intfs(self):
102+
def get_all_mux_intfs_modes(self):
100103
"""
101-
Returns a list of all mux cable interfaces that are configured to auto-switch
104+
Returns a list of all mux cable interfaces, with suggested modes
105+
Setting mux initial modes is crucial to kick off the statemachines,
106+
have to set the modes for all mux/gRPC ports.
102107
"""
108+
intf_modes = {}
103109
all_intfs = self.config_db.get_table('MUX_CABLE')
104-
auto_intfs = [intf for intf, status in all_intfs.items()
105-
if status['state'].lower() == 'auto']
106-
return auto_intfs
110+
for intf, status in all_intfs.items():
111+
state = status['state'].lower()
112+
if state in ['active', 'standby']:
113+
intf_modes[intf] = state
114+
elif state in ['auto', 'manual']:
115+
if ('soc_ipv4' in status or 'soc_ipv6' in status or
116+
('cable_type' in status and status['cable_type'] == 'active-active')):
117+
intf_modes[intf] = self.default_active_active_state
118+
else:
119+
intf_modes[intf] = self.default_active_standby_state
120+
return intf_modes
107121

108122
def tunnel_exists(self):
109123
"""
@@ -144,19 +158,26 @@ def apply_mux_config(self):
144158
logger.log_warning("Skip setting mux state due to ongoing warmrestart.")
145159
return
146160

147-
intfs = self.get_auto_mux_intfs()
148-
state = 'standby'
161+
modes = self.get_all_mux_intfs_modes()
149162
if self.wait_for_tunnel():
150-
logger.log_warning("Applying {} state to interfaces {}".format(state, intfs))
163+
logger.log_warning("Applying state to interfaces {}".format(modes))
151164
producer_state_table = ProducerStateTable(self.appl_db, 'MUX_CABLE_TABLE')
152-
fvs = create_fvs(state=state)
153165

154-
for intf in intfs:
166+
for intf, state in modes.items():
167+
fvs = create_fvs(state=state)
155168
producer_state_table.set(intf, fvs)
156169
else:
157170
logger.log_error("Timed out waiting for tunnel {}, mux state will not be written".format(self.tunnel_name))
158171

159172

160173
if __name__ == '__main__':
161-
mux_writer = MuxStateWriter()
174+
parser = argparse.ArgumentParser(description='Write initial mux state')
175+
parser.add_argument('-a', '--active_active',
176+
help='state: intial state for "auto" and/or "manual" config in active-active mode, default "active"',
177+
type=str, required=False, default='active')
178+
parser.add_argument('-s', '--active_standby',
179+
help='state: intial state for "auto" and/or "manual" config in active-standby mode, default "standby"',
180+
type=str, required=False, default='standby')
181+
args = parser.parse_args()
182+
mux_writer = MuxStateWriter(activeactive=args.active_active, activestandby=args.active_standby)
162183
mux_writer.apply_mux_config()

0 commit comments

Comments
 (0)