Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 19 additions & 12 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def _update_vdm_dict(self, dict_to_update, new_key, vdm_raw_dict, vdm_observable
def freeze_vdm_stats(self):
'''
This function freeze all the vdm statistics reporting registers.
When raised by the host, causes the module to freeze and hold all
reported statistics reporting registers (minimum, maximum and
When raised by the host, causes the module to freeze and hold all
reported statistics reporting registers (minimum, maximum and
average values)in Pages 24h-27h.

Returns True if the provision succeeds and False incase of failure.
Expand All @@ -184,9 +184,9 @@ def get_vdm_freeze_status(self):
def unfreeze_vdm_stats(self):
'''
This function unfreeze all the vdm statistics reporting registers.
When freeze is ceased by the host, releases the freeze request, allowing the
When freeze is ceased by the host, releases the freeze request, allowing the
reported minimum, maximum and average values to update again.

Returns True if the provision succeeds and False incase of failure.
'''
return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_UNFREEZE)
Expand Down Expand Up @@ -378,7 +378,7 @@ def get_transceiver_info_firmware_versions(self):
( _, _, _, _, _, _, _, _, ActiveFirmware, InactiveFirmware) = result['result']
except (ValueError, TypeError):
return return_dict

return_dict["active_firmware"] = ActiveFirmware
return_dict["inactive_firmware"] = InactiveFirmware
return return_dict
Expand Down Expand Up @@ -589,6 +589,13 @@ def get_voltage(self):
return None
return float("{:.3f}".format(voltage))

def is_copper(self):
'''
Returns True if the module is copper, False otherwise
'''
media_intf = self.get_module_media_type()
return media_intf == "passive_copper_media_interface" if media_intf else None

@read_only_cached_api_return
def is_flat_memory(self):
return self.xcvr_eeprom.read(consts.FLAT_MEM_FIELD) is not False
Expand Down Expand Up @@ -1068,10 +1075,10 @@ def get_media_lane_count(self, appl=1):
'''
if self.is_flat_memory():
return 0

if (appl <= 0):
return 0

appl_advt = self.get_application_advertisement()
return appl_advt[appl]['media_lane_count'] if len(appl_advt) >= appl else 0

Expand Down Expand Up @@ -1104,10 +1111,10 @@ def get_media_lane_assignment_option(self, appl=1):
'''
if self.is_flat_memory():
return 'N/A'

if (appl <= 0):
return 0

appl_advt = self.get_application_advertisement()
return appl_advt[appl]['media_lane_assignment_options'] if len(appl_advt) >= appl else 0

Expand Down Expand Up @@ -2348,7 +2355,7 @@ def get_transceiver_vdm_real_value(self):
biasyq{lane_num} = FLOAT ; modulator bias yq in percentage
biasyp{lane_num} = FLOAT ; modulator bias yq in percentage
cdshort{lane_num} = FLOAT ; chromatic dispersion, high granularity, short link in ps/nm
cdlong{lane_num} = FLOAT ; chromatic dispersion, high granularity, long link in ps/nm
cdlong{lane_num} = FLOAT ; chromatic dispersion, high granularity, long link in ps/nm
dgd{lane_num} = FLOAT ; differential group delay in ps
sopmd{lane_num} = FLOAT ; second order polarization mode dispersion in ps^2
soproc{lane_num} = FLOAT ; state of polarization rate of change in krad/s
Expand Down Expand Up @@ -2377,7 +2384,7 @@ def get_transceiver_vdm_thresholds(self):
Returns:
A dict containing the following keys/values :
========================================================================
xxx refers to HALARM/LALARM/HWARN/LWARN threshold
xxx refers to HALARM/LALARM/HWARN/LWARN threshold
;Defines Transceiver VDM high/low alarm/warning threshold for a port
key = TRANSCEIVER_VDM_XXX_THRESHOLD|ifname ; information module VDM high/low alarm/warning threshold on port
; field = value
Expand Down Expand Up @@ -2700,7 +2707,7 @@ def decommission_all_datapaths(self):
name = "DP{}State".format(lane + 1)
if dp_state[name] != 'DataPathDeactivated':
return False

name = "ConfigStatusLane{}".format(lane + 1)
if config_state[name] != 'ConfigSuccess':
return False
Expand Down
13 changes: 13 additions & 0 deletions tests/sonic_xcvr/test_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ def test_get_voltage(self, mock_response, expected):
result = self.api.get_voltage()
assert result == expected

def test_is_copper(self):
with patch.object(self.api, 'xcvr_eeprom') as mock_eeprom:
mock_eeprom.read = MagicMock()
mock_eeprom.read.return_value = None
assert self.api.is_copper() is None
self.api.get_module_media_type = MagicMock()
self.api.get_module_media_type.return_value = "passive_copper_media_interface"
assert self.api.is_copper()
self.api.get_module_media_type.return_value = "active_cable_media_interface"
assert not self.api.is_copper()
self.api.get_module_media_type.return_value = "sm_media_interface"
assert not self.api.is_copper()

@pytest.mark.parametrize("mock_response, expected", [
(False, False)
])
Expand Down
Loading