Skip to content

Commit

Permalink
Merge pull request #5350 from poncovka/master-kernel_arguments_task
Browse files Browse the repository at this point in the history
bootloader: Create an installation task for collecting kernel arguments
  • Loading branch information
poncovka authored Nov 28, 2023
2 parents c47c54c + 8a7641e commit b2006da
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 39 deletions.
26 changes: 15 additions & 11 deletions pyanaconda/modules/storage/bootloader/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,21 +738,13 @@ def check(self):
def timeout(self, seconds):
self._timeout = seconds

def prepare(self, storage):
"""Prepare the bootloader for the installation.
FIXME: Move this function into a task.
"""
def prepare(self):
"""Prepare the bootloader for the installation."""
bootloader_proxy = STORAGE.get_proxy(BOOTLOADER)
self._update_flags(bootloader_proxy)
self._apply_password(bootloader_proxy)
self._apply_timeout(bootloader_proxy)
self._apply_zipl_secure_boot(bootloader_proxy)
self._set_extra_boot_args(bootloader_proxy)
self._set_storage_boot_args(storage)
self._preserve_some_boot_args()
self._set_graphical_boot_args()
self._set_security_boot_args()

def _update_flags(self, bootloader_proxy):
"""Update flags."""
Expand Down Expand Up @@ -790,8 +782,20 @@ def _apply_zipl_secure_boot(self, bootloader_proxy):
log.debug("Applying ZIPL Secure Boot: %s", secure_boot)
self.secure = secure_boot

def _set_extra_boot_args(self, bootloader_proxy):
def collect_arguments(self, storage):
"""Collect kernel arguments for the installation.
FIXME: Move this code out of this class.
"""
self._set_extra_boot_args()
self._set_storage_boot_args(storage)
self._preserve_some_boot_args()
self._set_graphical_boot_args()
self._set_security_boot_args()

def _set_extra_boot_args(self):
"""Set the extra boot args."""
bootloader_proxy = STORAGE.get_proxy(BOOTLOADER)
self.boot_args.update(bootloader_proxy.ExtraArguments)

def _set_storage_boot_args(self, storage):
Expand Down
6 changes: 5 additions & 1 deletion pyanaconda/modules/storage/bootloader/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
from pyanaconda.modules.storage.bootloader.bootloader_interface import BootloaderInterface
from pyanaconda.modules.storage.bootloader.installation import ConfigureBootloaderTask, \
InstallBootloaderTask, FixZIPLBootloaderTask, FixBTRFSBootloaderTask, RecreateInitrdsTask, \
CreateRescueImagesTask, CreateBLSEntriesTask
CreateRescueImagesTask, CreateBLSEntriesTask, CollectKernelArgumentsTask
from pyanaconda.modules.storage.constants import BootloaderMode, ZIPLSecureBoot
from pyanaconda.modules.storage.storage_subscriber import StorageSubscriberModule

Expand Down Expand Up @@ -469,6 +469,10 @@ def install_bootloader_with_tasks(self, payload_type, kernel_versions):
kernel_versions=kernel_versions,
sysroot=conf.target.system_root
),
CollectKernelArgumentsTask(
storage=self.storage,
mode=self.bootloader_mode
),
InstallBootloaderTask(
storage=self.storage,
mode=self.bootloader_mode
Expand Down
59 changes: 56 additions & 3 deletions pyanaconda/modules/storage/bootloader/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

from pyanaconda.anaconda_loggers import get_module_logger
from pyanaconda.modules.storage.bootloader.utils import configure_boot_loader, \
install_boot_loader, recreate_initrds, create_rescue_images, create_bls_entries
recreate_initrds, create_rescue_images, create_bls_entries
from pyanaconda.core.configuration.anaconda import conf
from pyanaconda.modules.common.task import Task

Expand All @@ -37,7 +37,7 @@

__all__ = ["ConfigureBootloaderTask", "InstallBootloaderTask", "FixBTRFSBootloaderTask",
"FixZIPLBootloaderTask", "RecreateInitrdsTask", "CreateRescueImagesTask",
"CreateBLSEntriesTask"]
"CreateBLSEntriesTask", "CollectKernelArgumentsTask"]


class CreateRescueImagesTask(Task):
Expand Down Expand Up @@ -105,6 +105,50 @@ def run(self):
)


class CollectKernelArgumentsTask(Task):
"""Installation task for collecting the kernel arguments."""

def __init__(self, storage, mode):
"""Create a new task."""
super().__init__()
self._storage = storage
self._mode = mode

@property
def name(self):
"""Name of the task."""
return "Collect kernel arguments"

