Skip to content

Commit

Permalink
bootloader: Detect bootupd and skip regular install
Browse files Browse the repository at this point in the history
(cherry picked from commit 0d42d2f)

Related: RHEL-2250
  • Loading branch information
VladimirSlavik authored and cgwalters committed Jan 25, 2024
1 parent 18142c0 commit 15d423a
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 @@ -482,7 +482,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.core.util import execInSysroot
Expand Down Expand Up @@ -108,11 +109,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 All @@ -135,6 +138,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

try:
install_boot_loader(storage=self._storage)
except BootLoaderError as e:
Expand Down Expand Up @@ -249,7 +256,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 @@ -380,15 +381,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.set_boot_args.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 @@ -649,7 +690,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 15d423a

Please sign in to comment.