Skip to content

Commit 65a5a6b

Browse files
authored
Fixing get port speed when oper status is down (sonic-net#2123)
* Fixing get port speed when oper status is down Signed-off-by: Sudharsan Dhamal Gopalarathnam <[email protected]> * Removing redundant if condition
1 parent c752457 commit 65a5a6b

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

scripts/intfutil

+4-2
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ def port_oper_speed_get(db, intf_name):
154154
Get port oper speed
155155
"""
156156
oper_speed = db.get(db.STATE_DB, PORT_STATE_TABLE_PREFIX + intf_name, PORT_SPEED)
157-
if oper_speed is None or oper_speed == "N/A":
157+
oper_status = db.get(db.APPL_DB, PORT_STATUS_TABLE_PREFIX + intf_name, PORT_OPER_STATUS)
158+
if oper_speed is None or oper_speed == "N/A" or oper_status != "up":
158159
return appl_db_port_status_get(db, intf_name, PORT_SPEED)
159160

160161
return '{}G'.format(oper_speed[:-3])
@@ -164,7 +165,8 @@ def port_oper_speed_get_raw(db, intf_name):
164165
Get port raw speed. E.g. 100000, 50000 and so on.
165166
"""
166167
speed = db.get(db.STATE_DB, PORT_STATE_TABLE_PREFIX + intf_name, PORT_SPEED)
167-
if speed is None or speed == "N/A":
168+
oper_status = db.get(db.APPL_DB, PORT_STATUS_TABLE_PREFIX + intf_name, PORT_OPER_STATUS)
169+
if speed is None or speed == "N/A" or oper_status != "up":
168170
speed = db.get(db.APPL_DB, PORT_STATUS_TABLE_PREFIX + intf_name, PORT_SPEED)
169171
return speed
170172

scripts/portstat

+2-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ class Portstat(object):
216216
for ns in self.multi_asic.get_ns_list_based_on_options():
217217
self.db = multi_asic.connect_to_all_dbs_for_ns(ns)
218218
speed = self.db.get(self.db.STATE_DB, state_db_table_id, PORT_SPEED_FIELD)
219-
if speed is None or speed == STATUS_NA:
219+
oper_status = self.db.get(self.db.APPL_DB, app_db_table_id, PORT_OPER_STATUS_FIELD)
220+
if speed is None or speed == STATUS_NA or oper_status != "up":
220221
speed = self.db.get(self.db.APPL_DB, app_db_table_id, PORT_SPEED_FIELD)
221222
if speed is not None:
222223
return int(speed)

scripts/voqutil

+4-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SYSTEM_PORT_CORE = "core_index"
3838
SYSTEM_PORT_CORE_PORT = "core_port_index"
3939
SYSTEM_PORT_SPEED = "speed"
4040
SYSTEM_PORT_SWITCH_ID = "switch_id"
41+
SYSTEM_PORT_OPER_STATUS = "oper_status"
4142

4243
SYSTEM_NEIGH_TABLE_PREFIX = swsscommon.CHASSIS_APP_SYSTEM_NEIGH_TABLE_NAME + "|"
4344
SYSTEM_NEIGH_MAC = "neigh"
@@ -116,7 +117,9 @@ def port_oper_speed_get(db, system_port_name):
116117
"""
117118
full_table_id = SYSTEM_STATE_PORT_TABLE_PREFIX + system_port_name
118119
oper_speed = db.get(db.STATE_DB, full_table_id, SYSTEM_PORT_SPEED)
119-
if oper_speed is None or oper_speed == "N/A":
120+
oper_status = db.get(db.APPL_DB, SYSTEM_PORT_TABLE_PREFIX + system_port_name,
121+
SYSTEM_PORT_OPER_STATUS)
122+
if oper_speed is None or oper_speed == "N/A" or oper_status != "up":
120123
return appl_db_system_port_status_get(db, system_port_name, SYSTEM_PORT_SPEED)
121124

122125
return '{}G'.format(oper_speed[:-3])

tests/dump_tests/dump_state_test.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def compare_json_output(exp_json, rec, exclude_paths=None):
3434
| | | | PORT_TABLE|Ethernet0 | +------------------+--------------------------+ | |
3535
| | | | | | field | value | | |
3636
| | | | | |------------------+--------------------------| | |
37+
| | | | | | speed | 100000 | | |
3738
| | | | | | supported_speeds | 10000,25000,40000,100000 | | |
3839
| | | | | +------------------+--------------------------+ | |
3940
| | | +----------------------+-------------------------------------------------+ |
@@ -119,7 +120,7 @@ def test_identifier_single(self):
119120
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': []},
120121
'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': []},
121122
'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'}},
122-
'STATE_DB': {'keys': [{'PORT_TABLE|Ethernet0': {'supported_speeds': '10000,25000,40000,100000'}}], 'tables_not_found': []}}}
123+
'STATE_DB': {'keys': [{'PORT_TABLE|Ethernet0': {'speed': '100000', 'supported_speeds': '10000,25000,40000,100000'}}], 'tables_not_found': []}}}
123124

124125
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
125126
# 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
@@ -136,7 +137,7 @@ def test_identifier_multiple(self):
136137
{"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": []},
137138
"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": []},
138139
"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"}},
139-
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}},
140+
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}},
140141
"Ethernet4":
141142
{"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": []},
142143
"APPL_DB": {"keys": [], "tables_not_found": ["PORT_TABLE"]},
@@ -165,7 +166,7 @@ def test_option_db_filtering(self):
165166
result = runner.invoke(dump.state, ["port", "Ethernet0", "--db", "ASIC_DB", "--db", "STATE_DB"])
166167
print(result.output)
167168
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"}},
168-
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}}}
169+
"STATE_DB": {"keys": [{"PORT_TABLE|Ethernet0": {"speed": "100000", "supported_speeds": "10000,25000,40000,100000"}}], "tables_not_found": []}}}
169170
assert result.exit_code == 0, "exit code: {}, Exception: {}, Traceback: {}".format(result.exit_code, result.exception, result.exc_info)
170171
ddiff = compare_json_output(expected, result.output)
171172
assert not ddiff, ddiff

tests/mock_tables/state_db.json

+1
Original file line numberDiff line numberDiff line change
@@ -643,6 +643,7 @@
643643
"access": "False"
644644
},
645645
"PORT_TABLE|Ethernet0": {
646+
"speed" : "100000",
646647
"supported_speeds": "10000,25000,40000,100000"
647648
},
648649
"PORT_TABLE|Ethernet112": {

0 commit comments

Comments
 (0)