Skip to content
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

Allow fw update for other boot type against on the previous "none" boot fw update #2040

Merged
merged 11 commits into from
Apr 29, 2022
10 changes: 8 additions & 2 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 @@ -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)):
Expand All @@ -903,6 +903,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 {} again on top of the previous {} reboot".format(boot, boot_type))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this been manually tested? Do we have any unit tests for this?

boot_type is not defined in this latest change as far as I can tell.

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
24 changes: 7 additions & 17 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,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')

Expand Down