Skip to content

Commit

Permalink
drop LINK_TRAINING and typo fix
Browse files Browse the repository at this point in the history
Signed-off-by: Dante Su <[email protected]>
  • Loading branch information
ds952811 committed May 11, 2022
1 parent 4643e75 commit 5903101
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 41 deletions.
2 changes: 1 addition & 1 deletion config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3684,7 +3684,7 @@ def speed(ctx, interface_name, interface_speed, verbose):
@click.argument('mode', metavar='<mode>', required=True, type=click.Choice(["on", "off"]))
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
def link_training(ctx, interface_name, mode, verbose):
"""Set interface auto negotiation mode"""
"""Set interface link training mode"""
# Get the config_db connector
config_db = ctx.obj['config_db']

Expand Down
17 changes: 4 additions & 13 deletions scripts/intfutil
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ except KeyError:
PORT_STATUS_TABLE_PREFIX = "PORT_TABLE:"
PORT_STATE_TABLE_PREFIX = "PORT_TABLE|"
PORT_TRANSCEIVER_TABLE_PREFIX = "TRANSCEIVER_INFO|"
PORT_LINK_TRAINING_STATUS_TABLE_PREFIX = "LINK_TRAINING|"
PORT_LANES_STATUS = "lanes"
PORT_ALIAS = "alias"
PORT_OPER_STATUS = "oper_status"
Expand All @@ -52,7 +51,7 @@ PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
PORT_TPID = "tpid"
OPTICS_TYPE_RJ45 = 'RJ45'
PORT_LINK_TRAINING = 'link_training'
PORT_LINK_TRAINING_STATUS = 'status'
PORT_LINK_TRAINING_STATUS = 'link_training_status'

VLAN_SUB_INTERFACE_SEPARATOR = "."
VLAN_SUB_INTERFACE_TYPE = "802.1q-encapsulation"
Expand Down Expand Up @@ -222,14 +221,6 @@ def state_db_port_optics_get(state_db, intf_name, type):
return "N/A"
return optics_type

def state_db_port_link_training_status_get(state_db, intf_name, type):
"""
Get link training status for port
"""
full_table_id = PORT_LINK_TRAINING_STATUS_TABLE_PREFIX + intf_name
status = state_db.get(state_db.STATE_DB, full_table_id, type)
return "N/A" if status is None else status

