diff --git a/fwutil/lib.py b/fwutil/lib.py index 8e994d3514..5f59445c94 100755 --- a/fwutil/lib.py +++ b/fwutil/lib.py @@ -790,7 +790,7 @@ def update_firmware(self, chassis_name, module_name, component_name): def update_au_status_file(self, au_info_data, filename=FW_AU_STATUS_FILE_PATH): with open(filename, 'w') as f: - json.dump(au_info_data, f) + json.dump(au_info_data, f, indent=4, sort_keys=True) def read_au_status_file_if_exists(self, filename=FW_AU_STATUS_FILE_PATH): data = None @@ -836,6 +836,8 @@ def set_firmware_auto_update_status(self, component_path, fw_version, boot, rt_c comp_au_status['version'] = fw_version comp_au_status['info'] = info + click.echo("{} firmware auto-update status from {} to {} : {}".format(component_path, fw_version.split('/')[0], fw_version.split('/')[1], info)) + au_status.append(comp_au_status) self.update_au_status_file(data, FW_AU_STATUS_FILE_PATH) @@ -883,7 +885,6 @@ def auto_update_firmware(self, component_au_info, boot): rt_code = int(rt_code.strip()) else: rt_code = component.auto_update_firmware(firmware_path, boot) - click.echo("{} firmware auto-update status return_code: {}".format(component_path, int(rt_code))) (status, info) = self.set_firmware_auto_update_status(component_path, fw_version, boot, rt_code) log_helper.log_fw_auto_update_end(component_path, firmware_path, boot, status, info) except KeyboardInterrupt: @@ -894,7 +895,7 @@ def auto_update_firmware(self, component_au_info, boot): raise - def is_first_auto_update(self, boot): + def is_capable_auto_update(self, boot): task_file = None status_file = None for task_file in glob.glob(os.path.join(FIRMWARE_AU_STATUS_DIR, FW_AU_TASK_FILE_REGEX)): @@ -903,6 +904,12 @@ def is_first_auto_update(self, boot): return False for status_file in glob.glob(os.path.join(FIRMWARE_AU_STATUS_DIR, FW_AU_STATUS_FILE)): if status_file is not None: + data = self.read_au_status_file_if_exists(FW_AU_STATUS_FILE_PATH) + if data is not None: + if boot is "none" or boot in data: + click.echo("Allow firmware auto-update with boot_type {} again".format(boot)) + return True + click.echo("{} firmware auto-update is already performed, {} firmware auto update is not allowed any more".format(status_file, boot)) return False click.echo("Firmware auto-update for boot_type {} is allowed".format(boot)) diff --git a/fwutil/main.py b/fwutil/main.py index 2f378da306..0dac25b5c6 100755 --- a/fwutil/main.py +++ b/fwutil/main.py @@ -89,10 +89,10 @@ def update(ctx): ctx.obj[COMPONENT_PATH_CTX_KEY] = [ ] -# 'auto_update' group +# 'all_update' group @click.group() @click.pass_context -def auto_update(ctx): +def all_update(ctx): """Auto-update platform firmware""" pass @@ -343,7 +343,7 @@ def fw_update(ctx, yes, force, image): # 'fw' subcommand -@auto_update.command(name='fw') +@all_update.command(name='fw') @click.option('-i', '--image', 'image', type=click.Choice(["current", "next"]), default="current", show_default=True, help="Update firmware using current/next SONiC image") @click.option('-f', '--fw_image', 'fw_image', help="Custom FW package path") @click.option('-b', '--boot', 'boot', type=click.Choice(["any", "cold", "fast", "warm", "none"]), default="none", show_default=True, help="Necessary boot option after the firmware update") @@ -380,7 +380,7 @@ def fw_auto_update(ctx, boot, image=None, fw_image=None): if cup is not None: au_component_list = cup.get_update_available_components() if au_component_list: - if cup.is_first_auto_update(boot): + if cup.is_capable_auto_update(boot): for au_component in au_component_list: cup.auto_update_firmware(au_component, boot) log_helper.print_warning("All firmware auto-update has been performed") @@ -462,18 +462,10 @@ def status(ctx): # 'updates' subcommand -@click.group() +@show.command(name='update-all-status') @click.pass_context -def show_update(ctx): - """status : Show platform components auto_update status""" - pass - - -# 'status' subcommand -@show_update.command(name='status') -@click.pass_context -def update_status(ctx): - """Show platform components auto_update status""" +def update_all_status(ctx): + """Show platform components update all status""" try: csp = ComponentStatusProvider() click.echo(csp.get_au_status()) @@ -487,14 +479,12 @@ def version(): """Show utility version""" click.echo("fwutil version {0}".format(VERSION)) -show.add_command(show_update, name='update') - install.add_command(chassis_install, name='chassis') install.add_command(module_install, name='module') update.add_command(chassis_update, name='chassis') update.add_command(module_update, name='module') -update.add_command(auto_update, name='all') +update.add_command(all_update, name='all') chassis_install.add_command(component_install, name='component') module_install.add_command(component_install, name='component')