Skip to content

Commit b6221f4

Browse files
author
Praveen Chaudhary
authored
[config] Add unit tests for 'config interface breakout' command (#1223)
Consideration for sonic utilities breakout config tests: -- create a breakout config file, -- mock load_configMgmt() to return specially constructed configMgmtDPB instance. -- Device info get_ path*__file function should return default file so it should be mocked. -- config db must have breakout config table. -- mock get child ports to return interfaces, if needed. -- mock shut down interfaces, if needed. *Test Plan:* *>>> Test _get_ breakout options()* -- create a file breakout config. This can be a PY test fixture. -- mock device information part to return breakout file. -- pass argument incomplete as below and observe the results: a.) 1x1 b.) 4x c.) 2x d.) Wrong interface. *>> Test Verbose Args:* Pass verbose as args, and observe that loadConfigMgmt is called with verbose. *>> Test breakout_extra_table_warning Args:* Test breakout_extra_table_warning for breakout port. Add unknown_table to config with port which will be broken out Observe: Warning and ask User confirmation for the tables WithOut Yang models. *>>> Test Negative case: Test negative case of breakout port. Such as: Wrong Interface, wrong option and Wrong breakout Mode for DPB Command. *>>> Test below Config Breakout commands:* [Mock loadConfigMgmt and device info part for all below tests] [Load a fixed config in Data Tree, i.e. may not be same as configDB from mockTables] [Replace the configDB.json with test config if needed. Or correct configDB then use it. Also replace it at the end with original Config] [Note: we are testing only main.py part not config_mgmt.py] [Observe point for all below will be: a.) Click.echo part and b.) Update to BRK_CFG table in in-memory DB] # Ethernet8: start from 4x25G-->2x50G with -f -l sudo config interface breakout Ethernet8 2x50G -f -l # Ethernet8: move from 2x50G-->1x100G without force, list deps sudo config interface breakout Ethernet8 1x100G[40G] -f -l # Ethernet8: move from 2x50G-->1x100G with force, where deps exists sudo config interface breakout Ethernet8 1x100G[40G] -f # Ethernet8: move from 1x100G-->4x25G without force, no deps sudo config interface breakout Ethernet8 4x25G # Ethernet8: move from 4x25G-->1x100G with force, no deps sudo config interface breakout Ethernet8 1x100G -f # Ethernet8: move from 1x100G-->1x50G(2)+2x25G(2) with -f -l, sudo config interface breakout Ethernet8 1x50G(2)+2x25G(2) -f -l # Ethernet4: breakout from 4x25G to 2x50G with -f -l sudo config interface breakout Ethernet4 2x50G -f -l Signed-off-by: Praveen Chaudhary<[email protected]>
1 parent 150642e commit b6221f4

File tree

2 files changed

+673
-3
lines changed

2 files changed

+673
-3
lines changed

config/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ def synchronous_mode(sync_mode):
12581258
config reload -y \n
12591259
2. systemctl restart swss
12601260
"""
1261-
1261+
12621262
if sync_mode == 'enable' or sync_mode == 'disable':
12631263
config_db = ConfigDBConnector()
12641264
config_db.connect()
@@ -2352,12 +2352,12 @@ def breakout(ctx, interface_name, mode, verbose, force_remove_dependencies, load
23522352
portJson = dict(); portJson['PORT'] = port_dict
23532353

23542354
# breakout_Ports will abort operation on failure, So no need to check return
2355-
breakout_Ports(cm, delPorts=final_delPorts, portJson=portJson, force=force_remove_dependencies,
2355+
breakout_Ports(cm, delPorts=final_delPorts, portJson=portJson, force=force_remove_dependencies,
23562356
loadDefConfig=load_predefined_config, verbose=verbose)
23572357

23582358
# Set Current Breakout mode in config DB
23592359
brkout_cfg_keys = config_db.get_keys('BREAKOUT_CFG')
2360-
if interface_name.decode("utf-8") not in brkout_cfg_keys:
2360+
if interface_name not in brkout_cfg_keys:
23612361
click.secho("[ERROR] {} is not present in 'BREAKOUT_CFG' Table!".format(interface_name), fg='red')
23622362
raise click.Abort()
23632363
config_db.set_entry("BREAKOUT_CFG", interface_name, {'brkout_mode': target_brkout_mode})
@@ -2367,6 +2367,7 @@ def breakout(ctx, interface_name, mode, verbose, force_remove_dependencies, load
23672367

23682368
except Exception as e:
23692369
click.secho("Failed to break out Port. Error: {}".format(str(e)), fg='magenta')
2370+
23702371
sys.exit(0)
23712372

23722373
def _get_all_mgmtinterface_keys():

0 commit comments

Comments
 (0)