Skip to content

Commit edc0140

Browse files
committed
[write_standby] update write_standby.py script
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. Signed-off-by: Ying Xie <[email protected]>
1 parent b29dda2 commit edc0140

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

files/scripts/write_standby.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,21 @@ def is_warmrestart(self):
9696

9797
return status and value == 'true'
9898

99-
def get_auto_mux_intfs(self):
99+
def get_all_mux_intfs_modes(self):
100100
"""
101-
Returns a list of all mux cable interfaces that are configured to auto-switch
101+
Returns a list of all mux cable interfaces, with suggested modes
102+
Setting mux initial modes is crucial to kick off the statemachines,
103+
have to set the modes for all mux/gRPC ports.
102104
"""
105+
intf_modes = {}
103106
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
107+
for intf, status in all_intfs.items():
108+
state = status['state'].lower()
109+
if state == 'standby':
110+
intf_modes[intf] = 'standby'
111+
elif state in ['active', 'auto', 'manual']:
112+
intf_modes[intf] = 'active'
113+
return intf_modes
107114

108115
def tunnel_exists(self):
109116
"""
@@ -144,14 +151,13 @@ def apply_mux_config(self):
144151
logger.log_warning("Skip setting mux state due to ongoing warmrestart.")
145152
return
146153

147-
intfs = self.get_auto_mux_intfs()
148-
state = 'standby'
154+
modes = self.get_all_mux_intfs_modes()
149155
if self.wait_for_tunnel():
150-
logger.log_warning("Applying {} state to interfaces {}".format(state, intfs))
156+
logger.log_warning("Applying state to interfaces {}".format(modes))
151157
producer_state_table = ProducerStateTable(self.appl_db, 'MUX_CABLE_TABLE')
152-
fvs = create_fvs(state=state)
153158

154-
for intf in intfs:
159+
for intf, state in modes.items():
160+
fvs = create_fvs(state=state)
155161
producer_state_table.set(intf, fvs)
156162
else:
157163
logger.log_error("Timed out waiting for tunnel {}, mux state will not be written".format(self.tunnel_name))

0 commit comments

Comments
 (0)