Exemplo n.º 1
0
def test_set_spec_ver_empty_changelog(tmpdir):
    t = Path(str(tmpdir))

    u_remote_path = t / "upstream_remote"
    u_remote_path.mkdir(parents=True, exist_ok=True)

    subprocess.check_call(["git", "init", "--bare", "."], cwd=u_remote_path)

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

    with cwd(tmpdir):
        c = get_test_config()

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

        ups = Upstream(c, pc, lp)

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

    assert ups.get_specfile_version() == new_ver
    assert "%changelog" not in u.joinpath("beer.spec").read_text()
Exemplo n.º 2
0
def test_basic_local_update_direct_push(upstream_distgit_remote,
                                        mock_remote_functionality_upstream):
    """ basic propose-update test: mock remote API, use local upstream and dist-git """
    upstream, distgit, remote_dir = upstream_distgit_remote

    with cwd(upstream):
        c = get_test_config()

        pc = get_local_package_config(str(upstream))
        pc.upstream_project_url = str(upstream)
        pc.dist_git_clone_path = str(distgit)
        up_lp = LocalProject(working_dir=str(upstream))
        api = PackitAPI(c, pc, up_lp)
        api.sync_release("master", "0.1.0", create_pr=False)

        remote_dir_clone = Path(f"{remote_dir}-clone")
        subprocess.check_call(
            ["git", "clone", remote_dir,
             str(remote_dir_clone)],
            cwd=str(remote_dir_clone.parent),
        )

        spec = get_specfile(str(remote_dir_clone / "beer.spec"))
        assert spec.get_version() == "0.1.0"
        assert (remote_dir_clone / "README.packit").is_file()
Exemplo n.º 3
0
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git):
    # TODO: we need a better test case here which will mimic the systemd use case
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path / "fedora")
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref="0.1.0")
    assert list(sg_path.glob("beer-0.1.0-1.*.src.rpm"))[0].is_file()
Exemplo n.º 4
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
Exemplo n.º 5
0
def test_srpm_merge_storm(mock_remote_functionality_sourcegit,
                          api_instance_source_git):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path / "fedora")
    create_merge_commit_in_source_git(sg_path, go_nuts=True)
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref="0.1.0")
    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 set([x.name
                for x in sg_path.joinpath("fedora").glob("*.patch")]) == {
                    "0001-MERGE-COMMIT.patch",
                    "0002-ugly-merge-commit.patch",
                }
Exemplo 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
Exemplo n.º 7
0
def run_dist2src(*args, working_dir=None, **kwargs):
    working_dir = working_dir or Path.cwd()
    with cwd(working_dir):
        cli_runner = CliRunner()
        # if you want to run debugger inside you need to do 2 things:
        # get real std{in,out} at the level of imports because click patches it
        # invoke pdb like this: "import pdb; pdb.Pdb(stdin=stdin, stdout=stdout).set_trace()"
        cli_runner.invoke(cli, *args, catch_exceptions=False, **kwargs)
Exemplo n.º 8
0
def test_srpm_command_for_path(upstream_or_distgit_path, tmpdir):
    with cwd(tmpdir):
        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)
Exemplo n.º 9
0
def test_srpm_on_example(example_repo):
    c = get_test_config()
    api = get_packit_api(
        config=c, local_project=LocalProject(working_dir=str(example_repo)))
    with cwd(example_repo):
        path = api.create_srpm()
    assert path.exists()
    build_srpm(path)
Exemplo n.º 10
0
def run_packit(*args, working_dir=None, **kwargs):
    working_dir = working_dir or Path.cwd()
    with cwd(working_dir):
        cli_runner = CliRunner()
        cli_result = cli_runner.invoke(packit_base,
                                       *args,
                                       catch_exceptions=False,
                                       **kwargs)
    print(cli_result.stdout)  # contains both std{err,out}
Exemplo n.º 11
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)
Exemplo n.º 12
0
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path / "fedora")
    create_merge_commit_in_source_git(sg_path)
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref="0.1.0")
    srpm_path = list(sg_path.glob("beer-0.1.0-2.*.src.rpm"))[0]
    assert srpm_path.is_file()
    build_srpm(srpm_path)
Exemplo n.º 13
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)
Exemplo n.º 14
0
def test_srpm_snapd(snapd):
    pc = get_local_package_config(str(snapd))
    up_lp = LocalProject(working_dir=str(snapd))
    c = get_test_config()
    api = PackitAPI(c, pc, up_lp)
    with cwd(snapd):
        path = api.create_srpm()
    assert path.exists()
    build_srpm(path)
