Skip to content

Commit

Permalink
Updates to show command and testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
judyjoseph committed Aug 31, 2020
1 parent 41c16a0 commit 4de1197
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 78 deletions.
34 changes: 33 additions & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from swsssdk import ConfigDBConnector, SonicV2Connector, SonicDBConfig
from utilities_common.db import Db
from utilities_common.intf_filter import parse_interface_in_filter
from utilities_common.multi_asic import get_port_namespace
import utilities_common.cli as clicommon
from .utils import log

Expand Down Expand Up @@ -396,6 +395,39 @@ def is_interface_bind_to_vrf(config_db, interface_name):
return True
return False

# Return the namespace where an interface belongs
# The port name input could be in default mode or in alias mode.
def get_port_namespace(port):
# If it is a non multi-asic platform, or if the interface is management interface
# return DEFAULT_NAMESPACE
if not multi_asic.is_multi_asic() or port == 'eth0':
return DEFAULT_NAMESPACE

# Get the table to check for interface presence
table_name = get_port_table_name(port)
if table_name == "":
return None

ns_list = multi_asic.get_all_namespaces()
namespaces = ns_list['front_ns'] + ns_list['back_ns']
for namespace in namespaces:
config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=namespace)
config_db.connect()

# If the interface naming mode is alias, search the tables for alias_name.
if clicommon.get_interface_naming_mode() == "alias":
port_dict = config_db.get_table(table_name)
if port_dict:
for port_name in port_dict.keys():
if port == port_dict[port_name]['alias']:
return namespace
else:
entry = config_db.get_entry(table_name, port)
if entry:
return namespace

return None

def del_interface_bind_to_vrf(config_db, vrf_name):
"""del interface bind to vrf
"""
Expand Down
9 changes: 5 additions & 4 deletions scripts/sfpshow
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ from tabulate import tabulate

from utilities_common import multi_asic as multi_asic_util
from sonic_py_common.interface import front_panel_prefix, backplane_prefix
from sonic_py_common import multi_asic

