Skip to content

Commit 1e6a0a9

Browse files
committed
drop LINK_TRAINING and typo fix
Signed-off-by: Dante Su <[email protected]>
1 parent bf6f33c commit 1e6a0a9

File tree

5 files changed

+59
-45
lines changed

5 files changed

+59
-45
lines changed

config/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3439,7 +3439,7 @@ def speed(ctx, interface_name, interface_speed, verbose):
34393439
@click.argument('mode', metavar='<mode>', required=True, type=click.Choice(["on", "off"]))
34403440
@click.option('-v', '--verbose', is_flag=True, help="Enable verbose output")
34413441
def link_training(ctx, interface_name, mode, verbose):
3442-
"""Set interface auto negotiation mode"""
3442+
"""Set interface link training mode"""
34433443
# Get the config_db connector
34443444
config_db = ctx.obj['config_db']
34453445

scripts/intfutil

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ except KeyError:
3333
PORT_STATUS_TABLE_PREFIX = "PORT_TABLE:"
3434
PORT_STATE_TABLE_PREFIX = "PORT_TABLE|"
3535
PORT_TRANSCEIVER_TABLE_PREFIX = "TRANSCEIVER_INFO|"
36-
PORT_LINK_TRAINING_STATUS_TABLE_PREFIX = "LINK_TRAINING|"
3736
PORT_LANES_STATUS = "lanes"
3837
PORT_ALIAS = "alias"
3938
PORT_OPER_STATUS = "oper_status"
@@ -50,7 +49,7 @@ PORT_INTERFACE_TYPE = 'interface_type'
5049
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
5150
PORT_TPID = "tpid"
5251
PORT_LINK_TRAINING = 'link_training'
53-
PORT_LINK_TRAINING_STATUS = 'status'
52+
PORT_LINK_TRAINING_STATUS = 'link_training_status'
5453

5554
VLAN_SUB_INTERFACE_SEPARATOR = "."
5655
VLAN_SUB_INTERFACE_TYPE = "802.1q-encapsulation"
@@ -152,6 +151,32 @@ def appl_db_port_status_get(appl_db, intf_name, status_type):
152151
status = ','.join(new_speed_list)
153152
return status
154153

154+
def state_db_port_status_get(db, intf_name, field):
155+
"""
156+
Get the port status
157+
"""
158+
full_table_id = PORT_STATE_TABLE_PREFIX + intf_name
159+
status = db.get(db.STATE_DB, full_table_id, field)
160+
if not status:
161+
return "N/A"
162+
if field == PORT_SPEED and status != "N/A":
163+
speed = int(status)
164+
if speed >= 1000:
165+
status = '{}G'.format(int(speed / 1000))
166+
else:
167+
status = '{}M'.format(speed)
168+
elif field == PORT_ADV_SPEEDS and status not in ["N/A", "all"]:
169+
speed_list = status.split(',')
170+
new_speed_list = []
171+
for s in natsorted(speed_list):
172+
speed = int(s)
173+
if speed >= 1000:
174+
new_speed_list.append('{}G'.format(int(speed / 1000)))
175+
else:
176+
new_speed_list.append('{}M'.format(speed))
177+
status = ','.join(new_speed_list)
178+
return status
179+
155180
def port_oper_speed_get(db, intf_name):
156181
"""
157182
Get port oper speed
@@ -183,14 +208,6 @@ def state_db_port_optics_get(state_db, intf_name, type):
183208
return "N/A"
184209
return optics_type
185210

186-
def state_db_port_link_training_status_get(state_db, intf_name, type):
187-
"""
188-
Get link training status for port
189-
"""
190-
full_table_id = PORT_LINK_TRAINING_STATUS_TABLE_PREFIX + intf_name
191-
status = state_db.get(state_db.STATE_DB, full_table_id, type)
192-
return "N/A" if status is None else status
193-
194211
def merge_dicts(x,y):
195212
# store a copy of x, but overwrite with y's values where applicable
196213
merged = dict(x,**y)
@@ -759,9 +776,9 @@ class IntfLinkTrainingStatus(object):
759776
lt_admin = appl_db_port_status_get(self.db, key, PORT_LINK_TRAINING)
760777
if lt_admin not in ['on', 'off']:
761778
lt_admin = '-'
762-
lt_status = state_db_port_link_training_status_get(self.db, key, PORT_LINK_TRAINING_STATUS)
763-
if lt_status in ['N/A', '']:
764-
lt_status = '-'
779+
lt_status = state_db_port_status_get(self.db, key, PORT_LINK_TRAINING_STATUS)
780+
if lt_status in ['N/A', '', None]:
781+
lt_status = 'off'
765782
table.append((key,
766783
lt_status.replace('_', ' '),
767784
lt_admin,

tests/dump_tests/dump_state_test.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,21 @@ def compare_json_output(exp_json, rec, exclude_paths=None):
2525

2626

2727
table_display_output = '''\
28-
+-------------+-----------+----------------------------------------------------------------------------+
29-
| port_name | DB_NAME | DUMP |
30-
+=============+===========+============================================================================+
31-
| Ethernet0 | STATE_DB | +----------------------+-------------------------------------------------+ |
32-
| | | | Keys | field-value pairs | |
33-
| | | +======================+=================================================+ |
34-
| | | | PORT_TABLE|Ethernet0 | +------------------+--------------------------+ | |
35-
| | | | | | field | value | | |
36-
| | | | | |------------------+--------------------------| | |
37-
| | | | | | speed | 100000 | | |
38-
| | | | | | supported_speeds | 10000,25000,40000,100000 | | |
39-
| | | | | +------------------+--------------------------+ | |
40-
| | | +----------------------+-------------------------------------------------+ |
41-
+-------------+-----------+----------------------------------------------------------------------------+
28+
+-------------+-----------+--------------------------------------------------------------------------------+
29+
| port_name | DB_NAME | DUMP |
30+
+=============+===========+================================================================================+
31+
| Ethernet0 | STATE_DB | +----------------------+-----------------------------------------------------+ |
32+
| | | | Keys | field-value pairs | |
33+
| | | +======================+=====================================================+ |
34+
| | | | PORT_TABLE|Ethernet0 | +----------------------+--------------------------+ | |
35+
| | | | | | field | value | | |
36+
| | | | | |----------------------+--------------------------| | |
37+
| | | | | | speed | 100000 | | |
38+
| | | | | | supported_speeds | 10000,25000,40000,100000 | | |
39+
| | | | | | link_training_status | not_trained | | |
40+
| | | | | +----------------------+--------------------------+ | |
41+
| | | +----------------------+-----------------------------------------------------+ |
42+
+-------------+-----------+--------------------------------------------------------------------------------+
4243
'''
4344

4445

@@ -120,7 +121,7 @@ def test_identifier_single(self):
120121
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': []},
121122
'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': []},
122123
'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'}},
123-
'STATE_DB': {'keys': [{'PORT_TABLE|Ethernet0': {'speed': '100000', 'supported_speeds': '10000,25000,40000,100000'}}], 'tables_not_found': []}}}
124+
'STATE_DB': {'keys': [{'PORT_TABLE|Ethernet0': {'speed': '100000', 'supported_speeds': '10000,25000,40000,100000', 'link_training_status': 'not_trained'}}], 'tables_not_found': []}}}
124125

125126
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
126127
# 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
@@ -137,7 +138,7 @@ def test_identifier_multiple(self):
137138
{"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": []},
138139
"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": []},
139140
"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"}},
140-
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}},
141+
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"speed": "100000", "supported_speeds": "10000,25000,40000,100000", "link_training_status": "not_trained"}}], "tables_not_found": []}},
141142
"Ethernet4":
142143
{"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": []},
143144
"APPL_DB": {"keys": [], "tables_not_found": ["PORT_TABLE"]},
@@ -166,7 +167,7 @@ def test_option_db_filtering(self):
166167
result = runner.invoke(dump.state, ["port", "Ethernet0", "--db", "ASIC_DB", "--db", "STATE_DB"])
167168
print(result.output)
168169
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"}},
169-
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}}}
170+
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"speed": "100000", "supported_speeds": "10000,25000,40000,100000", 'link_training_status': 'not_trained'}}], "tables_not_found": []}}}
170171
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
171172
ddiff = compare_json_output(expected, result.output)
172173
assert not ddiff, ddiff

tests/intfutil_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@
9191
Ethernet0 not trained on down up
9292
Ethernet32 trained on up up
9393
Ethernet112 off off up up
94-
Ethernet116 - - up up
95-
Ethernet120 - - up up
96-
Ethernet124 - - up up
94+
Ethernet116 off - up up
95+
Ethernet120 off - up up
96+
Ethernet124 off - up up
9797
"""
9898

9999
class TestIntfutil(TestCase):

tests/mock_tables/state_db.json

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -612,10 +612,15 @@
612612
},
613613
"PORT_TABLE|Ethernet0": {
614614
"speed" : "100000",
615-
"supported_speeds": "10000,25000,40000,100000"
615+
"supported_speeds": "10000,25000,40000,100000",
616+
"link_training_status": "not_trained"
617+
},
618+
"PORT_TABLE|Ethernet32": {
619+
"link_training_status": "trained"
616620
},
617621
"PORT_TABLE|Ethernet112": {
618-
"speed": "40000"
622+
"speed": "40000",
623+
"link_training_status": "off"
619624
},
620625
"PCIE_DEVICE|00:01.0": {
621626
"correctable|BadDLLP": "0",
@@ -726,14 +731,5 @@
726731
"pck_expected_count": "840",
727732
"link_prober_unknown_start": "2022-Jan-26 03:13:05.366900",
728733
"link_prober_unknown_end": "2022-Jan-26 03:17:35.446580"
729-
},
730-
"LINK_TRAINING|Ethernet0": {
731-
"status": "not_trained"
732-
},
733-
"LINK_TRAINING|Ethernet32": {
734-
"status": "trained"
735-
},
736-
"LINK_TRAINING|Ethernet112": {
737-
"status": "off"
738734
}
739735
}

0 commit comments

Comments
 (0)