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

fixed bootloader method verify_image_sign to have dummy implementation… #2646

Closed
Closed
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
15 changes: 10 additions & 5 deletions sonic_installer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,16 @@ def install(url, force, skip_platform_check=False, skip_migration=False, skip_pa

# Calling verification script by default - signature will be checked if enabled in bios
echo_and_log("Verifing image {} signature...".format(binary_image_version))
if not bootloader.verify_image_sign(image_path):
echo_and_log('Error: Failed verify image signature', LOG_ERR)
raise click.Abort()
else:
echo_and_log('Verification successful')
try:
if not bootloader.verify_image_sign(image_path):
echo_and_log('Error: Failed verify image signature', LOG_ERR)
raise click.Abort()
else:
echo_and_log('Verification successful')
except AttributeError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except AttributeError:

This looks like a hack to workaround the logic error inside implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@qiluo-msft whats in your mind? How do you want the fix ?

echo_and_log("Skip Verifing image {} signature,".format(binary_image_version) +
" method not implemented for the current bootloader type: {}".format(bootloader.__class__.__name__))
pass

echo_and_log("Installing image {} and setting it as default...".format(binary_image_version))
with SWAPAllocator(not skip_setup_swap, swap_mem_size, total_mem_threshold, available_mem_threshold):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_sonic_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def rootfs_path_mock(path):
result = runner.invoke(sonic_installer.commands["install"], [sonic_image_filename, "-y"])
print(result.output)

assert result.exit_code != 0
mock_bootloader_verify_image_sign_not_implemented = mock_bootloader
mock_bootloader_verify_image_sign_not_implemented.verify_image_sign = Mock(side_effect=AttributeError)
get_bootloader.return_value=mock_bootloader_verify_image_sign_not_implemented
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}")
Expand Down Expand Up @@ -89,6 +96,11 @@ def rootfs_path_mock(path):
call(["umount", "-f", "-R", mounted_image_folder], raise_exception=False),
call(["umount", "-r", "-f", mounted_image_folder], raise_exception=False),
call(["rm", "-rf", mounted_image_folder], raise_exception=False),
call(['mkdir', '-p', mounted_image_folder]),
call(["mount", "-t", "squashfs", mounted_image_folder, mounted_image_folder]),
call(["sonic-cfggen", "-d", "-y", f"{mounted_image_folder}/etc/sonic/sonic_version.yml", "-t", f"{mounted_image_folder}/usr/share/sonic/templates/sonic-environment.j2"]),
call(["umount", "-r", "-f", mounted_image_folder], raise_exception=True),
call(["rm", "-rf", mounted_image_folder], raise_exception=True),
]
assert run_command_or_raise.call_args_list == expected_call_list

Expand Down