@property
def _bootloader(self):
"""Representation of the bootloader."""
return self._storage.bootloader

def run(self):
"""Run the task."""
if conf.target.is_directory:
log.debug("The bootloader installation is disabled for dir installations.")
return

if self._mode == BootloaderMode.DISABLED:
log.debug("The bootloader installation is disabled.")
return

if self._mode == BootloaderMode.SKIPPED:
log.debug("The bootloader installation is skipped.")
return

log.debug("Collecting the kernel arguments.")

stage1_device = self._bootloader.stage1_device
log.info("boot loader stage1 target device is %s", stage1_device.name)

stage2_device = self._bootloader.stage2_device
log.info("boot loader stage2 target device is %s", stage2_device.name)

self._bootloader.collect_arguments(self._storage)


class InstallBootloaderTask(Task):
"""Installation task for the bootloader."""

Expand All @@ -116,8 +160,14 @@ def __init__(self, storage, mode):

@property
def name(self):
"""Name of the task."""
return "Install the bootloader"

@property
def _bootloader(self):
"""Representation of the bootloader."""
return self._storage.bootloader

def run(self):
"""Run the task.
Expand All @@ -135,8 +185,11 @@ def run(self):
log.debug("The bootloader installation is skipped.")
return

log.debug("Installing the boot loader.")

try:
install_boot_loader(storage=self._storage)
self._bootloader.prepare()
self._bootloader.write()
except BootLoaderError as e:
log.exception("Bootloader installation has failed: %s", e)
raise BootloaderInstallationError(str(e)) from None
Expand Down
24 changes: 1 addition & 23 deletions pyanaconda/modules/storage/bootloader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
from pyanaconda.anaconda_loggers import get_module_logger
log = get_module_logger(__name__)

__all__ = ["configure_boot_loader", "install_boot_loader", "recreate_initrds",
"create_rescue_images"]
__all__ = ["configure_boot_loader", "recreate_initrds", "create_rescue_images"]


def create_rescue_images(sysroot, kernel_versions):
Expand Down Expand Up @@ -194,27 +193,6 @@ def _write_sysconfig_kernel(sysroot, storage):
f.close()


def install_boot_loader(storage):
"""Do the final write of the boot loader.
:param storage: an instance of the storage
:raise: BootLoaderError if the installation fails
"""
log.debug("Installing the boot loader.")

stage1_device = storage.bootloader.stage1_device
log.info("boot loader stage1 target device is %s", stage1_device.name)

stage2_device = storage.bootloader.stage2_device
log.info("boot loader stage2 target device is %s", stage2_device.name)

# Prepare the bootloader for the installation.
storage.bootloader.prepare(storage)

# Install the bootloader.
storage.bootloader.write()


def create_bls_entries(sysroot, storage, kernel_versions):
"""Create BLS entries.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from pyanaconda.modules.storage.bootloader.bootloader_interface import BootloaderInterface
from pyanaconda.modules.storage.bootloader.installation import ConfigureBootloaderTask, \
InstallBootloaderTask, FixZIPLBootloaderTask, FixBTRFSBootloaderTask, RecreateInitrdsTask, \
CreateRescueImagesTask, CreateBLSEntriesTask
CreateRescueImagesTask, CreateBLSEntriesTask, CollectKernelArgumentsTask


class BootloaderInterfaceTestCase(unittest.TestCase):
Expand Down Expand Up @@ -201,6 +201,7 @@ def test_install_bootloader_with_tasks(self, publisher):
task_classes = [
CreateRescueImagesTask,
ConfigureBootloaderTask,
CollectKernelArgumentsTask,
InstallBootloaderTask,
CreateBLSEntriesTask
]
Expand Down Expand Up @@ -375,6 +376,20 @@ def test_configure(self):
assert image.label == "anaconda"
assert image.device == storage.root_device

def test_collect_kernel_arguments(self):
"""Test the collection of the kernel arguments for the installation."""
bootloader = Mock()
storage = Mock(bootloader=bootloader)

CollectKernelArgumentsTask(storage, BootloaderMode.DISABLED).run()
bootloader.collect_arguments.assert_not_called()

CollectKernelArgumentsTask(storage, BootloaderMode.SKIPPED).run()
bootloader.collect_arguments.assert_not_called()

CollectKernelArgumentsTask(storage, BootloaderMode.ENABLED).run()
bootloader.collect_arguments.assert_called_once_with(storage)

def test_install(self):
"""Test the installation task for the boot loader."""
bootloader = Mock()
Expand Down

0 comments on commit b2006da

Please sign in to comment.