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

Fix handling of zipl.conf in plain zipl bootloader #2612

Merged
merged 1 commit into from
Aug 11, 2024
Merged
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
25 changes: 12 additions & 13 deletions kiwi/bootloader/config/zipl.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from kiwi.bootloader.template.zipl import BootLoaderTemplateZipl
from kiwi.bootloader.config.bootloader_spec_base import BootLoaderSpecBase
from kiwi.command import Command
from kiwi.utils.temporary import Temporary

from kiwi.exceptions import (
KiwiTemplateError,
Expand All @@ -44,7 +45,9 @@ def create_loader_image(self, target: str) -> None:

def setup_loader(self, target: str) -> None:
"""
Setup main zipl.conf and install zipl for supported targets
Setup temporary zipl config and install zipl for supported targets.
Please note we are not touching the main zipl.conf file provided
by the distributors

:param str target:
target identifier, one of disk, live(iso) or install(iso)
Expand Down Expand Up @@ -72,15 +75,19 @@ def setup_loader(self, target: str) -> None:
self.custom_args['initrd'] = \
f'{boot_path}/{kernel_info.initrd_name}'

runtime_zipl_config_file = Temporary(
path=self.root_mount.mountpoint, prefix='kiwi_zipl.conf_'
).new_file()

BootLoaderZipl._write_config_file(
BootLoaderTemplateZipl().get_loader_template(),
f'{self.root_mount.mountpoint}/etc/zipl.conf',
runtime_zipl_config_file.name,
self._get_template_parameters()
)
self.set_loader_entry(
self.root_mount.mountpoint, self.target.disk
)
self._install_zipl(root_dir)
self._install_zipl(root_dir, runtime_zipl_config_file.name)

def set_loader_entry(self, root_dir: str, target: str) -> None:
"""
Expand All @@ -97,26 +104,18 @@ def set_loader_entry(self, root_dir: str, target: str) -> None:
self._get_template_parameters(entry_name)
)

def _install_zipl(self, root_dir: str) -> None:
def _install_zipl(self, root_dir: str, zipl_config: str) -> None:
"""
Install zipl on target
"""
zipl = [
'chroot', root_dir, 'zipl',
'--noninteractive',
'--config', '/etc/zipl.conf',
'--config', zipl_config.replace(root_dir, ''),
'--blsdir', self.entries_dir,
'--verbose'
]
Command.run(zipl)
# rewrite zipl.conf without loop device reference
template_parameters = self._get_template_parameters()
template_parameters['targetbase'] = ''
BootLoaderZipl._write_config_file(
BootLoaderTemplateZipl().get_loader_template(),
f'{self.root_mount.mountpoint}/etc/zipl.conf',
template_parameters
)

def _get_template_parameters(
self, default_entry: str = ''
Expand Down
17 changes: 8 additions & 9 deletions test/unit/bootloader/config/zipl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,20 @@ def test_setup_loader_raises_invalid_target(self):
@patch('kiwi.bootloader.config.zipl.Path.create')
@patch('kiwi.bootloader.config.zipl.Command.run')
@patch('kiwi.bootloader.config.zipl.BootLoaderTemplateZipl')
@patch('kiwi.bootloader.config.zipl.Temporary.new_file')
@patch.object(BootLoaderZipl, '_write_config_file')
@patch.object(BootLoaderZipl, '_get_template_parameters')
@patch.object(BootLoaderSpecBase, 'get_entry_name')
def test_setup_loader(
self, mock_get_entry_name, mock_get_template_parameters,
mock_write_config_file, mock_BootLoaderTemplateZipl, mock_Command_run,
mock_write_config_file, mock_Temporary_new_file,
mock_BootLoaderTemplateZipl, mock_Command_run,
mock_Path_create, mock_Path_wipe, mock_BootImageBase_get_boot_names,
mock_os_path_exists
):
temporary = Mock()
temporary.name = 'system_root_mount/kiwi_zipl.conf_'
mock_Temporary_new_file.return_value = temporary
mock_get_entry_name.return_value = \
'opensuse-leap-5.3.18-59.10-default.conf'

Expand All @@ -82,7 +87,7 @@ def test_setup_loader(
call(
mock_BootLoaderTemplateZipl.
return_value.get_loader_template.return_value,
'system_root_mount/etc/zipl.conf',
'system_root_mount/kiwi_zipl.conf_',
mock_get_template_parameters.return_value
),
call(
Expand All @@ -91,20 +96,14 @@ def test_setup_loader(
'system_root_mount/boot/loader/entries/'
'opensuse-leap-5.3.18-59.10-default.conf',
mock_get_template_parameters.return_value
),
call(
mock_BootLoaderTemplateZipl.
return_value.get_loader_template.return_value,
'system_root_mount/etc/zipl.conf',
{'targetbase': ''}
)
]
assert self.bootloader._mount_system.called
mock_Command_run.assert_called_once_with(
[
'chroot', 'system_root_mount', 'zipl',
'--noninteractive',
'--config', '/etc/zipl.conf',
'--config', '/kiwi_zipl.conf_',
'--blsdir', '/boot/loader/entries',
'--verbose'
]
Expand Down
Loading