Skip to content

Commit

Permalink
Allow fw update for other boot type against on the previous "none" bo…
Browse files Browse the repository at this point in the history
…ot fw update (#2040)

sonic-net/sonic-buildimage#8928
sonic-net/sonic-buildimage#8926
sonic-net/sonic-buildimage#8925
sonic-net/sonic-buildimage#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.
  • Loading branch information
sujinmkang authored Apr 29, 2022
1 parent a54a091 commit fdb79b8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 21 deletions.
13 changes: 10 additions & 3 deletions fwutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -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)):
Expand All @@ -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))
Expand Down
26 changes: 8 additions & 18 deletions fwutil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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())
Expand All @@ -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')
Expand Down

0 comments on commit fdb79b8

Please sign in to comment.