-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Image-installer: Fix duplication of image prefix (#2172)
* SONiC prefix shown twice when working branch contains "image-" in its name. #### Why I did it SONiC prefix is shown twice when the working branch contains "image-" in its name. <img width="583" alt="Screenshot 2022-05-18 at 14 08 12" src="https://user-images.githubusercontent.com/35844154/169044815-4ff57d56-8aff-46a6-a0e3-9a54665afcde.png"> #### How I did it Fixed sonic-installer's one bootloader wrapper to show correct version. <img width="558" alt="Screenshot 2022-05-18 at 14 08 33" src="https://user-images.githubusercontent.com/35844154/169044849-a1db656c-f1b1-4a5c-ba87-7aafcf8daa5a.png"> #### How to verify it Build image (the branch is important): ``` cd sonic-buildimage git checkout -b dev-image-test make configure PLATFORM=mellanox && make target/sonic-mellanox.bin ``` Run image on the switch and execute: ``` sudo sonic-installer list ``` #### Previous command output (if the output of a command-line utility has changed) <img width="583" alt="Screenshot 2022-05-18 at 14 08 12" src="https://user-images.githubusercontent.com/35844154/169044815-4ff57d56-8aff-46a6-a0e3-9a54665afcde.png"> #### New command output (if the output of a command-line utility has changed) <img width="558" alt="Screenshot 2022-05-18 at 14 08 33" src="https://user-images.githubusercontent.com/35844154/169044849-a1db656c-f1b1-4a5c-ba87-7aafcf8daa5a.png">
- Loading branch information
Showing
11 changed files
with
154 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from unittest.mock import Mock, patch | ||
|
||
# Import test module | ||
import sonic_installer.bootloader.aboot as aboot | ||
|
||
# Constants | ||
image_dir = f'{aboot.IMAGE_DIR_PREFIX}expeliarmus-{aboot.IMAGE_DIR_PREFIX}abcde' | ||
exp_image = f'{aboot.IMAGE_PREFIX}expeliarmus-{aboot.IMAGE_DIR_PREFIX}abcde' | ||
image_dirs = [image_dir] | ||
|
||
|
||
@patch('sonic_installer.bootloader.aboot.is_secureboot', | ||
Mock(return_value=False)) | ||
def test_swi_image_path(): | ||
# Constants | ||
image_id = f'{aboot.IMAGE_PREFIX}expeliarmus-{aboot.IMAGE_PREFIX}abcde' | ||
exp_image_path = f'flash:{aboot.IMAGE_DIR_PREFIX}expeliarmus-'\ | ||
f'{aboot.IMAGE_PREFIX}abcde/.sonic-boot.swi' | ||
|
||
bootloader = aboot.AbootBootloader() | ||
|
||
# Verify converted swi image path | ||
image_path = bootloader._swi_image_path(image_id) | ||
assert image_path == exp_image_path | ||
|
||
|
||
@patch("sonic_installer.bootloader.aboot.re.search") | ||
def test_get_current_image(re_search_patch): | ||
bootloader = aboot.AbootBootloader() | ||
|
||
# Test convertion image dir to image name | ||
re_search_patch().group = Mock(return_value=image_dir) | ||
assert bootloader.get_current_image() == exp_image | ||
|
||
|
||
@patch('sonic_installer.bootloader.aboot.os.listdir', | ||
Mock(return_value=image_dirs)) | ||
def test_get_installed_images(): | ||
bootloader = aboot.AbootBootloader() | ||
|
||
# Test convertion image dir to image name | ||
assert bootloader.get_installed_images() == [exp_image] | ||
|
||
|
||
@patch("sonic_installer.bootloader.aboot.re.search") | ||
def test_get_next_image(re_search_patch): | ||
bootloader = aboot.AbootBootloader() | ||
bootloader._boot_config_read = Mock(return_value={'SWI': None}) | ||
|
||
# Test convertion image dir to image name | ||
re_search_patch().group = Mock(return_value=image_dir) | ||
assert bootloader.get_next_image() == exp_image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import os | ||
|
||
# Import test module | ||
import sonic_installer.bootloader.bootloader as bl | ||
|
||
|
||
def test_get_image_path(): | ||
# Constants | ||
image = f'{bl.IMAGE_PREFIX}expeliarmus-{bl.IMAGE_PREFIX}abcde' | ||
path_prefix = os.path.join(bl.HOST_PATH, bl.IMAGE_DIR_PREFIX) | ||
exp_image_path = f'{path_prefix}expeliarmus-{bl.IMAGE_PREFIX}abcde' | ||
|
||
bootloader = bl.Bootloader() | ||
|
||
# Test replacement image id with image path | ||
assert bootloader.get_image_path(image) == exp_image_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
from unittest.mock import Mock, patch | ||
|
||
# Import test module | ||
import sonic_installer.bootloader.grub as grub | ||
|
||
|
||
@patch("sonic_installer.bootloader.grub.subprocess.call", Mock()) | ||
@patch("sonic_installer.bootloader.grub.open") | ||
@patch("sonic_installer.bootloader.grub.run_command") | ||
@patch("sonic_installer.bootloader.grub.re.search") | ||
def test_remove_image(open_patch, run_command_patch, re_search_patch): | ||
# Constants | ||
image_path_prefix = os.path.join(grub.HOST_PATH, grub.IMAGE_DIR_PREFIX) | ||
exp_image_path = f'{image_path_prefix}expeliarmus-{grub.IMAGE_PREFIX}abcde' | ||
image = f'{grub.IMAGE_PREFIX}expeliarmus-{grub.IMAGE_PREFIX}abcde' | ||
|
||
bootloader = grub.GrubBootloader() | ||
|
||
# Verify rm command was executed with image path | ||
bootloader.remove_image(image) | ||
args_list = grub.subprocess.call.call_args_list | ||
assert len(args_list) > 0 | ||
|
||
args, _ = args_list[0] | ||
assert exp_image_path in args[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from unittest.mock import Mock, patch | ||
|
||
# Import test module | ||
import sonic_installer.bootloader.onie as onie | ||
|
||
|
||
@patch("sonic_installer.bootloader.onie.re.search") | ||
def test_get_current_image(re_search): | ||
# Constants | ||
image = f'{onie.IMAGE_DIR_PREFIX}expeliarmus-{onie.IMAGE_DIR_PREFIX}abcde' | ||
exp_image = f'{onie.IMAGE_PREFIX}expeliarmus-{onie.IMAGE_DIR_PREFIX}abcde' | ||
|
||
bootloader = onie.OnieInstallerBootloader() | ||
|
||
# Test image dir conversion | ||
onie.re.search().group = Mock(return_value=image) | ||
assert bootloader.get_current_image() == exp_image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import os | ||
from unittest.mock import Mock, patch | ||
|
||
# Import test module | ||
import sonic_installer.bootloader.uboot as uboot | ||
|
||
|
||
@patch("sonic_installer.bootloader.uboot.subprocess.call", Mock()) | ||
@patch("sonic_installer.bootloader.uboot.run_command") | ||
def test_remove_image(run_command_patch): | ||
# Constants | ||
image_path_prefix = os.path.join(uboot.HOST_PATH, uboot.IMAGE_DIR_PREFIX) | ||
exp_image_path = f'{image_path_prefix}expeliarmus-{uboot.IMAGE_PREFIX}abcde' | ||
|
||
intstalled_images = [ | ||
f'{uboot.IMAGE_PREFIX}expeliarmus-{uboot.IMAGE_PREFIX}abcde', | ||
f'{uboot.IMAGE_PREFIX}expeliarmus-abcde', | ||
] | ||
|
||
bootloader = uboot.UbootBootloader() | ||
bootloader.get_installed_images = Mock(return_value=intstalled_images) | ||
|
||
# Verify rm command was executed with image path | ||
bootloader.remove_image(intstalled_images[0]) | ||
args_list = uboot.subprocess.call.call_args_list | ||
assert len(args_list) > 0 | ||
|
||
args, _ = args_list[0] | ||
assert exp_image_path in args[0] |