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 zipl bootloader setup for s390 images #1264

Merged
merged 1 commit into from
Nov 14, 2019
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
14 changes: 10 additions & 4 deletions kiwi/bootloader/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def write_meta_data(self, root_uuid=None, boot_options='', iso_boot=False):
pass

def setup_disk_image_config(
self, boot_uuid, root_uuid, hypervisor, kernel, initrd, boot_options
self, boot_uuid, root_uuid, hypervisor, kernel, initrd, boot_options={}
):
"""
Create boot config file to boot from disk.
Expand All @@ -99,9 +99,15 @@ def setup_disk_image_config(
:param string hypervisor: hypervisor name
:param string kernel: kernel name
:param string initrd: initrd name
:param string boot_options:
custom options required to setup the boot. The scope
of the options is specified in the implementation
:param dict boot_options:
custom options dictionary required to setup the bootloader.
The scope of the options covers all information needed
to setup and configure the bootloader and gets effective
in the individual implementation. boot_options should
not be mixed up with commandline options used at boot time.
This information is provided from the get_*_cmdline
methods. The contents of the dictionary can vary between
bootloaders or even not be needed
schaefi marked this conversation as resolved.
Show resolved Hide resolved

Implementation in specialized bootloader class required
"""
Expand Down
2 changes: 1 addition & 1 deletion kiwi/bootloader/config/grub2.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def setup_disk_image_config(
:param string hypervisor: unused
:param string kernel: unused
:param string initrd: unused
:param string boot_options:
:param dict boot_options:
options dictionary that has to contain the root and boot
device and optional volume configuration. KIWI has to
mount the system prior to run grub2-mkconfig.
Expand Down
31 changes: 4 additions & 27 deletions kiwi/bootloader/config/zipl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import platform
import logging
import re
import os

# project
from kiwi.bootloader.config.base import BootLoaderConfigBase
Expand Down Expand Up @@ -101,29 +100,9 @@ def write(self):
with open(config_file, 'w') as config:
config.write(self.config)

log.info('Moving initrd/kernel to zipl boot directory')
Command.run(
[
'mv',
os.sep.join(
[
self.boot_dir, 'boot',
os.readlink(self.boot_dir + '/boot/initrd')
]
),
os.sep.join(
[
self.boot_dir, 'boot',
os.readlink(self.boot_dir + '/boot/image')
]
),
self._get_zipl_boot_path()
]
)

def setup_disk_image_config(
self, boot_uuid=None, root_uuid=None, hypervisor=None,
kernel=None, initrd=None, boot_options=''
kernel='image', initrd='initrd', boot_options={}
schaefi marked this conversation as resolved.
Show resolved Hide resolved
):
"""
Create the zipl config in memory from a template suitable to
Expand All @@ -134,7 +113,7 @@ def setup_disk_image_config(
:param string hypervisor: unused
:param string kernel: kernel name
:param string initrd: initrd name
:param string boot_options: kernel options as string
:param dict boot_options: unused
"""
log.info('Creating zipl config file from template')
parameters = {
Expand All @@ -149,10 +128,8 @@ def setup_disk_image_config(
'title': self.quote_title(self.get_menu_entry_title()),
'kernel_file': kernel,
'initrd_file': initrd,
'boot_options': ' '.join([self.cmdline, boot_options]),
'failsafe_boot_options': ' '.join(
[self.cmdline_failsafe, boot_options]
)
'boot_options': self.cmdline,
schaefi marked this conversation as resolved.
Show resolved Hide resolved
'failsafe_boot_options': self.cmdline_failsafe
}
log.info('--> Using standard disk boot template')
template = self.zipl.get_template(self.failsafe_boot, self.target_type)
Expand Down
6 changes: 3 additions & 3 deletions kiwi/bootloader/install/zipl.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with kiwi. If not, see <http://www.gnu.org/licenses/>
#
import os
import logging

# project
Expand Down Expand Up @@ -77,9 +78,8 @@ def install(self):

bash_command = ' '.join(
[
'cd', self.boot_mount.mountpoint, '&&',
'zipl', '-V', '-c', self.boot_mount.mountpoint + '/config',
'-m', 'menu'
'cd', os.sep.join([self.root_dir, 'boot']), '&&',
'zipl', '-V', '-c', 'zipl/config', '-m', 'menu'
]
)
zipl_call = Command.run(
Expand Down
2 changes: 2 additions & 0 deletions kiwi/builder/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,8 @@ def _install_bootloader(self, device_map):
self.bootloader_config.setup_disk_image_config(
boot_options=custom_install_arguments
)
if 's390' in self.arch:
self.bootloader_config.write()

# cleanup bootloader config resources taken prior to next steps
del self.bootloader_config
Expand Down
31 changes: 9 additions & 22 deletions test/unit/bootloader/config/zipl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,11 @@ def test_post_init_no_target_base(self, mock_machine):
BootLoaderConfigZipl(mock.Mock(), 'root_dir')

@patch('os.path.exists')
@patch('os.readlink')
@patch('kiwi.bootloader.config.zipl.Path.create')
@patch('kiwi.bootloader.config.zipl.Command.run')
def test_write(
self, mock_command, mock_path, mock_readlink, mock_exists
self, mock_command, mock_path, mock_exists
):
mock_readlink.side_effect = [
'initrd_readlink_name',
'kernel_readlink_name'
]
mock_exists.return_value = True

self.bootloader.config = 'some-data'
Expand All @@ -111,14 +106,6 @@ def test_write(
m_open.return_value.write.assert_called_once_with(
'some-data'
)
mock_command.assert_called_once_with(
[
'mv',
'root_dir/boot/initrd_readlink_name',
'root_dir/boot/kernel_readlink_name',
'root_dir/boot/zipl'
]
)

def test_setup_disk_boot_images(self):
# does nothing on s390
Expand Down Expand Up @@ -205,7 +192,7 @@ def side_effect(arg):
mock_command.side_effect = side_effect

self.bootloader.setup_disk_image_config(
kernel='kernel', initrd='initrd', boot_options='foo'
kernel='image', initrd='initrd'
)

self.zipl.get_template.assert_called_once_with(True, 'CDL')
Expand All @@ -215,14 +202,14 @@ def side_effect(arg):
'initrd_file': 'initrd',
'offset': 168,
'device': '/dev/loop0',
'kernel_file': 'kernel',
'kernel_file': 'image',
'title': 'image-name_(_OEM_)',
'geometry': '10017,15,12',
'boot_options': 'cmdline foo',
'boot_options': 'cmdline',
'target_type': 'CDL',
'boot_timeout': '200',
'failsafe_boot_options': 'cmdline ide=nodma apm=off '
'noresume edd=off nomodeset 3 foo',
'noresume edd=off nomodeset 3',
'default_boot': '1',
'bootpath': '.'
}
Expand Down Expand Up @@ -261,7 +248,7 @@ def side_effect(arg):
mock_command.side_effect = side_effect

self.bootloader.setup_disk_image_config(
kernel='kernel', initrd='initrd'
kernel='image', initrd='initrd'
)

self.zipl.get_template.assert_called_once_with(True, 'CDL')
Expand All @@ -271,14 +258,14 @@ def side_effect(arg):
'initrd_file': 'initrd',
'offset': 129024,
'device': '/dev/loop0',
'kernel_file': 'kernel',
'kernel_file': 'image',
'title': 'image-name_(_OEM_)',
'geometry': '242251,256,63',
'boot_options': 'cmdline ',
'boot_options': 'cmdline',
'target_type': 'CDL',
'boot_timeout': '200',
'failsafe_boot_options': 'cmdline ide=nodma apm=off noresume '
'edd=off nomodeset 3 ',
'edd=off nomodeset 3',
'default_boot': '1',
'bootpath': '.'
}
Expand Down
15 changes: 5 additions & 10 deletions test/unit/bootloader/install/zipl_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from mock import (
patch, call, Mock
patch, Mock
)
from pytest import raises

Expand Down Expand Up @@ -35,17 +35,12 @@ def test_install_required(self):
assert self.bootloader.install_required() is True

@patch('kiwi.bootloader.install.zipl.Command.run')
def test_install(self, mock_command):
def test_install(self, mock_Command_run):
self.bootloader.install()
self.bootloader.boot_mount.mount.assert_called_once_with()
mock_command.call_args_list == [
call(
['bash', '-c', 'cd tmpdir && zipl -V -c tmpdir/config -m menu']
),
call(
['umount', 'tmpdir']
)
]
mock_Command_run.assert_called_once_with(
['bash', '-c', 'cd root_dir/boot && zipl -V -c zipl/config -m menu']
)

def test_destructor(self):
self.bootloader.__del__()
Expand Down
19 changes: 13 additions & 6 deletions test/unit/builder/disk_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@ def test_create_disk_standard_root_with_dracut_initrd(
'kiwi-repart'
)
self.boot_image_task.omit_module.assert_called_once_with('multipath')
assert self.boot_image_task.write_system_config_file.call_args_list == []
assert self.boot_image_task.write_system_config_file.call_args_list == \
[]

@patch('kiwi.builder.disk.FileSystem')
@patch('kiwi.builder.disk.FileSystemSquashFs')
Expand Down Expand Up @@ -602,6 +603,7 @@ def test_create_disk_standard_root_xen_server_boot(
def test_create_disk_standard_root_s390_boot(
self, mock_grub_dir, mock_command, mock_fs
):
self.disk_builder.arch = 's390x'
filesystem = mock.Mock()
mock_fs.return_value = filesystem
self.disk_builder.volume_manager_name = None
Expand All @@ -613,6 +615,8 @@ def test_create_disk_standard_root_s390_boot(
with patch('builtins.open'):
self.disk_builder.create_disk()

self.bootloader_config.write.assert_called_once_with()

assert mock_fs.call_args_list[1] == call(
'ext2', self.device_map['boot'], 'root_dir/boot/zipl/'
)
Expand Down Expand Up @@ -728,11 +732,14 @@ def test_create_disk_volume_managed_root(
volume_manager.create_volumes.assert_called_once_with('btrfs')
volume_manager.mount_volumes.call_args_list[0].assert_called_once_with()
volume_manager.get_fstab.assert_called_once_with(None, 'btrfs')
volume_manager.sync_data.assert_called_once_with([
'image', '.profile', '.kconfig', '.buildenv', 'var/cache/kiwi',
'boot/*', 'boot/.*', 'boot/efi/*', 'boot/efi/.*'
])
volume_manager.umount_volumes.call_args_list[0].assert_called_once_with()
volume_manager.sync_data.assert_called_once_with(
[
'image', '.profile', '.kconfig', '.buildenv', 'var/cache/kiwi',
'boot/*', 'boot/.*', 'boot/efi/*', 'boot/efi/.*'
]
)
volume_manager.umount_volumes.call_args_list[0].assert_called_once_with(
)
self.setup.create_fstab.assert_called_once_with(
[
'fstab_volume_entries',
Expand Down