Skip to content

Commit

Permalink
[CMIS]Fix low-power to high power mode transition (sonic-net#268)
Browse files Browse the repository at this point in the history
* [CMIS]Fix low-power to high power mode transition

* Remove python2 tests

* Improve code coverage

* Parametrize the test

* Improve code coverage
  • Loading branch information
prgeor authored May 4, 2022
1 parent f918125 commit d62d3d6
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 244 deletions.
28 changes: 0 additions & 28 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ steps:

- script: |
set -xe
sudo pip2 install swsssdk-2.0.1-py2-none-any.whl
sudo pip2 install sonic_py_common-1.0-py2-none-any.whl
sudo pip2 install sonic_config_engine-1.0-py2-none-any.whl
sudo pip3 install swsssdk-2.0.1-py3-none-any.whl
sudo pip3 install sonic_py_common-1.0-py3-none-any.whl
sudo pip3 install sonic_yang_mgmt-1.0-py3-none-any.whl
Expand All @@ -66,31 +63,6 @@ steps:
sudo apt-get install -y dotnet-sdk-5.0
displayName: "Install .NET CORE"

# Python 2
- script: |
python2 setup.py test
displayName: 'Test Python 2'

- task: PublishTestResults@2
inputs:
testResultsFiles: '$(System.DefaultWorkingDirectory)/test-results.xml'
testRunTitle: Python 2
failTaskOnFailedTests: true
condition: succeededOrFailed()
displayName: 'Publish Python 2 test results'

- task: PublishCodeCoverageResults@1
inputs:
codeCoverageTool: Cobertura
summaryFileLocation: '$(System.DefaultWorkingDirectory)/coverage.xml'
reportDirectory: '$(System.DefaultWorkingDirectory)/htmlcov/'
displayName: 'Publish Python 2 test coverage'

- script: |
set -e
python2 setup.py bdist_wheel
displayName: 'Build Python 2 wheel'

# Python 3
- script: |
python3 setup.py test
Expand Down
17 changes: 10 additions & 7 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

class CmisApi(XcvrApi):
NUM_CHANNELS = 8
LowPwrRequestSW = 4
LowPwrAllowRequestHW = 6

def __init__(self, xcvr_eeprom):
super(CmisApi, self).__init__(xcvr_eeprom)
Expand Down Expand Up @@ -930,19 +932,20 @@ def set_lpmode(self, lpmode):
lpmode_val = self.xcvr_eeprom.read(consts.MODULE_LEVEL_CONTROL)
if lpmode_val is not None:
if lpmode is True:
lpmode_val = lpmode_val | (1 << 4)
# Force module transition to LowPwr under SW control
lpmode_val = lpmode_val | (1 << CmisApi.LowPwrRequestSW)
self.xcvr_eeprom.write(consts.MODULE_LEVEL_CONTROL, lpmode_val)
time.sleep(0.1)
return self.get_lpmode()
else:
lpmode_val = lpmode_val & ~(1 << 4)
# Force transition from LowPwr to HighPower state under SW control.
# This will transition LowPwrS signal to False. (see Table 6-12 CMIS v5.0)
lpmode_val = lpmode_val & ~(1 << CmisApi.LowPwrRequestSW)
lpmode_val = lpmode_val & ~(1 << CmisApi.LowPwrAllowRequestHW)
self.xcvr_eeprom.write(consts.MODULE_LEVEL_CONTROL, lpmode_val)
time.sleep(1)
lpmode = self.xcvr_eeprom.read(consts.TRANS_MODULE_STATUS_FIELD)
if lpmode is not None:
if lpmode.get('ModuleState') == 'ModuleReady':
return True
return False
mstate = self.get_module_state()
return True if mstate == 'ModuleReady' else False
return False

def get_loopback_capability(self):
Expand Down
Loading

0 comments on commit d62d3d6

Please sign in to comment.