Exemplo n.º 15
0
def api_instance_source_git(sourcegit_n_distgit):
    sourcegit, distgit = sourcegit_n_distgit
    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
Exemplo n.º 16
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=str(upstream_path))
    c = get_test_config()
    api = PackitAPI(c, pc, up_lp)

    with cwd(upstream_path):
        api.create_srpm()
Exemplo n.º 17
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()
Exemplo n.º 18
0
    def download_upstream_archive(self) -> Path:
        """
        Fetch archive for the current upstream release defined in dist-git's spec

        :return: str, path to the archive
        """
        with cwd(self.local_project.working_dir):
            self.specfile.download_remote_sources()
        archive = self.absolute_specfile_dir / self.upstream_archive_name
        logger.info(f"Downloaded archive: {archive}")
        return archive
Exemplo n.º 19
0
def test_raw_files_to_sync(packit_files, expected):
    with cwd(TESTS_DIR):
        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)
Exemplo n.º 20
0
def upstream_instance(upstream_n_distgit, tmpdir):
    with cwd(tmpdir):
        u, d = upstream_n_distgit
        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
Exemplo n.º 21
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
Exemplo n.º 22
0
    def download_upstream_archive(self) -> Path:
        """
        Fetch archive for the current upstream release defined in dist-git's spec

        :return: str, path to the archive
        """
        with cwd(self.local_project.working_dir):
            self.specfile.download_remote_sources()
        archive = self.absolute_specfile_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
Exemplo n.º 23
0
 def fetch_upstream_archive(self):
     # TODO: there is a bug in rebase-helper that it saves the source in cwd
     #   File "/src/packit/base_git.py", line 298, in fetch_upstream_archive
     #     self.specfile.download_remote_sources()
     #   File "rebasehelper/specfile.py", line 220, in download_remote_sources
     #     LookasideCacheHelper.download('fedpkg', os.path.dirname(self.path), self.get_
     #   File "rebasehelper/helpers/lookaside_cache_helper.py", line 122, in download
     #     cls._download_source(tool, url, package, source['filename'], source['hashtype'],
     #   File "rebasehelper/helpers/lookaside_cache_helper.py", line 109, in _download_source
     #     try:
     #   File "rebasehelper/helpers/download_helper.py", line 162, in download_file
     #     with open(destination_path, 'wb') as local_file:
     # PermissionError: [Errno 13] Permission denied: 'systemd-8bca462.tar.gz'
     with cwd(self.absolute_specfile_dir):
         self.specfile.download_remote_sources()
Exemplo n.º 24
0
def test_basic_bodhi_update(
    upstream_n_distgit,
    mock_remote_functionality_upstream,
    branch,
    update_type,
    update_notes,
    koji_builds,
    bodhi_response,
):
    # https://github.com/fedora-infra/bodhi/issues/3058
    from bodhi.client.bindings import BodhiClient

    u, d = upstream_n_distgit
    with cwd(u):
        c = get_test_config()

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

        api = PackitAPI(c, pc, up_lp)

        flexmock(
            BodhiClient,
            latest_builds=lambda package: {
                "f29-override": "sen-0.6.0-3.fc29",
                "f29-updates": "sen-0.6.0-3.fc29",
                "f29-updates-candidate": "sen-0.6.0-3.fc29",
                "f29-updates-pending": "sen-0.6.0-3.fc29",
                "f29-updates-testing": "sen-0.6.0-3.fc29",
                "f29-updates-testing-pending": "sen-0.6.0-3.fc29",
                "f30-override": "sen-0.6.0-4.fc30",
                "f30-updates": "sen-0.6.0-4.fc30",
                "f30-updates-candidate": "sen-0.6.1-1.fc30",
                "f30-updates-pending": "sen-0.6.0-4.fc30",
                "f30-updates-testing": "sen-0.6.0-4.fc30",
                "f30-updates-testing-pending": "sen-0.6.0-4.fc30",
            },
            save=lambda **kwargs: bodhi_response,
        )
        api.create_update(
            dist_git_branch=branch,
            update_type=update_type,
            update_notes=update_notes,
            koji_builds=koji_builds,
        )
