Skip to content

Commit

Permalink
CLI enhancement, change ASIC_DB2 to APPL_DB
Browse files Browse the repository at this point in the history
  • Loading branch information
slogan621 committed Jun 4, 2020
1 parent 9196818 commit 1d4b6a0
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 75 deletions.
62 changes: 7 additions & 55 deletions scripts/gearboxutil
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ GEARBOX_TABLE_PORT_PREFIX = "_GEARBOX_TABLE:phy:{}:ports:{}"

PORT_TABLE_ETHERNET_PREFIX = "PORT_TABLE:{}"

ASIC_STATE_TABLE_PORT_PREFIX = "ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:{}"
ASIC_STATE_TABLE_SWITCH_PREFIX = "ASIC_STATE:SAI_OBJECT_TYPE_SWITCH:oid:{}"
ASIC_GEARBOX_TABLE_SWITCH_PREFIX = "ASIC_GEARBOX|MISC_SAI_SWITCH_ATTR:{}"

PHY_NAME = "name"
PHY_ID = "phy_id"
PHY_OID = "phy_oid"
PHY_FIRMWARE_MAJOR_VERSION = "SAI_SWITCH_ATTR_FIRMWARE_MAJOR_VERSION"
PHY_FIRMWARE_MAJOR_VERSION = "firmware_major_version"
PHY_LINE_LANES = "line_lanes"
PHY_SYSTEM_LANES = "system_lanes"

Expand Down Expand Up @@ -71,27 +67,6 @@ def get_appl_key_attr(db, key, attr, lane_count=1):

return val

def get_asic2_key_attr(asic_db, phy_oid, attr):
"""
Get the phy attribute
"""

full_table_id = ASIC_GEARBOX_TABLE_SWITCH_PREFIX.format(phy_oid)
# Replace needed for mock_table unit testing
full_table_id = full_table_id.replace("ATTR:0", "ATTR:oid:0")
val = asic_db.get(asic_db.ASIC_DB2, full_table_id, attr)
if val is None:
return "N/A"

return val

def db_connect_asic2():
asic_db = swsssdk.SonicV2Connector(host='127.0.0.1')
if asic_db is None:
return None
asic_db.connect(asic_db.ASIC_DB2)
return asic_db

def db_connect_appl():
appl_db = swsssdk.SonicV2Connector(host='127.0.0.1')
if appl_db is None:
Expand All @@ -117,23 +92,17 @@ def appl_db_keys_get(appl_db):

def appl_db_interface_keys_get(appl_db):
"""
Get ASIC_DB Keys
Get APPL_DB Keys
"""
return appl_db.keys(appl_db.APPL_DB, GEARBOX_TABLE_INTERFACE_PREFIX.format("*"))

def asic2_db_keys_get(asic_db):
"""
Get ASIC_DB Keys
"""
return asic_db.keys(asic_db.ASIC_DB2, ASIC_GEARBOX_TABLE_SWITCH_PREFIX.format("*"))

# ========================== phy-status logic ==========================

phy_header_status = ['PHY Id', 'Name', 'Firmware']

class PhyStatus(object):

def display_phy_status(self, appl_db_keys, asic_db_keys):
def display_phy_status(self, appl_db_keys):
"""
Generate phy status output
"""
Expand All @@ -149,8 +118,7 @@ class PhyStatus(object):
data_row = (
phy_id,
get_appl_key_attr(self.appl_db, GEARBOX_TABLE_PHY_PREFIX.format(phy_id), PHY_NAME),
get_asic2_key_attr(self.asic_db, phy_oid, PHY_FIRMWARE_MAJOR_VERSION))

get_appl_key_attr(self.appl_db, GEARBOX_TABLE_PHY_PREFIX.format(phy_id), PHY_FIRMWARE_MAJOR_VERSION))
table.append(data_row)

# Sorting and tabulating the result table.
Expand All @@ -159,31 +127,23 @@ class PhyStatus(object):

def __init__(self):

self.asic_db = db_connect_asic2()
self.appl_db = db_connect_appl()

if self.asic_db is None:
return
if self.appl_db is None:
return

appl_db_keys = appl_db_keys_get(self.appl_db)
if appl_db_keys is None:
return

asic_db_keys = asic2_db_keys_get(self.asic_db)
if asic_db_keys is None:
return

self.display_phy_status(appl_db_keys, asic_db_keys)
self.display_phy_status(appl_db_keys)

# ========================== interface-status logic ==========================

intf_header_status = ['PHY Id', 'Interface', 'MAC Lanes', 'MAC Lane Speed', 'PHY Lanes', 'PHY Lane Speed', 'Line Lanes', 'Line Lane Speed', 'Oper', 'Admin']

class InterfaceStatus(object):

def display_intf_status(self, appl_db_keys, asic_db_keys):
def display_intf_status(self, appl_db_keys):
"""
Generate phy status output
"""
Expand Down Expand Up @@ -225,23 +185,15 @@ class InterfaceStatus(object):

def __init__(self):

self.asic_db = db_connect_asic2()
self.appl_db = db_connect_appl()

if self.asic_db is None:
return
if self.appl_db is None:
return

appl_db_keys = appl_db_interface_keys_get(self.appl_db)
if appl_db_keys is None:
return

asic_db_keys = asic2_db_keys_get(self.asic_db)
if asic_db_keys is None:
return

self.display_intf_status(appl_db_keys, asic_db_keys)
self.display_intf_status(appl_db_keys)

def main(args):
"""
Expand Down
6 changes: 4 additions & 2 deletions sonic-utilities-tests/mock_tables/appl_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
"_GEARBOX_TABLE:phy:1": {
"name": "sesto-1",
"phy_id": "1",
"phy_oid": "0x21000000000002"
"phy_oid": "0x21000000000002",
"firmware_major_version": "v0.2"
},
"_GEARBOX_TABLE:phy:2": {
"name": "sesto-2",
"phy_id": "2",
"phy_oid": "0x21000000000003"
"phy_oid": "0x21000000000003",
"firmware_major_version": "v0.3"
},
"_GEARBOX_TABLE:interface:200": {
"name": "Ethernet200",
Expand Down
16 changes: 0 additions & 16 deletions sonic-utilities-tests/mock_tables/asic_db2.json

This file was deleted.

2 changes: 0 additions & 2 deletions sonic-utilities-tests/mock_tables/dbconnector.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ def __init__(self, *args, **kwargs):
fname = 'config_db.json'
elif db == 6:
fname = 'state_db.json'
elif db == 8:
fname = 'asic_db2.json'
else:
raise ValueError("Invalid db")
self.pubsub = MockPubSub()
Expand Down

0 comments on commit 1d4b6a0

Please sign in to comment.