Skip to content

Commit

Permalink
Signed-off-by: Jaganathan Anbalagan <jaganbal@cisco.com>
Browse files Browse the repository at this point in the history
Addressing PR comments.
Removed VDM statistics freeze/unfreeze performed inside standard APIs.
It should be performed by xcvrd explicitly.
  • Loading branch information
Jaganathan Anbalagan committed Oct 26, 2023
1 parent 0c6ec79 commit e24e792
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 28 deletions.
4 changes: 2 additions & 2 deletions sonic_platform_base/sonic_xcvr/api/public/c_cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def freeze_vdm_stats(self):
'''
return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_FREEZE)

def get_freeze_vdm_stats(self):
def get_vdm_freeze_status(self):
'''
This function reads and returns the vdm Freeze done status.
Expand All @@ -176,7 +176,7 @@ def unfreeze_vdm_stats(self):
'''
return self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_UNFREEZE)

def get_unfreeze_vdm_stats(self):
def get_vdm_unfreeze_status(self):
'''
This function reads and returns the vdm unfreeze status.
Expand Down
8 changes: 0 additions & 8 deletions sonic_platform_base/sonic_xcvr/api/public/cmisVDM.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,6 @@ def get_vdm_allpage(self):
return None
VDM_START_PAGE = 0x20
vdm = dict()
# 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.
# When ceased by the host, releases the freeze request, allowing the
# reported minimum, maximum and average values to update again.
self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_FREEZE)
time.sleep(1)
self.xcvr_eeprom.write(consts.VDM_CONTROL, VDM_UNFREEZE)
vdm_flag_page = self.xcvr_eeprom.read_raw(VDM_FLAG_PAGE * PAGE_SIZE + PAGE_OFFSET, PAGE_SIZE)
for page in range(VDM_START_PAGE, VDM_START_PAGE + vdm_page_supported_raw + 1):
vdm_current_page = self.get_vdm_page(page, vdm_flag_page)
Expand Down
26 changes: 20 additions & 6 deletions sonic_platform_base/sonic_xcvr/sfp_optoe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def freeze_vdm_stats(self):
Returns True if the provision succeeds and False incase of failure.
'''
api = self.get_xcvr_api()
return api.freeze_vdm_stats() if api is not None else None
try:
return api.freeze_vdm_stats() if api is not None else False
except (NotImplementedError, AttributeError):
return False

def unfreeze_vdm_stats(self):
'''
Expand All @@ -72,25 +75,36 @@ def unfreeze_vdm_stats(self):
Returns True if the provision succeeds and False incase of failure.
'''
api = self.get_xcvr_api()
return api.unfreeze_vdm_stats() if api is not None else None
try:
return api.unfreeze_vdm_stats() if api is not None else False
except (NotImplementedError, AttributeError):
return False


def get_freeze_vdm_stats(self):
def get_vdm_freeze_status(self):
'''
This function reads and returns the vdm Freeze done status.
Returns True if the vdm stats freeze is successful and False if not freeze.
'''
api = self.get_xcvr_api()
return api.get_freeze_vdm_stats() if api is not None else None
try:
return api.get_vdm_freeze_status() if api is not None else False
except (NotImplementedError, AttributeError):
return False

def get_unfreeze_vdm_stats(self):
def get_vdm_unfreeze_status(self):
'''
This function reads and returns the vdm unfreeze status.
Returns True if the vdm stats unfreeze is successful and False if not unfreeze.
'''
api = self.get_xcvr_api()
return api.get_unfreeze_vdm_stats() if api is not None else None
try:
return api.get_vdm_unfreeze_status() if api is not None else False
except (NotImplementedError, AttributeError):
return False


def get_rx_los(self):
api = self.get_xcvr_api()
Expand Down
8 changes: 4 additions & 4 deletions tests/sonic_xcvr/test_ccmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,20 +629,20 @@ def test_get_transceiver_pm(self, mock_response, expected):
(0, 0),
(1, 1),
])
def test_get_freeze_vdm_stats(self, mock_response, expected):
def test_get_vdm_freeze_status(self, mock_response, expected):
self.api.xcvr_eeprom.read = MagicMock()
self.api.xcvr_eeprom.read.return_value = mock_response
result = self.api.get_freeze_vdm_stats()
result = self.api.get_vdm_freeze_status()
assert result == expected

@pytest.mark.parametrize("mock_response, expected", [
(0, 0),
(1, 1),
])
def test_get_unfreeze_vdm_stats(self, mock_response, expected):
def test_get_vdm_unfreeze_status(self, mock_response, expected):
self.api.xcvr_eeprom.read = MagicMock()
self.api.xcvr_eeprom.read.return_value = mock_response
result = self.api.get_unfreeze_vdm_stats()
result = self.api.get_vdm_unfreeze_stats()
assert result == expected

@pytest.mark.parametrize("mock_response, expected", [
Expand Down
16 changes: 8 additions & 8 deletions tests/sonic_xcvr/test_sfp_optoe_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,26 @@ def test_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected):
(1, ccmis_api, 1),
(None, None, None),
])
def test_get_freeze_vdm_stats(self, mock_response1, mock_response2, expected):
def test_get_vdm_freeze_status(self, mock_response1, mock_response2, expected):
self.sfp_optoe_api.get_xcvr_api = MagicMock()
self.sfp_optoe_api.get_xcvr_api.return_value = mock_response2
self.ccmis_api.get_freeze_vdm_stats = MagicMock()
self.ccmis_api.get_freeze_vdm_stats.return_value = mock_response1
self.ccmis_api.get_vdm_freeze_status = MagicMock()
self.ccmis_api.get_vdm_freeze_status.return_value = mock_response1

result = self.sfp_optoe_api.get_freeze_vdm_stats()
result = self.sfp_optoe_api.get_vdm_freeze_status()
assert result == expected

@pytest.mark.parametrize("mock_response1, mock_response2, expected", [
(0, ccmis_api, 0),
(1, ccmis_api, 1),
(None, None, None),
])
def test_get_unfreeze_vdm_stats(self, mock_response1, mock_response2, expected):
def test_get_vdm_unfreeze_status(self, mock_response1, mock_response2, expected):
self.sfp_optoe_api.get_xcvr_api = MagicMock()
self.sfp_optoe_api.get_xcvr_api.return_value = mock_response2
self.ccmis_api.get_unfreeze_vdm_stats = MagicMock()
self.ccmis_api.get_unfreeze_vdm_stats.return_value = mock_response1
self.ccmis_api.get_vdm_unfreeze_status = MagicMock()
self.ccmis_api.get_vdm_unfreeze_status.return_value = mock_response1

result = self.sfp_optoe_api.get_unfreeze_vdm_stats()
result = self.sfp_optoe_api.get_vdm_unfreeze_status()
assert result == expected

0 comments on commit e24e792

Please sign in to comment.