Skip to content

Commit d1ca2cd

Browse files
authored
[armhf][sonic-installer] Fix the issue of sonic-installer list after 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 #12609 This PR is needed by branch 202012 and 2022o5 Signed-off-by: mlok <[email protected]>
1 parent d5a6da3 commit d1ca2cd

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

sonic_installer/bootloader/uboot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def get_next_image(self):
4040
proc = subprocess.Popen("/usr/bin/fw_printenv -n boot_next", shell=True, text=True, stdout=subprocess.PIPE)
4141
(out, _) = proc.communicate()
4242
image = out.rstrip()
43-
if "sonic_image_2" in image:
43+
if "sonic_image_2" in image and len(images) == 2:
4444
next_image_index = 1
4545
else:
4646
next_image_index = 0

tests/installer_bootloader_uboot_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,37 @@ def test_remove_image(run_command_patch):
3535
args, _ = args_list[0]
3636
assert exp_image_path in args[0]
3737

38+
@patch("sonic_installer.bootloader.uboot.subprocess.Popen")
39+
@patch("sonic_installer.bootloader.uboot.run_command")
40+
def test_get_next_image(run_command_patch, popen_patch):
41+
class MockProc():
42+
commandline = "boot_next"
43+
def communicate(self):
44+
return MockProc.commandline, None
45+
46+
def mock_run_command(cmd):
47+
# Remove leading string "/usr/bin/fw_setenv boot_next " -- the 29 characters
48+
MockProc.commandline = cmd[29:]
49+
50+
# Constants
51+
intstalled_images = [
52+
f'{uboot.IMAGE_PREFIX}expeliarmus-{uboot.IMAGE_PREFIX}abcde',
53+
f'{uboot.IMAGE_PREFIX}expeliarmus-abcde',
54+
]
55+
56+
run_command_patch.side_effect = mock_run_command
57+
popen_patch.return_value = MockProc()
58+
59+
bootloader = uboot.UbootBootloader()
60+
bootloader.get_installed_images = Mock(return_value=intstalled_images)
61+
62+
bootloader.set_default_image(intstalled_images[1])
63+
64+
# Verify get_next_image was executed with image path
65+
next_image=bootloader.get_next_image()
66+
67+
assert next_image == intstalled_images[1]
68+
3869
@patch("sonic_installer.bootloader.uboot.subprocess.Popen")
3970
@patch("sonic_installer.bootloader.uboot.run_command")
4071
def test_set_fips_uboot(run_command_patch, popen_patch):

0 commit comments

Comments
 (0)