Esempio n. 1
0
def test_srpm_empty_patch(mock_remote_functionality_sourcegit,
                          api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0")

    api_instance_source_git.up.specfile.spec_content.section(
        "%package")[10:10] = (
            "Patch1: amarillo.patch",
            "Patch2: citra.patch",
            "Patch5: saaz.patch",
            "Patch8: malt.patch",
        )
    api_instance_source_git.up.specfile.save()

    create_history_with_empty_commit(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath("fedora").glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "saaz.patch",
                "malt.patch",
            }
    assert sg_path.joinpath("fedora", "saaz.patch").read_text() == ""
Esempio n. 2
0
def test_srpm_merge_storm(mock_remote_functionality_sourcegit,
                          api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0")
    create_merge_commit_in_source_git(sg_path, go_nuts=True)
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)
    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)
    branches = subprocess.check_output(
        ["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"],
        cwd=sg_path).split(b"\n")
    for b in branches:
        if b and b.startswith(b"packit-patches-"):
            break
    else:
        raise AssertionError(
            "packit-patches- branch was not found - this should trigger the linearization"
        )
    assert {x.name
            for x in sg_path.joinpath("fedora").glob("*.patch")} == {
                "0001-MERGE-COMMIT.patch",
                "0002-ugly-merge-commit.patch",
            }
Esempio n. 3
0
def test_srpm_merge_storm(mock_remote_functionality_sourcegit,
                          api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0")
    create_merge_commit_in_source_git(sg_path, go_nuts=True)

    # linearization creates a new branch, make some arbitrary moves to verify
    # we end up in the former branch after the build
    subprocess.check_call(["git", "checkout", "-B", "test-branch"],
                          cwd=sg_path)
    subprocess.check_call(["git", "checkout", "main"], cwd=sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)
    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)
    branches = subprocess.check_output(
        ["git", "for-each-ref", "--format=%(refname:short)", "refs/heads/"],
        cwd=sg_path).split(b"\n")
    for b in branches:
        if b and b.startswith(b"packit-patches-"):
            break
    else:
        raise AssertionError(
            "packit-patches- branch was not found - this should trigger the linearization"
        )
    # make sure we are on the main branch
    assert ("main" == subprocess.check_output(
        ["git", "branch", "--show-current"], cwd=sg_path).decode().strip())
    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "0001-MERGE-COMMIT.patch",
                "0002-ugly-merge-commit.patch",
            }
