Skip to content

Commit

Permalink
Fixed switch role check for IDF isolation configuration (sonic-net#19543
Browse files Browse the repository at this point in the history
)

Fixed switch role check for IDF isolation configuration
  • Loading branch information
tjchadaga authored and vvolam committed Sep 11, 2024
1 parent 3a4fcee commit fb8c655
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/sonic-bgpcfgd/bgpcfgd/managers_bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def __init__(self, common_objs, db_name, table_name, peer_type, check_neig_meta)

deps = [
("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/bgp_asn"),
("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/type"),
("CONFIG_DB", swsscommon.CFG_LOOPBACK_INTERFACE_TABLE_NAME, "Loopback0"),
("CONFIG_DB", swsscommon.CFG_BGP_DEVICE_GLOBAL_TABLE_NAME, "tsa_enabled"),
("CONFIG_DB", swsscommon.CFG_BGP_DEVICE_GLOBAL_TABLE_NAME, "idf_isolation_state"),
Expand Down
24 changes: 11 additions & 13 deletions src/sonic-bgpcfgd/bgpcfgd/managers_device_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def __init__(self, common_objs, db, table):
:param common_objs: common object dictionary
:param db: name of the db
:param table: name of the table in the db
"""
self.switch_type = ""
"""
self.switch_role = ""
self.chassis_tsa = ""
self.directory = common_objs['directory']
self.cfg_mgr = common_objs['cfg_mgr']
Expand All @@ -29,8 +29,8 @@ def __init__(self, common_objs, db, table):
self.tsb_template = common_objs['tf'].from_file("bgpd/tsa/bgpd.tsa.unisolate.conf.j2")
self.wcmp_template = common_objs['tf'].from_file("bgpd/wcmp/bgpd.wcmp.conf.j2")
self.idf_isolate_template = common_objs['tf'].from_file("bgpd/idf_isolate/idf_isolate.conf.j2")
self.idf_unisolate_template = common_objs['tf'].from_file("bgpd/idf_isolate/idf_unisolate.conf.j2")
self.directory.subscribe([("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/switch_type"),], self.on_switch_type_change)
self.idf_unisolate_template = common_objs['tf'].from_file("bgpd/idf_isolate/idf_unisolate.conf.j2")
self.directory.subscribe([("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/type"),], self.handle_type_update)
super(DeviceGlobalCfgMgr, self).__init__(
common_objs,
[],
Expand All @@ -48,18 +48,16 @@ def __init__(self, common_objs, db, table):
if not self.directory.path_exist(self.db_name, self.table_name, "idf_isolation_state"):
self.directory.put(self.db_name, self.table_name, "idf_isolation_state", self.IDF_DEFAULTS)

def on_switch_type_change(self):
log_debug("DeviceGlobalCfgMgr:: Switch type update handler")
if self.directory.path_exist("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/switch_type"):
self.switch_type = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]["switch_type"]
log_debug("DeviceGlobalCfgMgr:: Switch type: %s" % self.switch_type)
def handle_type_update(self):
log_debug("DeviceGlobalCfgMgr:: Switch role update handler")
if self.directory.path_exist("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME, "localhost/type"):
self.switch_role = self.directory.get_slot("CONFIG_DB", swsscommon.CFG_DEVICE_METADATA_TABLE_NAME)["localhost"]["type"]
log_debug("DeviceGlobalCfgMgr:: Switch role: %s" % self.switch_role)

def set_handler(self, key, data):
""" Handle device TSA/W-ECMP state change """
log_debug("DeviceGlobalCfgMgr:: set handler")

if self.switch_type:
log_debug("DeviceGlobalCfgMgr:: Switch type: %s" % self.switch_type)
if not data:
log_err("DeviceGlobalCfgMgr:: data is None")
return False
Expand Down Expand Up @@ -259,8 +257,8 @@ def downstream_isolate_unisolate(self, idf_isolation_state):
log_err("IDF: invalid value({}) is provided".format(idf_isolation_state))
return False

if self.switch_type and self.switch_type != "SpineRouter":
log_debug("DeviceGlobalCfgMgr:: Skipping IDF isolation configuration on Switch type: %s" % self.switch_type)
if self.switch_role and self.switch_role != "SpineRouter":
log_debug("DeviceGlobalCfgMgr:: Skipping IDF isolation configuration on %s" % self.switch_role)
return True

cmd = "\n"
Expand Down

0 comments on commit fb8c655

Please sign in to comment.