def _prepare_mount_targets(self, data):
     """ Prepare the ostree root """
     from pyanaconda.modules.payloads.payload.rpm_ostree.installation import \
         PrepareOSTreeMountTargetsTask
     task = PrepareOSTreeMountTargetsTask(
         sysroot=conf.target.system_root,
         physroot=conf.target.physical_root,
         source_config=data)
     bindmounts = task.run()
     self._internal_mounts.extend(bindmounts)
示例#2
0
    def test_run_with_var(self, exist_mock, storage_mock, mkdir_mock, exec_mock):
        """Test OSTree mount target prepare task run() with /var"""
        exec_mock.return_value = 0

        data = _make_config_data()
        devicetree_mock = storage_mock.get_proxy()

        devicetree_mock.GetMountPoints.return_value = {
            "/": "somewhere", "/etc": "elsewhere", "/home": "here", "/var": "whatever"
        }

        task = PrepareOSTreeMountTargetsTask("/sysroot", "/physroot", data)
        created_mount_points = task.run()

        assert created_mount_points == \
            ["/sysroot/usr", "/sysroot/dev", "/sysroot/proc", "/sysroot/run", "/sysroot/sys",
             "/sysroot/var", "/sysroot/etc", "/sysroot/home", "/sysroot/sysroot"]
        exec_mock.assert_has_calls([
            call("mount", ["--bind", "/sysroot/usr", "/sysroot/usr"]),
            call("mount", ["--bind", "-o", "remount,ro", "/sysroot/usr", "/sysroot/usr"]),
            call("mount", ["--rbind", "/physroot/dev", "/sysroot/dev"]),
            call("mount", ["--rbind", "/physroot/proc", "/sysroot/proc"]),
            call("mount", ["--rbind", "/physroot/run", "/sysroot/run"]),
            call("mount", ["--rbind", "/physroot/sys", "/sysroot/sys"]),
            call("mount", ["--bind", "/physroot/var", "/sysroot/var"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/home"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/roothome"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/lib/rpm"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/opt"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/srv"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/usrlocal"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/mnt"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/media"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/spool"]),
            call("systemd-tmpfiles",
                 ["--create", "--boot", "--root=/sysroot", "--prefix=/var/spool/mail"]),
            call("mount", ["--bind", "/physroot/etc", "/sysroot/etc"]),
            call("mount", ["--bind", "/physroot/home", "/sysroot/home"]),
            call("mount", ["--bind", "/physroot/", "/sysroot/sysroot"])
        ])
        assert len(exec_mock.mock_calls) == 20
        mkdir_mock.assert_called_once_with("/sysroot/var/lib")
示例#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
示例#4
0
    def test_run_failed(self, storage_mock, mkdir_mock, exec_mock):
        """Test the failed OSTree mount target prepare task."""
        exec_mock.return_value = 1

        data = _make_config_data()
        devicetree_mock = storage_mock.get_proxy()

        devicetree_mock.GetMountPoints.return_value = {
            "/": "somewhere", "/etc": "elsewhere", "/home": "here"
        }
        task = PrepareOSTreeMountTargetsTask("/sysroot", "/physroot", data)

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

        msg = "The command 'mount --bind /sysroot/usr /sysroot/usr' exited with the code 1."
        assert str(cm.value) == msg
示例#5
0
    def setup_internal_bindmount_test(self, exec_mock):
        """Test OSTree mount target prepare task _setup_internal_bindmount()"""
        data = _make_config_data()
        task = PrepareOSTreeMountTargetsTask("/sysroot", "/physroot", data)
        self.assertEqual(len(task._internal_mounts), 0)

        # everything left out
        task._setup_internal_bindmount("/src")
        exec_mock.assert_called_once_with(
            "mount", ["--rbind", "/physroot/src", "/sysroot/src"])
        self.assertListEqual(task._internal_mounts, ["/sysroot/src"])
        task._internal_mounts.clear()
        exec_mock.reset_mock()

        # all equal to defaults but present - same as above but dest is used
        task._setup_internal_bindmount("/src", "/dest", True, False, True)
        exec_mock.assert_called_once_with(
            "mount", ["--rbind", "/physroot/src", "/sysroot/dest"])
        self.assertListEqual(task._internal_mounts, ["/sysroot/dest"])
        task._internal_mounts.clear()
        exec_mock.reset_mock()

        # src_physical off - makes it sysroot->sysroot
        task._setup_internal_bindmount("/src", "/dest", False, False, True)
        exec_mock.assert_called_once_with(
            "mount", ["--rbind", "/sysroot/src", "/sysroot/dest"])
        self.assertListEqual(task._internal_mounts, ["/sysroot/dest"])
        task._internal_mounts.clear()
        exec_mock.reset_mock()

        # bind_ro requires two calls
        task._setup_internal_bindmount("/src", "/dest", True, True, True)
        exec_mock.assert_has_calls([
            call("mount", ["--bind", "/physroot/src", "/physroot/src"]),
            call("mount", [
                "--bind", "-o", "remount,ro", "/physroot/src", "/physroot/src"
            ])
        ])
        self.assertEqual(len(exec_mock.mock_calls), 2)
        self.assertListEqual(task._internal_mounts, ["/physroot/src"])
        task._internal_mounts.clear()
        exec_mock.reset_mock()

        # recurse off - bind instead of rbind
        task._setup_internal_bindmount("/src", "/dest", True, False, False)
        exec_mock.assert_called_once_with(
            "mount", ["--bind", "/physroot/src", "/sysroot/dest"])
        self.assertListEqual(task._internal_mounts, ["/sysroot/dest"])
        task._internal_mounts.clear()
        exec_mock.reset_mock()
示例#6
0
    def run_without_var_test(self, storage_mock, mkdir_mock, exec_mock):
        """Test OSTree mount target prepare task run() without /var"""
        data = _make_config_data()
        devicetree_mock = storage_mock.get_proxy()

        devicetree_mock.GetMountPoints.return_value = {
            "/": "somewhere",
            "/etc": "elsewhere",
            "/home": "here"
        }
        task = PrepareOSTreeMountTargetsTask("/sysroot", "/physroot", data)
        created_mount_points = task.run()

        self.assertListEqual(created_mount_points, [
            "/sysroot/usr", "/sysroot/dev", "/sysroot/proc", "/sysroot/run",
            "/sysroot/sys", "/sysroot/var", "/sysroot/etc", "/sysroot/home",
            "/sysroot/sysroot"
        ])
        exec_mock.assert_has_calls([
            call("mount", ["--bind", "/sysroot/usr", "/sysroot/usr"]),
            call(
                "mount",
                ["--bind", "-o", "remount,ro", "/sysroot/usr", "/sysroot/usr"
                 ]),
            call("mount", ["--rbind", "/physroot/dev", "/sysroot/dev"]),
            call("mount", ["--rbind", "/physroot/proc", "/sysroot/proc"]),
            call("mount", ["--rbind", "/physroot/run", "/sysroot/run"]),
            call("mount", ["--rbind", "/physroot/sys", "/sysroot/sys"]),
            call("mount", [
                "--bind", "/physroot/ostree/deploy/osname/var", "/sysroot/var"
            ]),
            call("systemd-tmpfiles", [
                "--create", "--boot", "--root=/sysroot", "--prefix=/var/home"
            ]),
            call("systemd-tmpfiles", [
                "--create", "--boot", "--root=/sysroot",
                "--prefix=/var/roothome"
            ]),
            call("systemd-tmpfiles", [
                "--create", "--boot", "--root=/sysroot",
                "--prefix=/var/lib/rpm"
            ]),
            call(
                "systemd-tmpfiles",
                ["--create", "--boot", "--root=/sysroot", "--prefix=/var/opt"
                 ]),
            call(
                "systemd-tmpfiles",
                ["--create", "--boot", "--root=/sysroot", "--prefix=/var/srv"
                 ]),
            call("systemd-tmpfiles", [
                "--create", "--boot", "--root=/sysroot",
                "--prefix=/var/usrlocal"
            ]),
            call(
                "systemd-tmpfiles",
                ["--create", "--boot", "--root=/sysroot", "--prefix=/var/mnt"
                 ]),
            call("systemd-tmpfiles", [
                "--create", "--boot", "--root=/sysroot", "--prefix=/var/media"
            ]),
            call("systemd-tmpfiles", [
                "--create", "--boot", "--root=/sysroot", "--prefix=/var/spool"
            ]),
            call("systemd-tmpfiles", [
                "--create", "--boot", "--root=/sysroot",
                "--prefix=/var/spool/mail"
            ]),
            call("mount", ["--bind", "/physroot/etc", "/sysroot/etc"]),
            call("mount", ["--bind", "/physroot/home", "/sysroot/home"]),
            call("mount", ["--bind", "/physroot/", "/sysroot/sysroot"])
        ])
        self.assertEqual(len(exec_mock.mock_calls), 20)
        mkdir_mock.assert_called_once_with("/sysroot/var/lib")
示例#7
0
    def test_setup_internal_bindmount(self, exec_mock, mkdir_mock, exists_mock):
        """Test OSTree mount target prepare task _setup_internal_bindmount()"""
        exec_mock.return_value = 0
        exists_mock.return_value = True

        data = _make_config_data()
        task = PrepareOSTreeMountTargetsTask("/sysroot", "/physroot", data)
        assert len(task._internal_mounts) == 0

        # everything left out
        task._setup_internal_bindmount("/src")
        exec_mock.assert_called_once_with("mount", ["--rbind", "/physroot/src", "/sysroot/src"])
        assert task._internal_mounts == ["/sysroot/src"]
        mkdir_mock.assert_not_called()
        task._internal_mounts.clear()
        exec_mock.reset_mock()

        # all equal to defaults but present - same as above but dest is used
        task._setup_internal_bindmount("/src", "/dest", True, False, True)
        exec_mock.assert_called_once_with("mount", ["--rbind", "/physroot/src", "/sysroot/dest"])
        assert task._internal_mounts == ["/sysroot/dest"]
        mkdir_mock.assert_not_called()
        task._internal_mounts.clear()
        exec_mock.reset_mock()

        # src_physical off - makes it sysroot->sysroot
        task._setup_internal_bindmount("/src", "/dest", False, False, True)
        exec_mock.assert_called_once_with("mount", ["--rbind", "/sysroot/src", "/sysroot/dest"])
        assert task._internal_mounts == ["/sysroot/dest"]
        mkdir_mock.assert_not_called()
        task._internal_mounts.clear()
        exec_mock.reset_mock()

        # bind_ro requires two calls
        task._setup_internal_bindmount("/src", "/dest", True, True, True)
        exec_mock.assert_has_calls([
            call("mount", ["--bind", "/physroot/src", "/physroot/src"]),
            call("mount", ["--bind", "-o", "remount,ro", "/physroot/src", "/physroot/src"])
        ])
        assert len(exec_mock.mock_calls) == 2
        assert task._internal_mounts == ["/physroot/src"]
        mkdir_mock.assert_not_called()
        task._internal_mounts.clear()
        exec_mock.reset_mock()

        # recurse off - bind instead of rbind
        task._setup_internal_bindmount("/src", "/dest", True, False, False)
        exec_mock.assert_called_once_with("mount", ["--bind", "/physroot/src", "/sysroot/dest"])
        assert task._internal_mounts == ["/sysroot/dest"]
        mkdir_mock.assert_not_called()
        task._internal_mounts.clear()
        exec_mock.reset_mock()

        # with user defined mount point
        # directory for the mount point doesn't exists yet, we should create it
        exists_mock.return_value = False
        task._setup_internal_bindmount("/src", "/dest", True, False, False)
        exec_mock.assert_called_once_with("mount", ["--bind", "/physroot/src", "/sysroot/dest"])
        assert task._internal_mounts == ["/sysroot/dest"]
        mkdir_mock.assert_called_with("/sysroot/dest")
        task._internal_mounts.clear()
        exec_mock.reset_mock()
        exists_mock.return_value = True