Skip to content

Commit b4bf4ac

Browse files
committed
[mux] skip mux operations during warm shutdown (#11937)
* [mux] skip mux operations during warm shutdown - Enhance write_standby.py script to skip actions during warm shutdown. - Expand the support to BGP service. - MuX support was added by a previous PR. - don't skip action during warm recovery Signed-off-by: Ying Xie <[email protected]>
1 parent 67d9acd commit b4bf4ac

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

files/build_templates/per_namespace/bgp.service.j2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ User={{ sonicadmin_user }}
1515
ExecStartPre=/usr/local/bin/{{docker_container_name}}.sh start{% if multi_instance == 'true' %} %i{% endif %}
1616
ExecStart=/usr/local/bin/{{docker_container_name}}.sh wait{% if multi_instance == 'true' %} %i{% endif %}
1717
ExecStop=/usr/local/bin/{{docker_container_name}}.sh stop{% if multi_instance == 'true' %} %i{% endif %}
18-
ExecStopPost=/usr/local/bin/write_standby.py
18+
ExecStopPost=/usr/local/bin/write_standby.py --shutdown bgp
1919

2020
RestartSec=30
2121

files/scripts/write_standby.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ class MuxStateWriter(object):
2020
Class used to write standby mux state to APP DB
2121
"""
2222

23-
def __init__(self, activeactive, activestandby):
23+
def __init__(self, activeactive, activestandby, shutdown_module):
2424
self.config_db_connector = None
2525
self.appl_db_connector = None
2626
self.state_db_connector = None
2727
self.asic_db_connector = None
2828
self.default_active_active_state = activeactive
2929
self.default_active_standby_state = activestandby
30+
self.shutdown_module = shutdown_module
31+
self.is_shutdwon = (self.shutdown_module != None)
3032

3133
@property
3234
def config_db(self):
@@ -97,7 +99,15 @@ def is_warmrestart(self):
9799
tbl = Table(self.state_db, 'WARM_RESTART_ENABLE_TABLE')
98100
(status, value) = tbl.hget('system', 'enable')
99101

100-
return status and value == 'true'
102+
if status and value == 'true':
103+
return True
104+
105+
if self.shutdown_module:
106+
(status, value) = tbl.hget(self.shutdown_module, 'enable')
107+
if status and value == 'true':
108+
return True
109+
110+
return False
101111

102112
def get_all_mux_intfs_modes(self):
103113
"""
@@ -153,7 +163,7 @@ def apply_mux_config(self):
153163
# If not running on a dual ToR system, take no action
154164
return
155165

156-
if self.is_warmrestart:
166+
if self.is_warmrestart and self.is_shutdwon:
157167
# If in warmrestart context, take no action
158168
logger.log_warning("Skip setting mux state due to ongoing warmrestart.")
159169
return
@@ -178,12 +188,12 @@ def apply_mux_config(self):
178188
parser.add_argument('-s', '--active_standby',
179189
help='state: intial state for "auto" and/or "manual" config in active-standby mode, default "standby"',
180190
type=str, required=False, default='standby')
181-
parser.add_argument('--shutdown', help='write mux state after shutdown other services, supported: mux',
182-
type=str, required=False, choices=['mux'])
191+
parser.add_argument('--shutdown', help='write mux state after shutdown other services, supported: mux, bgp',
192+
type=str, required=False, choices=['mux', 'bgp'], default=None)
183193
args = parser.parse_args()
184194
active_active_state = args.active_active
185195
active_standby_state = args.active_standby
186-
if args.shutdown == 'mux':
196+
if args.shutdown in ['mux', 'bgp']:
187197
active_active_state = "standby"
188-
mux_writer = MuxStateWriter(activeactive=active_active_state, activestandby=active_standby_state)
198+
mux_writer = MuxStateWriter(activeactive=active_active_state, activestandby=active_standby_state, shutdown_module=args.shutdown)
189199
mux_writer.apply_mux_config()

0 commit comments

Comments
 (0)