Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 23 additions & 28 deletions fwutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
NA = "N/A"
NEWLINE = "\n"
PLATFORM_COMPONENTS_FILE = "platform_components.json"
FIRMWARE_UPDATE_DIR = "/tmp/firmwareupdate/"
FIRMWARE_UPDATE_DIR = "/var/platform/"
FWUPDATE_FWPACKAGE_DIR = os.path.join(FIRMWARE_UPDATE_DIR, "fwpackage/")
FW_AU_TASK_FILE_REGEX = "*_fw_au_task"
FW_AU_STATUS_FILE = "fw_au_status"
Expand Down Expand Up @@ -843,27 +843,6 @@ def set_firmware_auto_update_status(self, component_path, boot, rt_code):
self.update_au_status_file(data, FW_AU_STATUS_FILE_PATH)
return (status, info)

def get_au_status(self):
au_status = []
auto_updated_status_table = []
data = self.read_au_status_file_if_exists(FW_AU_STATUS_FILE_PATH)

if data is None:
return None

boot_type = list(data.keys())[0]
click.echo("Firmware auto-update performed for {} reboot".format(boot_type))

au_status = data[boot_type]
for comp_au_status in au_status:
r = []
r.append(comp_au_status['comp'] if 'comp' in comp_au_status else "")
r.append(comp_au_status['status'] if 'status' in comp_au_status else "")
r.append(comp_au_status['info'] if 'info' in comp_au_status else "")
auto_updated_status_table.append(r)

return tabulate(auto_updated_status_table, self.AU_STATUS_HEADER, tablefmt=self.FORMAT)

def auto_update_firmware(self, component_au_info, boot):
is_chassis_component = component_au_info[0]
chassis_name = component_au_info[1]
Expand Down Expand Up @@ -972,12 +951,19 @@ class ComponentStatusProvider(PlatformDataProvider):
ComponentStatusProvider
"""
HEADER = [ "Chassis", "Module", "Component", "Version", "Description" ]
AU_STATUS_HEADER = [ "Component", "Status", "Info", "Boot" ]
AU_STATUS_HEADER = [ "Component", "Version", "Status", "Info" ]
FORMAT = "simple"
INFO_KEY = "info"

def __init__(self):
PlatformDataProvider.__init__(self)

def __is_dict(self, obj):
return isinstance(obj, dict)

def __parser_fail_fw_au_status(self, msg):
raise RuntimeError("Failed to parse \"{}\": {}".format(FW_AU_STATUS_FILE_PATH, msg))

def get_status(self):
status_table = [ ]

Expand Down Expand Up @@ -1050,13 +1036,22 @@ def get_au_status(self):
if data is None:
return None

boot_type = list(data.keys())[0]
click.echo("Firmware auto-update performed for {} reboot".format(boot_type))
for comp_path, comp_au_status in data.items():
if not self.__is_dict(comp_au_status):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the value for comp_path is a list, please iterate over it seperately.

Suggested change
for comp_path, comp_au_status in data.items():
if not self.__is_dict(comp_au_status):
for comp_path, au_status in data.items():
for comp_au_status in au_status:
if not self.__is_dict(comp_au_status):

self.__parser_fail_fw_au_status("dictionary is expected: key={}".format(comp_path))

if comp_au_status:
if len(comp_au_status) is not 4:
self.__parser_fail_fw_au_status("unexpected number of records: key={}".format(comp_path))


#for key, value in comp_au_status.items():
# if not self.__is_str(value):
# self.__parser_fail_fw_au_status("string is expected: key={}".format(key))

au_status = data[boot_type]
for comp_au_status in au_status:
r = []
r.append(comp_au_status['comp'] if 'comp' in comp_au_status else "")
r.append(comp_path)
r.append("{}/{}".format(comp_au_status['from'], comp_au_status['to']))
r.append(comp_au_status['status'] if 'status' in comp_au_status else "")
r.append(comp_au_status['info'] if 'info' in comp_au_status else "")
auto_updated_status_table.append(r)
Expand Down