Esempio n. 4
0
def test_srpm_git_no_prefix_patches(mock_remote_functionality_sourcegit,
                                    api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0")

    api_instance_source_git.up.specfile.spec_content.section(
        "%package")[10:10] = (
            "Patch1: amarillo.patch",
            "Patch2: citra.patch",
            "Patch8: malt.patch",
        )
    api_instance_source_git.up.specfile.spec_content.section("%prep")[0:2] = [
        "%setup -n %{upstream_name}-%{version}",
        "%patch1 -p1",
        "%patch2 -p0",
        "%patch8 -p1",
    ]
    api_instance_source_git.up.specfile.save()

    create_patch_mixed_history(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath("fedora").glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "malt.patch",
            }
Esempio n. 5
0
def test_update_on_cockpit_ostree_pr_exists(cockpit_ostree):
    upstream_path, dist_git_path = cockpit_ostree

    def mocked_new_sources(sources=None):
        if not Path(sources).is_file():
            raise RuntimeError("archive does not exist")

    flexmock(PkgTool, new_sources=mocked_new_sources)
    flexmock(PackitAPI, init_kerberos_ticket=lambda: None)

    flexmock(
        DistGit,
        push_to_fork=lambda *args, **kwargs: None,
        is_archive_in_lookaside_cache=lambda archive_path: False,
        upload_to_lookaside_cache=lambda archive, pkg_tool: None,
        download_upstream_archive=lambda: "the-archive",
    )
    pr = flexmock(url="https://example.com/pull/1")
    flexmock(DistGit).should_receive("existing_pr").and_return(pr)

    pc = get_local_package_config(str(upstream_path))
    up_lp = LocalProject(working_dir=upstream_path)
    c = get_test_config()
    api = PackitAPI(c, pc, up_lp)
    api._dg = DistGit(c, pc)
    api._dg._local_project = LocalProject(working_dir=dist_git_path)

    with cwd(upstream_path):
        assert pr == api.sync_release(
            dist_git_branch="main",
            use_local_content=False,
            version="179",
            force_new_sources=False,
            create_pr=True,
        )
Esempio n. 6
0
def test_schema_validation(tmpdir, raw_package_config, expected_output):
    with cwd(tmpdir):
        Path("packit.json").write_text(raw_package_config)
        Path("packit.spec").write_text("hello")

        output = PackitAPI.validate_package_config(Path("."))
        assert expected_output in output
Esempio n. 7
0
def cwd_upstream_or_distgit(
    request,
    upstream_and_remote,
    distgit_and_remote,
    ogr_distgit_and_remote,
    upstream_and_remote_with_multiple_sources,
):
    """
    Run the code from upstream, downstream and ogr-distgit.

    When using be careful to
        - specify this fixture in the right place
        (the order of the parameters means order of the execution)
        - to not overwrite the cwd in the other fixture or in the test itself
    """
    cwd_path = {
        "upstream":
        upstream_and_remote[0],
        "distgit":
        distgit_and_remote[0],
        "ogr-distgit":
        ogr_distgit_and_remote[0],
        "upstream-with-multiple-sources":
        upstream_and_remote_with_multiple_sources[0],
    }[request.param]

    with cwd(cwd_path):
        yield cwd_path
Esempio n. 8
0
def test_srpm_add_patch_with_ids(mock_remote_functionality_sourcegit,
                                 api_instance_source_git):
    ref = "0.1.0"
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, ref)

    create_history_with_patch_ids(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "malt.patch",
            }
    with api_instance_source_git.up.specfile.patches() as patches:
        assert patches[0].filename == "amarillo.patch"
        assert patches[0].number == 3
        assert patches[1].filename == "citra.patch"
        assert patches[1].number == 4
        assert patches[2].filename == "malt.patch"
        assert patches[2].number == 100
Esempio n. 9
0
def test_set_spec_macro_source(tmp_path):
    u_remote_path = tmp_path / "upstream_remote"
    u_remote_path.mkdir(parents=True, exist_ok=True)

    create_new_repo(u_remote_path, ["--bare"])

    u = tmp_path / "upstream_git"
    shutil.copytree(UPSTREAM_MACRO_IN_SOURCE, u)
    initiate_git_repo(u, tag="0.1.0")

    with cwd(tmp_path):
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        lp = LocalProject(working_dir=u)

        ups = Upstream(c, pc, lp)

    expected_sources = ups.specfile.sources
    new_ver = "1.2.3"
    ups.specfile.set_spec_version(version=new_ver, changelog_entry="- asdqwe")

    assert ups.get_specfile_version() == new_ver
    assert ups.specfile.sources == expected_sources

    expected_sources = ups.specfile.sources
    new_rel = "121"
    ups.specfile.set_spec_version(release=new_rel)

    assert ups.specfile.get_release() == new_rel
    assert ups.specfile.sources == expected_sources
