Skip to content

Commit 8410e7d

Browse files
committed
Modifying ClassName and adding Func^Con to warn user about extra tables
Signed-off-by: Sangita Maity <sangitamaity0211@gmail.com>
1 parent 2646959 commit 8410e7d

1 file changed

Lines changed: 32 additions & 9 deletions

File tree

config/main.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import ipaddress
1515
from swsssdk import ConfigDBConnector, SonicV2Connector, SonicDBConfig
1616
from minigraph import parse_device_desc_xml
17-
from config_mgmt import configMgmt
17+
from config_mgmt import ConfigMgmt, ConfigMgmtDPB
1818

1919
import aaa
2020
import mlnx
@@ -208,17 +208,37 @@ def _validate_interface_mode(ctx, BREAKOUT_CFG_FILE, interface_name, target_brko
208208
sys.exit(0)
209209
return True
210210

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

219+
"""
220+
Funtion to warn user about extra tables while Dynamic Port Breakout(DPB).
221+
confirm: re-confirm from user to proceed.
222+
Config Tables Without Yang model considered extra tables.
223+
cm = instance of config MGMT class.
224+
"""
225+
def breakout_warnUser_extraTables(cm, final_delPorts, confirm=True):
226+
227+
try:
228+
# check if any extra tables exist
229+
eTables = cm.tablesWithOutYang()
230+
if len(eTables):
231+
# find relavent tables in extra tables, i.e. one which can have deleted
232+
# ports
233+
tables = cm.configWithKeys(configIn=eTables, keys=final_delPorts)
234+
click.secho("Below Config can not be verified, It may cause harm "\
235+
"to the system\n {}".format(json.dumps(tables, indent=2)))
236+
click.confirm('Do you wish to Continue?', abort=True)
237+
except Exception as e:
238+
raise Exception("Failed in breakout_warnUser_extraTables. Error: {}".format(str(e)))
239+
240+
return
241+
222242
def breakout_Ports(cm, delPorts=list(), addPorts=list(), portJson=dict(), \
223243
force=False, loadDefConfig=True, verbose=False):
224244

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

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

0 commit comments

Comments
 (0)