-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Changes to persist TSA/B state across reloads #11257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4d3a4c6
TSA persistence changes for reload
tjchadaga 0ae596f
added unit test code and other fixes
tjchadaga 1c66aba
Timing issue fix
tjchadaga 2481aa7
Fixes
tjchadaga 32772c0
Fixes
tjchadaga b92f4da
yang test files
2209fc0
yang file update
8ebc5b1
Remove bringup dependency
72540ea
Fixed minor issue, addressed review comments
tjchadaga 37dbaf6
Fixed json formatting
tjchadaga 2ed1d5c
Fix flaky unit test
tjchadaga 5f5aa31
Merge branch 'Azure:master' into tsa_reload
tjchadaga ba68869
Minor updates based on comments
tjchadaga File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 | ||
tjchadaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "Please execute 'config save' to preserve System mode in Maintenance after reboot or config reload" | ||
| fi | ||
|
|
||
| /usr/bin/TS TSA | ||
This file contains hidden or 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 | ||
tjchadaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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() | ||
tjchadaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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): | ||
tjchadaga marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.