Skip to content

Commit

Permalink
[armhf][sonic-installer] Fix the issue of sonic-installer list after …
Browse files Browse the repository at this point in the history
…set-default and cleanup (#2479)

What I did
sonic-installer list will throw a exception when install images as the following step

(onie-nos-install ) Install first image A
(sonic-installer) Install Image B and not reboot it
(sonic-installer) set default to back to Image A
sudo sonic-installer cleanup
At this time, executing sonic-installer list will throw exception

How I did it
Modify the get_next_image() in uboot.py to check and return index 1 when the images list contains two elements.
This PR should work with sonic-net/sonic-buildimage#12609

This PR is needed by branch 202012 and 2022o5

Signed-off-by: mlok <marty.lok@nokia.com>
  • Loading branch information
mlok-nokia authored and yxieca committed Nov 10, 2022
1 parent b2d50f4 commit 8cb6124
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sonic_installer/bootloader/uboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def get_next_image(self):
proc = subprocess.Popen("/usr/bin/fw_printenv -n boot_next", shell=True, text=True, stdout=subprocess.PIPE)
(out, _) = proc.communicate()
image = out.rstrip()
if "sonic_image_2" in image:
if "sonic_image_2" in image and len(images) == 2:
next_image_index = 1
else:
next_image_index = 0
Expand Down
31 changes: 31 additions & 0 deletions tests/installer_bootloader_uboot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,37 @@ def communicate():
def mock_run_command(cmd):
MockProc.commandline = cmd

@patch("sonic_installer.bootloader.uboot.subprocess.Popen")
@patch("sonic_installer.bootloader.uboot.run_command")
def test_get_next_image(run_command_patch, popen_patch):
class MockProc():
commandline = "boot_next"
def communicate(self):
return MockProc.commandline, None

def mock_run_command(cmd):
# Remove leading string "/usr/bin/fw_setenv boot_next " -- the 29 characters
MockProc.commandline = cmd[29:]

# Constants
intstalled_images = [
f'{uboot.IMAGE_PREFIX}expeliarmus-{uboot.IMAGE_PREFIX}abcde',
f'{uboot.IMAGE_PREFIX}expeliarmus-abcde',
]

run_command_patch.side_effect = mock_run_command
popen_patch.return_value = MockProc()

bootloader = uboot.UbootBootloader()
bootloader.get_installed_images = Mock(return_value=intstalled_images)

bootloader.set_default_image(intstalled_images[1])

# Verify get_next_image was executed with image path
next_image=bootloader.get_next_image()

assert next_image == intstalled_images[1]

@patch("sonic_installer.bootloader.uboot.subprocess.Popen")
@patch("sonic_installer.bootloader.uboot.run_command")
def test_set_fips_uboot(run_command_patch, popen_patch):
Expand Down

0 comments on commit 8cb6124

Please sign in to comment.