Esempio n. 1
0
    def run(self):
        """Run the task.

        :return: a path of the download location
        """
        path = pick_download_location(self._dnf_manager)

        if os.path.exists(path):
            log.info("Removing existing package download location: %s", path)
            shutil.rmtree(path)

        self._dnf_manager.set_download_location(path)
        return path
Esempio n. 2
0
    def test_pick_download_location(self, free_space_getter):
        """Test the pick_download_location function."""
        download_size = Size(100)
        installation_size = Size(200)
        total_size = Size(300)

        dnf_manager = Mock()
        dnf_manager.get_download_size.return_value = download_size
        dnf_manager.get_installation_size.return_value = installation_size

        # Found mount points for download and install.
        # Don't use /mnt/sysroot if possible.
        free_space_getter.return_value = {
            "/var/tmp": download_size,
            "/mnt/sysroot": total_size,
        }

        path = pick_download_location(dnf_manager)
        assert path == "/var/tmp/dnf.package.cache"

        # Found mount points only for download.
        # Use the biggest mount point.
        free_space_getter.return_value = {
            "/mnt/sysroot/tmp": download_size + 1,
            "/mnt/sysroot/home": download_size,
        }

        path = pick_download_location(dnf_manager)
        assert path == "/mnt/sysroot/tmp/dnf.package.cache"

        # No mount point to use.
        # Fail with an exception.
        free_space_getter.return_value = {}

        with pytest.raises(RuntimeError) as cm:
            pick_download_location(dnf_manager)

        msg = "Not enough disk space to download the packages; size 100 B."
        assert str(cm.value) == msg