def run_efi_nolink_test(self, unlink_mock, islink_mock, exec_mock,
                            listdir_mock, isdir_mock, storage_mock):
        """Test OSTree bootloader copy task run() with EFI, efi dir, and no links"""
        bootloader_mock = storage_mock.get_proxy()
        bootloader_mock.IsEFI.return_value = True

        isdir_mock.side_effect = [True, False, True, True,
                                  True]  # boot source, 3x listdir, efi
        listdir_mock.return_value = ["some_file", "directory", "efi"]
        islink_mock.return_value = False

        task = CopyBootloaderDataTask("/sysroot", "/physroot")
        task.run()

        exec_mock.assert_has_calls([
            call("cp", [
                "-r", "-p", "/sysroot/usr/lib/ostree-boot/directory",
                "/physroot/boot"
            ]),
            call("cp", [
                "-r", "-p", "/sysroot/usr/lib/ostree-boot/efi",
                "/physroot/boot"
            ])
        ])
        unlink_mock.assert_not_called()
Beispiel #2
0
    def test_run_failed(self, listdir_mock, isdir_mock, storage_mock):
        """Test OSTree bootloader copy task run() with an exception."""
        bootloader_mock = storage_mock.get_proxy()
        bootloader_mock.IsEFI.return_value = False

        isdir_mock.return_value = False
        listdir_mock.side_effect = OSError("Fake!")

        task = CopyBootloaderDataTask("/sysroot", "/physroot")

        with pytest.raises(PayloadInstallationError) as cm:
            task.run()

        assert str(cm.value) == "Failed to copy bootloader data: Fake!"
Beispiel #3
0
    def install_with_tasks(self):
        """Install the payload.

        :return: list of tasks
        """
        ostree_source = self._get_source(SourceType.RPM_OSTREE)

        if not ostree_source:
            log.debug("No OSTree RPM source is available.")
            return []

        tasks = [
            InitOSTreeFsAndRepoTask(physroot=conf.target.physical_root),
            ChangeOSTreeRemoteTask(physroot=conf.target.physical_root,
                                   data=ostree_source.configuration),
            PullRemoteAndDeleteTask(data=ostree_source.configuration),
            DeployOSTreeTask(physroot=conf.target.physical_root,
                             data=ostree_source.configuration),
            SetSystemRootTask(physroot=conf.target.physical_root),
            CopyBootloaderDataTask(physroot=conf.target.physical_root,
                                   sysroot=conf.target.system_root),
            PrepareOSTreeMountTargetsTask(physroot=conf.target.physical_root,
                                          sysroot=conf.target.system_root,
                                          data=ostree_source.configuration)
        ]

        flatpak_source = self._get_source(SourceType.FLATPAK)

        if flatpak_source:
            task = InstallFlatpaksTask(sysroot=conf.target.system_root)
            tasks.append(task)

        self._collect_mount_points_on_success(tasks)
        return tasks
    def run_noefi_notadir_test(self, unlink_mock, islink_mock, exec_mock,
                               listdir_mock, isdir_mock, storage_mock):
        """Test OSTree bootloader copy task run() with non-directory source of data"""
        bootloader_mock = storage_mock.get_proxy()
        bootloader_mock.IsEFI.return_value = False

        isdir_mock.side_effect = [False, False,
                                  True]  # boot source, 2x listdir
        listdir_mock.return_value = ["some_file", "directory"]
        islink_mock.return_value = False

        task = CopyBootloaderDataTask("/sysroot", "/physroot")
        task.run()

        exec_mock.assert_called_once_with(
            "cp", ["-r", "-p", "/sysroot/boot/directory", "/physroot/boot"])
        unlink_mock.assert_not_called()
    def run_noefi_efidir_link_test(self, unlink_mock, islink_mock, exec_mock,
                                   listdir_mock, isdir_mock, storage_mock):
        """Test OSTree bootloader copy task run() with no EFI but efi dir and link"""
        bootloader_mock = storage_mock.get_proxy()
        bootloader_mock.IsEFI.return_value = False

        isdir_mock.side_effect = [True, False, True, True,
                                  True]  # boot source, 3x listdir, efi
        listdir_mock.return_value = ["some_file", "directory", "efi"]
        islink_mock.return_value = True

        task = CopyBootloaderDataTask("/sysroot", "/physroot")
        task.run()

        exec_mock.assert_called_once_with("cp", [
            "-r", "-p", "/sysroot/usr/lib/ostree-boot/directory",
            "/physroot/boot"
        ])
        unlink_mock.assert_called_with("/physroot/boot/grub2/grubenv")
Beispiel #6
0
    def test_run_noefi_noefidir_nolink(
            self, unlink_mock, islink_mock, exec_mock, listdir_mock, isdir_mock, storage_mock):
        """Test OSTree bootloader copy task run() with no EFI, no efi dir, and no links"""
        exec_mock.return_value = 0

        bootloader_mock = storage_mock.get_proxy()
        bootloader_mock.IsEFI.return_value = False

        isdir_mock.side_effect = [True, False, True]  # boot source, 2x listdir
        listdir_mock.return_value = ["some_file", "directory"]
        islink_mock.return_value = False

        task = CopyBootloaderDataTask("/sysroot", "/physroot")
        task.run()

        exec_mock.assert_called_once_with(
            "cp", ["-r", "-p", "/sysroot/usr/lib/ostree-boot/directory", "/physroot/boot"]
        )
        unlink_mock.assert_not_called()
    def _install(self, data):
        log.info("executing ostreesetup=%r", data)

        from pyanaconda.modules.payloads.payload.rpm_ostree.installation import \
            InitOSTreeFsAndRepoTask
        task = InitOSTreeFsAndRepoTask(conf.target.physical_root)
        task.run()

        # Here, we use the physical root as sysroot, because we haven't
        # yet made a deployment.
        from pyanaconda.modules.payloads.payload.rpm_ostree.installation import \
            ChangeOSTreeRemoteTask
        task = ChangeOSTreeRemoteTask(data,
                                      use_root=False,
                                      root=conf.target.physical_root)
        task.run()

        from pyanaconda.modules.payloads.payload.rpm_ostree.installation import \
            PullRemoteAndDeleteTask
        task = PullRemoteAndDeleteTask(data)
        task.progress_changed_signal.connect(self._progress_cb)
        task.run()

        from pyanaconda.modules.payloads.payload.rpm_ostree.installation import DeployOSTreeTask
        task = DeployOSTreeTask(data, conf.target.physical_root)
        task.progress_changed_signal.connect(self._progress_cb)
        task.run()

        # Reload now that we've deployed, find the path to the new deployment
        from pyanaconda.modules.payloads.payload.rpm_ostree.installation import SetSystemRootTask
        task = SetSystemRootTask(conf.target.physical_root)
        task.run()

        try:
            from pyanaconda.modules.payloads.payload.rpm_ostree.installation import \
                CopyBootloaderDataTask
            task = CopyBootloaderDataTask(sysroot=conf.target.system_root,
                                          physroot=conf.target.physical_root)
            task.run()
        except (OSError, RuntimeError) as e:
            raise PayloadInstallError("Failed to copy bootloader data: %s" %
                                      e) from e