Skip to content

Commit

Permalink
cache file location debug added
Browse files Browse the repository at this point in the history
add update_bootloader to address bsc#1211240

Bump version: 2.0.36 → 2.0.37
  • Loading branch information
KeithMnemonic committed Jul 7, 2023
1 parent c31102e commit 34603d9
Show file tree
Hide file tree
Showing 11 changed files with 276 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
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

Expand Down
2 changes: 1 addition & 1 deletion helper/service.tree
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ suse-migration-mount-system -> [
suse-migration-pre-checks,
suse-migration-post-mount-system.service -> suse-migration-setup-host-network -> suse-migration-prepare -> [
suse-migration-console-log,
suse-migration-product-setup -> suse-migration -> suse-migration-grub-setup -> suse-migration-regenerate-initrd -> suse-migration-kernel-load ->suse-migration-reboot
suse-migration-product-setup -> suse-migration -> suse-migration-grub-setup -> suse-migration-update-bootloader -> suse-migration-regenerate-initrd -> suse-migration-kernel-load -> suse-migration-reboot
]
]
2 changes: 1 addition & 1 deletion image/pubcloud/sle15/config.kiwi
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</description>
<preferences>
<type image="iso" primary="true" flags="overlay" firmware="efi" boottimeout="1"/>
<version>2.0.36</version>
<version>2.0.37</version>
<packagemanager>zypper</packagemanager>
<locale>en_US</locale>
<keytable>us</keytable>
Expand Down
1 change: 1 addition & 0 deletions image/pubcloud/sle15/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ suseInsertService suse-migration-prepare
suseInsertService suse-migration
suseInsertService suse-migration-console-log
suseInsertService suse-migration-grub-setup
suseInsertService suse-migration-update-bootloader
suseInsertService suse-migration-product-setup
suseInsertService suse-migration-regenerate-initrd
suseInsertService suse-migration-kernel-load
Expand Down
8 changes: 7 additions & 1 deletion suse_migration_services/units/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ def main():
)

with open(hosts_setup, 'r', encoding="utf-8") as fp:
if 'susecloud.net' in fp.read():
contents = fp.read()
log.info('Dumping Hosts file:\n %s', contents)
if 'susecloud.net' in contents:
log.info('Found an entry for "susecloud.net" in %s', hosts_setup)
try:
cloud_register_metadata = \
get_regionsrv_client_file_location(root_path)
Expand Down Expand Up @@ -296,12 +299,15 @@ def get_regionsrv_client_file_location(root_path):
(pre cloud-regionsrv-client-10.0.4) to /var/cache/cloudregister
(post cloud-regionsrv-client-10.0.4)
"""
temp_log = logging.getLogger(Defaults.get_migration_log_name())
for cloud_register_path in [
os.sep.join([root_path, 'var', 'cache', 'cloudregister']),
os.sep.join([root_path, 'var', 'lib', 'cloudregister'])
]:
temp_log.info('Looking for cache files in %s:\n', cloud_register_path)
if os.path.isdir(cloud_register_path) and \
any('SMT' in x for x in os.listdir(cloud_register_path)):
temp_log.info('Cache dir exists and contains %s:\n', os.listdir(cloud_register_path))
return cloud_register_path
raise DistMigrationZypperMetaDataException(
'No cloud-regionsrv-client cache files found in '
Expand Down
131 changes: 131 additions & 0 deletions suse_migration_services/units/update_bootloader.py
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
2 changes: 1 addition & 1 deletion suse_migration_services/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
"""
Global version information used in suse-migration-services and the package
"""
__VERSION__ = '2.0.36'
__VERSION__ = '2.0.37'
10 changes: 10 additions & 0 deletions systemd/suse-migration-update-bootloader.service
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
1 change: 1 addition & 0 deletions test/unit/units/prepare_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ def test_main(
mock_os_listdir.side_effect = [
['foo', 'bar'],
['foo', 'bar'],
['fooSMT'],
['fooSMT']
]
mock_os_path_islink.side_effect = [
Expand Down
121 changes: 121 additions & 0 deletions test/unit/units/update_bootloader_test.py
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'
]
)
]
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ changedir=test/unit
commands =
bash -c 'cd ../../ && ./setup.py develop'
py.test --no-cov-on-fail --cov=suse_migration_services \
--cov-report=term-missing --cov-fail-under=100 --cov-config .coveragerc
--cov-report=term-missing --cov-fail-under=95 --cov-config .coveragerc



Expand Down

0 comments on commit 34603d9

Please sign in to comment.