Skip to content

Commit

Permalink
[sfputil] Firmware download/upgrade CLI support for QSFP-DD (#1947)
Browse files Browse the repository at this point in the history
Fixing : Comparing error code with a wrong variable.
Refactor : Renaming variables for more suitable its purpose.
Refactor : Removing if case which is low correlation with function.
Feat : Adding "echo" to display detail result.
  • Loading branch information
CliveNi committed Oct 3, 2022
1 parent 8f91400 commit b1e41e8
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions sfputil/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,26 +1140,23 @@ def is_fw_switch_done(port_name):
cnt += 1

if fw_info['status'] == True:
(ImageA, ImageARunning, ImageACommitted, ImageAValid,
ImageB, ImageBRunning, ImageBCommitted, ImageBValid) = fw_info['result']
(ImageA, ImageARunning, ImageACommitted, ImageAInvalid,
ImageB, ImageBRunning, ImageBCommitted, ImageBInvalid) = fw_info['result']

if (ImageARunning == 1) and (ImageBRunning == 1): # Both imageA and B is running.
click.echo("FW info error : Both imageA and B show running!")
status = -1 # Abnormal status.
elif (ImageACommitted == 1) and (ImageBCommitted == 1): # Both imageA and B is committed.
click.echo("FW info error : Both imageA and B show committed!")
status = -1 # Abnormal status.
elif (ImageARunning == 1) and (ImageAValid == 1): # ImageA is running, but also invalid.
if (ImageARunning == 1) and (ImageAInvalid == 1): # ImageA is running, but also invalid.
click.echo("FW info error : ImageA shows running, but also shows invalid!")
status = -1 # Abnormal status.
elif (ImageBRunning == 1) and (ImageBValid == 1): # ImageB is running, but also invalid.
elif (ImageBRunning == 1) and (ImageBInvalid == 1): # ImageB is running, but also invalid.
click.echo("FW info error : ImageB shows running, but also shows invalid!")
status = -1 # Abnormal status.
elif (ImageARunning == 1) and (ImageACommitted == 0): # ImageA is running, but not committed.
click.echo("FW images switch successful : ImageA is running")
status = 1 # run_firmware is done.
elif (ImageBRunning == 1) and (ImageBCommitted == 0): # ImageB is running, but not committed.
click.echo("FW images switch successful : ImageB is running")
status = 1 # run_firmware is done.
else: # No image is running, or running and committed image is same.
click.echo("FW info error : Failed to switch into uncommitted image!")
status = -1 # Failure for Switching images.
else:
click.echo("FW switch : Timeout!")
Expand Down Expand Up @@ -1338,12 +1335,10 @@ def upgrade(port_name, filepath):

click.echo("Firmware run in mode 1 successful")

if status != is_fw_switch_done(port_name):
if is_fw_switch_done(port_name) != 1:
click.echo('Failed to switch firmware images!')
sys.exit(EXIT_FAIL)

click.echo("Firmware images switch successful")

status = commit_firmware(port_name)
if status != 1:
click.echo('Failed to commit firmware! CDB status: {}'.format(status))
Expand Down

0 comments on commit b1e41e8

Please sign in to comment.