-
Notifications
You must be signed in to change notification settings - Fork 646
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fwutil Auto-update support #1165
Changes from 3 commits
8bf63af
8a3a278
a71c72b
aa119ff
b6af9f4
3a7457c
921e89c
059cdca
a733df5
e51d44f
c382d89
c395e14
510d0ad
59a511d
13bd06b
ca92e36
0c3a97f
00a2570
f14bbe5
e889212
63c6733
1753f22
8af9aee
ef5f212
e3d3d92
acfa824
061f428
42efc03
99de167
97dec12
927bf9b
e2ec825
ee6bc49
0d49a85
11526df
673f98d
a9cdd27
12e1a0f
b693cf6
6cbec6b
d5eb2f8
40377d3
5f42bbe
b226159
dadfc18
3f15835
8f156df
599b43a
939e331
929ff7c
71aa221
f412e52
8079558
bd8d6c7
f46c27e
412cfa1
bd32dbe
d0fc10c
05dbbb8
3f8db37
b657538
dfcf286
cf81eb6
e54cc58
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,6 +287,7 @@ class PlatformComponentsParser(object): | |
MODULE_KEY = "module" | ||
COMPONENT_KEY = "component" | ||
FIRMWARE_KEY = "firmware" | ||
UTILITY_KEY = "utility" | ||
VERSION_KEY = "version" | ||
|
||
UTF8_ENCODING = "utf-8" | ||
|
@@ -538,8 +539,9 @@ def __validate_platform_schema(self, pcp): | |
pcp.module_component_map | ||
) | ||
|
||
def get_status(self): | ||
def get_updates_status(self): | ||
status_table = [ ] | ||
update_status_table = [ ] | ||
|
||
append_chassis_name = self.is_chassis_has_components() | ||
append_module_na = not self.is_modular_chassis() | ||
|
@@ -583,6 +585,17 @@ def get_status(self): | |
] | ||
) | ||
|
||
update_status_table.append( | ||
[ | ||
chassis_name, | ||
module_name, | ||
chassis_component_name, | ||
firmware_path, | ||
firmware_version, | ||
status | ||
] | ||
) | ||
|
||
if append_chassis_name: | ||
append_chassis_name = False | ||
|
||
|
@@ -633,17 +646,41 @@ def get_status(self): | |
] | ||
) | ||
|
||
update_status_table.append( | ||
[ | ||
chassis_name, | ||
module_name, | ||
chassis_component_name, | ||
firmware_path, | ||
firmware_version, | ||
status | ||
] | ||
) | ||
|
||
if append_chassis_name: | ||
append_chassis_name = False | ||
|
||
if append_module_name: | ||
append_module_name = False | ||
|
||
return status_table, update_status_table | ||
|
||
def get_status(self): | ||
status_table, update_status_table = self.get_updates_status() | ||
if not status_table: | ||
return None | ||
|
||
return tabulate(status_table, self.STATUS_HEADER, tablefmt=self.FORMAT) | ||
|
||
def get_update_available_components(self): | ||
update_available_components = [] | ||
status_table, update_status_table = self.get_updates_status() | ||
for component_status in update_status_table: | ||
if component_status[-1] is self.FW_STATUS_UPDATE_REQUIRED: | ||
update_available_components.append(component_status) | ||
|
||
return update_available_components | ||
|
||
def get_notification(self, chassis_name, module_name, component_name): | ||
if self.is_modular_chassis(): | ||
component = self.module_component_map[module_name][component_name] | ||
|
@@ -695,6 +732,43 @@ def update_firmware(self, chassis_name, module_name, component_name): | |
log_helper.log_fw_update_end(component_path, firmware_path, False, e) | ||
raise | ||
|
||
def auto_update_firmware(self, component, boot): | ||
chassis_name = component[-6] | ||
module_name = component[-5] | ||
component_name = component[-4] | ||
|
||
if self.is_modular_chassis(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if the module_name is N/A, for modular chassis, it fails since module_component_map is being used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good catch! fixed in the latest. |
||
component = self.module_component_map[module_name][component_name] | ||
parser = self.__pcp.module_component_map[module_name][component_name] | ||
|
||
component_path = "{}/{}/{}".format(chassis_name, module_name, component_name) | ||
else: | ||
component = self.chassis_component_map[chassis_name][component_name] | ||
parser = self.__pcp.chassis_component_map[chassis_name][component_name] | ||
|
||
component_path = "{}/{}".format(chassis_name, component_name) | ||
|
||
if not parser: | ||
return | ||
|
||
firmware_path = parser[self.__pcp.FIRMWARE_KEY] | ||
|
||
if self.__root_path is not None: | ||
firmware_path = self.__root_path + firmware_path | ||
|
||
try: | ||
click.echo("Autoupdating firmware for {} with boot action {}".format(component_name, boot)) | ||
click.echo(TAB + firmware_path) | ||
log_helper.log_fw_auto_update_start(component_path, firmware_path, boot) | ||
component.auto_update_firmware(firmware_path, boot) | ||
log_helper.log_fw_auto_update_end(component_path, firmware_path, True, boot) | ||
except KeyboardInterrupt: | ||
log_helper.log_fw_auto_update_end(component_path, firmware_path, False, "Keyboard interrupt", boot) | ||
raise | ||
except Exception as e: | ||
log_helper.log_fw_auto_update_end(component_path, firmware_path, False, e, boot) | ||
raise | ||
|
||
def is_firmware_update_available(self, chassis_name, module_name, component_name): | ||
if self.is_modular_chassis(): | ||
component = self.__pcp.module_component_map[module_name][component_name] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,11 +28,12 @@ class LogHelper(object): | |
FW_ACTION_DOWNLOAD = "download" | ||
FW_ACTION_INSTALL = "install" | ||
FW_ACTION_UPDATE = "update" | ||
FW_ACTION_AUTO_UPDATE = "auto-update" | ||
|
||
STATUS_SUCCESS = "success" | ||
STATUS_FAILURE = "failure" | ||
|
||
def __log_fw_action_start(self, action, component, firmware): | ||
def __log_fw_action_start(self, action, component, firmware, boot=None): | ||
caption = "Firmware {} started".format(action) | ||
template = "{}: component={}, firmware={}" | ||
|
||
|
@@ -44,41 +45,77 @@ def __log_fw_action_start(self, action, component, firmware): | |
) | ||
) | ||
|
||
def __log_fw_action_end(self, action, component, firmware, status, exception=None): | ||
def __log_fw_action_end(self, action, component, firmware, status, exception=None, boot=None): | ||
caption = "Firmware {} ended".format(action) | ||
|
||
status_template = "{}: component={}, firmware={}, status={}" | ||
status_boot_template = "{}: component={}, firmware={}, boot={}, status={}" | ||
exception_template = "{}: component={}, firmware={}, status={}, exception={}" | ||
exception_boot_template = "{}: component={}, firmware={}, boot={}, status={}, exception={}" | ||
|
||
if status: | ||
log.log_info( | ||
status_template.format( | ||
caption, | ||
component, | ||
firmware, | ||
self.STATUS_SUCCESS | ||
) | ||
) | ||
else: | ||
if exception is None: | ||
log.log_error( | ||
if boot is None: | ||
log.log_info( | ||
status_template.format( | ||
caption, | ||
component, | ||
firmware, | ||
self.STATUS_FAILURE | ||
self.STATUS_SUCCESS | ||
) | ||
) | ||
else: | ||
log.log_error( | ||
exception_template.format( | ||
log.log_info( | ||
status_boot_template.format( | ||
caption, | ||
component, | ||
firmware, | ||
self.STATUS_FAILURE, | ||
str(exception) | ||
boot, | ||
self.STATUS_SUCCESS | ||
) | ||
) | ||
else: | ||
if exception: | ||
if boot is None: | ||
log.log_error( | ||
status_template.format( | ||
caption, | ||
component, | ||
firmware, | ||
self.STATUS_FAILURE | ||
) | ||
) | ||
else: | ||
log.log_info( | ||
status_boot_template.format( | ||
caption, | ||
component, | ||
firmware, | ||
boot, | ||
self.STATUS_FAILURE | ||
) | ||
) | ||
else: | ||
if boot is None: | ||
log.log_error( | ||
status_template.format( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this has to be exception_template? |
||
caption, | ||
component, | ||
firmware, | ||
self.STATUS_FAILURE, | ||
str(exception) | ||
) | ||
) | ||
else: | ||
log.log_error( | ||
exception_boot_template.format( | ||
caption, | ||
component, | ||
firmware, | ||
boot, | ||
self.STATUS_FAILURE, | ||
str(exception) | ||
) | ||
) | ||
|
||
def log_fw_download_start(self, component, firmware): | ||
self.__log_fw_action_start(self.FW_ACTION_DOWNLOAD, component, firmware) | ||
|
@@ -98,6 +135,12 @@ def log_fw_update_start(self, component, firmware): | |
def log_fw_update_end(self, component, firmware, status, exception=None): | ||
self.__log_fw_action_end(self.FW_ACTION_UPDATE, component, firmware, status, exception) | ||
|
||
def log_fw_auto_update_start(self, component, firmware, boot): | ||
self.__log_fw_action_start(self.FW_ACTION_AUTO_UPDATE, component, firmware, boot) | ||
|
||
def log_fw_auto_update_end(self, component, firmware, status, exception=None, boot=None): | ||
self.__log_fw_action_end(self.FW_ACTION_AUTO_UPDATE, component, firmware, status, exception, boot) | ||
|
||
def print_error(self, msg): | ||
click.echo("Error: {}.".format(msg)) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has to be module_component_name instead chassis_component_name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, fixed in the latest pr.