@@ -5,6 +5,13 @@ import os
5
5
import re
6
6
import sys
7
7
8
+ from natsort import natsorted
9
+ from tabulate import tabulate
10
+ from utilities_common import constants
11
+ from utilities_common import multi_asic as multi_asic_util
12
+ from utilities_common .intf_filter import parse_interface_in_filter
13
+ from sonic_py_common .interface import get_intf_longname
14
+
8
15
# mock the redis for unit test purposes #
9
16
try :
10
17
if os .environ ["UTILITIES_UNIT_TESTING" ] == "2" :
13
20
sys .path .insert (0 , modules_path )
14
21
sys .path .insert (0 , tests_path )
15
22
import mock_tables .dbconnector
16
- from mock_platform_sfputil .mock_platform_sfputil import mock_platform_sfputil_helper
17
- mock_platform_sfputil_helper ()
18
23
if os .environ ["UTILITIES_UNIT_TESTING_TOPOLOGY" ] == "multi_asic" :
19
24
import mock_tables .mock_multi_asic
20
25
mock_tables .dbconnector .load_namespace_config ()
21
26
22
27
except KeyError :
23
28
pass
24
29
25
- from natsort import natsorted
26
- from tabulate import tabulate
27
- from utilities_common import constants
28
- from utilities_common import multi_asic as multi_asic_util
29
- from utilities_common .intf_filter import parse_interface_in_filter
30
- from utilities_common .platform_sfputil_helper import is_rj45_port , RJ45_PORT_TYPE
31
- from sonic_py_common .interface import get_intf_longname
32
-
33
30
# ========================== Common interface-utils logic ==========================
34
31
35
32
@@ -52,7 +49,7 @@ PORT_RMT_ADV_SPEEDS = 'rmt_adv_speeds'
52
49
PORT_INTERFACE_TYPE = 'interface_type'
53
50
PORT_ADV_INTERFACE_TYPES = 'adv_interface_types'
54
51
PORT_TPID = "tpid"
55
- OPTICS_TYPE_RJ45 = RJ45_PORT_TYPE
52
+ OPTICS_TYPE_RJ45 = 'RJ45'
56
53
PORT_LINK_TRAINING = 'link_training'
57
54
PORT_LINK_TRAINING_STATUS = 'link_training_status'
58
55
@@ -164,10 +161,10 @@ def appl_db_port_status_get(appl_db, intf_name, status_type):
164
161
if status is None :
165
162
return "N/A"
166
163
if status_type == PORT_SPEED and status != "N/A" :
167
- optics_type = port_optics_get (appl_db , intf_name , PORT_OPTICS_TYPE )
164
+ optics_type = state_db_port_optics_get (appl_db , intf_name , PORT_OPTICS_TYPE )
168
165
status = port_speed_parse (status , optics_type )
169
166
elif status_type == PORT_ADV_SPEEDS and status != "N/A" and status != "all" :
170
- optics_type = port_optics_get (appl_db , intf_name , PORT_OPTICS_TYPE )
167
+ optics_type = state_db_port_optics_get (appl_db , intf_name , PORT_OPTICS_TYPE )
171
168
speed_list = status .split (',' )
172
169
new_speed_list = []
173
170
for s in natsorted (speed_list ):
@@ -184,7 +181,7 @@ def state_db_port_status_get(db, intf_name, field):
184
181
if not status :
185
182
return "N/A"
186
183
if field in [PORT_RMT_ADV_SPEEDS ] and status not in ["N/A" , "all" ]:
187
- optics_type = port_optics_get (db , intf_name , PORT_OPTICS_TYPE )
184
+ optics_type = state_db_port_optics_get (db , intf_name , PORT_OPTICS_TYPE )
188
185
speed_list = status .split (',' )
189
186
new_speed_list = []
190
187
for s in natsorted (speed_list ):
@@ -201,7 +198,7 @@ def port_oper_speed_get(db, intf_name):
201
198
if oper_speed is None or oper_speed == "N/A" or oper_status != "up" :
202
199
return appl_db_port_status_get (db , intf_name , PORT_SPEED )
203
200
else :
204
- optics_type = port_optics_get (db , intf_name , PORT_OPTICS_TYPE )
201
+ optics_type = state_db_port_optics_get (db , intf_name , PORT_OPTICS_TYPE )
205
202
return port_speed_parse (oper_speed , optics_type )
206
203
207
204
def port_oper_speed_get_raw (db , intf_name ):
@@ -214,17 +211,14 @@ def port_oper_speed_get_raw(db, intf_name):
214
211
speed = db .get (db .APPL_DB , PORT_STATUS_TABLE_PREFIX + intf_name , PORT_SPEED )
215
212
return speed
216
213
217
- def port_optics_get (state_db , intf_name , type ):
214
+ def state_db_port_optics_get (state_db , intf_name , type ):
218
215
"""
219
216
Get optic type info for port
220
217
"""
221
218
full_table_id = PORT_TRANSCEIVER_TABLE_PREFIX + intf_name
222
219
optics_type = state_db .get (state_db .STATE_DB , full_table_id , type )
223
220
if optics_type is None :
224
- if is_rj45_port (intf_name ):
225
- return OPTICS_TYPE_RJ45
226
- else :
227
- return "N/A"
221
+ return "N/A"
228
222
return optics_type
229
223
230
224
def merge_dicts (x ,y ):
@@ -331,13 +325,13 @@ def po_speed_dict(po_int_dict, appl_db):
331
325
# If no speed was returned, append None without format
332
326
po_list .append (None )
333
327
else :
334
- optics_type = port_optics_get (appl_db , value [0 ], PORT_OPTICS_TYPE )
328
+ optics_type = state_db_port_optics_get (appl_db , value [0 ], PORT_OPTICS_TYPE )
335
329
interface_speed = port_speed_parse (interface_speed , optics_type )
336
330
po_list .append (interface_speed )
337
331
elif len (value ) > 1 :
338
332
for intf in value :
339
333
temp_speed = port_oper_speed_get_raw (appl_db , intf )
340
- optics_type = port_optics_get (appl_db , intf , PORT_OPTICS_TYPE )
334
+ optics_type = state_db_port_optics_get (appl_db , intf , PORT_OPTICS_TYPE )
341
335
temp_speed = int (temp_speed ) if temp_speed else 0
342
336
agg_speed_list .append (temp_speed )
343
337
interface_speed = sum (agg_speed_list )
@@ -483,7 +477,7 @@ class IntfStatus(object):
483
477
config_db_vlan_port_keys_get (self .combined_int_to_vlan_po_dict , self .front_panel_ports_list , key ),
484
478
appl_db_port_status_get (self .db , key , PORT_OPER_STATUS ),
485
479
appl_db_port_status_get (self .db , key , PORT_ADMIN_STATUS ),
486
- port_optics_get (self .db , key , PORT_OPTICS_TYPE ),
480
+ state_db_port_optics_get (self .db , key , PORT_OPTICS_TYPE ),
487
481
appl_db_port_status_get (self .db , key , PORT_PFC_ASYM_STATUS )))
488
482
489
483
for po , value in self .portchannel_speed_dict .items ():
0 commit comments