diff --git a/pyanaconda/modules/storage/bootloader/bootloader.py b/pyanaconda/modules/storage/bootloader/bootloader.py index 3f4839c04a09..e77fbca8302d 100644 --- a/pyanaconda/modules/storage/bootloader/bootloader.py +++ b/pyanaconda/modules/storage/bootloader/bootloader.py @@ -471,7 +471,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, diff --git a/pyanaconda/modules/storage/bootloader/installation.py b/pyanaconda/modules/storage/bootloader/installation.py index 1dfb917491fd..8e4616d3d5d6 100644 --- a/pyanaconda/modules/storage/bootloader/installation.py +++ b/pyanaconda/modules/storage/bootloader/installation.py @@ -17,12 +17,14 @@ # License and may only be used or replicated with the express permission of # Red Hat, Inc. # +import os.path from blivet import arch from blivet.devices import BTRFSDevice from pyanaconda.core.constants import PAYLOAD_TYPE_RPM_OSTREE, PAYLOAD_LIVE_TYPES from pyanaconda.modules.storage.bootloader import BootLoaderError from pyanaconda.modules.storage.bootloader.systemd import SystemdBoot from pyanaconda.core.util import execWithRedirect +from pyanaconda.core.path import join_paths from pyanaconda.modules.common.errors.installation import BootloaderInstallationError from pyanaconda.modules.storage.constants import BootloaderMode @@ -108,16 +110,22 @@ 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): return "Install the bootloader" + def _have_bootupd(self): + """Is bootupd/bootupctl present in sysroot?""" + return os.path.exists(join_paths(self._sysroot, "/usr/bin/bootupctl")) + def run(self): """Run the task. @@ -135,6 +143,10 @@ def run(self): log.debug("The bootloader installation is skipped.") return + if self._payload_type == PAYLOAD_TYPE_RPM_OSTREE and self._have_bootupd(): + log.debug("Will not install regular bootloader for ostree with bootupd") + return + try: install_boot_loader(storage=self._storage) except BootLoaderError as e: @@ -253,7 +265,9 @@ def run(self): InstallBootloaderTask( self._storage, - self._mode + self._mode, + self._payload_type, + self._sysroot ).run() diff --git a/tests/unit_tests/pyanaconda_tests/modules/storage/test_module_bootloader.py b/tests/unit_tests/pyanaconda_tests/modules/storage/test_module_bootloader.py index da9bbf5b88a2..b50589dd5131 100644 --- a/tests/unit_tests/pyanaconda_tests/modules/storage/test_module_bootloader.py +++ b/tests/unit_tests/pyanaconda_tests/modules/storage/test_module_bootloader.py @@ -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 @@ -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 @@ -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.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): @@ -654,7 +695,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')