Exemplo n.º 25
0
def test_basic_local_update_from_downstream(
        downstream_n_distgit, mock_downstream_remote_functionality):
    flexmock(LocalProject, _parse_namespace_from_git_url=lambda: None)
    u, d = downstream_n_distgit

    with cwd(u):
        c = get_test_config()
        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        pc.dist_git_clone_path = str(d)
        up_lp = LocalProject(working_dir=str(u))
        api = PackitAPI(c, pc, up_lp)
        api.sync_from_downstream("master", "master", True)

        assert (u / "beer.spec").is_file()
        spec = get_specfile(str(u / "beer.spec"))
        assert spec.get_version() == "0.0.0"
Exemplo n.º 26
0
def test_srpm(mock_remote_functionality_sourcegit, api_instance_source_git):
    sg_path = Path(api_instance_source_git.upstream_local_project.working_dir)
    mock_spec_download_remote_s(sg_path / "fedora")
    create_merge_commit_in_source_git(sg_path)
    with cwd(sg_path):
        api_instance_source_git.create_srpm(upstream_ref="0.1.0")
    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-"):
            raise AssertionError(
                "packit-patches- branch was found - the history shouldn't have been linearized"
            )
    assert set([x.name
                for x in sg_path.joinpath("fedora").glob("*.patch")]) == {
                    "0001-switching-to-amarillo-hops.patch",
                    "0002-actually-let-s-do-citra.patch",
                }
Exemplo n.º 27
0
def test_push_updates(upstream_n_distgit, query_response, request_response):

    from bodhi.client.bindings import BodhiClient

    u, d = upstream_n_distgit
    with cwd(u):
        c = get_test_config()

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

        api = PackitAPI(c, pc, up_lp)

        flexmock(BodhiClient)
        BodhiClient.should_receive("query").and_return(query_response).once()
        BodhiClient.should_receive("request").with_args(
            update="FEDORA-2019-89c99f680c", request="stable"
        ).and_return(request_response).once()

        api.push_updates()
Exemplo n.º 28
0
def test_update_on_cockpit_ostree(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(FedPKG,
             init_ticket=lambda x=None: None,
             new_sources=mocked_new_sources)

    flexmock(
        DistGit,
        push_to_fork=lambda *args, **kwargs: None,
        is_archive_in_lookaside_cache=lambda archive_path: False,
        upload_to_lookaside_cache=lambda path: None,
        download_upstream_archive=lambda: "the-archive",
    )
    flexmock(
        PackitAPI,
        push_and_create_pr=lambda pr_title, pr_description, dist_git_branch:
        None,
    )

    pc = get_local_package_config(str(upstream_path))
    up_lp = LocalProject(working_dir=str(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):
        api.sync_release(
            "master",
            use_local_content=False,
            version="179",
            force_new_sources=False,
            create_pr=True,
        )
Exemplo n.º 29
0
def test_basic_build(upstream_n_distgit, mock_remote_functionality_upstream):
    u, d = upstream_n_distgit

    with cwd(u):
        c = get_test_config()

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

        api = PackitAPI(c, pc, up_lp)
        flexmock(utils).should_receive("run_command").with_args(
            cmd=[
                "fedpkg", "build", "--scratch", "--nowait", "--target",
                "asdqwe"
            ],
            cwd=api.dg.local_project.working_dir,
            error_message="Submission of build to koji failed.",
            fail=True,
        ).once()
        api.build("master", scratch=True, nowait=True, koji_target="asdqwe")
Exemplo n.º 30
0
def test_basic_local_update(upstream_n_distgit,
                            mock_remote_functionality_upstream):
    """ basic propose-update test: mock remote API, use local upstream and dist-git """
    u, d = upstream_n_distgit

    with cwd(u):
        c = get_test_config()

        pc = get_local_package_config(str(u))
        pc.upstream_project_url = str(u)
        pc.dist_git_clone_path = str(d)
        up_lp = LocalProject(working_dir=str(u))
        api = PackitAPI(c, pc, up_lp)
        api.sync_release("master", "0.1.0")

        assert (d / TARBALL_NAME).is_file()
        spec = get_specfile(str(d / "beer.spec"))
        assert spec.get_version() == "0.1.0"
        assert (d / "README.packit").is_file()
        # assert that we have changelog entries for both versions
        changelog = "\n".join(spec.spec_content.section("%changelog"))
        assert "0.0.0" in changelog
        assert "0.1.0" in changelog