-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add update_bootloader to address bsc#1211240 Bump version: 2.0.36 → 2.0.37
- Loading branch information
1 parent
c31102e
commit 34603d9
Showing
11 changed files
with
276 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 2.0.36 | ||
current_version = 2.0.37 | ||
commit = True | ||
tag = True | ||
|
||
|
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,131 @@ | ||
# Copyright (c) 2022 SUSE Linux LLC. All rights reserved. | ||
# | ||
# This file is part of suse-migration-services. | ||
# | ||
# suse-migration-services is free software: you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# suse-migration-services is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with suse-migration-services. If not, see <http://www.gnu.org/licenses/> | ||
# | ||
"""systemd service to install the shim package and update the bootloader""" | ||
import logging | ||
|
||
# project | ||
from suse_migration_services.command import Command | ||
from suse_migration_services.defaults import Defaults | ||
from suse_migration_services.logger import Logger | ||
|
||
from suse_migration_services.exceptions import ( | ||
DistMigrationCommandException | ||
) | ||
|
||
|
||
def main(): | ||
""" | ||
DistMigration install the shim pacakge, enable "Secure boot" | ||
and update the bootloader | ||
""" | ||
Logger.setup() | ||
log = logging.getLogger(Defaults.get_migration_log_name()) | ||
|
||
root_path = Defaults.get_system_root_path() | ||
|
||
log.info('Installing the shim package') | ||
install_shim_package(root_path) | ||
log.info('Updating the shimbootloader') | ||
install_secure_bootloader(root_path) | ||
log.info('Updating the bootloader') | ||
update_bootloader_config(root_path) | ||
|
||
|
||
def install_shim_package(root_path,): | ||
"""Function to do instal the "shim" package""" | ||
|
||
log = logging.getLogger(Defaults.get_migration_log_name()) | ||
|
||
try: | ||
log.info( | ||
'Running chroot {0} zypper in shim'.format(root_path) | ||
) | ||
Command.run( | ||
[ | ||
'chroot', | ||
root_path, | ||
'zypper', | ||
'in', | ||
'shim' | ||
] | ||
) | ||
except Exception as issue: | ||
log.error( | ||
'Failed to install the shim package: {0}'.format(issue) | ||
) | ||
raise DistMigrationCommandException( | ||
'Failed to install the shim package: {0}'.format( | ||
issue | ||
) | ||
) from issue | ||
|
||
|
||
def install_secure_bootloader(root_path): | ||
"""Function to run 'shim-install'""" | ||
|
||
log = logging.getLogger(Defaults.get_migration_log_name()) | ||
|
||
try: | ||
log.info( | ||
'Running chroot {0} shim-install --removable'.format(root_path) | ||
) | ||
Command.run( | ||
[ | ||
'chroot', | ||
root_path, | ||
'shim-install', | ||
'--removable' | ||
] | ||
) | ||
except Exception as issue: | ||
log.error( | ||
'Failed to run shim-install: {0}'.format(issue) | ||
) | ||
raise DistMigrationCommandException( | ||
'Failed to run shim-install: {0}'.format( | ||
issue | ||
) | ||
) from issue | ||
|
||
|
||
def update_bootloader_config(root_path): | ||
"""Function run 'update-bootloader""" | ||
|
||
log = logging.getLogger(Defaults.get_migration_log_name()) | ||
|
||
try: | ||
log.info( | ||
'Running chroot {0} update-bootloader --reinit'.format(root_path) | ||
) | ||
Command.run( | ||
[ | ||
'chroot', | ||
root_path, | ||
'update-bootloader', | ||
'--reinit' | ||
] | ||
) | ||
except Exception as issue: | ||
log.error( | ||
'Failed to run update-bootloader: {0}'.format(issue) | ||
) | ||
raise DistMigrationCommandException( | ||
'Failed to run update-bootloader: {0}'.format( | ||
issue | ||
) | ||
) from issue |
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,10 @@ | ||
[Unit] | ||
Description=Update the bootloader | ||
After=suse-migration-update-bootloader.service | ||
|
||
[Service] | ||
Type=oneshot | ||
ExecStart=/usr/bin/suse-migration-update-bootloader | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
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,121 @@ | ||
""" Tests for update_bootloader""" | ||
import logging | ||
|
||
from mock import ( | ||
patch, call | ||
) | ||
from pytest import ( | ||
raises, fixture | ||
) | ||
from suse_migration_services.units.update_bootloader import ( | ||
main, | ||
install_shim_package, | ||
install_secure_bootloader, | ||
update_bootloader_config | ||
) | ||
from suse_migration_services.exceptions import ( | ||
DistMigrationCommandException | ||
) | ||
|
||
|
||
@patch('suse_migration_services.logger.Logger.setup') | ||
@patch('os.path.exists') | ||
class TestUpdateBootloader(): | ||
@fixture(autouse=True) | ||
def inject_fixtures(self, caplog): | ||
"""Setup capture log""" | ||
self._caplog = caplog | ||
|
||
@patch('suse_migration_services.command.Command.run') | ||
def test_install_shim_package_raises( | ||
self, | ||
mock_Command_run, | ||
mock_os_path_exists, | ||
mock_logger_setup | ||
): | ||
""" Test exception raised when running update_bootloader""" | ||
|
||
mock_Command_run.side_effect = [ | ||
Exception('error') | ||
] | ||
with self._caplog.at_level(logging.ERROR): | ||
with raises(DistMigrationCommandException): | ||
install_shim_package('/system-root') | ||
assert mock_Command_run.call_args_list == [ | ||
call( | ||
[ | ||
'chroot', | ||
'/system-root', | ||
'zypper', | ||
'in', | ||
'shim' | ||
] | ||
) | ||
] | ||
|
||
@patch('suse_migration_services.command.Command.run') | ||
def test_install_secure_bootloader_raises_on_update_bootloader( | ||
self, | ||
mock_Command_run, | ||
mock_os_path_exists, | ||
mock_logger_setup | ||
): | ||
""" Test exception raised when running dracut_bind_mounts()""" | ||
mock_Command_run.side_effect = [ | ||
Exception('error') | ||
] | ||
with self._caplog.at_level(logging.ERROR): | ||
with raises(DistMigrationCommandException): | ||
install_secure_bootloader('/system-root') | ||
|
||
@patch('suse_migration_services.command.Command.run') | ||
def test_update_bootloader_config_raise_on_update_bootloader( | ||
self, | ||
mock_Command_run, | ||
mock_os_path_exists, | ||
mock_logger_setup | ||
): | ||
""" Test exception raised when running dracut_bind_mounts()""" | ||
mock_Command_run.side_effect = [ | ||
Exception('error') | ||
] | ||
with self._caplog.at_level(logging.ERROR): | ||
with raises(DistMigrationCommandException): | ||
update_bootloader_config('/system-root') | ||
|
||
@patch('suse_migration_services.command.Command.run') | ||
def test_main( | ||
self, | ||
mock_Command_run, | ||
mock_os_path_exists, | ||
mock_logger_setup | ||
): | ||
""" Test running update_bootloader""" | ||
main() | ||
assert mock_Command_run.call_args_list == [ | ||
call( | ||
[ | ||
'chroot', | ||
'/system-root', | ||
'zypper', | ||
'in', | ||
'shim' | ||
] | ||
), | ||
call( | ||
[ | ||
'chroot', | ||
'/system-root', | ||
'shim-install', | ||
'--removable' | ||
] | ||
), | ||
call( | ||
[ | ||
'chroot', | ||
'/system-root', | ||
'update-bootloader', | ||
'--reinit' | ||
] | ||
) | ||
] |
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