Skip to content

Commit

Permalink
Merge branch 'Azure:master' into front_panel_port_name_regex
Browse files Browse the repository at this point in the history
  • Loading branch information
itamar-talmon authored and Itamar Talmon committed Jan 12, 2023
2 parents 8ab675b + 0d45adb commit f317926
Show file tree
Hide file tree
Showing 21 changed files with 3,201 additions and 616 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
4 changes: 4 additions & 0 deletions sonic_platform_base/chassis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ class ChassisBase(device_base.DeviceBase):
REBOOT_CAUSE_INSUFFICIENT_FAN_SPEED = "Insufficient Fan Speed"
REBOOT_CAUSE_WATCHDOG = "Watchdog"
REBOOT_CAUSE_HARDWARE_OTHER = "Hardware - Other"
REBOOT_CAUSE_HARDWARE_BIOS = "BIOS"
REBOOT_CAUSE_HARDWARE_CPU = "CPU"
REBOOT_CAUSE_HARDWARE_BUTTON = "Push button"
REBOOT_CAUSE_HARDWARE_RESET_FROM_ASIC = "Reset from ASIC"
REBOOT_CAUSE_NON_HARDWARE = "Non-Hardware"

def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion sonic_platform_base/sonic_eeprom/eeprom_tlvinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TlvInfoDecoder(eeprom_base.EepromDecoder):
_TLV_CODE_QUANTA_MODEL_NAME = _TLV_CODE_UNDEFINED

# TLV Value Display Switch
_TLV_DISPLAY_VENDOR_EXT = False
_TLV_DISPLAY_VENDOR_EXT = True


def __init__(self, path, start, status, ro, max_len=_TLV_INFO_MAX_LEN):
Expand Down
8 changes: 4 additions & 4 deletions sonic_platform_base/sonic_sfp/bcmshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def getreg(self, reg, fields=False):
#
t = self.re_oneline.sub('', t)
t = t.split('\n')
if t[-1] is '':
if t[-1] == '':
t.pop()

# get the results into a dict (module) of lists (array) of values/fields
Expand All @@ -253,10 +253,10 @@ def __parse_reg__(text, fields=False):
# now optimize the return
#
for I in iter(d):
if len(d[I]) is 1:
if len(d[I]) == 1:
d[I] = d[I][0]

if len(d) is 1:
if len(d) == 1:
return d.values()[0]
else:
return d
Expand Down Expand Up @@ -319,7 +319,7 @@ def gettable(self, table, fields=False, start=None, entries=None):
t = self.re_table_header.sub('', t)
t = self.re_table_trailer.sub('', t)
t = t.split('\n')
if t[-1] is '':
if t[-1] == '':
t.pop()

# parse the contents
Expand Down
41 changes: 24 additions & 17 deletions sonic_platform_base/sonic_sfp/sfputilhelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from natsort import natsorted
from portconfig import get_port_config
from sonic_py_common import device_info
from sonic_py_common import device_info, multi_asic
from sonic_py_common.interface import backplane_prefix, inband_prefix, recirc_prefix

except ImportError as e:
Expand All @@ -22,6 +22,7 @@
# Global Variable
PLATFORM_JSON = 'platform.json'
PORT_CONFIG_INI = 'port_config.ini'
ASIC_NAME_PREFIX = 'asic'

class SfpUtilHelper(object):
# List to specify filter for sfp_ports
Expand Down Expand Up @@ -52,7 +53,12 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):
fp_port_index = 1

(platform, hwsku) = device_info.get_platform_and_hwsku()
ports, _, _ = get_port_config(hwsku, platform)

asic_name = None
if multi_asic.is_multi_asic():
asic_name = ASIC_NAME_PREFIX + str(asic_inst)

ports, _, _ = get_port_config(hwsku, platform, asic_name=asic_name)

if not ports:
ports, _, _ = get_port_config(hwsku, platform, porttabfile)
Expand All @@ -65,9 +71,9 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):
logical_list.append(intf)

