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
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
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