Esempio n. 10
0
def test_srpm_git_am(mock_remote_functionality_sourcegit,
                     api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0")

    with api_instance_source_git.up.specfile.prep() as prep:
        prep.autosetup.options.S = "git_am"

    create_git_am_style_history(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "citra.patch",
                "0001-m04r-malt.patch",
                "malt.patch",
            }
    run_prep_for_srpm(srpm_path)
    prep_root = sg_path.joinpath("beerware-0.1.0")
    assert prep_root.joinpath("malt").read_text() == "Munich\n"
    assert prep_root.joinpath("hops").read_text() == "Saaz\n"
Esempio n. 11
0
def test_srpm_git_am(mock_remote_functionality_sourcegit,
                     api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0")

    api_instance_source_git.up.specfile.spec_content.section(
        "%package")[10:10] = (
            "Patch1: citra.patch",
            "Patch2: malt.patch",
            "Patch8: 0001-m04r-malt.patch",
        )
    autosetup_line = api_instance_source_git.up.specfile.spec_content.section(
        "%prep")[0]
    autosetup_line = autosetup_line.replace("-S patch", "-S git_am")
    api_instance_source_git.up.specfile.spec_content.section(
        "%prep")[0] = autosetup_line
    api_instance_source_git.up.specfile.save()

    create_git_am_style_history(sg_path)

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath("fedora").glob("*.patch")} == {
                "citra.patch",
                "0001-m04r-malt.patch",
                "malt.patch",
            }
Esempio n. 12
0
def test_set_spec_ver_empty_changelog(tmp_path):
    u_remote_path = tmp_path / "upstream_remote"
    u_remote_path.mkdir(parents=True, exist_ok=True)

    create_new_repo(u_remote_path, ["--bare"])

    u = tmp_path / "upstream_git"
    shutil.copytree(EMPTY_CHANGELOG, u)
    initiate_git_repo(u, tag="0.1.0")

    with cwd(tmp_path):
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        lp = LocalProject(working_dir=u)

        ups = Upstream(c, pc, lp)

    new_ver = "1.2.3"
    ups.specfile.version = new_ver
    ups.specfile.add_changelog_entry("- asdqwe")

    assert ups.get_specfile_version() == new_ver
    assert "%changelog" not in u.joinpath("beer.spec").read_text()
Esempio n. 13
0
def test_srpm_on_example(example_repo):
    c = get_test_config()
    api = get_packit_api(config=c,
                         local_project=LocalProject(working_dir=example_repo))
    with cwd(example_repo):
        path = api.create_srpm()
    assert path.exists()
    build_srpm(path)
Esempio n. 14
0
def test_srpm_command_for_path(upstream_or_distgit_path, tmp_path):
    with cwd(tmp_path):
        call_real_packit(
            parameters=["--debug", "srpm",
                        str(upstream_or_distgit_path)])
        srpm_path = list(Path.cwd().glob("*.src.rpm"))[0]
        assert srpm_path.exists()
        build_srpm(srpm_path)
Esempio n. 15
0
def mock_api_for_source_git(
    sourcegit: Path, distgit: Path, up_local_project: LocalProject
):
    with cwd(sourcegit):
        c = get_test_config()
        pc = get_local_package_config(str(sourcegit))
        pc.upstream_project_url = str(sourcegit)
        pc.dist_git_clone_path = str(distgit)
        return PackitAPI(c, pc, up_local_project)
Esempio n. 16
0
def test_srpm_command_for_path_with_multiple_sources(
    upstream_and_remote_with_multiple_sources, ):
    workdir, _ = upstream_and_remote_with_multiple_sources
    with cwd(workdir):
        call_real_packit(parameters=["--debug", "srpm", str(workdir)])
        srpm_path = list(Path.cwd().glob("*.src.rpm"))[0]
        assert srpm_path.exists()
        assert (Path.cwd() / "python-ogr.spec").exists()
        build_srpm(srpm_path)
Esempio n. 17
0
def test_srpm_on_cockpit_ostree(cockpit_ostree):
    upstream_path, dist_git_path = cockpit_ostree

    pc = get_local_package_config(str(upstream_path))
    up_lp = LocalProject(working_dir=upstream_path)
    c = get_test_config()
    api = PackitAPI(c, pc, up_lp)

    with cwd(upstream_path):
        api.create_srpm()
Esempio n. 18
0
def test_generate_pass(upstream_without_config):
    with cwd(upstream_without_config):
        assert not (upstream_without_config / ".packit.yaml").is_file()

        # This test requires packit on pythonpath
        result = call_packit(parameters=["generate"])

        assert result.exit_code == 0

        assert (upstream_without_config / ".packit.yaml").is_file()
Esempio n. 19
0
def api_instance_source_git(sourcegit_and_remote, distgit_and_remote):
    sourcegit, _ = sourcegit_and_remote
    distgit, _ = distgit_and_remote
    with cwd(sourcegit):
        c = get_test_config()
        pc = get_local_package_config(str(sourcegit))
        pc.upstream_project_url = str(sourcegit)
        pc.dist_git_clone_path = str(distgit)
        up_lp = LocalProject(working_dir=str(sourcegit))
        api = PackitAPI(c, pc, up_lp)
        return api
Esempio n. 20
0
def test_raw_files_to_sync(packit_files, expected):
    with cwd(DATA_DIR / "sync_files"):
        pc = PackageConfig(
            dist_git_base_url="https://packit.dev/",
            downstream_package_name="packit",
            dist_git_namespace="awesome",
            specfile_path="fedora/package.spec",
            synced_files=packit_files,
        )
        assert set(pc.synced_files.get_raw_files_to_sync(
            Path("."), Path("."))) == set(expected)
Esempio n. 21
0
def test_schema_validation(tmpdir, raw_package_config, expected_output):
    with cwd(tmpdir):
        Path("test_dir").mkdir()
        Path("test_dir/packit.yaml").write_text(raw_package_config)
        Path("test_dir/packit.spec").write_text("hello")
        Path("test_dir/a.md").write_text("a")
        Path("test_dir/b.md").write_text("b")
        Path("test_dir/c.txt").write_text("c")

        output = PackitAPI.validate_package_config(Path("test_dir"))
        assert expected_output in output
Esempio n. 22
0
def test_srpm_merge_storm_dirty(api_instance_source_git):
    """verify the linearization is halted when a source-git repo si dirty"""
    ref = "0.1.0"
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, ref)
    create_merge_commit_in_source_git(sg_path, go_nuts=True)
    (sg_path / "malt").write_text("Mordor\n")
    with pytest.raises(PackitException) as ex:
        with cwd("/"):  # let's mimic p-s by having different cwd than the project
            api_instance_source_git.create_srpm(upstream_ref=ref)
    assert "The source-git repo is dirty" in str(ex.value)
