From 3df267e252bfd669c52f3221b0a29412a129153d Mon Sep 17 00:00:00 2001 From: Sangita Maity Date: Tue, 19 Jan 2021 16:40:52 -0800 Subject: [PATCH] [config] Fix Breakout mode option and BREAKOUT_CFG table check method (#1270) Made a robust check for below cases: - when the interface is wrong and the mode is correct. - BREAKOUT_CFG table is NOT present in CONFIG DB Also, Fixed Breakout mode option when options are not available for easy readability. Signed-off-by: Sangita Maity --- config/main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/config/main.py b/config/main.py index ea798a1a2e20..5816f02f960c 100644 --- a/config/main.py +++ b/config/main.py @@ -116,7 +116,7 @@ def _get_breakout_options(ctx, args, incomplete): for i in breakout_mode_list.split(','): breakout_mode_options.append(i) all_mode_options = [str(c) for c in breakout_mode_options if incomplete in c] - return all_mode_options + return all_mode_options def shutdown_interfaces(ctx, del_intf_dict): """ shut down all the interfaces before deletion """ @@ -2422,6 +2422,14 @@ def breakout(ctx, interface_name, mode, verbose, force_remove_dependencies, load # Get current breakout mode cur_brkout_dict = config_db.get_table('BREAKOUT_CFG') + if len(cur_brkout_dict) == 0: + click.secho("[ERROR] BREAKOUT_CFG table is NOT present in CONFIG DB", fg='red') + raise click.Abort() + + if interface_name not in cur_brkout_dict.keys(): + click.secho("[ERROR] {} interface is NOT present in BREAKOUT_CFG table of CONFIG DB".format(interface_name), fg='red') + raise click.Abort() + cur_brkout_mode = cur_brkout_dict[interface_name]["brkout_mode"] # Validate Interface and Breakout mode