# Mock the redis for unit test purposes #
try:
Expand Down Expand Up @@ -368,8 +369,8 @@ def cli():
@click.option('-d', '--dom', 'dump_dom', is_flag=True, help="Also display Digital Optical Monitoring (DOM) data")
@click.option('-n', '--namespace', default=None, help="Display interfaces for specific namespace")
def eeprom(port, dump_dom, namespace):
if port:
ns = multi_asic_util.get_port_namespace(port)
if port and multi_asic.is_multi_asic():
ns = multi_asic.get_namespace_for_port(port)
if namespace is not None and ns != namespace:
print("Error: Interface {} don't belong to this namespace {}".format(port, namespace))
return
Expand All @@ -384,8 +385,8 @@ def eeprom(port, dump_dom, namespace):
@click.option('-p', '--port', metavar='<port_name>', help="Display SFP presence for port <port_name> only")
@click.option('-n', '--namespace', default=None, help="Display interfaces for specific namespace")
def presence(port, namespace):
if port:
ns = multi_asic_util.get_port_namespace(port)
if port and multi_asic.is_multi_asic():
ns = multi_asic.get_namespace_for_port(port)
if namespace is not None and ns != namespace:
print("Error: Interface {} don't belong to this namespace {}".format(port, namespace))
return
Expand Down
207 changes: 207 additions & 0 deletions tests/mock_tables/asic0/state_db.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
{
"TRANSCEIVER_INFO|Ethernet0": {
"type": "QSFP28 or later",
"hardware_rev": "AC",
"serial": "MT1706FT02064",
"manufacturer": "Mellanox",
"model": "MFA1A00-C003",
"vendor_oui": "00-02-c9",
"vendor_date": "2017-01-13 ",
"connector": "No separable connector",
"encoding": "64B66B",
"ext_identifier": "Power Class 3(2.5W max), CDR present in Rx Tx",
"ext_rateselect_compliance": "QSFP+ Rate Select Version 1",
"cable_type": "Length Cable Assembly(m)",
"cable_length": "3",
"specification_compliance": "{'10/40G Ethernet Compliance Code': '40G Active Cable (XLPPI)'}",
"nominal_bit_rate": "255",
"application_advertisement": "N/A"
},
"TRANSCEIVER_DOM_SENSOR|Ethernet0": {
"temperature": "30.9258",
"voltage": "3.2824",
"rx1power": "0.3802",
"rx2power": "-0.4871",
"rx3power": "-0.0860",
"rx4power": "0.3830",
"tx1bias": "6.7500",
"tx2bias": "6.7500",
"tx3bias": "6.7500",
"tx4bias": "6.7500",
"tx1power": "N/A",
"tx2power": "N/A",
"tx3power": "N/A",
"tx4power": "N/A",
"rxpowerhighalarm": "3.4001",
"rxpowerhighwarning": "2.4000",
"rxpowerlowalarm": "-13.5067",
"rxpowerlowwarning": "-9.5001",
"txbiashighalarm": "10.0000",
"txbiashighwarning": "9.5000",
"txbiaslowalarm": "0.5000",
"txbiaslowwarning": "1.0000",
"temphighalarm": "75.0000",
"temphighwarning": "70.0000",
"templowalarm": "-5.0000",
"templowwarning": "0.0000",
"vcchighalarm": "3.6300",
"vcchighwarning": "3.4650",
"vcclowalarm": "2.9700",
"vcclowwarning": "3.1349"
},
"CHASSIS_INFO|chassis 1": {
"psu_num": "2"
},
"PSU_INFO|PSU 1": {
"presence": "true",
"status": "true",
"led_status": "green"
},
"PSU_INFO|PSU 2": {
"presence": "true",
"status": "true",
"led_status": "green"
},
"SWITCH_CAPABILITY|switch": {
"MIRROR": "true",
"MIRRORV6": "true",
"ACL_ACTIONS|INGRESS": "PACKET_ACTION,REDIRECT_ACTION,MIRROR_INGRESS_ACTION",
"ACL_ACTIONS|EGRESS": "PACKET_ACTION,MIRROR_EGRESS_ACTION",
"ACL_ACTION|PACKET_ACTION": "FORWARD"
},
"DEBUG_COUNTER_CAPABILITIES|PORT_INGRESS_DROPS": {
"reasons": "[IP_HEADER_ERROR,NO_L3_HEADER]",
"count": "4"
},
"DEBUG_COUNTER_CAPABILITIES|SWITCH_EGRESS_DROPS": {
"reasons": "[ACL_ANY,L2_ANY,L3_ANY]",
"count": "2"
},
"LAG_MEMBER_TABLE|PortChannel0001|Ethernet112": {
"runner.actor_lacpdu_info.state": "5",
"runner.state": "disabled",
"runner.partner_lacpdu_info.port": "0",
"runner.actor_lacpdu_info.port": "113",
"runner.selected": "false",
"runner.partner_lacpdu_info.state": "0",
"ifinfo.dev_addr": "52:54:00:f2:e1:23",
"runner.partner_lacpdu_info.system": "00:00:00:00:00:00",
"link_watches.list.link_watch_0.up": "false",
"runner.actor_lacpdu_info.system": "52:54:00:f2:e1:23",
"runner.aggregator.selected": "false",
"runner.aggregator.id": "0",
"link.up": "false",
"ifinfo.ifindex": "98"
},
"LAG_MEMBER_TABLE|PortChannel0002|Ethernet116": {
"runner.actor_lacpdu_info.state": "61",
"runner.state": "current",
"runner.partner_lacpdu_info.port": "1",
"runner.actor_lacpdu_info.port": "117",
"runner.selected": "true",
"runner.partner_lacpdu_info.state": "61",
"ifinfo.dev_addr": "52:54:00:f2:e1:23",
"runner.partner_lacpdu_info.system": "1e:af:77:fc:79:ee",
"link_watches.list.link_watch_0.up": "false",
"runner.actor_lacpdu_info.system": "52:54:00:f2:e1:23",
"runner.aggregator.selected": "true",
"runner.aggregator.id": "97",
"link.up": "true",
"ifinfo.ifindex": "97"
},
"LAG_MEMBER_TABLE|PortChannel0003|Ethernet120": {
"runner.actor_lacpdu_info.state": "61",
"runner.state": "current",
"runner.partner_lacpdu_info.port": "1",
"runner.actor_lacpdu_info.port": "121",
"runner.selected": "true",
"runner.partner_lacpdu_info.state": "61",
"ifinfo.dev_addr": "52:54:00:f2:e1:23",
"runner.partner_lacpdu_info.system": "16:0e:58:6f:3c:dd",
"link_watches.list.link_watch_0.up": "false",
"runner.actor_lacpdu_info.system": "52:54:00:f2:e1:23",
"runner.aggregator.selected": "true",
"runner.aggregator.id": "100",
"link.up": "true",
"ifinfo.ifindex": "100"
},
"LAG_TABLE|PortChannel0001": {
"runner.fallback": "false",
"team_device.ifinfo.dev_addr": "52:54:00:f2:e1:23",
"team_device.ifinfo.ifindex": "71",
"setup.pid": "32",
"state": "ok",
"runner.fast_rate": "false",
"setup.kernel_team_mode_name": "loadbalance",
"runner.active": "true"
},
"LAG_TABLE|PortChannel0002": {
"runner.fallback": "false",
"team_device.ifinfo.dev_addr": "52:54:00:f2:e1:23",
"team_device.ifinfo.ifindex": "72",
"setup.pid": "40",
"state": "ok",
"runner.fast_rate": "false",
"setup.kernel_team_mode_name": "loadbalance",
"runner.active": "true"
},
"LAG_TABLE|PortChannel0003": {
"runner.fallback": "false",
"team_device.ifinfo.dev_addr": "52:54:00:f2:e1:23",
"team_device.ifinfo.ifindex": "73",
"setup.pid": "48",
"state": "ok",
"runner.fast_rate": "false",
"setup.kernel_team_mode_name": "loadbalance",
"runner.active": "true"
},
"LAG_TABLE|PortChannel0004": {
"runner.fallback": "false",
"team_device.ifinfo.dev_addr": "52:54:00:f2:e1:23",
"team_device.ifinfo.ifindex": "74",
"setup.pid": "56",
"state": "ok",
"runner.fast_rate": "false",
"setup.kernel_team_mode_name": "loadbalance",
"runner.active": "true"
},
"FAN_INFO|fan1": {
"drawer_name": "drawer1",
"presence": "True",
"model": "N/A",
"serial": "N/A",
"status": "True",
"direction": "intake",
"speed": "30",
"speed_tolerance": "50",
"speed_target": "20",
"led_status": "red",
"timestamp": "20200813 01:32:30"
},
"FAN_INFO|fan2": {
"drawer_name": "drawer2",
"presence": "True",
"model": "N/A",
"serial": "N/A",
"status": "False",
"direction": "intake",
"speed": "50",
"speed_tolerance": "50",
"speed_target": "50",
"led_status": "green",
"timestamp": "20200813 01:32:30"
},
"FAN_INFO|fan3": {
"drawer_name": "drawer3",
"presence": "True",
"model": "N/A",
"serial": "N/A",
"status": "Updating",
"direction": "intake",
"speed": "50",
"speed_tolerance": "50",
"speed_target": "50",
"led_status": "green",
"timestamp": "20200813 01:32:30"
}
}
6 changes: 2 additions & 4 deletions tests/mock_tables/mock_multi_asic.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# MONKEY PATCH!!!
import mock
from sonic_py_common import multi_asic
from utilities_common import multi_asic as multi_asic_util


