Skip to content

Commit

Permalink
[config] Add unit tests for 'config interface breakout' command (soni…
Browse files Browse the repository at this point in the history
…c-net#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]>
  • Loading branch information
Praveen Chaudhary authored and anand-kumar-subramanian committed Mar 2, 2021
1 parent 8f2dfd2 commit 297bbb7
Show file tree
Hide file tree
Showing 2 changed files with 673 additions and 3 deletions.
7 changes: 4 additions & 3 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ def synchronous_mode(sync_mode):
config reload -y \n
2. systemctl restart swss
"""

if sync_mode == 'enable' or sync_mode == 'disable':
config_db = ConfigDBConnector()
config_db.connect()
Expand Down Expand Up @@ -2440,12 +2440,12 @@ def breakout(ctx, interface_name, mode, verbose, force_remove_dependencies, load
portJson = dict(); portJson['PORT'] = port_dict

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

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

except Exception as e:
click.secho("Failed to break out Port. Error: {}".format(str(e)), fg='magenta')

sys.exit(0)

def _get_all_mgmtinterface_keys():
Expand Down
Loading

0 comments on commit 297bbb7

Please sign in to comment.