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

[action] [PR:3433] sonic-installer: enhance next image detection for Aboot (#3433) #3540

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion sonic_installer/bootloader/aboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ class AbootBootloader(Bootloader):

def _boot_config_read(self, path=BOOT_CONFIG_PATH):
config = collections.OrderedDict()
if not os.path.exists(path):
return config
with open(path) as f:
for line in f.readlines():
line = line.strip()
Expand Down Expand Up @@ -112,7 +114,10 @@ def get_installed_images(self):

def get_next_image(self):
config = self._boot_config_read()
match = re.search(r"flash:/*(\S+)/", config['SWI'])
swi = config.get('SWI', '')
match = re.search(r"flash:/*(\S+)/", swi)
if not match:
return swi.split(':', 1)[-1]
return match.group(1).replace(IMAGE_DIR_PREFIX, IMAGE_PREFIX, 1)

def set_default_image(self, image):
Expand Down
21 changes: 17 additions & 4 deletions tests/installer_bootloader_aboot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

# Constants
image_dir = f'{aboot.IMAGE_DIR_PREFIX}expeliarmus-{aboot.IMAGE_DIR_PREFIX}abcde'
image_chainloader = f'{image_dir}/.sonic-boot.swi'
exp_image = f'{aboot.IMAGE_PREFIX}expeliarmus-{aboot.IMAGE_DIR_PREFIX}abcde'
image_dirs = [image_dir]

Expand Down Expand Up @@ -45,15 +46,27 @@ def test_get_installed_images():
assert bootloader.get_installed_images() == [exp_image]


@patch("sonic_installer.bootloader.aboot.re.search")
def test_get_next_image(re_search_patch):
def test_get_next_image():
bootloader = aboot.AbootBootloader()
bootloader._boot_config_read = Mock(return_value={'SWI': None})

# Test missing boot-config
bootloader._boot_config_read()

# Test missing SWI value
bootloader._boot_config_read = Mock(return_value={})
assert bootloader.get_next_image() == ''

# Test convertion image dir to image name
re_search_patch().group = Mock(return_value=image_dir)
swi = f'flash:{image_chainloader}'
bootloader._boot_config_read = Mock(return_value={'SWI': swi})
assert bootloader.get_next_image() == exp_image

# Test some other image
next_image = 'EOS.swi'
bootloader._boot_config_read = Mock(return_value={'SWI': f'flash:{next_image}'})
assert bootloader.get_next_image() == next_image


def test_install_image():
image_path = 'sonic'
env = os.environ.copy()
Expand Down
Loading