Esempio n. 23
0
def call_packit(fnc=None, parameters=None, envs=None, working_dir=None):
    working_dir = working_dir or "."
    fnc = fnc or packit_base
    runner = CliRunner()
    envs = envs or {}
    parameters = parameters or []
    # catch exceptions enables debugger
    with cwd(working_dir):
        return runner.invoke(fnc,
                             args=parameters,
                             env=envs,
                             catch_exceptions=False)
Esempio n. 24
0
def test_validate_paths(tmpdir, existing_files, existing_directories,
                        raw_package_config, expected_output):
    with cwd(tmpdir):
        Path("packit.json").write_text(raw_package_config)
        Path("packit.spec").write_text("hello")
        for existing_file in existing_files:
            Path(existing_file).write_text("")
        for existing_directory in existing_directories:
            Path(existing_directory).mkdir()

        output = PackitAPI.validate_package_config(Path("."))
        assert expected_output in output
Esempio n. 25
0
def test_linearization(api_instance_source_git):
    ref = "0.1.0"
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, ref)
    create_merge_commit_in_source_git(sg_path, go_nuts=True)
    with cwd("/"):  # let's mimic p-s by having different cwd than the project
        pg = PatchGenerator(api_instance_source_git.upstream_local_project)
        pg.create_patches(ref, sg_path / DISTRO_DIR)
    assert {x.name for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
        "0001-sourcegit-content.patch",
        "0002-MERGE-COMMIT.patch",
        "0003-ugly-merge-commit.patch",
    }
