Skip to content

Commit

Permalink
Modifying ClassName and adding Func^Con to warn user about extra tables
Browse files Browse the repository at this point in the history
Signed-off-by: Sangita Maity <sangitamaity0211@gmail.com>
  • Loading branch information
samaity committed May 14, 2020
1 parent 2646959 commit 8410e7d
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import ipaddress
from swsssdk import ConfigDBConnector, SonicV2Connector, SonicDBConfig
from minigraph import parse_device_desc_xml
from config_mgmt import configMgmt
from config_mgmt import ConfigMgmt, ConfigMgmtDPB

import aaa
import mlnx
Expand Down Expand Up @@ -208,17 +208,37 @@ def _validate_interface_mode(ctx, BREAKOUT_CFG_FILE, interface_name, target_brko
sys.exit(0)
return True

def load_configMgmt(verbose):
def load_ConfigMgmt(verbose):
""" Load config for the commands which are capable of change in config DB. """
try:
# TODO: set allowExtraTables to False, i.e we should have yang models for
# each table in Config. [TODO: Create Yang model for each Table]
# cm = configMgmt(debug=verbose, allowExtraTables=False)
cm = configMgmt(debug=verbose, allowExtraTables=True)
cm = ConfigMgmtDPB(debug=verbose)
return cm
except Exception as e:
raise Exception("Failed to load the config. Error: {}".format(str(e)))

"""
Funtion to warn user about extra tables while Dynamic Port Breakout(DPB).
confirm: re-confirm from user to proceed.
Config Tables Without Yang model considered extra tables.
cm = instance of config MGMT class.
"""
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)
click.secho("Below Config can not be verified, It may cause harm "\
"to the system\n {}".format(json.dumps(tables, indent=2)))
click.confirm('Do you wish to Continue?', abort=True)
except Exception as e:
raise Exception("Failed in breakout_warnUser_extraTables. Error: {}".format(str(e)))

return

def breakout_Ports(cm, delPorts=list(), addPorts=list(), portJson=dict(), \
force=False, loadDefConfig=True, verbose=False):

Expand Down Expand Up @@ -2060,11 +2080,14 @@ def breakout(ctx, interface_name, mode, verbose, force_remove_dependencies, load
# Start Interation with Dy Port BreakOut Config Mgmt
try:
""" Load config for the commands which are capable of change in config DB """
cm = load_configMgmt(verbose)
cm = load_ConfigMgmt(verbose)

""" Delete all ports if forced else print dependencies using configMgmt API """
""" Delete all ports if forced else print dependencies using ConfigMgmt API """
final_delPorts = [intf for intf in del_intf_dict.keys()]
""" Add ports with its attributes using configMgmt API """
""" Warn user if tables without yang models exist and have final_delPorts """
breakout_warnUser_extraTables(cm, final_delPorts, confirm=True)
# prompt
""" Add ports with its attributes using ConfigMgmt API """
final_addPorts = [intf for intf in port_dict.keys()]
portJson = dict(); portJson['PORT'] = port_dict
# breakout_Ports will abort operation on failure, So no need to check return
Expand Down

0 comments on commit 8410e7d

Please sign in to comment.