Skip to content

Commit

Permalink
Fixed coverage issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ycoheNvidia committed Oct 20, 2022
1 parent baa6918 commit 3cf5935
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions sonic_installer/bootloader/grub.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def verify_image_platform(self, image_path):
return self.platform_in_platforms_asic(platform, image_path)

def verify_image_sign(self, image_path):
click.echo('Verifying image signature')
verification_script_name = 'verify_image_sign.sh'
script_path = os.path.join('/usr', 'local', 'bin', verification_script_name)
if not os.path.exists(script_path):
Expand Down
8 changes: 8 additions & 0 deletions tests/installer_bootloader_grub_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,11 @@ def test_set_fips_grub():

# Cleanup the _tmp_host folder
shutil.rmtree(tmp_host_path)

def test_verify_image():

bootloader = grub.GrubBootloader()
image = f'{grub.IMAGE_PREFIX}expeliarmus-{grub.IMAGE_PREFIX}abcde'

# command should fail
assert not bootloader.verify_image_sign(image)
8 changes: 7 additions & 1 deletion tests/test_sonic_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from sonic_installer.main import sonic_installer
from click.testing import CliRunner
from unittest.mock import patch, Mock, call
from sonic_installer.bootloader import GrubBootloader

@patch("sonic_installer.main.SWAPAllocator")
@patch("sonic_installer.main.get_bootloader")
Expand Down Expand Up @@ -32,7 +33,6 @@ def test_install(run_command, run_command_or_raise, get_bootloader, swap, fs):
mock_bootloader.get_installed_images = Mock(return_value=[current_image_version])
mock_bootloader.get_image_path = Mock(return_value=new_image_folder)
mock_bootloader.verify_image_sign = Mock(return_value=True)

@contextmanager
def rootfs_path_mock(path):
yield mounted_image_folder
Expand All @@ -46,7 +46,13 @@ def rootfs_path_mock(path):
print(result.output)

assert result.exit_code == 0
mock_bootloader_verify_image_sign_fail = mock_bootloader
mock_bootloader_verify_image_sign_fail.verify_image_sign = Mock(return_value=False)
get_bootloader.return_value=mock_bootloader_verify_image_sign_fail
result = runner.invoke(sonic_installer.commands["install"], [sonic_image_filename, "-y"])
print(result.output)

assert result.exit_code != 0
# Assert bootloader install API was called
mock_bootloader.install_image.assert_called_with(f"./{sonic_image_filename}")
# Assert all below commands were called, so we ensure that
Expand Down

0 comments on commit 3cf5935

Please sign in to comment.