Esempio n. 26
0
def upstream_instance(upstream_and_remote, distgit_and_remote, tmp_path):
    with cwd(tmp_path):
        u, _ = upstream_and_remote
        d, _ = distgit_and_remote
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        pc.dist_git_clone_path = str(d)
        lp = LocalProject(working_dir=str(u))

        ups = Upstream(c, pc, lp)
        yield u, ups
Esempio n. 27
0
    def download_upstream_archive(self) -> Path:
        """
        Fetch archive for the current upstream release defined in dist-git's spec

        :return: path to the archive
        """
        with cwd(self.local_project.working_dir):
            self.download_remote_sources()
        archive = self.absolute_source_dir / self.upstream_archive_name
        if not archive.exists():
            raise PackitException(
                "Upstream archive was not downloaded, something is wrong.")
        logger.info(f"Downloaded archive: {archive}")
        return archive
Esempio n. 28
0
def test_prepare_sources_command_for_path(upstream_or_distgit_path, tmp_path):
    with cwd(tmp_path):
        call_real_packit(parameters=[
            "--debug",
            "prepare-sources",
            "--result-dir",
            Path.cwd(),
            str(upstream_or_distgit_path),
        ])

        tarball_path = list(Path.cwd().glob("*.tar.gz"))[0]
        assert tarball_path.exists()
        specfile_path = list(Path.cwd().glob("*.spec"))[0]
        assert specfile_path.exists()
Esempio n. 29
0
def test_srpm_patch_non_conseq_indices(mock_remote_functionality_sourcegit,
                                       api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / "fedora", "0.1.0")

    api_instance_source_git.up.specfile.spec_content.section(
        "%package")[10:10] = (
            "Patch0: amarillo.patch",
            "Patch3: citra.patch",
            "Patch4: saaz.patch",
            "Patch5: malt.patch",
        )
    api_instance_source_git.up.specfile.save()

    create_history_with_empty_commit(sg_path)

    malt = sg_path.joinpath("malt")
    malt.write_text("Wheat\n")
    git_add_and_commit(directory=sg_path,
                       message="Weißbier! Summer is coming!")

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    # make sure the patch is inserted AFTER existing patches
    patches = api_instance_source_git.up.specfile.tags.filter(name="Patch*",
                                                              valid=None)
    last_patch = list(patches)[-1]
    assert last_patch.name == "Patch6"
    assert (os.path.basename(
        api_instance_source_git.up.specfile.get_applied_patches()[-1].path) ==
            "0004-Wei-bier-Summer-is-coming.patch")

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath("fedora").glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "saaz.patch",
                "malt.patch",
                "0004-Wei-bier-Summer-is-coming.patch",
            }
    assert sg_path.joinpath("fedora", "saaz.patch").read_text() == ""
Esempio n. 30
0
def test_srpm_patch_non_conseq_indices(mock_remote_functionality_sourcegit,
                                       api_instance_source_git, ref):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path, sg_path / DISTRO_DIR, "0.1.0")

    with api_instance_source_git.up.specfile.sections() as sections:
        sections.package[10:10] = (
            "Patch0: amarillo.patch",
            "Patch3: citra.patch",
            "Patch4: saaz.patch",
            "Patch5: malt.patch",
        )

    create_history_with_empty_commit(sg_path)

    malt = sg_path.joinpath("malt")
    malt.write_text("Wheat\n")
    git_add_and_commit(directory=sg_path,
                       message="Weißbier! Summer is coming!")

    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref=ref)

    # make sure the patch is inserted AFTER existing patches
    with api_instance_source_git.up.specfile.patches() as patches:
        last_patch = patches[-1]
    assert last_patch.number == 6
    assert last_patch.filename == "0004-Wei-bier-Summer-is-coming.patch"

    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)

    assert {x.name
            for x in sg_path.joinpath(DISTRO_DIR).glob("*.patch")} == {
                "amarillo.patch",
                "citra.patch",
                "saaz.patch",
                "malt.patch",
                "0004-Wei-bier-Summer-is-coming.patch",
            }
    assert sg_path.joinpath(DISTRO_DIR, "saaz.patch").read_text() == ""