Skip to content

Commit

Permalink
[config/main.py]: Filter table from input config while config validat…
Browse files Browse the repository at this point in the history
…ion\DPB.

Changes:
-- Filter table, which does not impact Back-End, from input config
   while config validation or while Dynamic Port Breakout(DPB).
-- Ask for confirmation from user while DPB, only when deleted ports
   exists in extra tables[i.e in tables without YANG].
-- Test for filter Table.
-- Filter BREAKOUT_CFG table while DPB, because back-end does not process
   BREAKOUT_CFG table.

Signed-off-by: Praveen Chaudhary pchaudhary@linkedin.com
  • Loading branch information
Praveen Chaudhary committed Mar 3, 2021
1 parent e555ea9 commit 4d6bdc6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
22 changes: 20 additions & 2 deletions config/config_mgmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,24 @@ def sysLog(self, logLevel=syslog.LOG_INFO, msg=None, doPrint=False):

return

def _filterTablesInConfig(self, config):
"""
Check if any table should not be considered in Input Config, remove
such table from Input Config.
Parameters:
config(dict): Input Config
Returns:
void
"""
# nonConfigTables should not be considered in Input Config.
nonConfigTables = ['BREAKOUT_CFG']
for t in nonConfigTables:
if t in config.keys():
self.sysLog(msg='Filtering {}'.format(t))
del config[t]

return

def readConfigDBJson(self, source=CONFIG_DB_JSON_FILE):
'''
Read the config from a Config File.
Expand All @@ -172,7 +190,7 @@ def readConfigDBJson(self, source=CONFIG_DB_JSON_FILE):
if not self.configdbJsonIn:
raise Exception("Can not load config from config DB json file")
self.sysLog(msg='Reading Input {}'.format(self.configdbJsonIn))

self._filterTablesInConfig(self.configdbJsonIn)
return

"""
Expand All @@ -197,7 +215,7 @@ def readConfigDB(self):
self.configdbJsonIn = FormatConverter.to_serialized(data)
self.sysLog(syslog.LOG_DEBUG, 'Reading Input from ConfigDB {}'.\
format(self.configdbJsonIn))

self._filterTablesInConfig(self.configdbJsonIn)
return

def writeConfigDB(self, jDiff):
Expand Down
17 changes: 11 additions & 6 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,12 +186,18 @@ def breakout_warnUser_extraTables(cm, final_delPorts, confirm=True):
try:
# check if any extra tables exist
eTables = cm.tablesWithOutYang()
if len(eTables):
# find relavent tables in extra tables, i.e. one which can have deleted
# ports
tables = cm.configWithKeys(configIn=eTables, keys=final_delPorts)
if len(eTables) == 0:
return
# let user know that extra tables exist in config
click.secho("Below Table(s) can not be verified using YANG models:")
click.secho("{}".format(eTables.keys()))
# find relavent tables in extra tables, i.e. one which can have deleted
# ports
tables = cm.configWithKeys(configIn=eTables, keys=final_delPorts)
if len(tables):
click.secho("Below Config can not be verified, It may cause harm "\
"to the system\n {}".format(json.dumps(tables, indent=2)))
"to the system:\n{}".format(json.dumps(tables, indent=2)))
# Need to confirm if extra Tables have any deleted ports.
click.confirm('Do you wish to Continue?', abort=True)
except Exception as e:
raise Exception("Failed in breakout_warnUser_extraTables. Error: {}".format(str(e)))
Expand Down Expand Up @@ -698,7 +704,6 @@ def _restart_services():
click.echo("Enabling container monitoring ...")
clicommon.run_command("sudo monit monitor container_checker")


def interface_is_in_vlan(vlan_member_table, interface_name):
""" Check if an interface is in a vlan """
for _, intf in vlan_member_table:
Expand Down
24 changes: 24 additions & 0 deletions tests/config_mgmt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,30 @@ def test_break_out(self):
self.dpb_port4_4x25G_2x50G_f_l(curConfig)
return

def test_extra_brk_cfg_tables_cases(self):
# make sure no prompt with BREAKOUT_CFG
curConfig = dict(configDbJson)
brk_cfg = {
"BREAKOUT_CFG": {
"Ethernet0": {
"brkout_mode": "1x100G[40G]"
}
}
}
self.updateConfig(curConfig, brk_cfg)
prevLen = len(curConfig)
cm = self.config_mgmt_dpb(curConfig)
# Assert BREAKOUT_CFG is removed from Input Config
assert (len(cm.configdbJsonIn) == prevLen-1) and \
'BREAKOUT_CFG' not in cm.configdbJsonIn.keys()
# Test by direct Call
prevLen = len(curConfig)
cm._filterTablesInConfig(curConfig)
assert (len(curConfig) == prevLen-1) and \
'BREAKOUT_CFG' not in curConfig.keys()

return

def tearDown(self):
try:
os.remove(config_mgmt.CONFIG_DB_JSON_FILE)
Expand Down

0 comments on commit 4d6bdc6

Please sign in to comment.