def mock_get_num_asics():
return 2
Expand All @@ -15,10 +13,10 @@ def mock_is_multi_asic():
def mock_get_namespace_list(namespace=None):
return ['asic0', 'asic1']

def mock_get_port_namespace(port):
def mock_get_namespace_for_port(port):
return 'asic0'

multi_asic.get_num_asics = mock_get_num_asics
multi_asic.is_multi_asic = mock_is_multi_asic
multi_asic.get_namespace_list = mock_get_namespace_list
multi_asic.get_port_namespace = mock_get_port_namespace
multi_asic.get_namespace_for_port = mock_get_namespace_for_port
58 changes: 29 additions & 29 deletions tests/multi_asic_intfutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,43 @@
scripts_path = os.path.join(modules_path, "scripts")

intf_status_all = """\
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- ------------ ------- ----- ----- -------------- --------------- ------ ------- ------ ----------
Ethernet0 33,34,35,36 40G 9100 N/A Ethernet1/1 PortChannel1002 up up N/A off
Ethernet4 29,30,31,32 40G 9100 N/A Ethernet1/2 PortChannel1002 up up N/A off
Ethernet-BP0 93,94,95,96 40G 9100 N/A Ethernet-BP0 PortChannel4001 up up N/A off
Ethernet-BP4 97,98,99,100 40G 9100 N/A Ethernet-BP4 PortChannel4001 up up N/A off
Ethernet-BP256 61,62,63,64 40G 9100 N/A Ethernet-BP256 PortChannel4009 up up N/A off
Ethernet-BP260 57,58,59,60 40G 9100 N/A Ethernet-BP260 PortChannel4009 up up N/A off
PortChannel1002 N/A 80G 9100 N/A N/A routed up up N/A N/A
PortChannel4001 N/A 80G 9100 N/A N/A routed up up N/A N/A
PortChannel4009 N/A 80G 9100 N/A N/A routed up up N/A N/A
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- ------------ ------- ----- ----- -------------- --------------- ------ ------- --------------- ----------
Ethernet0 33,34,35,36 40G 9100 N/A Ethernet1/1 PortChannel1002 up up QSFP28 or later off
Ethernet4 29,30,31,32 40G 9100 N/A Ethernet1/2 PortChannel1002 up up N/A off
Ethernet-BP0 93,94,95,96 40G 9100 N/A Ethernet-BP0 PortChannel4001 up up N/A off
Ethernet-BP4 97,98,99,100 40G 9100 N/A Ethernet-BP4 PortChannel4001 up up N/A off
Ethernet-BP256 61,62,63,64 40G 9100 N/A Ethernet-BP256 PortChannel4009 up up N/A off
Ethernet-BP260 57,58,59,60 40G 9100 N/A Ethernet-BP260 PortChannel4009 up up N/A off
PortChannel1002 N/A 80G 9100 N/A N/A routed up up N/A N/A
PortChannel4001 N/A 80G 9100 N/A N/A routed up up N/A N/A
PortChannel4009 N/A 80G 9100 N/A N/A routed up up N/A N/A
"""
intf_status = """\
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- ----------- ------- ----- ----- ----------- --------------- ------ ------- ------ ----------
Ethernet0 33,34,35,36 40G 9100 N/A Ethernet1/1 PortChannel1002 up up N/A off
Ethernet4 29,30,31,32 40G 9100 N/A Ethernet1/2 PortChannel1002 up up N/A off
PortChannel1002 N/A 80G 9100 N/A N/A routed up up N/A N/A
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- ----------- ------- ----- ----- ----------- --------------- ------ ------- --------------- ----------
Ethernet0 33,34,35,36 40G 9100 N/A Ethernet1/1 PortChannel1002 up up QSFP28 or later off
Ethernet4 29,30,31,32 40G 9100 N/A Ethernet1/2 PortChannel1002 up up N/A off
PortChannel1002 N/A 80G 9100 N/A N/A routed up up N/A N/A
"""