# Ignore if this is an internal backplane interface and Inband interface
logical = [name for name in logical
logical = [name for name in logical_list
if not name.startswith((backplane_prefix(), inband_prefix(), recirc_prefix()))]
logical = natsorted(logical_list, key=lambda y: y.lower())
logical = natsorted(logical, key=lambda y: y.lower())
logical_to_physical, physical_to_logical = OrderedDict(), OrderedDict()

for intf_name in logical:
Expand All @@ -83,24 +89,25 @@ def read_porttab_mappings(self, porttabfile, asic_inst=0):
# Mapping of logical port names available on a system to ASIC instance
self.logical_to_asic[intf_name] = asic_inst

self.logical = logical
self.logical_to_physical = logical_to_physical
self.physical_to_logical = physical_to_logical
self.logical.extend(logical)
self.logical = list(set(self.logical))
self.logical_to_physical.update(logical_to_physical)
self.physical_to_logical.update(physical_to_logical)

return None


def read_all_porttab_mappings(self, platform_dir, num_asic_inst):
# In multi asic scenario, get all the port_config files for different asics
for inst in range(num_asic_inst):
port_map_dir = os.path.join(platform_dir, str(inst))
port_map_file = os.path.join(port_map_dir, PORT_CONFIG_INI)
if os.path.exists(port_map_file):
self.read_porttab_mappings(port_map_file, inst)
else:
port_json_file = os.path.join(port_map_dir, PLATFORM_JSON)
if os.path.exists(port_json_file):
self.read_porttab_mappings(port_json_file, inst)
# In multi asic scenario, get all the port_config files for different asic
for inst in range(num_asic_inst):
port_map_dir = os.path.join(platform_dir, str(inst))
port_map_file = os.path.join(port_map_dir, PORT_CONFIG_INI)
if os.path.exists(port_map_file):
self.read_porttab_mappings(port_map_file, inst)
else:
port_json_file = os.path.join(platform_dir, PLATFORM_JSON)
if os.path.exists(port_json_file):
self.read_porttab_mappings(port_json_file, inst)

def get_physical_to_logical(self, port_num):
"""Returns list of logical ports for the given physical port"""
Expand Down
68 changes: 52 additions & 16 deletions sonic_platform_base/sonic_ssd/ssd_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

NOT_AVAILABLE = "N/A"

# Set Vendor Specific IDs
INNODISK_HEALTH_ID = 169
INNODISK_TEMPERATURE_ID = 194

class SsdUtil(SsdBase):
"""
Expand Down Expand Up @@ -76,35 +79,65 @@ def fetch_generic_ssd_info(self, diskdev):
def parse_generic_ssd_info(self):
if "nvme" in self.dev:
self.model = self._parse_re('Model Number:\s*(.+?)\n', self.ssd_info)
health_raw = self._parse_re('Percentage Used\s*(.+?)\n', self.ssd_info).split()[-1]
self.health = 100 - float(health_raw.strip('%'))
self.temperature = float(self._parse_re('Temperature\s*(.+?)\n', self.ssd_info).split()[-2])

health_raw = self._parse_re('Percentage Used\s*(.+?)\n', self.ssd_info)
if health_raw == NOT_AVAILABLE:
self.health = NOT_AVAILABLE
else:
health_raw = health_raw.split()[-1]
self.health = 100 - float(health_raw.strip('%'))

temp_raw = self._parse_re('Temperature\s*(.+?)\n', self.ssd_info)
if temp_raw == NOT_AVAILABLE:
self.temperature = NOT_AVAILABLE
else:
temp_raw = temp_raw.split()[-2]
self.temperature = float(temp_raw)
else:
self.model = self._parse_re('Device Model:\s*(.+?)\n', self.ssd_info)
self.health = self._parse_re('Remaining_Lifetime_Perc\s*(.+?)\n', self.ssd_info).split()[-1]
self.temperature = self._parse_re('Temperature_Celsius\s*(.+?)\n', self.ssd_info).split()[-6]

health_raw = self._parse_re('Remaining_Lifetime_Perc\s*(.+?)\n', self.ssd_info)
if health_raw == NOT_AVAILABLE:
self.health = NOT_AVAILABLE
else:
self.health = health_raw.split()[-1]

temp_raw = self._parse_re('Temperature_Celsius\s*(.+?)\n', self.ssd_info)
if temp_raw == NOT_AVAILABLE:
self.temperature = NOT_AVAILABLE
else:
self.temperature = temp_raw.split()[-6]

self.serial = self._parse_re('Serial Number:\s*(.+?)\n', self.ssd_info)
self.firmware = self._parse_re('Firmware Version:\s*(.+?)\n', self.ssd_info)

def parse_innodisk_info(self):
self.health = self._parse_re('Health:\s*(.+?)%', self.vendor_ssd_info)
self.temperature = self._parse_re('Temperature\s*\[\s*(.+?)\]', self.vendor_ssd_info)
if self.vendor_ssd_info:
self.health = self._parse_re('Health:\s*(.+?)%', self.vendor_ssd_info)
self.temperature = self._parse_re('Temperature\s*\[\s*(.+?)\]', self.vendor_ssd_info)
else:
if self.health == NOT_AVAILABLE:
health_raw = self.parse_id_number(INNODISK_HEALTH_ID)
self.health = health_raw.split()[-1]
if self.temperature == NOT_AVAILABLE:
temp_raw = self.parse_id_number(INNODISK_TEMPERATURE_ID)
self.temperature = temp_raw.split()[-6]

def parse_virtium_info(self):
self.temperature = self._parse_re('Temperature_Celsius\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info)
nand_endurance = self._parse_re('NAND_Endurance\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info)
avg_erase_count = self._parse_re('Average_Erase_Count\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info)
try:
self.health = 100 - (float(avg_erase_count) * 100 / float(nand_endurance))
except ValueError:
pass
if self.vendor_ssd_info:
self.temperature = self._parse_re('Temperature_Celsius\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info)
nand_endurance = self._parse_re('NAND_Endurance\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info)
avg_erase_count = self._parse_re('Average_Erase_Count\s*\d*\s*(\d+?)\s+', self.vendor_ssd_info)
try:
self.health = 100 - (float(avg_erase_count) * 100 / float(nand_endurance))
except (ValueError, ZeroDivisionError):
pass

def fetch_vendor_ssd_info(self, diskdev, model):
self.vendor_ssd_info = self._execute_shell(self.vendor_ssd_utility[model]["utility"].format(diskdev))

def parse_vendor_ssd_info(self, model):
if self.vendor_ssd_info:
self.vendor_ssd_utility[model]["parser"]()
self.vendor_ssd_utility[model]["parser"]()

def get_health(self):
"""
Expand Down Expand Up @@ -161,3 +194,6 @@ def get_vendor_output(self):
A string holding some vendor specific disk information
"""
return self.vendor_ssd_info

def parse_id_number(self, id):
return self._parse_re('{}\s*(.+?)\n'.format(id), self.ssd_info)
37 changes: 27 additions & 10 deletions sonic_platform_base/sonic_xcvr/api/public/cmis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@

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

def __init__(self, xcvr_eeprom):
super(CmisApi, self).__init__(xcvr_eeprom)
self.vdm = CmisVdmApi(xcvr_eeprom)
self.cdb = CmisCdbApi(xcvr_eeprom)
self.vdm = CmisVdmApi(xcvr_eeprom) if not self.is_flat_memory() else None
self.cdb = CmisCdbApi(xcvr_eeprom) if not self.is_flat_memory() else None

def get_model(self):
'''
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 Expand Up @@ -1012,7 +1015,7 @@ def get_vdm(self):
'''
This function returns all the VDM items, including real time monitor value, threholds and flags
'''
vdm = self.vdm.get_vdm_allpage() if not self.is_flat_memory() else {}
vdm = self.vdm.get_vdm_allpage() if self.vdm is not None else {}
return vdm

def get_module_firmware_fault_state_changed(self):
Expand Down Expand Up @@ -1113,6 +1116,9 @@ def get_module_fw_mgmt_feature(self, verbose = False):
the following upgrade with depend on these parameters.
"""
txt = ''
if self.cdb is None:
return {'status': False, 'info': "CDB Not supported", 'result': None}

# get fw upgrade features (CMD 0041h)
starttime = time.time()
autopaging = self.xcvr_eeprom.read(consts.AUTO_PAGING_SUPPORT)
Expand Down Expand Up @@ -1163,6 +1169,10 @@ def get_module_fw_info(self):
Validity Status: 1 = invalid, 0 = valid
"""
txt = ''

if self.cdb is None:
return {'status': False, 'info': "CDB Not supported", 'result': None}

# get fw info (CMD 0100h)
rpllen, rpl_chkcode, rpl = self.cdb.get_fw_info()
# password issue
Expand Down Expand Up @@ -1247,6 +1257,8 @@ def module_fw_run(self, mode = 0x01):
"""
# run module FW (CMD 0109h)
txt = ''
if self.cdb is None:
return False, "CDB NOT supported on this module"
starttime = time.time()
fw_run_status = self.cdb.run_fw_image(mode)
if fw_run_status == 1:
Expand Down Expand Up @@ -1277,6 +1289,8 @@ def module_fw_commit(self):
Otherwise it will return False.
"""
txt = ''
if self.cdb is None:
return False, "CDB NOT supported on this module"
# commit module FW (CMD 010Ah)
starttime = time.time()
fw_commit_status= self.cdb.commit_fw_image()
Expand Down Expand Up @@ -1334,6 +1348,9 @@ def module_fw_download(self, startLPLsize, maxblocksize, lplonly_flag, autopagin
This function returns True if download successfully completes. Otherwise it will return False where it fails.
"""
txt = ''
if self.cdb is None:
return False, "CDB NOT supported on this module"

# start fw download (CMD 0101h)
starttime = time.time()
try:
Expand Down
Loading

0 comments on commit f317926

Please sign in to comment.