From 7e2d955feec2f63e0e130de0c34437057bbb318f Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 12 Sep 2019 00:54:10 +0000 Subject: [PATCH 01/18] Add sub port interface to intfutil status Signed-off-by: Wenda Ni --- scripts/intfutil | 77 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/scripts/intfutil b/scripts/intfutil index f8509db93f..12da00d180 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -24,6 +24,8 @@ PORT_MTU_STATUS = "mtu" PORT_DESCRIPTION = "description" PORT_OPTICS_TYPE = "type" PORT_PFC_ASYM_STATUS = "pfc_asym" +VLAN_SUB_INTERFACE_SEPARATOR = "." +VLAN_SUB_INTERFACE_TYPE = "dot1q-encapsulation" def db_connect_configdb(): """ @@ -43,6 +45,15 @@ def get_frontpanel_port_list(config_db): return front_panel_ports_list +def get_sub_port_intf_list(config_db): + sub_intf_dict = config_db.get_table('VLAN_SUB_INTERFACE') + sub_intf_list = [] + for sub_intf in sub_intf_dict.keys(): + if isinstance(sub_intf, basestring): + sub_intf_list.append(sub_intf) + return sub_intf_list + + def get_interface_vlan_dict(config_db): """ Get info from REDIS ConfigDB and create interface to vlan mapping @@ -93,6 +104,23 @@ def appl_db_keys_get(appl_db, front_panel_ports_list, intf_name): return appl_db_keys +def appl_db_sub_intf_keys_get(appl_db, sub_intf_list, sub_intf_name): + """ + Get APPL_DB sub port interface keys + """ + if sub_intf_name is None: + appl_db_sub_intf_keys = [] + appl_db_intf_keys = appl_db.keys(appl_db.APPL_DB, "INTF_TABLE:*") + for appl_db_intf_key in appl_db_intf_keys: + if re.split(':', appl_db_intf_key, maxsplit=1)[-1].strip() in sub_intf_list: + appl_db_sub_intf_keys.append(appl_db_intf_key) + elif sub_intf_name in sub_intf_list: + appl_db_sub_intf_keys = appl_db.keys(appl_db.APPL_DB, "INTF_TABLE:%s" % sub_intf_name) + else: + return None + return appl_db_sub_intf_keys + + def appl_db_port_status_get(appl_db, intf_name, status_type): """ Get the port status @@ -267,13 +295,41 @@ def appl_db_portchannel_status_get(appl_db, config_db, po_name, status_type, por return "N/A" return status +def appl_db_sub_intf_status_get(appl_db, config_db, front_panel_ports_list, portchannel_speed_dict, sub_intf_name, status_type): + sub_intf_sep_idx = sub_intf_name.find(VLAN_SUB_INTERFACE_SEPARATOR) + if (sub_intf_sep_idx != -1): + parent_port_name = sub_intf_name[:sub_intf_sep_idx] + vlan_id = sub_intf_name[sub_intf_sep_idx + 1:] + + full_intf_table_name = "INTF_TABLE" + ":" + sub_intf_name + + if status_type == "vlan": + return vlan_id + + if status_type == "admin_status": + status = appl_db.get(appl_db.APPL_DB, full_intf_table_name, status_type) + return status if status is not None else "N/A" + + if status_type == "type": + return VLAN_SUB_INTERFACE_TYPE + + if status_type == "mtu" or status_type == "speed": + if parent_port_name in front_panel_ports_list: + return appl_db_port_status_get(appl_db, parent_port_name, status_type) + elif parent_port_name in portchannel_speed_dict.keys(): + return appl_db_portchannel_status_get(appl_db, config_db, parent_port_name, status_type, portchannel_speed_dict) + else: + return "N/A" + + return "N/A" + # ========================== interface-status logic ========================== header_stat = ['Interface', 'Lanes', 'Speed', 'MTU', 'Alias', 'Vlan', 'Oper', 'Admin', 'Type', 'Asym PFC'] class IntfStatus(object): - def display_intf_status(self, appl_db_keys, front_panel_ports_list, portchannel_speed_dict): + def display_intf_status(self, appl_db_keys, front_panel_ports_list, portchannel_speed_dict, appl_db_sub_intf_keys, sub_intf_list): """ Generate interface-status output """ @@ -313,6 +369,20 @@ class IntfStatus(object): appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_OPTICS_TYPE, self.portchannel_speed_dict), appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_PFC_ASYM_STATUS, self.portchannel_speed_dict))) + for key in appl_db_sub_intf_keys: + sub_intf = re.split(':', key, maxsplit=1)[-1].strip() + if sub_intf in sub_intf_list: + table.append((sub_intf, + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_LANES_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_SPEED), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_MTU_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_ALIAS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, "vlan"), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPER_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_ADMIN_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPTICS_TYPE), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_PFC_ASYM_STATUS))) + # Sorting and tabulating the result table. sorted_table = natsorted(table) print tabulate(sorted_table, header_stat, tablefmt="simple", stralign='right') @@ -344,9 +414,12 @@ class IntfStatus(object): self.combined_int_to_vlan_po_dict = merge_dicts(self.int_to_vlan_dict, self.int_po_dict) self.portchannel_speed_dict = po_speed_dict(self.po_int_dict, self.appl_db) self.portchannel_keys = self.portchannel_speed_dict.keys() + + self.sub_intf_list = get_sub_port_intf_list(self.config_db) + appl_db_sub_intf_keys = appl_db_sub_intf_keys_get(self.appl_db, self.sub_intf_list, intf_name) if appl_db_keys is None: return - self.display_intf_status(appl_db_keys, self.front_panel_ports_list, self.portchannel_speed_dict) + self.display_intf_status(appl_db_keys, self.front_panel_ports_list, self.portchannel_speed_dict, appl_db_sub_intf_keys, self.sub_intf_list) From 80714f0321834ccb68d85e4aee9ea826d9b5ad83 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 12 Sep 2019 02:04:18 +0000 Subject: [PATCH 02/18] Format change Signed-off-by: Wenda Ni --- scripts/intfutil | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/scripts/intfutil b/scripts/intfutil index 12da00d180..03c77c1095 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -346,16 +346,16 @@ class IntfStatus(object): key = re.split(':', i, maxsplit=1)[-1].strip() if key in front_panel_ports_list: table.append((key, - appl_db_port_status_get(self.appl_db, key, PORT_LANES_STATUS), - appl_db_port_status_get(self.appl_db, key, PORT_SPEED), - appl_db_port_status_get(self.appl_db, key, PORT_MTU_STATUS), - appl_db_port_status_get(self.appl_db, key, PORT_ALIAS), - config_db_vlan_port_keys_get(self.combined_int_to_vlan_po_dict, self.front_panel_ports_list, key), - appl_db_port_status_get(self.appl_db, key, PORT_OPER_STATUS), - appl_db_port_status_get(self.appl_db, key, PORT_ADMIN_STATUS), - state_db_port_optics_get(self.state_db, key, PORT_OPTICS_TYPE), - appl_db_port_status_get(self.appl_db, key, PORT_PFC_ASYM_STATUS))) - # Sorting and tabulating the result table. + appl_db_port_status_get(self.appl_db, key, PORT_LANES_STATUS), + appl_db_port_status_get(self.appl_db, key, PORT_SPEED), + appl_db_port_status_get(self.appl_db, key, PORT_MTU_STATUS), + appl_db_port_status_get(self.appl_db, key, PORT_ALIAS), + config_db_vlan_port_keys_get(self.combined_int_to_vlan_po_dict, self.front_panel_ports_list, key), + appl_db_port_status_get(self.appl_db, key, PORT_OPER_STATUS), + appl_db_port_status_get(self.appl_db, key, PORT_ADMIN_STATUS), + state_db_port_optics_get(self.state_db, key, PORT_OPTICS_TYPE), + appl_db_port_status_get(self.appl_db, key, PORT_PFC_ASYM_STATUS))) + for po, value in portchannel_speed_dict.iteritems(): if po: table.append((po, From b50f09e2a27c741d2cd73f3d950cc073001fc97e Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 12 Sep 2019 03:35:59 +0000 Subject: [PATCH 03/18] Hook 'intfutil status' with show subinterfaces status Signed-off-by: Wenda Ni --- show/main.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/show/main.py b/show/main.py index 5a4ba17cde..a800eb58b7 100755 --- a/show/main.py +++ b/show/main.py @@ -661,6 +661,23 @@ def portchannel(verbose): cmd = "sudo teamshow" run_command(cmd, display_cmd=verbose) +# +# 'subinterfaces' group ("show subinterfaces ...") +# + +@cli.group(cls=AliasedGroup, default_if_no_args=False) +def subinterfaces(): + """Show details of the sub port interfaces""" + pass + +# 'subinterfaces' subcommand ("show subinterfaces status") +@subinterfaces.command() +@click.option('--verbose', is_flag=True, help="Enable verbose output") +def status(verbose): + """Show sub port interface status information""" + cmd = "intfutil status" + run_command(cmd, display_cmd=verbose) + # # 'pfc' group ("show pfc ...") # From cf1b51cc84c20ac25b08e0e6924d3539c6d687f5 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 12 Sep 2019 03:37:21 +0000 Subject: [PATCH 04/18] Add 'intfutil status subport' to show only the status of sub port interfaces Signed-off-by: Wenda Ni --- scripts/intfutil | 112 +++++++++++++++++++++++++++++------------------ 1 file changed, 69 insertions(+), 43 deletions(-) diff --git a/scripts/intfutil b/scripts/intfutil index 03c77c1095..a690c02898 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -24,9 +24,12 @@ PORT_MTU_STATUS = "mtu" PORT_DESCRIPTION = "description" PORT_OPTICS_TYPE = "type" PORT_PFC_ASYM_STATUS = "pfc_asym" + VLAN_SUB_INTERFACE_SEPARATOR = "." VLAN_SUB_INTERFACE_TYPE = "dot1q-encapsulation" +SUB_PORT = "subport" + def db_connect_configdb(): """ Connect to configdb @@ -326,10 +329,11 @@ def appl_db_sub_intf_status_get(appl_db, config_db, front_panel_ports_list, port # ========================== interface-status logic ========================== header_stat = ['Interface', 'Lanes', 'Speed', 'MTU', 'Alias', 'Vlan', 'Oper', 'Admin', 'Type', 'Asym PFC'] +header_stat_sub_intf = ['Sub port interface', 'Speed', 'MTU', 'Vlan', 'Admin', 'Type'] class IntfStatus(object): - def display_intf_status(self, appl_db_keys, front_panel_ports_list, portchannel_speed_dict, appl_db_sub_intf_keys, sub_intf_list): + def display_intf_status(self, appl_db_keys, front_panel_ports_list, portchannel_speed_dict, appl_db_sub_intf_keys, sub_intf_list, sub_intf_only): """ Generate interface-status output """ @@ -342,49 +346,61 @@ class IntfStatus(object): # Iterate through all the keys and append port's associated state to # the result table. # - for i in appl_db_keys: - key = re.split(':', i, maxsplit=1)[-1].strip() - if key in front_panel_ports_list: - table.append((key, - appl_db_port_status_get(self.appl_db, key, PORT_LANES_STATUS), - appl_db_port_status_get(self.appl_db, key, PORT_SPEED), - appl_db_port_status_get(self.appl_db, key, PORT_MTU_STATUS), - appl_db_port_status_get(self.appl_db, key, PORT_ALIAS), - config_db_vlan_port_keys_get(self.combined_int_to_vlan_po_dict, self.front_panel_ports_list, key), - appl_db_port_status_get(self.appl_db, key, PORT_OPER_STATUS), - appl_db_port_status_get(self.appl_db, key, PORT_ADMIN_STATUS), - state_db_port_optics_get(self.state_db, key, PORT_OPTICS_TYPE), - appl_db_port_status_get(self.appl_db, key, PORT_PFC_ASYM_STATUS))) - - for po, value in portchannel_speed_dict.iteritems(): - if po: - table.append((po, - appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_LANES_STATUS, self.portchannel_speed_dict), - appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_SPEED, self.portchannel_speed_dict), - appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_MTU_STATUS, self.portchannel_speed_dict), - appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_ALIAS, self.portchannel_speed_dict), - appl_db_portchannel_status_get(self.appl_db, self.config_db, po, "vlan", self.portchannel_speed_dict), - appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_OPER_STATUS, self.portchannel_speed_dict), - appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_ADMIN_STATUS, self.portchannel_speed_dict), - appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_OPTICS_TYPE, self.portchannel_speed_dict), - appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_PFC_ASYM_STATUS, self.portchannel_speed_dict))) - - for key in appl_db_sub_intf_keys: - sub_intf = re.split(':', key, maxsplit=1)[-1].strip() - if sub_intf in sub_intf_list: - table.append((sub_intf, - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_LANES_STATUS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_SPEED), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_MTU_STATUS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_ALIAS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, "vlan"), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPER_STATUS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_ADMIN_STATUS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPTICS_TYPE), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_PFC_ASYM_STATUS))) + if not sub_intf_only: + for i in appl_db_keys: + key = re.split(':', i, maxsplit=1)[-1].strip() + if key in front_panel_ports_list: + table.append((key, + appl_db_port_status_get(self.appl_db, key, PORT_LANES_STATUS), + appl_db_port_status_get(self.appl_db, key, PORT_SPEED), + appl_db_port_status_get(self.appl_db, key, PORT_MTU_STATUS), + appl_db_port_status_get(self.appl_db, key, PORT_ALIAS), + config_db_vlan_port_keys_get(self.combined_int_to_vlan_po_dict, self.front_panel_ports_list, key), + appl_db_port_status_get(self.appl_db, key, PORT_OPER_STATUS), + appl_db_port_status_get(self.appl_db, key, PORT_ADMIN_STATUS), + state_db_port_optics_get(self.state_db, key, PORT_OPTICS_TYPE), + appl_db_port_status_get(self.appl_db, key, PORT_PFC_ASYM_STATUS))) + + for po, value in portchannel_speed_dict.iteritems(): + if po: + table.append((po, + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_LANES_STATUS, self.portchannel_speed_dict), + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_SPEED, self.portchannel_speed_dict), + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_MTU_STATUS, self.portchannel_speed_dict), + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_ALIAS, self.portchannel_speed_dict), + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, "vlan", self.portchannel_speed_dict), + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_OPER_STATUS, self.portchannel_speed_dict), + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_ADMIN_STATUS, self.portchannel_speed_dict), + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_OPTICS_TYPE, self.portchannel_speed_dict), + appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_PFC_ASYM_STATUS, self.portchannel_speed_dict))) + + for key in appl_db_sub_intf_keys: + sub_intf = re.split(':', key, maxsplit=1)[-1].strip() + if sub_intf in sub_intf_list: + table.append((sub_intf, + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_LANES_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_SPEED), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_MTU_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_ALIAS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, "vlan"), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPER_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_ADMIN_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPTICS_TYPE), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_PFC_ASYM_STATUS))) + else: + for key in appl_db_sub_intf_keys: + sub_intf = re.split(':', key, maxsplit=1)[-1].strip() + if sub_intf in sub_intf_list: + table.append((sub_intf, + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_SPEED), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_MTU_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, "vlan"), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_ADMIN_STATUS), + appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPTICS_TYPE))) + # Sorting and tabulating the result table. sorted_table = natsorted(table) - print tabulate(sorted_table, header_stat, tablefmt="simple", stralign='right') + print tabulate(sorted_table, header_stat if not sub_intf_only else header_stat_sub_intf, tablefmt="simple", stralign='right') def __init__(self, intf_name): @@ -403,6 +419,12 @@ class IntfStatus(object): return if self.config_db is None: return + + sub_intf_only = False + if intf_name is not None and intf_name == SUB_PORT: + intf_name = None + sub_intf_only = True + self.front_panel_ports_list = get_frontpanel_port_list(self.config_db) appl_db_keys = appl_db_keys_get(self.appl_db, self.front_panel_ports_list, intf_name) self.int_to_vlan_dict = get_interface_vlan_dict(self.config_db) @@ -419,7 +441,7 @@ class IntfStatus(object): appl_db_sub_intf_keys = appl_db_sub_intf_keys_get(self.appl_db, self.sub_intf_list, intf_name) if appl_db_keys is None: return - self.display_intf_status(appl_db_keys, self.front_panel_ports_list, self.portchannel_speed_dict, appl_db_sub_intf_keys, self.sub_intf_list) + self.display_intf_status(appl_db_keys, self.front_panel_ports_list, self.portchannel_speed_dict, appl_db_sub_intf_keys, self.sub_intf_list, sub_intf_only) @@ -465,6 +487,10 @@ class IntfDescription(object): return if self.config_db is None: return + + if intf_name is not None and intf_name == SUB_PORT: + intf_name = None + self.front_panel_ports_list = get_frontpanel_port_list(self.config_db) appl_db_keys = appl_db_keys_get(self.appl_db, self.front_panel_ports_list, intf_name) if appl_db_keys is None: From b6a4ac730804a12bb35492777f1e38f650c24965 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 12 Sep 2019 03:39:56 +0000 Subject: [PATCH 05/18] Hook 'intfutil status subport' with 'show subinterfaces status' Signed-off-by: Wenda Ni --- show/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/show/main.py b/show/main.py index a800eb58b7..544f8c34e1 100755 --- a/show/main.py +++ b/show/main.py @@ -675,7 +675,7 @@ def subinterfaces(): @click.option('--verbose', is_flag=True, help="Enable verbose output") def status(verbose): """Show sub port interface status information""" - cmd = "intfutil status" + cmd = "intfutil status subport" run_command(cmd, display_cmd=verbose) # From 7c45d13d63ee1f6431ace36ba6f14f12522c55b8 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 12 Sep 2019 04:46:59 +0000 Subject: [PATCH 06/18] Support intfutil status Signed-off-by: Wenda Ni --- scripts/intfutil | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/intfutil b/scripts/intfutil index a690c02898..f0ece3c47f 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -120,7 +120,7 @@ def appl_db_sub_intf_keys_get(appl_db, sub_intf_list, sub_intf_name): elif sub_intf_name in sub_intf_list: appl_db_sub_intf_keys = appl_db.keys(appl_db.APPL_DB, "INTF_TABLE:%s" % sub_intf_name) else: - return None + return [] return appl_db_sub_intf_keys @@ -300,7 +300,7 @@ def appl_db_portchannel_status_get(appl_db, config_db, po_name, status_type, por def appl_db_sub_intf_status_get(appl_db, config_db, front_panel_ports_list, portchannel_speed_dict, sub_intf_name, status_type): sub_intf_sep_idx = sub_intf_name.find(VLAN_SUB_INTERFACE_SEPARATOR) - if (sub_intf_sep_idx != -1): + if sub_intf_sep_idx != -1: parent_port_name = sub_intf_name[:sub_intf_sep_idx] vlan_id = sub_intf_name[sub_intf_sep_idx + 1:] @@ -421,9 +421,17 @@ class IntfStatus(object): return sub_intf_only = False - if intf_name is not None and intf_name == SUB_PORT: - intf_name = None - sub_intf_only = True + sub_intf_name = intf_name + if intf_name is not None: + if intf_name == SUB_PORT: + intf_name = None + sub_intf_name = None + sub_intf_only = True + else: + sub_intf_sep_idx = intf_name.find(VLAN_SUB_INTERFACE_SEPARATOR) + if sub_intf_sep_idx != -1: + sub_intf_only = True + intf_name = intf_name[:sub_intf_sep_idx] self.front_panel_ports_list = get_frontpanel_port_list(self.config_db) appl_db_keys = appl_db_keys_get(self.appl_db, self.front_panel_ports_list, intf_name) @@ -438,7 +446,7 @@ class IntfStatus(object): self.portchannel_keys = self.portchannel_speed_dict.keys() self.sub_intf_list = get_sub_port_intf_list(self.config_db) - appl_db_sub_intf_keys = appl_db_sub_intf_keys_get(self.appl_db, self.sub_intf_list, intf_name) + appl_db_sub_intf_keys = appl_db_sub_intf_keys_get(self.appl_db, self.sub_intf_list, sub_intf_name) if appl_db_keys is None: return self.display_intf_status(appl_db_keys, self.front_panel_ports_list, self.portchannel_speed_dict, appl_db_sub_intf_keys, self.sub_intf_list, sub_intf_only) From 360a5c92c82b7d9a8c2154b49742796c182bdb38 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Fri, 13 Sep 2019 03:36:08 +0000 Subject: [PATCH 07/18] Add alias naming mode support Signed-off-by: Wenda Ni --- show/main.py | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/show/main.py b/show/main.py index 544f8c34e1..3a537c4d6a 100755 --- a/show/main.py +++ b/show/main.py @@ -22,6 +22,8 @@ SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' +VLAN_SUB_INTERFACE_SEPARATOR = '.' + try: # noinspection PyPep8Naming import ConfigParser as configparser @@ -74,25 +76,42 @@ def name_to_alias(self, interface_name): """Return vendor interface alias if SONiC interface name is given as argument """ + vlan_id = '' + sub_intf_sep_idx = -1 if interface_name is not None: + sub_intf_sep_idx = interface_name.find(VLAN_SUB_INTERFACE_SEPARATOR) + if sub_intf_sep_idx != -1: + vlan_id = interface_name[sub_intf_sep_idx + 1:] + # interface_name holds the parent port name + interface_name = interface_name[:sub_intf_sep_idx] + for port_name in self.port_dict.keys(): if interface_name == port_name: - return self.port_dict[port_name]['alias'] + return self.port_dict[port_name]['alias'] if sub_intf_sep_idx == -1 \ + else self.port_dict[port_name]['alias'] + VLAN_SUB_INTERFACE_SEPARATOR + vlan_id # interface_name not in port_dict. Just return interface_name - return interface_name + return interface_name if sub_intf_sep_idx == -1 else interface_name + VLAN_SUB_INTERFACE_SEPARATOR + vlan_id def alias_to_name(self, interface_alias): """Return SONiC interface name if vendor port alias is given as argument """ + vlan_id = '' + sub_intf_sep_idx = -1 if interface_alias is not None: + sub_intf_sep_idx = interface_alias.find(VLAN_SUB_INTERFACE_SEPARATOR) + if sub_intf_sep_idx != -1: + vlan_id = interface_alias[sub_intf_sep_idx + 1:] + # interface_alias holds the parent port alias + interface_alias = interface_alias[:sub_intf_sep_idx] + for port_name in self.port_dict.keys(): if interface_alias == self.port_dict[port_name]['alias']: - return port_name + return port_name if sub_intf_sep_idx == -1 else port_name + VLAN_SUB_INTERFACE_SEPARATOR + vlan_id # interface_alias not in port_dict. Just return interface_alias - return interface_alias + return interface_alias if sub_intf_sep_idx == -1 else interface_alias + VLAN_SUB_INTERFACE_SEPARATOR + vlan_id # Global Config object @@ -672,10 +691,19 @@ def subinterfaces(): # 'subinterfaces' subcommand ("show subinterfaces status") @subinterfaces.command() +@click.argument('subinterfacename', type=str, required=False) @click.option('--verbose', is_flag=True, help="Enable verbose output") -def status(verbose): +def status(subinterfacename, verbose): """Show sub port interface status information""" - cmd = "intfutil status subport" + cmd = "intfutil status" + + if subinterfacename is not None: + if get_interface_mode() == "alias": + subinterfacename = iface_alias_converter.alias_to_name(subinterfacename) + + cmd += " {}".format(subinterfacename) + else: + cmd += " subport" run_command(cmd, display_cmd=verbose) # From 7e16f0285171df95d4fe1c5f95e89a808ed17166 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 26 Sep 2019 00:41:59 +0000 Subject: [PATCH 08/18] Address comments Signed-off-by: Wenda Ni --- scripts/intfutil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/intfutil b/scripts/intfutil index f0ece3c47f..d2ca4c33fa 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -26,7 +26,7 @@ PORT_OPTICS_TYPE = "type" PORT_PFC_ASYM_STATUS = "pfc_asym" VLAN_SUB_INTERFACE_SEPARATOR = "." -VLAN_SUB_INTERFACE_TYPE = "dot1q-encapsulation" +VLAN_SUB_INTERFACE_TYPE = "802.1q-encapsulation" SUB_PORT = "subport" From 926286df76f5a35422781bdf9a9b377ed81fad94 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Thu, 26 Sep 2019 00:42:24 +0000 Subject: [PATCH 09/18] Address comment: concatenate command line, and validate input Signed-off-by: Wenda Ni --- show/main.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/show/main.py b/show/main.py index f7871c4bbc..0af1fb1d7d 100755 --- a/show/main.py +++ b/show/main.py @@ -695,15 +695,20 @@ def subinterfaces(): @click.option('--verbose', is_flag=True, help="Enable verbose output") def status(subinterfacename, verbose): """Show sub port interface status information""" - cmd = "intfutil status" + cmd = "intfutil status " if subinterfacename is not None: + sub_intf_sep_idx = subinterfacename.find(VLAN_SUB_INTERFACE_SEPARATOR) + if sub_intf_sep_idx == -1: + print("Invalid sub port interface name") + return + if get_interface_mode() == "alias": subinterfacename = iface_alias_converter.alias_to_name(subinterfacename) - cmd += " {}".format(subinterfacename) + cmd += subinterfacename else: - cmd += " subport" + cmd += "subport" run_command(cmd, display_cmd=verbose) # From 80293ce45403d28b70d718dc58e5c1c476801358 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Wed, 16 Oct 2019 23:24:20 +0000 Subject: [PATCH 10/18] Address comment: keep show interface status intact Signed-off-by: Wenda Ni --- scripts/intfutil | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/scripts/intfutil b/scripts/intfutil index d2ca4c33fa..22f6bb7398 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -373,20 +373,6 @@ class IntfStatus(object): appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_ADMIN_STATUS, self.portchannel_speed_dict), appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_OPTICS_TYPE, self.portchannel_speed_dict), appl_db_portchannel_status_get(self.appl_db, self.config_db, po, PORT_PFC_ASYM_STATUS, self.portchannel_speed_dict))) - - for key in appl_db_sub_intf_keys: - sub_intf = re.split(':', key, maxsplit=1)[-1].strip() - if sub_intf in sub_intf_list: - table.append((sub_intf, - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_LANES_STATUS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_SPEED), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_MTU_STATUS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_ALIAS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, "vlan"), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPER_STATUS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_ADMIN_STATUS), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_OPTICS_TYPE), - appl_db_sub_intf_status_get(self.appl_db, self.config_db, self.front_panel_ports_list, self.portchannel_speed_dict, sub_intf, PORT_PFC_ASYM_STATUS))) else: for key in appl_db_sub_intf_keys: sub_intf = re.split(':', key, maxsplit=1)[-1].strip() From f0faf8f3b2a0e28b95d961d26644165b82aec7b3 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Sat, 2 Nov 2019 22:15:40 +0000 Subject: [PATCH 11/18] Add unit test for show interfaces status / intfutil status Signed-off-by: Wenda Ni --- scripts/intfutil | 20 ++++++++--- sonic-utilities-tests/intfutil_test.py | 48 ++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 sonic-utilities-tests/intfutil_test.py diff --git a/scripts/intfutil b/scripts/intfutil index 22f6bb7398..bad72f27c4 100755 --- a/scripts/intfutil +++ b/scripts/intfutil @@ -8,7 +8,18 @@ from tabulate import tabulate from natsort import natsorted from swsssdk import ConfigDBConnector from pprint import pprint - +import os + +# mock the redis for unit test purposes # +try: + if os.environ["UTILITIES_UNIT_TESTING"] == "1": + modules_path = os.path.join(os.path.dirname(__file__), "..") + tests_path = os.path.join(modules_path, "sonic-utilities-tests") + sys.path.insert(0, modules_path) + sys.path.insert(0, tests_path) + import mock_tables.dbconnector +except KeyError: + pass # ========================== Common interface-utils logic ========================== @@ -114,9 +125,10 @@ def appl_db_sub_intf_keys_get(appl_db, sub_intf_list, sub_intf_name): if sub_intf_name is None: appl_db_sub_intf_keys = [] appl_db_intf_keys = appl_db.keys(appl_db.APPL_DB, "INTF_TABLE:*") - for appl_db_intf_key in appl_db_intf_keys: - if re.split(':', appl_db_intf_key, maxsplit=1)[-1].strip() in sub_intf_list: - appl_db_sub_intf_keys.append(appl_db_intf_key) + if appl_db_intf_keys is not None: + for appl_db_intf_key in appl_db_intf_keys: + if re.split(':', appl_db_intf_key, maxsplit=1)[-1].strip() in sub_intf_list: + appl_db_sub_intf_keys.append(appl_db_intf_key) elif sub_intf_name in sub_intf_list: appl_db_sub_intf_keys = appl_db.keys(appl_db.APPL_DB, "INTF_TABLE:%s" % sub_intf_name) else: diff --git a/sonic-utilities-tests/intfutil_test.py b/sonic-utilities-tests/intfutil_test.py new file mode 100644 index 0000000000..7e50de366f --- /dev/null +++ b/sonic-utilities-tests/intfutil_test.py @@ -0,0 +1,48 @@ +import os +import sys +from click.testing import CliRunner +from unittest import TestCase +import subprocess + +import show.main as show + +root_path = os.path.dirname(os.path.abspath(__file__)) +modules_path = os.path.dirname(root_path) +scripts_path = os.path.join(modules_path, "scripts") + +class TestIntfutil(TestCase): + @classmethod + def setup_class(cls): + print("SETUP") + os.environ["PATH"] += os.pathsep + scripts_path + os.environ["UTILITIES_UNIT_TESTING"] = "1" + + def setUp(self): + self.runner = CliRunner() + + # Test 'show interfaces status' / 'intfutil status' + def test_intf_status(self): + # Test 'show interfaces status' + result = self.runner.invoke(show.cli.commands["interfaces"].commands["status"], []) + print >> sys.stderr, result.output + expected_output = ( + "Interface Lanes Speed MTU Alias Vlan Oper Admin Type Asym PFC\n" + "----------- ------- ------- ----- --------- ------ ------ ------- --------------- ----------\n" + " Ethernet0 0 25G 9100 Ethernet0 routed down up QSFP28 or later off" + ) + self.assertEqual(result.output.strip(), expected_output) + + # Test 'intfutil status' + output = subprocess.check_output('intfutil status', stderr=subprocess.STDOUT, shell=True) + print >> sys.stderr, output + self.assertEqual(output.strip(), expected_output) + assert(0) + + def test_intf_status_verbose(self): + result = self.runner.invoke(show.cli.commands["interfaces"].commands["status"], ["--verbose"]) + + @classmethod + def teardown_class(cls): + print("TEARDOWN") + os.environ["PATH"] = os.pathsep.join(os.environ["PATH"].split(os.pathsep)[:-1]) + os.environ["UTILITIES_UNIT_TESTING"] = "0" From 03bc156b7a686869509afcd81af70dca1f5fa484 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Mon, 4 Nov 2019 00:47:18 +0000 Subject: [PATCH 12/18] Add unit test for 'show interfaces status --verbose' Signed-off-by: Wenda Ni --- sonic-utilities-tests/intfutil_test.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sonic-utilities-tests/intfutil_test.py b/sonic-utilities-tests/intfutil_test.py index 7e50de366f..eaaf11eff1 100644 --- a/sonic-utilities-tests/intfutil_test.py +++ b/sonic-utilities-tests/intfutil_test.py @@ -36,10 +36,14 @@ def test_intf_status(self): output = subprocess.check_output('intfutil status', stderr=subprocess.STDOUT, shell=True) print >> sys.stderr, output self.assertEqual(output.strip(), expected_output) - assert(0) + # Test 'show interfaces status --verbose' def test_intf_status_verbose(self): result = self.runner.invoke(show.cli.commands["interfaces"].commands["status"], ["--verbose"]) + print >> sys.stderr, result.output + expected_output = "Command: intfutil status" + self.assertEqual(result.output.split('\n')[0], expected_output) + assert(0) @classmethod def teardown_class(cls): From 9969e55709d3cd869863cfafff2d5bb9d29c2a29 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Mon, 4 Nov 2019 00:58:47 +0000 Subject: [PATCH 13/18] Add unit test for 'show subinterfaces status' / 'intfutil status subport' Signed-off-by: Wenda Ni --- sonic-utilities-tests/intfutil_test.py | 17 +++++++++++++++++ sonic-utilities-tests/mock_tables/appl_db.json | 5 ++++- .../mock_tables/config_db.json | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/sonic-utilities-tests/intfutil_test.py b/sonic-utilities-tests/intfutil_test.py index eaaf11eff1..ccd29a559b 100644 --- a/sonic-utilities-tests/intfutil_test.py +++ b/sonic-utilities-tests/intfutil_test.py @@ -43,6 +43,23 @@ def test_intf_status_verbose(self): print >> sys.stderr, result.output expected_output = "Command: intfutil status" self.assertEqual(result.output.split('\n')[0], expected_output) + + # Test 'show subinterfaces status' / 'intfutil status subport' + def test_subintf_status(self): + # Test 'show subinterfaces status' + result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], []) + print >> sys.stderr, result.output + expected_output = ( + "Sub port interface Speed MTU Vlan Admin Type\n" + "-------------------- ------- ----- ------ ------- --------------------\n" + " Ethernet0.10 25G 9100 10 up 802.1q-encapsulation" + ) + + # Test 'intfutil status subport' + output = subprocess.check_output('intfutil status subport', stderr=subprocess.STDOUT, shell=True) + print >> sys.stderr, output + self.assertEqual(output.strip(), expected_output) + assert(0) @classmethod diff --git a/sonic-utilities-tests/mock_tables/appl_db.json b/sonic-utilities-tests/mock_tables/appl_db.json index 1bc3af3c08..19768f75a2 100644 --- a/sonic-utilities-tests/mock_tables/appl_db.json +++ b/sonic-utilities-tests/mock_tables/appl_db.json @@ -18,5 +18,8 @@ "fec": "rs", "mtu": "9100", "pfc_asym": "off" + }, + "INTF_TABLE:Ethernet0.10": { + "admin_status": "up" } -} \ No newline at end of file +} diff --git a/sonic-utilities-tests/mock_tables/config_db.json b/sonic-utilities-tests/mock_tables/config_db.json index 6cb8e981c7..97ae4b2edb 100644 --- a/sonic-utilities-tests/mock_tables/config_db.json +++ b/sonic-utilities-tests/mock_tables/config_db.json @@ -42,6 +42,9 @@ "mtu": "9100", "speed": "40000" }, + "VLAN_SUB_INTERFACE|Ethernet0.10": { + "admin_status": "up" + }, "ACL_RULE|DATAACL|DEFAULT_RULE": { "PACKET_ACTION": "DROP", "PRIORITY": "1" From bc946e0292a8d150132471a2b7eaf8806b691eb0 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Mon, 4 Nov 2019 01:29:44 +0000 Subject: [PATCH 14/18] Add unit test for 'show subinterfaces status --verbose' Signed-off-by: Wenda Ni --- sonic-utilities-tests/intfutil_test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sonic-utilities-tests/intfutil_test.py b/sonic-utilities-tests/intfutil_test.py index ccd29a559b..e92a5d2f98 100644 --- a/sonic-utilities-tests/intfutil_test.py +++ b/sonic-utilities-tests/intfutil_test.py @@ -60,6 +60,13 @@ def test_subintf_status(self): print >> sys.stderr, output self.assertEqual(output.strip(), expected_output) + # Test 'show subinterfaces status --verbose' + def test_subintf_status_verbose(self): + result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["--verbose"]) + print >> sys.stderr, result.output + expected_output = "Command: intfutil status subport" + self.assertEqual(result.output.split('\n')[0], expected_output) + assert(0) @classmethod From 3a288e4f1f67746ca702f4eaae3b10c03a4bd212 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Mon, 4 Nov 2019 01:53:57 +0000 Subject: [PATCH 15/18] Add unit test for single sub interface status show Signed-off-by: Wenda Ni --- sonic-utilities-tests/intfutil_test.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/sonic-utilities-tests/intfutil_test.py b/sonic-utilities-tests/intfutil_test.py index e92a5d2f98..05add67318 100644 --- a/sonic-utilities-tests/intfutil_test.py +++ b/sonic-utilities-tests/intfutil_test.py @@ -67,6 +67,20 @@ def test_subintf_status_verbose(self): expected_output = "Command: intfutil status subport" self.assertEqual(result.output.split('\n')[0], expected_output) + # Test single sub interface status + def test_single_subintf_status(self): + result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["Ethernet0.10"]) + print >> sys.stderr, result.output + expected_output = ( + "Sub port interface Speed MTU Vlan Admin Type\n" + "-------------------- ------- ----- ------ ------- --------------------\n" + " Ethernet0.10 25G 9100 10 up 802.1q-encapsulation" + ) + + output = subprocess.check_output('intfutil status Ethernet0.10', stderr=subprocess.STDOUT, shell=True) + print >> sys.stderr, output + self.assertEqual(output.strip(), expected_output) + assert(0) @classmethod From 9b3c7116b5a8513b1ddf26ed8f89363690fd5f03 Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Mon, 4 Nov 2019 02:02:49 +0000 Subject: [PATCH 16/18] Add unit test for '--verbose' single sub interface status show Signed-off-by: Wenda Ni --- sonic-utilities-tests/intfutil_test.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sonic-utilities-tests/intfutil_test.py b/sonic-utilities-tests/intfutil_test.py index 05add67318..5fe8d0efcc 100644 --- a/sonic-utilities-tests/intfutil_test.py +++ b/sonic-utilities-tests/intfutil_test.py @@ -81,6 +81,13 @@ def test_single_subintf_status(self): print >> sys.stderr, output self.assertEqual(output.strip(), expected_output) + # Test '--verbose' of single sub interface status + def test_single_subintf_status_verbose(self): + result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["Ethernet0.10", "--verbose"]) + print >> sys.stderr, result.output + expected_output = "Command: intfutil status Ethernet0.10" + self.assertEqual(result.output.split('\n')[0], expected_output) + assert(0) @classmethod From 972e0f5af1f7ec3d03af59cffb52dc9c5d95e80a Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Mon, 4 Nov 2019 02:28:48 +0000 Subject: [PATCH 17/18] Add unit test for showing status of single sub interface in alias naming mode Signed-off-by: Wenda Ni --- sonic-utilities-tests/intfutil_test.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/sonic-utilities-tests/intfutil_test.py b/sonic-utilities-tests/intfutil_test.py index 5fe8d0efcc..b3c4505760 100644 --- a/sonic-utilities-tests/intfutil_test.py +++ b/sonic-utilities-tests/intfutil_test.py @@ -20,6 +20,7 @@ def setup_class(cls): def setUp(self): self.runner = CliRunner() + # Test 'show interfaces status' / 'intfutil status' def test_intf_status(self): # Test 'show interfaces status' @@ -44,6 +45,7 @@ def test_intf_status_verbose(self): expected_output = "Command: intfutil status" self.assertEqual(result.output.split('\n')[0], expected_output) + # Test 'show subinterfaces status' / 'intfutil status subport' def test_subintf_status(self): # Test 'show subinterfaces status' @@ -54,6 +56,7 @@ def test_subintf_status(self): "-------------------- ------- ----- ------ ------- --------------------\n" " Ethernet0.10 25G 9100 10 up 802.1q-encapsulation" ) + self.assertEqual(result.output.strip(), expected_output) # Test 'intfutil status subport' output = subprocess.check_output('intfutil status subport', stderr=subprocess.STDOUT, shell=True) @@ -67,8 +70,10 @@ def test_subintf_status_verbose(self): expected_output = "Command: intfutil status subport" self.assertEqual(result.output.split('\n')[0], expected_output) + # Test single sub interface status def test_single_subintf_status(self): + # Test 'show subinterfaces status Ethernet0.10' result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["Ethernet0.10"]) print >> sys.stderr, result.output expected_output = ( @@ -76,7 +81,9 @@ def test_single_subintf_status(self): "-------------------- ------- ----- ------ ------- --------------------\n" " Ethernet0.10 25G 9100 10 up 802.1q-encapsulation" ) + self.assertEqual(result.output.strip(), expected_output) + # Test 'intfutil status Ethernet0.10' output = subprocess.check_output('intfutil status Ethernet0.10', stderr=subprocess.STDOUT, shell=True) print >> sys.stderr, output self.assertEqual(output.strip(), expected_output) @@ -88,7 +95,22 @@ def test_single_subintf_status_verbose(self): expected_output = "Command: intfutil status Ethernet0.10" self.assertEqual(result.output.split('\n')[0], expected_output) + + # Test alias mode of single sub interface status + def test_single_subintf_status_alias_mode(self): + os.environ["SONIC_CLI_IFACE_MODE"] = "alias" + result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["etp1.10"]) + print >> sys.stderr, result.output + expected_output = ( + "Sub port interface Speed MTU Vlan Admin Type\n" + "-------------------- ------- ----- ------ ------- --------------------\n" + " Ethernet0.10 25G 9100 10 up 802.1q-encapsulation" + ) + self.assertEqual(result.output.strip(), expected_output) + os.environ["SONIC_CLI_IFACE_MODE"] = "default" + assert(0) + # Test '--verbose' alias mode of single sub interface status @classmethod def teardown_class(cls): From 94f0936c3c8d339430cbf744d05cf6f8177a86da Mon Sep 17 00:00:00 2001 From: Wenda Ni Date: Mon, 4 Nov 2019 02:44:23 +0000 Subject: [PATCH 18/18] Add unit test for '--verbose' status of single sub interface in alias naming mode Signed-off-by: Wenda Ni --- sonic-utilities-tests/intfutil_test.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/sonic-utilities-tests/intfutil_test.py b/sonic-utilities-tests/intfutil_test.py index b3c4505760..44791729bb 100644 --- a/sonic-utilities-tests/intfutil_test.py +++ b/sonic-utilities-tests/intfutil_test.py @@ -88,7 +88,7 @@ def test_single_subintf_status(self): print >> sys.stderr, output self.assertEqual(output.strip(), expected_output) - # Test '--verbose' of single sub interface status + # Test '--verbose' status of single sub interface def test_single_subintf_status_verbose(self): result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["Ethernet0.10", "--verbose"]) print >> sys.stderr, result.output @@ -96,9 +96,10 @@ def test_single_subintf_status_verbose(self): self.assertEqual(result.output.split('\n')[0], expected_output) - # Test alias mode of single sub interface status + # Test status of single sub interface in alias naming mode def test_single_subintf_status_alias_mode(self): os.environ["SONIC_CLI_IFACE_MODE"] = "alias" + result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["etp1.10"]) print >> sys.stderr, result.output expected_output = ( @@ -107,10 +108,19 @@ def test_single_subintf_status_alias_mode(self): " Ethernet0.10 25G 9100 10 up 802.1q-encapsulation" ) self.assertEqual(result.output.strip(), expected_output) + os.environ["SONIC_CLI_IFACE_MODE"] = "default" - assert(0) - # Test '--verbose' alias mode of single sub interface status + # Test '--verbose' status of single sub interface in alias naming mode + def test_single_subintf_status_alias_mode_verbose(self): + os.environ["SONIC_CLI_IFACE_MODE"] = "alias" + + result = self.runner.invoke(show.cli.commands["subinterfaces"].commands["status"], ["etp1.10", "--verbose"]) + print >> sys.stderr, result.output + expected_output = "Command: intfutil status Ethernet0.10" + self.assertEqual(result.output.split('\n')[0], expected_output) + + os.environ["SONIC_CLI_IFACE_MODE"] = "default" @classmethod def teardown_class(cls):