[BFN] Implementation API for platform component (#10180)

* [BFN] Implementation API for platform component
	SONiC has a concept of "platform components"
	this may include - CPLD, FPGA, BIOS, BMC, etc.

	These changes are needed to read the version of the BIOS and BMC component.

	What I did
		Create components.py module
		Add funcion for reading componet version to thrift interface
	How I did it
		The previous implementaion didn't have platform components API, so fwutil return an empty list.
		After implementation of the platform component API, we have actual list of platform components and firmware versions

	How to verify it
		Run manually 'fwutil show status' or run unit tests

	Previous command output
		Chassis                   Module    Component    Version    Description
		------------------------  --------  -----------  ---------  -------------

	New command output
		Chassis                   Module    Component    Version    Description
                ------------------------  --------  -----------  ---------  -------------
                Chassis1		  N/A       BIOS         1.2.3	   Chassis BIOS
                                                    BMC          5.1	   Chassis BMC
Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>

* [BFN] Implementation API for platform component
            SONiC has a concept of "platform components"
            this may include - CPLD, FPGA, BIOS, BMC, etc.

            These changes are needed to read the version of the BIOS and BMC component.

            What I did
                    Create components.py module
                    Add funcion for reading componet version to thrift interface
            How I did it
                    The previous implementaion didn't have platform components API, so fwutil return an empty list.
                    After implementation of the platform component API, we have actual list of platform components and firmware versions

            How to verify it
                    Run manually 'fwutil show status' or run unit tests

            Previous command output
                    Chassis                   Module    Component    Version    Description
                    ------------------------  --------  -----------  ---------  -------------

            New command output
                    Chassis                   Module    Component    Version    Description
                    ------------------------  --------  -----------  ---------  -------------
                    Chassis1                  N/A       BIOS         1.2.3     Chassis BIOS
                                                        BMC          5.1       Chassis BMC

Signed-off-by: Taras Keryk <tarasx.keryk@intel.com>

* [BFN] Implementation API for platform component
    get chassis name from json

* [BFN] Implementation API for platform component
      Updated platform and platrom_components json

* [BFN] Implementation API for platform component
      Fixed spaces in component.py

* [BFN] Implementation API for platform component
      Fixed exception in component.py

* Update chassis.py

* [BFN] Implementation API for platform component
      Fixed spaces in component.py, chassis.py

* [BFN] Implementation API for platform component: Fixed spaces in component.py, chassis.py

* Fixed exception in get_bios_version
This commit is contained in:
Taras Keryk 2022-03-10 12:55:06 +02:00 committed by GitHub
parent c8db7a2d52
commit a89f294fd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 1092 additions and 111 deletions

View File

@ -1,6 +1,14 @@
{
"chassis": {
"name": "Newport",
"components": [
{
"name": "BIOS"
},
{
"name": "BMC"
}
],
"fans": [
{
"name": "counter-rotating-fan-1"

View File

@ -1,8 +1,10 @@
{
"chassis": {
"Newport": {
"component": {
}
}
}
{
"chassis": {
"Newport": {
"component": {
"BIOS": { },
"BMC": { }
}
}
}
}

View File

@ -1,6 +1,14 @@
{
"chassis": {
"name": "Wedge100BF-32X-O-AC-F-BF",
"components": [
{
"name": "BIOS"
},
{
"name": "BMC"
}
],
"fans": [
{
"name": "counter-rotating-fan-1"

View File

@ -1,8 +1,10 @@
{
"chassis": {
"Wedge100BF-32X-O-AC-F-BF": {
"component": {
}
}
}
{
"chassis": {
"Wedge100BF-32X-O-AC-F-BF": {
"component": {
"BIOS": { },
"BMC": { }
}
}
}
}

View File

@ -19,6 +19,7 @@ try:
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
NUM_COMPONENT = 2
class Chassis(ChassisBase):
"""
Platform-specific Chassis class
@ -44,6 +45,7 @@ class Chassis(ChassisBase):
self.ready = False
self.phy_port_cur_state = {}
self.qsfp_interval = self.QSFP_CHECK_INTERVAL
self.__initialize_components()
@property
def _eeprom(self):
@ -128,6 +130,12 @@ class Chassis(ChassisBase):
self.PORT_END = self.QSFP_PORT_END
self.PORTS_IN_BLOCK = self.QSFP_PORT_END
def __initialize_components(self):
from sonic_platform.component import Components
for index in range(0, NUM_COMPONENT):
component = Components(index)
self._component_list.append(component)
def get_name(self):
"""
Retrieves the name of the chassis

View File

@ -0,0 +1,314 @@
try:
import subprocess
from sonic_platform_base.component_base import ComponentBase
from platform_thrift_client import thrift_try
import json
from collections import OrderedDict
from sonic_py_common import device_info
except ImportError as e:
raise ImportError(str(e) + "- required module not found")
def get_bios_version():
"""
Retrieves the firmware version of the BIOS
Returns:
A string containing the firmware version of the BIOS
"""
try:
return subprocess.check_output(['dmidecode', '-s', 'bios-version']).strip().decode()
except subprocess.CalledProcessError as e:
raise RuntimeError("Failed to getget BIOS version")
def get_bmc_version():
"""
Retrieves the firmware version of the BMC
Returns:
A string containing the firmware version of the BMC
"""
ver = "N/A"
def bmc_get(client):
return client.pltfm_mgr.pltfm_mgr_chss_mgmt_bmc_ver_get()
try:
ver = thrift_try(bmc_get)
except Exception:
pass
return ver
class BFPlatformComponentsParser(object):
"""
BFPlatformComponentsParser
"""
CHASSIS_KEY = "chassis"
MODULE_KEY = "module"
COMPONENT_KEY = "component"
FIRMWARE_KEY = "firmware"
def __init__(self, platform_components_path):
self.__chassis_component_map = OrderedDict()
self.__component_list = []
self.__bf_model = ""
self.__parse_platform_components(platform_components_path)
def __is_str(self, obj):
return isinstance(obj, str)
def __is_dict(self, obj):
return isinstance(obj, dict)
def __parser_fail(self, msg):
raise RuntimeError("Failed to parse \"{}\": {}".format(PLATFORM_COMPONENTS_FILE, msg))
def __parser_platform_fail(self, msg):
self.__parser_fail("invalid platform schema: {}".format(msg))
def __parser_chassis_fail(self, msg):
self.__parser_fail("invalid chassis schema: {}".format(msg))
def __parser_component_fail(self, msg):
self.__parser_fail("invalid component schema: {}".format(msg))
def __parse_component_section(self, section, component, is_module_component=False):
if not self.__is_dict(component):
self.__parser_component_fail("dictionary is expected: key={}".format(self.COMPONENT_KEY))
if not component:
return
missing_key = None
for key1, value1 in component.items():
if not self.__is_dict(value1):
self.__parser_component_fail("dictionary is expected: key={}".format(key1))
self.__chassis_component_map[section][key1] = OrderedDict()
if value1:
if len(value1) < 1 or len(value1) > 3:
self.__parser_component_fail("unexpected number of records: key={}".format(key1))
if self.FIRMWARE_KEY not in value1:
missing_key = self.FIRMWARE_KEY
break
for key2, value2 in value1.items():
if not self.__is_str(value2):
self.__parser_component_fail("string is expected: key={}".format(key2))
self.__chassis_component_map[section][key1] = value1
if missing_key is not None:
self.__parser_component_fail("\"{}\" key hasn't been found".format(missing_key))
def __parse_chassis_section(self, chassis):
self.__chassis_component_map = OrderedDict()
if not self.__is_dict(chassis):
self.__parser_chassis_fail("dictionary is expected: key={}".format(self.CHASSIS_KEY))
if not chassis:
self.__parser_chassis_fail("dictionary is empty: key={}".format(self.CHASSIS_KEY))
if len(chassis) != 1:
self.__parser_chassis_fail("unexpected number of records: key={}".format(self.CHASSIS_KEY))
for key, value in chassis.items():
if not self.__is_dict(value):
self.__parser_chassis_fail("dictionary is expected: key={}".format(key))
if not value:
self.__parser_chassis_fail("dictionary is empty: key={}".format(key))
if self.COMPONENT_KEY not in value:
self.__parser_chassis_fail("\"{}\" key hasn't been found".format(self.COMPONENT_KEY))
if len(value) != 1:
self.__parser_chassis_fail("unexpected number of records: key={}".format(key))
self.__chassis_component_map[key] = OrderedDict()
self.__parse_component_section(key, value[self.COMPONENT_KEY])
def get_components_list(self):
self.__component_list = []
for key, value in self.__chassis_component_map[self.__bf_model].items():
self.__component_list.append(key)
return self.__component_list
def get_chassis_component_map(self):
return self.__chassis_component_map
def __parse_platform_components(self, platform_components_path):
with open(platform_components_path) as platform_components:
data = json.load(platform_components)
kkey, val = list(data[self.CHASSIS_KEY].items())[0]
self.__bf_model = kkey
if not self.__is_dict(data):
self.__parser_platform_fail("dictionary is expected: key=root")
if not data:
self.__parser_platform_fail("dictionary is empty: key=root")
if self.CHASSIS_KEY not in data:
self.__parser_platform_fail("\"{}\" key hasn't been found".format(self.CHASSIS_KEY))
if len(data) != 1:
self.__parser_platform_fail("unexpected number of records: key=root")
self.__parse_chassis_section(data[self.CHASSIS_KEY])
chassis_component_map = property(fget=get_chassis_component_map)
class Components(ComponentBase):
"""BFN Montara Platform-specific Component class"""
bf_platform = device_info.get_path_to_platform_dir()
bf_platform_json = "{}/platform_components.json".format(bf_platform.strip())
bpcp = BFPlatformComponentsParser(bf_platform_json)
def __init__(self, component_index=0):
try:
self.index = component_index
self.name = "N/A"
self.version = "N/A"
self.description = "N/A"
self.name = self.bpcp.get_components_list()[self.index]
except IndexError as e:
print("Error: No components found in plaform_components.json")
if (self.name == "BMC"):
self.version = get_bmc_version()
self.description = "Chassis BMC"
elif (self.name == "BIOS"):
self.version = get_bios_version()
self.description = "Chassis BIOS"
def get_name(self):
"""
Retrieves the name of the component
Returns:
A string containing the name of the component
"""
if not self.name:
return "N/A"
return self.name
def get_description(self):
"""
Retrieves the description of the component
Returns:
A string containing the description of the component
"""
return self.description
def get_firmware_version(self):
"""
Retrieves the firmware version of the component
Returns:
A string containing the firmware version of the component
"""
return self.version
def install_firmware(self, image_path):
"""
Installs firmware to the component
Args:
image_path: A string, path to firmware image
Returns:
A boolean, True if install was successful, False if not
"""
return False
def get_presence(self):
"""
Retrieves the presence of the component
Returns:
bool: True if component is present, False if not
"""
return True
def get_model(self):
"""
Retrieves the model number (or part number) of the component
Returns:
string: Model/part number of component
"""
return 'N/A'
def get_serial(self):
"""
Retrieves the serial number of the component
Returns:
string: Serial number of component
"""
return 'N/A'
def get_status(self):
"""
Retrieves the operational status of the component
Returns:
A boolean value, True if component is operating properly, False if not
"""
return True
def get_position_in_parent(self):
"""
Retrieves 1-based relative physical position in parent device.
If the agent cannot determine the parent-relative position
for some reason, or if the associated value of
entPhysicalContainedIn is'0', then the value '-1' is returned
Returns:
integer: The 1-based relative physical position in parent device
or -1 if cannot determine the position
"""
return -1
def is_replaceable(self):
"""
Indicate whether this component is replaceable.
Returns:
bool: True if it is replaceable.
"""
return False
def get_available_firmware_version(self, image_path):
return 'None'
def get_firmware_update_notification(self, image_path):
"""
Retrieves a notification on what should be done in order to complete
the component firmware update
Args:
image_path: A string, path to firmware image
Returns:
A string containing the component firmware update notification if required.
By default 'None' value will be used, which indicates that no actions are required
"""
return 'None'
def update_firmware(self, image_path):
"""
Updates firmware of the component
This API performs firmware update: it assumes firmware installation and loading in a single call.
In case platform component requires some extra steps (apart from calling Low Level Utility)
to load the installed firmware (e.g, reboot, power cycle, etc.) - this will be done automatically by API
Args:
image_path: A string, path to firmware image
Raises:
RuntimeError: update failed
"""
return False
def auto_update_firmware(self, image_path, boot_action):
"""
Default handling of attempted automatic update for a component
Will skip the installation if the boot_action is 'warm' or 'fast' and will call update_firmware()
if boot_action is fast.
"""
return 1

View File

@ -1,5 +1,5 @@
#
# Autogenerated by Thrift Compiler (0.13.0)
# Autogenerated by Thrift Compiler (0.14.1)
#
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
#
@ -16,6 +16,24 @@ from thrift.transport import TTransport
all_structs = []
class qsfp_eeprom_page_t(object):
PAGE0_LOWER = 0
PAGE0_UPPER = 1
PAGE3 = 2
_VALUES_TO_NAMES = {
0: "PAGE0_LOWER",
1: "PAGE0_UPPER",
2: "PAGE3",
}
_NAMES_TO_VALUES = {
"PAGE0_LOWER": 0,
"PAGE0_UPPER": 1,
"PAGE3": 2,
}
class pltfm_mgr_sys_tmp_t(object):
"""
Attributes:
@ -241,37 +259,37 @@ class pltfm_mgr_eeprom_t(object):
iprot.skip(ftype)
elif fid == 2:
if ftype == TType.STRING:
self.prod_name = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.prod_name = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 3:
if ftype == TType.STRING:
self.prod_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.prod_part_num = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 4:
if ftype == TType.STRING:
self.sys_asm_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.sys_asm_part_num = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 5:
if ftype == TType.STRING:
self.bfn_pcba_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.bfn_pcba_part_num = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 6:
if ftype == TType.STRING:
self.bfn_pcbb_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.bfn_pcbb_part_num = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 7:
if ftype == TType.STRING:
self.odm_pcba_part_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.odm_pcba_part_num = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 8:
if ftype == TType.STRING:
self.odm_pcba_ser_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.odm_pcba_ser_num = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 9:
@ -291,42 +309,42 @@ class pltfm_mgr_eeprom_t(object):
iprot.skip(ftype)
elif fid == 12:
if ftype == TType.STRING:
self.prod_ser_num = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.prod_ser_num = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 13:
if ftype == TType.STRING:
self.prod_ast_tag = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.prod_ast_tag = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 14:
if ftype == TType.STRING:
self.sys_mfger = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.sys_mfger = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 15:
if ftype == TType.STRING:
self.sys_mfg_date = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.sys_mfg_date = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 16:
if ftype == TType.STRING:
self.pcb_mfger = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.pcb_mfger = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 17:
if ftype == TType.STRING:
self.assembled_at = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.assembled_at = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 18:
if ftype == TType.STRING:
self.loc_mac_addr = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.loc_mac_addr = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 19:
if ftype == TType.STRING:
self.ext_mac_addr = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.ext_mac_addr = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 20:
@ -336,7 +354,7 @@ class pltfm_mgr_eeprom_t(object):
iprot.skip(ftype)
elif fid == 21:
if ftype == TType.STRING:
self.location = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.location = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 22:
@ -535,17 +553,17 @@ class pltfm_mgr_pwr_supply_info_t(object):
iprot.skip(ftype)
elif fid == 8:
if ftype == TType.STRING:
self.model = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.model = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 9:
if ftype == TType.STRING:
self.serial = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.serial = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
elif fid == 10:
if ftype == TType.STRING:
self.rev = iprot.readString().decode('utf-8') if sys.version_info[0] == 2 else iprot.readString()
self.rev = iprot.readString().decode('utf-8', errors='replace') if sys.version_info[0] == 2 else iprot.readString()
else:
iprot.skip(ftype)
else:
@ -1278,26 +1296,39 @@ class InvalidPltfmMgrOperation(TException):
def __init__(self, code=None,):
self.code = code
super(InvalidPltfmMgrOperation, self).__setattr__('code', code)
def read(self, iprot):
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and self.thrift_spec is not None:
iprot._fast_decode(self, iprot, [self.__class__, self.thrift_spec])
return
def __setattr__(self, *args):
raise TypeError("can't modify immutable instance")
def __delattr__(self, *args):
raise TypeError("can't modify immutable instance")
def __hash__(self):
return hash(self.__class__) ^ hash((self.code, ))
@classmethod
def read(cls, iprot):
if iprot._fast_decode is not None and isinstance(iprot.trans, TTransport.CReadableTransport) and cls.thrift_spec is not None:
return iprot._fast_decode(None, iprot, [cls, cls.thrift_spec])
iprot.readStructBegin()
code = None
while True:
(fname, ftype, fid) = iprot.readFieldBegin()
if ftype == TType.STOP:
break
if fid == 1:
if ftype == TType.I32:
self.code = iprot.readI32()
code = iprot.readI32()
else:
iprot.skip(ftype)
else:
iprot.skip(ftype)
iprot.readFieldEnd()
iprot.readStructEnd()
return cls(
code=code,
)
def write(self, oprot):
if oprot._fast_encode is not None and self.thrift_spec is not None: