From dabdbbb70b4def9518ba064ea994fb1333d6344c Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Tue, 25 Jan 2022 12:35:54 -0800 Subject: [PATCH 1/8] remove empty line --- fwutil/lib.py | 9 ++++++++- fwutil/main.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/fwutil/lib.py b/fwutil/lib.py index 8e994d3514..bcb925d4d1 100755 --- a/fwutil/lib.py +++ b/fwutil/lib.py @@ -894,7 +894,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 +903,13 @@ 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: + boot_type = list(data.keys())[0] + if boot_type is "none": + click.echo("Allow firmware auto-update {} again on top of the previous {} reboot".format(boot, boot_type)) + 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..566e5fc485 100755 --- a/fwutil/main.py +++ b/fwutil/main.py @@ -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") From 4c61cd28987c5d71d9e5efa5c8d080d09147a83b Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Tue, 25 Jan 2022 12:45:19 -0800 Subject: [PATCH 2/8] check boot type is not same as the previous reboot type for --- fwutil/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fwutil/lib.py b/fwutil/lib.py index bcb925d4d1..36f3a36be8 100755 --- a/fwutil/lib.py +++ b/fwutil/lib.py @@ -906,7 +906,7 @@ def is_capable_auto_update(self, boot): data = self.read_au_status_file_if_exists(FW_AU_STATUS_FILE_PATH) if data is not None: boot_type = list(data.keys())[0] - if boot_type is "none": + if boot_type is "none" and boot_type is not boot: click.echo("Allow firmware auto-update {} again on top of the previous {} reboot".format(boot, boot_type)) return True From d93ba516d732c2bef5db6d3f3662a4e13bd19c0c Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Tue, 25 Jan 2022 13:12:18 -0800 Subject: [PATCH 3/8] readable fw_au_update_status file format --- fwutil/lib.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fwutil/lib.py b/fwutil/lib.py index 36f3a36be8..f5f083564c 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 From 6c700bf66fc3b858fa3708e0e6b15755959dc79e Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Tue, 25 Jan 2022 13:24:17 -0800 Subject: [PATCH 4/8] incorrectly autocompletes for fw update all --- fwutil/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fwutil/main.py b/fwutil/main.py index 566e5fc485..5a5c8eddf7 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") From 4dd845949254690d102bbd7788e76346a65c72c5 Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Tue, 25 Jan 2022 19:06:25 -0800 Subject: [PATCH 5/8] update cli for update all fw command --- fwutil/main.py | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/fwutil/main.py b/fwutil/main.py index 5a5c8eddf7..609db94187 100755 --- a/fwutil/main.py +++ b/fwutil/main.py @@ -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,8 +479,6 @@ 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') From 8ff2d49819e8880aae9d57a01555dc59950b90e0 Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Sun, 30 Jan 2022 23:25:08 -0800 Subject: [PATCH 6/8] allow auto update for boot type "none" or same boot type --- fwutil/lib.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fwutil/lib.py b/fwutil/lib.py index f5f083564c..3bd0413e33 100755 --- a/fwutil/lib.py +++ b/fwutil/lib.py @@ -905,8 +905,7 @@ def is_capable_auto_update(self, boot): if status_file is not None: data = self.read_au_status_file_if_exists(FW_AU_STATUS_FILE_PATH) if data is not None: - boot_type = list(data.keys())[0] - if boot_type is "none" and boot_type is not boot: + if boot is "none" or boot in data: click.echo("Allow firmware auto-update {} again on top of the previous {} reboot".format(boot, boot_type)) return True From fcf6e6c8bc5a948227d475badc91528fe1dd185d Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Thu, 3 Feb 2022 15:11:59 -0800 Subject: [PATCH 7/8] Update comment --- fwutil/lib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fwutil/lib.py b/fwutil/lib.py index 3bd0413e33..5f59445c94 100755 --- a/fwutil/lib.py +++ b/fwutil/lib.py @@ -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: @@ -906,7 +907,7 @@ def is_capable_auto_update(self, boot): 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 {} again on top of the previous {} reboot".format(boot, boot_type)) + 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)) From eb9f945dbaa73e562af4f8cee7bfe266bd6cd81c Mon Sep 17 00:00:00 2001 From: sujinmkang Date: Wed, 23 Feb 2022 22:05:30 +0000 Subject: [PATCH 8/8] fix mismatching command --- fwutil/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fwutil/main.py b/fwutil/main.py index 609db94187..0dac25b5c6 100755 --- a/fwutil/main.py +++ b/fwutil/main.py @@ -484,7 +484,7 @@ def version(): 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')