-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes to persist TSA/B state across reloads (#11257)
- Loading branch information
Showing
12 changed files
with
354 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
#!/bin/bash | ||
|
||
# toggle the mux to standby if dualtor and any mux active | ||
if | ||
[[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype | tr [:upper:] [:lower:])" == *"dualtor"* ]] && | ||
[[ $(show mux status | grep active | wc -l) > 0 ]]; | ||
then | ||
logger -t TSA -p user.info "Toggle all mux mode to standby" | ||
sudo config mux mode standby all | ||
|
||
if [[ "$(sonic-cfggen -d -v BGP_DEVICE_GLOBAL.STATE.tsa_enabled)" == "true" ]]; then | ||
echo "System is already in Maintenance" | ||
logger -t TSA -p user.info "System is already in Maintenance" | ||
else | ||
# toggle the mux to standby if dualtor and any mux active | ||
if | ||
[[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype | tr [:upper:] [:lower:])" == *"dualtor"* ]] && | ||
[[ $(show mux status | grep active | wc -l) > 0 ]]; | ||
then | ||
logger -t TSA -p user.info "Toggle all mux mode to standby" | ||
sudo config mux mode standby all | ||
fi | ||
|
||
/usr/bin/TS TSA | ||
echo "Please execute 'config save' to preserve System mode in Maintenance after reboot or config reload" | ||
fi | ||
|
||
/usr/bin/TS TSA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
#!/bin/bash | ||
|
||
# toggle the mux to auto if dualtor | ||
if [[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype | tr [:upper:] [:lower:])" == *"dualtor"* ]]; | ||
then | ||
logger -t TSB -p user.info "Toggle all mux mode to auto" | ||
sudo config mux mode auto all | ||
if [[ "$(sonic-cfggen -d -v BGP_DEVICE_GLOBAL.STATE.tsa_enabled)" == "false" ]]; then | ||
echo "System is already in Normal mode" | ||
logger -t TSB -p user.info "System is already in Normal mode" | ||
else | ||
# toggle the mux to auto if dualtor | ||
if [[ "$(sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype | tr [:upper:] [:lower:])" == *"dualtor"* ]]; | ||
then | ||
logger -t TSB -p user.info "Toggle all mux mode to auto" | ||
sudo config mux mode auto all | ||
fi | ||
|
||
/usr/bin/TS TSB | ||
echo "Please execute 'config save' to preserve System mode in Normal state after reboot or config reload" | ||
fi | ||
|
||
/usr/bin/TS TSB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
from .manager import Manager | ||
from .log import log_err, log_debug, log_notice | ||
import re | ||
from swsscommon import swsscommon | ||
|
||
class DeviceGlobalCfgMgr(Manager): | ||
"""This class responds to change in device-specific state""" | ||
|
||
def __init__(self, common_objs, db, table): | ||
""" | ||
Initialize the object | ||
:param common_objs: common object dictionary | ||
:param db: name of the db | ||
:param table: name of the table in the db | ||
""" | ||
self.directory = common_objs['directory'] | ||
self.cfg_mgr = common_objs['cfg_mgr'] | ||
self.constants = common_objs['constants'] | ||
self.tsa_template = common_objs['tf'].from_file("bgpd/tsa/bgpd.tsa.isolate.conf.j2") | ||
self.tsb_template = common_objs['tf'].from_file("bgpd/tsa/bgpd.tsa.unisolate.conf.j2") | ||
super(DeviceGlobalCfgMgr, self).__init__( | ||
common_objs, | ||
[], | ||
db, | ||
table, | ||
) | ||
|
||
def set_handler(self, key, data): | ||
log_debug("DeviceGlobalCfgMgr:: set handler") | ||
""" Handle device tsa_enabled state change """ | ||
if not data: | ||
log_err("DeviceGlobalCfgMgr:: data is None") | ||
return False | ||
|
||
if "tsa_enabled" in data: | ||
self.cfg_mgr.commit() | ||
self.cfg_mgr.update() | ||
self.isolate_unisolate_device(data["tsa_enabled"]) | ||
self.directory.put(self.db_name, self.table_name, "tsa_enabled", data["tsa_enabled"]) | ||
return True | ||
return False | ||
|
||
def del_handler(self, key): | ||
log_debug("DeviceGlobalCfgMgr:: del handler") | ||
return True | ||
|
||
def check_state_and_get_tsa_routemaps(self, cfg): | ||
""" API to get TSA route-maps if device is isolated""" | ||
cmd = "" | ||
if self.directory.path_exist("CONFIG_DB", swsscommon.CFG_BGP_DEVICE_GLOBAL_TABLE_NAME, "tsa_enabled"): | ||
tsa_status = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_BGP_DEVICE_GLOBAL_TABLE_NAME)["tsa_enabled"] | ||
if tsa_status == "true": | ||
cmds = cfg.replace("#012", "\n").split("\n") | ||
log_notice("DeviceGlobalCfgMgr:: Device is isolated. Applying TSA route-maps") | ||
cmd = self.get_ts_routemaps(cmds, self.tsa_template) | ||
return cmd | ||
|
||
def isolate_unisolate_device(self, tsa_status): | ||
""" API to get TSA/TSB route-maps and apply configuration""" | ||
cmd = "\n" | ||
if tsa_status == "true": | ||
log_notice("DeviceGlobalCfgMgr:: Device isolated. Executing TSA") | ||
cmd += self.get_ts_routemaps(self.cfg_mgr.get_text(), self.tsa_template) | ||
else: | ||
log_notice("DeviceGlobalCfgMgr:: Device un-isolated. Executing TSB") | ||
cmd += self.get_ts_routemaps(self.cfg_mgr.get_text(), self.tsb_template) | ||
|
||
self.cfg_mgr.push(cmd) | ||
log_debug("DeviceGlobalCfgMgr::Done") | ||
|
||
def get_ts_routemaps(self, cmds, ts_template): | ||
if not cmds: | ||
return "" | ||
|
||
route_map_names = self.__extract_out_route_map_names(cmds) | ||
return self.__generate_routemaps_from_template(route_map_names, ts_template) | ||
|
||
def __generate_routemaps_from_template(self, route_map_names, template): | ||
cmd = "\n" | ||
for rm in sorted(route_map_names): | ||
if "_INTERNAL_" in rm: | ||
continue | ||
if "V4" in rm: | ||
ipv="V4" ; ipp="ip" | ||
elif "V6" in rm: | ||
ipv="V6" ; ipp="ipv6" | ||
else: | ||
continue | ||
cmd += template.render(route_map_name=rm,ip_version=ipv,ip_protocol=ipp, constants=self.constants) | ||
cmd += "\n" | ||
return cmd | ||
|
||
def __extract_out_route_map_names(self, cmds): | ||
route_map_names = set() | ||
out_route_map = re.compile(r'^\s*neighbor \S+ route-map (\S+) out$') | ||
for line in cmds: | ||
result = out_route_map.match(line) | ||
if result: | ||
route_map_names.add(result.group(1)) | ||
return route_map_names | ||
|
33 changes: 33 additions & 0 deletions
33
src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_all_isolate.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
! | ||
! template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
neighbor PEER_V4 peer-group | ||
neighbor PEER_V6 peer-group | ||
address-family ipv4 | ||
neighbor PEER_V4 allowas-in 1 | ||
neighbor PEER_V4 soft-reconfiguration inbound | ||
neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in | ||
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out | ||
exit-address-family | ||
address-family ipv6 | ||
neighbor PEER_V6 allowas-in 1 | ||
neighbor PEER_V6 soft-reconfiguration inbound | ||
neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in | ||
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out | ||
exit-address-family | ||
! | ||
! end of template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
|
||
|
||
route-map TO_BGP_PEER_V4 permit 20 | ||
match ip address prefix-list PL_LoopbackV4 | ||
set community 12345:12345 | ||
route-map TO_BGP_PEER_V4 deny 30 | ||
! | ||
route-map TO_BGP_PEER_V6 permit 20 | ||
match ipv6 address prefix-list PL_LoopbackV6 | ||
set community 12345:12345 | ||
route-map TO_BGP_PEER_V6 deny 30 | ||
! | ||
|
29 changes: 29 additions & 0 deletions
29
src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_all_unisolate.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
! | ||
! template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
neighbor PEER_V4 peer-group | ||
neighbor PEER_V6 peer-group | ||
address-family ipv4 | ||
neighbor PEER_V4 allowas-in 1 | ||
neighbor PEER_V4 soft-reconfiguration inbound | ||
neighbor PEER_V4 route-map FROM_BGP_PEER_V4 in | ||
neighbor PEER_V4 route-map TO_BGP_PEER_V4 out | ||
exit-address-family | ||
address-family ipv6 | ||
neighbor PEER_V6 allowas-in 1 | ||
neighbor PEER_V6 soft-reconfiguration inbound | ||
neighbor PEER_V6 route-map FROM_BGP_PEER_V6 in | ||
neighbor PEER_V6 route-map TO_BGP_PEER_V6 out | ||
exit-address-family | ||
! | ||
! end of template: bgpd/templates/general/peer-group.conf.j2 | ||
! | ||
|
||
|
||
no route-map TO_BGP_PEER_V4 permit 20 | ||
no route-map TO_BGP_PEER_V4 deny 30 | ||
! | ||
no route-map TO_BGP_PEER_V6 permit 20 | ||
no route-map TO_BGP_PEER_V6 deny 30 | ||
! | ||
|
11 changes: 11 additions & 0 deletions
11
src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_isolate.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
route-map TO_BGP_PEER_V4 permit 20 | ||
match ip address prefix-list PL_LoopbackV4 | ||
set community 12345:12345 | ||
route-map TO_BGP_PEER_V4 deny 30 | ||
! | ||
route-map TO_BGP_PEER_V6 permit 20 | ||
match ipv6 address prefix-list PL_LoopbackV6 | ||
set community 12345:12345 | ||
route-map TO_BGP_PEER_V6 deny 30 | ||
! |
7 changes: 7 additions & 0 deletions
7
src/sonic-bgpcfgd/tests/data/general/peer-group.conf/result_unisolate.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
|
||
no route-map TO_BGP_PEER_V4 permit 20 | ||
no route-map TO_BGP_PEER_V4 deny 30 | ||
! | ||
no route-map TO_BGP_PEER_V6 permit 20 | ||
no route-map TO_BGP_PEER_V6 deny 30 | ||
! |
Oops, something went wrong.