Skip to content

Commit fdb79b8

Browse files
authored
Allow fw update for other boot type against on the previous "none" boot fw update (#2040)
#8928 #8926 #8925 #8924 #### What I did Allow fwutil update all for other boot type if any previous fw update done for "none" boot type #### How I did it Allow fwutil update all for other boot type if any previous fw update done for "none" boot type #### How to verify it 1. Run fwutil update all for boot_type="none" 2. Run fwutil update all for any other boot_type 3. Verify if the 2nd update is proceeded.
1 parent a54a091 commit fdb79b8

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

fwutil/lib.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ def update_firmware(self, chassis_name, module_name, component_name):
790790

791791
def update_au_status_file(self, au_info_data, filename=FW_AU_STATUS_FILE_PATH):
792792
with open(filename, 'w') as f:
793-
json.dump(au_info_data, f)
793+
json.dump(au_info_data, f, indent=4, sort_keys=True)
794794

795795
def read_au_status_file_if_exists(self, filename=FW_AU_STATUS_FILE_PATH):
796796
data = None
@@ -836,6 +836,8 @@ def set_firmware_auto_update_status(self, component_path, fw_version, boot, rt_c
836836
comp_au_status['version'] = fw_version
837837
comp_au_status['info'] = info
838838

839+
click.echo("{} firmware auto-update status from {} to {} : {}".format(component_path, fw_version.split('/')[0], fw_version.split('/')[1], info))
840+
839841
au_status.append(comp_au_status)
840842

841843
self.update_au_status_file(data, FW_AU_STATUS_FILE_PATH)
@@ -883,7 +885,6 @@ def auto_update_firmware(self, component_au_info, boot):
883885
rt_code = int(rt_code.strip())
884886
else:
885887
rt_code = component.auto_update_firmware(firmware_path, boot)
886-
click.echo("{} firmware auto-update status return_code: {}".format(component_path, int(rt_code)))
887888
(status, info) = self.set_firmware_auto_update_status(component_path, fw_version, boot, rt_code)
888889
log_helper.log_fw_auto_update_end(component_path, firmware_path, boot, status, info)
889890
except KeyboardInterrupt:
@@ -894,7 +895,7 @@ def auto_update_firmware(self, component_au_info, boot):
894895
raise
895896

896897

897-
def is_first_auto_update(self, boot):
898+
def is_capable_auto_update(self, boot):
898899
task_file = None
899900
status_file = None
900901
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):
903904
return False
904905
for status_file in glob.glob(os.path.join(FIRMWARE_AU_STATUS_DIR, FW_AU_STATUS_FILE)):
905906
if status_file is not None:
907+
data = self.read_au_status_file_if_exists(FW_AU_STATUS_FILE_PATH)
908+
if data is not None:
909+
if boot is "none" or boot in data:
910+
click.echo("Allow firmware auto-update with boot_type {} again".format(boot))
911+
return True
912+
906913
click.echo("{} firmware auto-update is already performed, {} firmware auto update is not allowed any more".format(status_file, boot))
907914
return False
908915
click.echo("Firmware auto-update for boot_type {} is allowed".format(boot))

fwutil/main.py

+8-18
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ def update(ctx):
8989
ctx.obj[COMPONENT_PATH_CTX_KEY] = [ ]
9090

9191

92-
# 'auto_update' group
92+
# 'all_update' group
9393
@click.group()
9494
@click.pass_context
95-
def auto_update(ctx):
95+
def all_update(ctx):
9696
"""Auto-update platform firmware"""
9797
pass
9898

@@ -343,7 +343,7 @@ def fw_update(ctx, yes, force, image):
343343

344344

345345
# 'fw' subcommand
346-
@auto_update.command(name='fw')
346+
@all_update.command(name='fw')
347347
@click.option('-i', '--image', 'image', type=click.Choice(["current", "next"]), default="current", show_default=True, help="Update firmware using current/next SONiC image")
348348
@click.option('-f', '--fw_image', 'fw_image', help="Custom FW package path")
349349
@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):
380380
if cup is not None:
381381
au_component_list = cup.get_update_available_components()
382382
if au_component_list:
383-
if cup.is_first_auto_update(boot):
383+
if cup.is_capable_auto_update(boot):
384384
for au_component in au_component_list:
385385
cup.auto_update_firmware(au_component, boot)
386386
log_helper.print_warning("All firmware auto-update has been performed")
@@ -462,18 +462,10 @@ def status(ctx):
462462

463463

464464
# 'updates' subcommand
465-
@click.group()
465+
@show.command(name='update-all-status')
466466
@click.pass_context
467-
def show_update(ctx):
468-
"""status : Show platform components auto_update status"""
469-
pass
470-
471-
472-
# 'status' subcommand
473-
@show_update.command(name='status')
474-
@click.pass_context
475-
def update_status(ctx):
476-
"""Show platform components auto_update status"""
467+
def update_all_status(ctx):
468+
"""Show platform components update all status"""
477469
try:
478470
csp = ComponentStatusProvider()
479471
click.echo(csp.get_au_status())
@@ -487,14 +479,12 @@ def version():
487479
"""Show utility version"""
488480
click.echo("fwutil version {0}".format(VERSION))
489481

490-
show.add_command(show_update, name='update')
491-
492482
install.add_command(chassis_install, name='chassis')
493483
install.add_command(module_install, name='module')
494484

495485
update.add_command(chassis_update, name='chassis')
496486
update.add_command(module_update, name='module')
497-
update.add_command(auto_update, name='all')
487+
update.add_command(all_update, name='all')
498488

499489
chassis_install.add_command(component_install, name='component')
500490
module_install.add_command(component_install, name='component')

0 commit comments

Comments
 (0)