intf_status_asic0 = """\
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- ----------- ------- ----- ----- ----------- --------------- ------ ------- ------ ----------
Ethernet0 33,34,35,36 40G 9100 N/A Ethernet1/1 PortChannel1002 up up N/A off
Ethernet4 29,30,31,32 40G 9100 N/A Ethernet1/2 PortChannel1002 up up N/A off
PortChannel1002 N/A 80G 9100 N/A N/A routed up up N/A N/A
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- ----------- ------- ----- ----- ----------- --------------- ------ ------- --------------- ----------
Ethernet0 33,34,35,36 40G 9100 N/A Ethernet1/1 PortChannel1002 up up QSFP28 or later off
Ethernet4 29,30,31,32 40G 9100 N/A Ethernet1/2 PortChannel1002 up up N/A off
PortChannel1002 N/A 80G 9100 N/A N/A routed up up N/A N/A
"""

intf_status_asic0_all = """\
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- ------------ ------- ----- ----- ------------ --------------- ------ ------- ------ ----------
Ethernet0 33,34,35,36 40G 9100 N/A Ethernet1/1 PortChannel1002 up up N/A off
Ethernet4 29,30,31,32 40G 9100 N/A Ethernet1/2 PortChannel1002 up up N/A off
Ethernet-BP0 93,94,95,96 40G 9100 N/A Ethernet-BP0 PortChannel4001 up up N/A off
Ethernet-BP4 97,98,99,100 40G 9100 N/A Ethernet-BP4 PortChannel4001 up up N/A off
PortChannel1002 N/A 80G 9100 N/A N/A routed up up N/A N/A
PortChannel4001 N/A 80G 9100 N/A N/A routed up up N/A N/A
Interface Lanes Speed MTU FEC Alias Vlan Oper Admin Type Asym PFC
--------------- ------------ ------- ----- ----- ------------ --------------- ------ ------- --------------- ----------
Ethernet0 33,34,35,36 40G 9100 N/A Ethernet1/1 PortChannel1002 up up QSFP28 or later off
Ethernet4 29,30,31,32 40G 9100 N/A Ethernet1/2 PortChannel1002 up up N/A off
Ethernet-BP0 93,94,95,96 40G 9100 N/A Ethernet-BP0 PortChannel4001 up up N/A off
Ethernet-BP4 97,98,99,100 40G 9100 N/A Ethernet-BP4 PortChannel4001 up up N/A off
PortChannel1002 N/A 80G 9100 N/A N/A routed up up N/A N/A
PortChannel4001 N/A 80G 9100 N/A N/A routed up up N/A N/A
"""
intf_description = """\
Interface Oper Admin Alias Description
Expand Down
Loading

0 comments on commit 4de1197

Please sign in to comment.