Skip to content

Commit

Permalink
bootloader: Detect bootupd and skip regular install
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirSlavik committed Nov 29, 2023
1 parent 1920bc1 commit 86da4e9
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 12 deletions.
4 changes: 3 additions & 1 deletion pyanaconda/modules/storage/bootloader/bootloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@ def install_bootloader_with_tasks(self, payload_type, kernel_versions):
),
InstallBootloaderTask(
storage=self.storage,
mode=self.bootloader_mode
mode=self.bootloader_mode,
payload_type=payload_type,
sysroot=conf.target.system_root
),
CreateBLSEntriesTask(
storage=self.storage,
Expand Down
13 changes: 11 additions & 2 deletions pyanaconda/modules/storage/bootloader/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from blivet import arch
from blivet.devices import BTRFSDevice
from pyanaconda.core.constants import PAYLOAD_TYPE_RPM_OSTREE, PAYLOAD_LIVE_TYPES
from pyanaconda.modules.payloads.payload.rpm_ostree.util import have_bootupd
from pyanaconda.modules.storage.bootloader import BootLoaderError
from pyanaconda.modules.storage.bootloader.systemd import SystemdBoot
from pyanaconda.core.util import execWithRedirect
Expand Down Expand Up @@ -152,11 +153,13 @@ def run(self):
class InstallBootloaderTask(Task):
"""Installation task for the bootloader."""

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

@property
def name(self):
Expand Down Expand Up @@ -185,6 +188,10 @@ def run(self):
log.debug("The bootloader installation is skipped.")
return

if self._payload_type == PAYLOAD_TYPE_RPM_OSTREE and have_bootupd(self._sysroot):
log.debug("Will not install regular bootloader for ostree with bootupd")
return

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

try:
Expand Down Expand Up @@ -306,7 +313,9 @@ def run(self):

InstallBootloaderTask(
self._storage,
self._mode
self._mode,
self._payload_type,
self._sysroot
).run()


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from tests.unit_tests.pyanaconda_tests import patch_dbus_publish_object, check_dbus_property, \
reset_boot_loader_factory, check_task_creation_list, check_task_creation

from pyanaconda.core.path import make_directories, touch
from pyanaconda.modules.storage import platform
from pyanaconda.modules.storage.bootloader import BootLoaderFactory
from pyanaconda.modules.storage.bootloader.base import BootLoader
Expand All @@ -45,7 +46,7 @@

from pyanaconda.modules.storage.bootloader.image import LinuxBootLoaderImage
from pyanaconda.core.constants import BOOTLOADER_SKIPPED, BOOTLOADER_LOCATION_PARTITION, \
PAYLOAD_TYPE_RPM_OSTREE, PAYLOAD_TYPE_LIVE_IMAGE
PAYLOAD_TYPE_RPM_OSTREE, PAYLOAD_TYPE_LIVE_IMAGE, PAYLOAD_TYPE_DNF
from pyanaconda.modules.common.constants.objects import BOOTLOADER
from pyanaconda.modules.storage.bootloader import BootloaderModule
from pyanaconda.modules.storage.bootloader.bootloader_interface import BootloaderInterface
Expand Down Expand Up @@ -395,15 +396,55 @@ def test_install(self):
bootloader = Mock()
storage = Mock(bootloader=bootloader)

InstallBootloaderTask(storage, BootloaderMode.DISABLED).run()
bootloader.write.assert_not_called()
with tempfile.TemporaryDirectory() as sysroot:
InstallBootloaderTask(
storage,
BootloaderMode.DISABLED,
PAYLOAD_TYPE_DNF,
sysroot
).run()
bootloader.write.assert_not_called()

InstallBootloaderTask(storage, BootloaderMode.SKIPPED).run()
bootloader.write.assert_not_called()
InstallBootloaderTask(
storage,
BootloaderMode.SKIPPED,
PAYLOAD_TYPE_DNF,
sysroot
).run()
bootloader.write.assert_not_called()

InstallBootloaderTask(storage, BootloaderMode.ENABLED).run()
bootloader.prepare.assert_called_once()
bootloader.write.assert_called_once()
InstallBootloaderTask(
storage,
BootloaderMode.ENABLED,
PAYLOAD_TYPE_DNF,
sysroot
).run()
bootloader.prepare.assert_called_once()
bootloader.write.assert_called_once()

bootloader.prepare.reset_mock()
bootloader.write.reset_mock()
InstallBootloaderTask(
storage,
BootloaderMode.ENABLED,
PAYLOAD_TYPE_RPM_OSTREE,
sysroot
).run()
bootloader.prepare.assert_called_once()
bootloader.write.assert_called_once()

bootloader.prepare.reset_mock()
bootloader.write.reset_mock()
make_directories(sysroot + "/usr/bin")
touch(sysroot + "/usr/bin/bootupctl")
InstallBootloaderTask(
storage,
BootloaderMode.ENABLED,
PAYLOAD_TYPE_RPM_OSTREE,
sysroot
).run()
bootloader.prepare.assert_not_called()
bootloader.write.assert_not_called()

@patch('pyanaconda.modules.storage.bootloader.utils.execWithRedirect')
def test_create_bls_entries(self, exec_mock):
Expand Down Expand Up @@ -669,7 +710,9 @@ def test_fix_btrfs(self, configure, install, conf):
)
install.assert_called_once_with(
storage,
BootloaderMode.ENABLED
BootloaderMode.ENABLED,
PAYLOAD_TYPE_LIVE_IMAGE,
sysroot
)

@patch('pyanaconda.modules.storage.bootloader.installation.conf')
Expand Down

0 comments on commit 86da4e9

Please sign in to comment.