def merge_dicts(x,y):
# store a copy of x, but overwrite with y's values where applicable
merged = dict(x,**y)
Expand Down Expand Up @@ -801,9 +792,9 @@ class IntfLinkTrainingStatus(object):
lt_admin = appl_db_port_status_get(self.db, key, PORT_LINK_TRAINING)
if lt_admin not in ['on', 'off']:
lt_admin = '-'
lt_status = state_db_port_link_training_status_get(self.db, key, PORT_LINK_TRAINING_STATUS)
if lt_status in ['N/A', '']:
lt_status = '-'
lt_status = state_db_port_status_get(self.db, key, PORT_LINK_TRAINING_STATUS)
if lt_status in ['N/A', '', None]:
lt_status = 'off'
table.append((key,
lt_status.replace('_', ' '),
lt_admin,
Expand Down
37 changes: 19 additions & 18 deletions tests/dump_tests/dump_state_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,22 @@ def compare_json_output(exp_json, rec, exclude_paths=None):


table_display_output = '''\
+-------------+-----------+----------------------------------------------------------------------------+
| port_name | DB_NAME | DUMP |
+=============+===========+============================================================================+
| Ethernet0 | STATE_DB | +----------------------+-------------------------------------------------+ |
| | | | Keys | field-value pairs | |
| | | +======================+=================================================+ |
| | | | PORT_TABLE|Ethernet0 | +------------------+--------------------------+ | |
| | | | | | field | value | | |
| | | | | |------------------+--------------------------| | |
| | | | | | rmt_adv_speeds | 10,100,1000 | | |
| | | | | | speed | 100000 | | |
| | | | | | supported_speeds | 10000,25000,40000,100000 | | |
| | | | | +------------------+--------------------------+ | |
| | | +----------------------+-------------------------------------------------+ |
+-------------+-----------+----------------------------------------------------------------------------+
+-------------+-----------+--------------------------------------------------------------------------------+
| port_name | DB_NAME | DUMP |
+=============+===========+================================================================================+
| Ethernet0 | STATE_DB | +----------------------+-----------------------------------------------------+ |
| | | | Keys | field-value pairs | |
| | | +======================+=====================================================+ |
| | | | PORT_TABLE|Ethernet0 | +----------------------+--------------------------+ | |
| | | | | | field | value | | |
| | | | | |----------------------+--------------------------| | |
| | | | | | rmt_adv_speeds | 10,100,1000 | | |
| | | | | | speed | 100000 | | |
| | | | | | supported_speeds | 10000,25000,40000,100000 | | |
| | | | | | link_training_status | not_trained | | |
| | | | | +----------------------+--------------------------+ | |
| | | +----------------------+-----------------------------------------------------+ |
+-------------+-----------+--------------------------------------------------------------------------------+
'''


Expand Down Expand Up @@ -121,7 +122,7 @@ def test_identifier_single(self):
expected = {'Ethernet0': {'CONFIG_DB': {'keys': [{'PORT|Ethernet0': {'alias': 'etp1', 'description': 'etp1', 'index': '0', 'lanes': '25,26,27,28', 'mtu': '9100', 'pfc_asym': 'off', 'speed': '40000'}}], 'tables_not_found': []},
'APPL_DB': {'keys': [{'PORT_TABLE:Ethernet0': {'index': '0', 'lanes': '0', 'alias': 'Ethernet0', 'description': 'ARISTA01T2:Ethernet1', 'speed': '25000', 'oper_status': 'down', 'pfc_asym': 'off', 'mtu': '9100', 'fec': 'rs', 'admin_status': 'up'}}], 'tables_not_found': []},
'ASIC_DB': {'keys': [{'ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd00000000056d': {'SAI_HOSTIF_ATTR_NAME': 'Ethernet0', 'SAI_HOSTIF_ATTR_OBJ_ID': 'oid:0x10000000004a4', 'SAI_HOSTIF_ATTR_OPER_STATUS': 'true', 'SAI_HOSTIF_ATTR_TYPE': 'SAI_HOSTIF_TYPE_NETDEV', 'SAI_HOSTIF_ATTR_VLAN_TAG': 'SAI_HOSTIF_VLAN_TAG_STRIP'}}, {'ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x10000000004a4': {'NULL': 'NULL', 'SAI_PORT_ATTR_ADMIN_STATE': 'true', 'SAI_PORT_ATTR_MTU': '9122', 'SAI_PORT_ATTR_SPEED': '100000'}}], 'tables_not_found': [], 'vidtorid': {'oid:0xd00000000056d': 'oid:0xd', 'oid:0x10000000004a4': 'oid:0x1690000000001'}},
'STATE_DB': {'keys': [{'PORT_TABLE|Ethernet0': {'rmt_adv_speeds': '10,100,1000', 'speed': '100000', 'supported_speeds': '10000,25000,40000,100000'}}], 'tables_not_found': []}}}
'STATE_DB': {'keys': [{'PORT_TABLE|Ethernet0': {'rmt_adv_speeds': '10,100,1000', 'speed': '100000', 'supported_speeds': '10000,25000,40000,100000', 'link_training_status': 'not_trained'}}], 'tables_not_found': []}}}

assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
# Cause other tests depend and change these paths in the mock_db, this test would fail everytime when a field or a value in changed in this path, creating noise
Expand All @@ -138,7 +139,7 @@ def test_identifier_multiple(self):
{"CONFIG_DB": {"keys": [{"PORT|Ethernet0": {"alias": "etp1", "description": "etp1", "index": "0", "lanes": "25,26,27,28", "mtu": "9100", "pfc_asym": "off", "speed": "40000"}}], "tables_not_found": []},
"APPL_DB": {"keys": [{"PORT_TABLE:Ethernet0": {"index": "0", "lanes": "0", "alias": "Ethernet0", "description": "ARISTA01T2:Ethernet1", "speed": "25000", "oper_status": "down", "pfc_asym": "off", "mtu": "9100", "fec": "rs", "admin_status": "up"}}], "tables_not_found": []},
"ASIC_DB": {"keys": [{"ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd00000000056d": {"SAI_HOSTIF_ATTR_NAME": "Ethernet0", "SAI_HOSTIF_ATTR_OBJ_ID": "oid:0x10000000004a4", "SAI_HOSTIF_ATTR_OPER_STATUS": "true", "SAI_HOSTIF_ATTR_TYPE": "SAI_HOSTIF_TYPE_NETDEV", "SAI_HOSTIF_ATTR_VLAN_TAG": "SAI_HOSTIF_VLAN_TAG_STRIP"}}, {"ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x10000000004a4": {"NULL": "NULL", "SAI_PORT_ATTR_ADMIN_STATE": "true", "SAI_PORT_ATTR_MTU": "9122", "SAI_PORT_ATTR_SPEED": "100000"}}], "tables_not_found": [], "vidtorid": {"oid:0xd00000000056d": "oid:0xd", "oid:0x10000000004a4": "oid:0x1690000000001"}},
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"rmt_adv_speeds": "10,100,1000", "speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}},
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"rmt_adv_speeds": "10,100,1000", "speed": "100000", "supported_speeds": "10000,25000,40000,100000", "link_training_status": "not_trained"}}], "tables_not_found": []}},
"Ethernet4":
{"CONFIG_DB": {"keys": [{"PORT|Ethernet4": {"admin_status": "up", "alias": "etp2", "description": "Servers0:eth0", "index": "1", "lanes": "29,30,31,32", "mtu": "9100", "pfc_asym": "off", "speed": "40000"}}], "tables_not_found": []},
"APPL_DB": {"keys": [], "tables_not_found": ["PORT_TABLE"]},
Expand Down Expand Up @@ -167,7 +168,7 @@ def test_option_db_filtering(self):
result = runner.invoke(dump.state, ["port", "Ethernet0", "--db", "ASIC_DB", "--db", "STATE_DB"])
print(result.output)
expected = {"Ethernet0": {"ASIC_DB": {"keys": [{"ASIC_STATE:SAI_OBJECT_TYPE_HOSTIF:oid:0xd00000000056d": {"SAI_HOSTIF_ATTR_NAME": "Ethernet0", "SAI_HOSTIF_ATTR_OBJ_ID": "oid:0x10000000004a4", "SAI_HOSTIF_ATTR_OPER_STATUS": "true", "SAI_HOSTIF_ATTR_TYPE": "SAI_HOSTIF_TYPE_NETDEV", "SAI_HOSTIF_ATTR_VLAN_TAG": "SAI_HOSTIF_VLAN_TAG_STRIP"}}, {"ASIC_STATE:SAI_OBJECT_TYPE_PORT:oid:0x10000000004a4": {"NULL": "NULL", "SAI_PORT_ATTR_ADMIN_STATE": "true", "SAI_PORT_ATTR_MTU": "9122", "SAI_PORT_ATTR_SPEED": "100000"}}], "tables_not_found": [], "vidtorid": {"oid:0xd00000000056d": "oid:0xd", "oid:0x10000000004a4": "oid:0x1690000000001"}},
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"rmt_adv_speeds": "10,100,1000", "speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}}}
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"rmt_adv_speeds": "10,100,1000", "speed": "100000", "supported_speeds": "10000,25000,40000,100000", "link_training_status": "not_trained"}}], "tables_not_found": []}}}
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
ddiff = compare_json_output(expected, result.output)
assert not ddiff, ddiff
Expand Down
14 changes: 7 additions & 7 deletions tests/intfutil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@
Interface LT Oper LT Admin Oper Admin
----------- ----------- ---------- ------ -------
Ethernet0 not trained on down up
Ethernet16 - - up up
Ethernet24 - - up up
Ethernet28 - - up up
Ethernet16 off - up up
Ethernet24 off - up up
Ethernet28 off - up up
Ethernet32 trained on up up
Ethernet36 - - up up
Ethernet36 off - up up
Ethernet112 off off up up
Ethernet116 - - up up
Ethernet120 - - up up
Ethernet124 - - up up
Ethernet116 off - up up
Ethernet120 off - up up
Ethernet124 off - up up
"""

class TestIntfutil(TestCase):
Expand Down
9 changes: 7 additions & 2 deletions tests/mock_tables/state_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -685,10 +685,15 @@
"PORT_TABLE|Ethernet0": {
"rmt_adv_speeds" : "10,100,1000",
"speed" : "100000",
"supported_speeds": "10000,25000,40000,100000"
"supported_speeds": "10000,25000,40000,100000",
"link_training_status": "not_trained"
},
"PORT_TABLE|Ethernet32": {
"link_training_status": "trained"
},
"PORT_TABLE|Ethernet112": {
"speed": "40000"
"speed": "40000",
"link_training_status": "off"
},
"PCIE_DEVICE|00:01.0": {
"correctable|BadDLLP": "0",
Expand Down

0 comments on commit 5903101

Please sign in to comment.