Skip to content

Commit 2dff8cd

Browse files
SFP-Refactor: bug fixes (#248)
* SFP-Refactor: bug fix
1 parent a2e6232 commit 2dff8cd

File tree

4 files changed

+20
-35
lines changed

4 files changed

+20
-35
lines changed

sonic_platform_base/sonic_xcvr/api/public/cmis.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def get_transceiver_info(self):
130130
"ext_identifier": "%s (%sW Max)" % (power_class, max_power),
131131
"ext_rateselect_compliance": "N/A", # Not supported
132132
"cable_type": "Length Cable Assembly(m)",
133-
"cable_length": admin_info[consts.LENGTH_ASSEMBLY_FIELD],
133+
"cable_length": float(admin_info[consts.LENGTH_ASSEMBLY_FIELD]),
134134
"nominal_bit_rate": 0, # Not supported
135135
"specification_compliance": admin_info[consts.MEDIA_TYPE_FIELD],
136136
"vendor_date": admin_info[consts.VENDOR_DATE_FIELD],
@@ -621,8 +621,6 @@ def get_module_media_type(self):
621621
'''
622622
This function returns module media type: MMF, SMF, Passive Copper Cable, Active Cable Assembly or Base-T.
623623
'''
624-
if self.is_flat_memory():
625-
return 'N/A'
626624
return self.xcvr_eeprom.read(consts.MEDIA_TYPE_FIELD)
627625

628626
def get_host_electrical_interface(self):
@@ -637,19 +635,16 @@ def get_module_media_interface(self):
637635
'''
638636
This function returns module media electrical interface. Table 4-6 ~ 4-10 in SFF-8024 Rev4.6
639637
'''
640-
if self.is_flat_memory():
641-
return 'N/A'
642-
643638
media_type = self.get_module_media_type()
644-
if media_type == 'Multimode Fiber (MMF)':
639+
if media_type == 'nm_850_media_interface':
645640
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_850NM)
646-
elif media_type == 'Single Mode Fiber (SMF)':
641+
elif media_type == 'sm_media_interface':
647642
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_SM)
648-
elif media_type == 'Passive Copper Cable':
643+
elif media_type == 'passive_copper_media_interface':
649644
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_PASSIVE_COPPER)
650-
elif media_type == 'Active Cable Assembly':
645+
elif media_type == 'active_cable_media_interface':
651646
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_ACTIVE_CABLE)
652-
elif media_type == 'BASE-T':
647+
elif media_type == 'base_t_media_interface':
653648
return self.xcvr_eeprom.read(consts.MODULE_MEDIA_INTERFACE_BASE_T)
654649
else:
655650
return 'Unknown media interface'

sonic_platform_base/sonic_xcvr/codes/public/cmis.py

-9
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@ class CmisCodes(Sff8024):
1212
7: "Power Class 8"
1313
}
1414

15-
MEDIA_TYPES = {
16-
0: "Undefined",
17-
1: "nm_850_media_interface",
18-
2: "sm_media_interface",
19-
3: "passive_copper_media_interface",
20-
4: "active_cable_media_interface",
21-
5: "base_t_media_interface",
22-
}
23-
2415
MEDIA_INTERFACE_TECH = {
2516
0: '850 nm VCSEL',
2617
1: '1310 nm VCSEL',

sonic_platform_base/sonic_xcvr/codes/public/sff8024.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,13 @@ class Sff8024(XcvrCodes):
174174
129: 'Capable of 128GFC'
175175
}
176176

177-
178177
MODULE_MEDIA_TYPE = {
179178
0: 'Undefined',
180-
1: 'Multimode Fiber (MMF)',
181-
2: 'Single Mode Fiber (SMF)',
182-
3: 'Passive Copper Cable',
183-
4: 'Active Cable Assembly',
184-
5: 'BASE-T'
179+
1: 'nm_850_media_interface',
180+
2: 'sm_media_interface',
181+
3: 'passive_copper_media_interface',
182+
4: 'active_cable_media_interface',
183+
5: 'base_t_media_interface'
185184
}
186185

187186
HOST_ELECTRICAL_INTERFACE = {

tests/sonic_xcvr/test_cmis.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ def test_get_power_override_support(self, ):
574574
assert result == False
575575

576576
@pytest.mark.parametrize("mock_response, expected", [
577-
("Single Mode Fiber (SMF)", "Single Mode Fiber (SMF)")
577+
("sm_media_interface", "sm_media_interface")
578578
])
579579
def test_get_module_media_type(self, mock_response, expected):
580580
self.api.xcvr_eeprom.read = MagicMock()
@@ -592,11 +592,11 @@ def test_get_host_electrical_interface(self, mock_response, expected):
592592
assert result == expected
593593

594594
@pytest.mark.parametrize("mock_response1, mock_response2, expected", [
595-
("Single Mode Fiber (SMF)", "400ZR", "400ZR"),
596-
("Multimode Fiber (MMF)", "100GE BiDi", "100GE BiDi"),
597-
("Passive Copper Cable", "Copper cable", "Copper cable"),
598-
("Active Cable Assembly", "Active Loopback module", "Active Loopback module"),
599-
("BASE-T", "1000BASE-T (Clause 40)", "1000BASE-T (Clause 40)"),
595+
("sm_media_interface", "400ZR", "400ZR"),
596+
("nm_850_media_interface", "100GE BiDi", "100GE BiDi"),
597+
("passive_copper_media_interface", "Copper cable", "Copper cable"),
598+
("active_cable_media_interface", "Active Loopback module", "Active Loopback module"),
599+
("base_t_media_interface", "1000BASE-T (Clause 40)", "1000BASE-T (Clause 40)"),
600600
("ABCD", "ABCD", "Unknown media interface")
601601
])
602602
def test_get_module_media_interface(self, mock_response1, mock_response2, expected):
@@ -1046,7 +1046,7 @@ def test_module_fw_upgrade(self, input_param, mock_response, expected):
10461046
'VendorPN': 'ABCD',
10471047
'Connector': 'LC',
10481048
'Length Cable Assembly': 0.0,
1049-
'ModuleMediaType': 'Single Mode Fiber (SMF)',
1049+
'ModuleMediaType': 'sm_media_interface',
10501050
'VendorDate': '21010100',
10511051
'VendorOUI': 'xx-xx-xx'
10521052
},
@@ -1060,7 +1060,7 @@ def test_module_fw_upgrade(self, input_param, mock_response, expected):
10601060
'5.0',
10611061
'0.1',
10621062
'0.0',
1063-
'Single Mode Fiber (SMF)'
1063+
'sm_media_interface'
10641064
],
10651065
{ 'type': 'QSFP-DD Double Density 8X Pluggable Transceiver',
10661066
'type_abbrv_name': 'QSFP-DD',
@@ -1071,7 +1071,7 @@ def test_module_fw_upgrade(self, input_param, mock_response, expected):
10711071
'cable_type': 'Length Cable Assembly(m)',
10721072
'cable_length': 0.0,
10731073
'nominal_bit_rate': 0,
1074-
'specification_compliance': 'Single Mode Fiber (SMF)',
1074+
'specification_compliance': 'sm_media_interface',
10751075
'application_advertisement': 'N/A',
10761076
'active_firmware': '0.1',
10771077
'media_lane_count': 1,

0 commit comments

Comments
 (0)