-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add vendor specific consts * replace vendor classes * Vendor specific CMIS api file * Vendor specific codes * Vendor specific mem_mps file * Address review comments 1. Cleanup unnecessary imports 2. update the comments * Update aec_800g.py * Address review comments Add string macros for offset and length to get vendor name and part number * Add Credo vendor class packages * Update xcvr_api_factory.py * Create test_xcvr_api_factory.py Add pytest for xcvc_api_factory file * Update test_xcvr_api_factory.py * Add test for create_xcvr_api * Update test_xcvr_api_factory.py
- Loading branch information
1 parent
c63abc0
commit d382ec8
Showing
7 changed files
with
137 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
aec_800g.py | ||
Implementation of Credo AEC cable specific in addition to the CMIS specification. | ||
""" | ||
|
||
from ...fields import consts | ||
from ..public.cmis import CmisApi | ||
|
||
class CmisAec800gApi(CmisApi): | ||
def set_firmware_download_target_end(self, target): | ||
return self.xcvr_eeprom.write(consts.TARGET_MODE, target) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from ..public.cmis import CmisCodes | ||
|
||
class CmisAec800gCodes(CmisCodes): | ||
TARGET_MODE = { | ||
0: 'local', | ||
1: 'remote-A', | ||
2: 'remote-B' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
""" | ||
aec_800g.py | ||
Implementation of Credo AEC cable specific XcvrMemMap for CMIS Rev 5.0 | ||
""" | ||
|
||
from ..public.cmis import CmisMemMap | ||
from ...fields.xcvr_field import ( | ||
CodeRegField, | ||
DateField, | ||
HexRegField, | ||
NumberRegField, | ||
RegBitField, | ||
RegGroupField, | ||
StringRegField, | ||
) | ||
from ...fields import consts | ||
|
||
class CmisAec800gMemMap(CmisMemMap): | ||
def __init__(self, codes): | ||
super(CmisAec800gMemMap, self).__init__(codes) | ||
|
||
self.VENDOR_CUSTOM = RegGroupField(consts.VENDOR_CUSTOM, | ||
NumberRegField(consts.TARGET_MODE, self.getaddr(0x0, 64), ro=False) | ||
) | ||
|
||
def getaddr(self, page, offset, page_size=128): | ||
return page * page_size + offset |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from unittest.mock import patch | ||
from mock import MagicMock | ||
import pytest | ||
|
||
from sonic_platform_base.sonic_xcvr.api.credo.aec_800g import CmisAec800gApi | ||
from sonic_platform_base.sonic_xcvr.mem_maps.credo.aec_800g import CmisAec800gMemMap | ||
from sonic_platform_base.sonic_xcvr.xcvr_eeprom import XcvrEeprom | ||
from sonic_platform_base.sonic_xcvr.codes.credo.aec_800g import CmisAec800gCodes | ||
from sonic_platform_base.sonic_xcvr.fields import consts | ||
from sonic_platform_base.sonic_xcvr.xcvr_api_factory import XcvrApiFactory | ||
|
||
class BytesMock(bytes): | ||
def decode(self, encoding='utf-8', errors='strict'): | ||
return 'DecodedCredo' | ||
|
||
class TestXcvrApiFactory(object): | ||
read_eeprom = MagicMock | ||
write_eeprom = MagicMock | ||
api = XcvrApiFactory(read_eeprom, write_eeprom) | ||
|
||
def test_get_vendor_name(self): | ||
self.api.reader = MagicMock() | ||
self.api.reader.return_value = b'Credo' | ||
with patch.object(BytesMock, 'decode', return_value='DecodedCredo'): | ||
result = self.api._get_vendor_name() | ||
assert result == 'Credo'.strip() | ||
|
||
def test_get_vendor_part_num(self): | ||
self.api.reader = MagicMock() | ||
self.api.reader.return_value = b'CAC81X321M2MC1MS' | ||
with patch.object(BytesMock, 'decode', return_value='DecodedCAC81X321M2MC1MS'): | ||
result = self.api._get_vendor_part_num() | ||
assert result == 'CAC81X321M2MC1MS'.strip() | ||
|
||
def mock_reader(self, start, length): | ||
return bytes([0x18]) | ||
|
||
@patch('sonic_platform_base.sonic_xcvr.xcvr_api_factory.XcvrApiFactory._get_vendor_name', MagicMock(return_value='Credo')) | ||
@patch('sonic_platform_base.sonic_xcvr.xcvr_api_factory.XcvrApiFactory._get_vendor_part_num', MagicMock(return_value='CAC81X321M2MC1MS')) | ||
def test_create_xcvr_api(self): | ||
self.api.reader = self.mock_reader | ||
CmisAec800gCodes = MagicMock() | ||
CmisAec800gMemMap = MagicMock() | ||
XcvrEeprom = MagicMock() | ||
CmisAec800gApi = MagicMock() | ||
self.api.create_xcvr_api() | ||
|