Esempio n. 1
0
 def get_test_config():
     try:
         conf = Config.get_user_config()
     except PackitException:
         conf = Config()
     conf.dry_run = True
     return conf
Esempio n. 2
0
 def config(self):
     if not self._config:
         try:
             self._config = Config.get_user_config()
         except PackitException:
             self._config = Config()
     return self._config
Esempio n. 3
0
def test_user_config_fork_token(tmpdir, recwarn):
    user_config_file_path = Path(tmpdir) / ".packit.yaml"
    user_config_file_path.write_text(
        "---\n"
        "pagure_fork_token: yes-is-true-in-yaml-are-you-kidding-me?\n")
    flexmock(os).should_receive("getenv").with_args(
        "XDG_CONFIG_HOME").and_return(str(tmpdir))
    Config.get_user_config()
    w = recwarn.pop(UserWarning)
    assert "pagure_fork_token" in str(w.message)
Esempio n. 4
0
    def get_test_config():
        conf = Config()
        pagure_user_token = os.environ.get("PAGURE_TOKEN", "test")
        github_token = os.environ.get("GITHUB_TOKEN", "test")
        conf.services = {
            PagureService(token=pagure_user_token),
            GithubService(token=github_token),
        }

        conf.dry_run = True
        return conf
Esempio n. 5
0
 def f(path: str):
     """ path points to a file where the http communication will be saved """
     conf = Config()
     # TODO: add pagure support
     # conf._pagure_user_token = os.environ.get("PAGURE_TOKEN", "test")
     # conf._pagure_fork_token = os.environ.get("PAGURE_FORK_TOKEN", "test")
     conf._github_token = os.getenv("GITHUB_TOKEN", None)
     conf.dry_run = True
     target_path: Path = SAVED_HTTPD_REQS / path
     target_path.parent.mkdir(parents=True, exist_ok=True)
     conf.github_requests_log_path = str(target_path)
     return conf
Esempio n. 6
0
def packit_base(ctx, debug, fas_user, keytab):
    c = Config()
    c.debug = debug
    c.fas_user = fas_user
    c.keytab_path = keytab
    ctx.obj = c
    if ctx.obj.debug:
        set_logging(level=logging.DEBUG)
        logger.debug("logging set to DEBUG")
    else:
        set_logging(level=logging.INFO)
        logger.debug("logging set to INFO")
Esempio n. 7
0
def packit_repository_base_with_sandcastle_object(tmp_path):
    c = Config()
    c.command_handler = RunCommandType.sandcastle
    b = PackitRepositoryBase(
        config=c,
        package_config=PackageConfig(
            actions={
                ActionName.pre_sync: "command -a",
                ActionName.get_current_version: "command -b",
            }),
    )
    b.local_project = LocalProject(working_dir=tmp_path)
    return b
Esempio n. 8
0
def test_get_output_from_action_defined_in_sandcastle():
    echo_cmd = "hello world"
    flexmock(Sandcastle).should_receive("get_api_client")
    flexmock(Sandcastle).should_receive("is_pod_already_deployed").and_return(True)
    c = Config()
    c.command_handler = RunCommandType.sandcastle
    packit_repository_base = PackitRepositoryBase(
        config=c, package_config=PackageConfig(actions={ActionName.pre_sync: echo_cmd})
    )
    packit_repository_base.local_project = LocalProject()

    flexmock(Sandcastle).should_receive("run")
    flexmock(Sandcastle).should_receive("exec").and_return(echo_cmd)
    result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
    assert result == echo_cmd
Esempio n. 9
0
def test_github_app(upstream_instance, tmpdir):
    u, ups = upstream_instance
    t = Path(tmpdir)

    fake_cert_path = t / "fake-cert.pem"
    fake_cert_path.write_text("hello!")

    user_config_file_path = t / ".packit.yaml"
    user_config_file_path.write_text(
        "---\n"
        f"github_app_cert_path: {fake_cert_path}\n"
        "github_app_id: qwe\n"
        "github_app_installation_id: asd\n")
    flexmock(os).should_receive("getenv").with_args(
        "XDG_CONFIG_HOME").and_return(str(tmpdir))
    ups.config = Config.get_user_config()

    def fake_init(github_app_id, private_key):
        assert github_app_id == "qwe"
        assert private_key == "hello!"

    def fake_get_access_token(inst_id):
        assert inst_id == "asd"
        return "good"

    flexmock(
        github.GithubIntegration,
        __init__=fake_init,
        get_access_token=fake_get_access_token,
    )

    assert ups.local_project.git_service._token == "good"
Esempio n. 10
0
def test_get_user_config_new_authentication(tmp_path):
    user_config_file_path = tmp_path / ".packit.yaml"
    user_config_file_path.write_text(
        "---\n"
        "debug: true\n"
        "fas_user: rambo\n"
        "keytab_path: './rambo.keytab'\n"
        "authentication:\n"
        "    github.com:\n"
        "        token: GITHUB_TOKEN\n"
        "    pagure:\n"
        "        token: PAGURE_TOKEN\n"
        '        instance_url: "https://my.pagure.org"\n')
    flexmock(os).should_receive("getenv").with_args(
        "XDG_CONFIG_HOME").and_return(str(tmp_path))
    config = Config.get_user_config()
    assert config.debug and isinstance(config.debug, bool)
    assert config.fas_user == "rambo"
    assert config.keytab_path == "./rambo.keytab"
    assert config.kerberos_realm == "FEDORAPROJECT.ORG"

    assert GithubService(token="GITHUB_TOKEN") in config.services
    assert (PagureService(token="PAGURE_TOKEN",
                          instance_url="https://my.pagure.org")
            in config.services)
Esempio n. 11
0
def packit_base(ctx, debug, fas_user, keytab, dry_run, remote):
    """Integrate upstream open source projects into Fedora operating system."""
    if debug:
        # to be able to logger.debug() also in get_user_config()
        set_logging(level=logging.DEBUG)

    c = Config.get_user_config()
    c.debug = debug or c.debug
    c.dry_run = dry_run or c.dry_run
    c.fas_user = fas_user or c.fas_user
    c.keytab_path = keytab or c.keytab_path
    c.upstream_git_remote = remote or c.upstream_git_remote
    ctx.obj = c

    if ctx.obj.debug:
        set_logging(level=logging.DEBUG)
        set_logging(logger_name="sandcastle", level=logging.DEBUG)
        set_logging(logger_name="rebasehelper", level=logging.DEBUG)
    else:
        set_logging(level=logging.INFO)
        # rebase-helper prints errors about missing patches which are not an error in our case
        #   Patch glibc-fedora-nscd.patch does not exist
        set_logging(logger_name="rebasehelper", level=logging.CRITICAL)

    packit_version = get_distribution("packitos").version
    logger.debug(f"Packit {packit_version} is being used.")
Esempio n. 12
0
def github_release():
    msg = request.get_json()

    buffer = StringIO()
    logHandler = logging.StreamHandler(buffer)
    logHandler.setLevel(logging.INFO)
    formatter = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
    )
    logHandler.setFormatter(formatter)
    logger.addHandler(logHandler)

    logger.debug(
        f"Received release event: "
        f"{msg['repository']['owner']}/{msg['repository']['name']} - {msg['release']['tag_name']}"
    )

    config = Config()
    api = PackitBotAPI(config)
    # Using fedmsg since the fields are the same
    api.sync_upstream_release_with_fedmsg({"msg": msg})

    logger.removeHandler(logHandler)
    buffer.flush()

    return buffer.getvalue()
Esempio n. 13
0
def test_github_app(upstream_instance, tmpdir):
    u, ups = upstream_instance
    t = Path(tmpdir)

    fake_cert_path = t / "fake-cert.pem"
    fake_cert_path.write_text("hello!")

    user_config_file_path = t / ".packit.yaml"
    user_config_file_path.write_text(
        "---\n"
        f"authentication:\n"
        f"    github.com:\n"
        f"        github_app_private_key_path: {fake_cert_path}\n"
        f"        github_app_id: qwe\n"
    )
    flexmock(os).should_receive("getenv").with_args("XDG_CONFIG_HOME").and_return(
        str(tmpdir)
    )
    ups.config = Config.get_user_config()
    assert (
        GithubService(
            github_app_private_key_path=str(fake_cert_path), github_app_id="qwe"
        )
        in ups.config.services
    )
Esempio n. 14
0
def test_get_user_config(tmpdir):
    user_config_file_path = Path(tmpdir) / ".packit.yaml"
    user_config_file_path.write_text(
        "---\n"
        "debug: true\n"
        "fas_user: rambo\n"
        "keytab_path: './rambo.keytab'\n"
        "github_token: ra\n"
        "pagure_user_token: mb\n"
        "pagure_fork_token: o\n"
    )
    flexmock(os).should_receive("getenv").with_args("XDG_CONFIG_HOME").and_return(
        str(tmpdir)
    )
    config = Config.get_user_config()
    assert config.debug and isinstance(config.debug, bool)
    assert config.fas_user == "rambo"
    assert config.keytab_path == "./rambo.keytab"
    flexmock(os).should_receive("getenv").with_args("GITHUB_TOKEN", "").and_return(None)
    assert config.github_token == "ra"
    flexmock(os).should_receive("getenv").with_args("PAGURE_USER_TOKEN", "").and_return(
        None
    )
    assert config.pagure_user_token == "mb"
    flexmock(os).should_receive("getenv").with_args("PAGURE_FORK_TOKEN", "").and_return(
        None
    )
    assert config.pagure_fork_token == "o"
Esempio n. 15
0
def test_centos_conf(cronie, tmp_path: Path):
    """ make sure the centos-specific configuration is correct """
    source_git_path = tmp_path.joinpath("cronie-sg")
    # create src-git
    source_git_path.mkdir()
    create_new_repo(source_git_path, [])
    sgg = SourceGitGenerator(
        LocalProject(working_dir=source_git_path),
        Config(),
        dist_git_path=cronie,
        upstream_ref="cronie-1.5.2",
        centos_package="cronie",
    )

    dg = sgg.dist_git
    assert isinstance(dg, CentOS8DistGit)

    flexmock(
        DistGit,
        download_upstream_archive=lambda: cronie / "SOURCES" /
        "cronie-1.5.2.tar.gz",
    )
    assert sgg.primary_archive == cronie / "SOURCES" / "cronie-1.5.2.tar.gz"

    assert dg.absolute_source_dir == cronie / "SOURCES"
    assert dg.absolute_specfile_dir == cronie / "SPECS"
    assert dg.absolute_specfile_path == cronie / "SPECS" / "cronie.spec"
Esempio n. 16
0
def packit_repository_base_more_actions():
    return PackitRepositoryBase(
        config=Config(),
        package_config=PackageConfig(
            actions={
                ActionName.pre_sync: ["command --a", "command --a"],
                ActionName.get_current_version: "command --b",
            }),
    )
Esempio n. 17
0
def packit_base(ctx, **kwargs):
    ctx.obj = Config(**kwargs)
    if ctx.obj.debug:
        set_logging(level=logging.DEBUG)
        logger.debug("logging set to DEBUG")

    elif ctx.obj.verbose:
        set_logging(level=logging.INFO, format="%(message)s")
        logger.debug("logging set to INFO")
Esempio n. 18
0
def test_run_in_sandbox():
    packit_repository_base = PackitRepositoryBase(
        config=Config(),
        package_config=PackageConfig(actions={ActionName.pre_sync: "ls -lha"}),
    )
    packit_repository_base.config.actions_handler = "sandcastle"

    result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
    assert "total 4.0K" in result
    assert "drwxr-xr-x. 1 root root" in result
Esempio n. 19
0
def distgit_with_actions():
    return DistGit(
        config=flexmock(Config()),
        package_config=flexmock(
            PackageConfig(
                actions={
                    ActionName.pre_sync: "command --a",
                    ActionName.get_current_version: "command --b",
                })),
    )
Esempio n. 20
0
def test_get_output_from_action_defined(echo_cmd, expected_output):
    packit_repository_base = PackitRepositoryBase(
        config=flexmock(Config()),
        package_config=flexmock(PackageConfig(actions={ActionName.pre_sync: echo_cmd})),
    )

    packit_repository_base.local_project = flexmock(working_dir=".")

    result = packit_repository_base.get_output_from_action(ActionName.pre_sync)
    assert result == expected_output
Esempio n. 21
0
def test_pr_exists(title, description, branch, prs, exists):
    local_project = LocalProject(
        git_project=flexmock(service="something", get_pr_list=lambda: prs),
        refresh=False,
    )
    distgit = DistGit(
        config=flexmock(Config()),
        package_config=flexmock(PackageConfig()),
        local_project=local_project,
    )
    assert distgit.pr_exists(title, description, branch) == exists
Esempio n. 22
0
def upstream_with_actions():
    return Upstream(
        config=flexmock(Config()),
        package_config=flexmock(
            PackageConfig(
                actions={
                    ActionName.pre_sync: "command --a",
                    ActionName.get_current_version: "command --b",
                })),
        local_project=flexmock(repo_name=flexmock()),
    )
Esempio n. 23
0
def test_base_push_good(upstream_distgit_remote):
    _, distgit, _ = upstream_distgit_remote
    b = PackitRepositoryBase(config=Config(), package_config=PackageConfig())
    b.local_project = LocalProject(
        working_dir=str(distgit),
        git_url="https://github.com/packit-service/lol")
    flexmock(
        LocalProject,
        push=lambda *args, **kwargs:
        [PushInfo(PushInfo.FAST_FORWARD, None, None, None, None)],
    )
    b.push("master")
Esempio n. 24
0
 def __init__(self, info):
     self.upstream_url = info['upstream_url']
     self.downstream_name = info['downstream_name']
     self.repo = None
     self.result = {
         'downstream_name': info['downstream_name'],
         'successful': False
     }
     self.operation = ''
     self.downstream_spec = ''
     self.packit_cfg = Config.get_user_config()
     self.packit_local_project = None
     self.packit_api = None
Esempio n. 25
0
def packit_base(ctx, debug, fas_user, keytab):
    """Integrate upstream open source projects into Fedora operating system."""
    c = Config.get_user_config()
    c.debug = debug or c.debug
    c.fas_user = fas_user or c.fas_user
    c.keytab_path = keytab or c.keytab_path
    ctx.obj = c
    if ctx.obj.debug:
        set_logging(level=logging.DEBUG)
        logger.debug("logging set to DEBUG")
    else:
        set_logging(level=logging.INFO)
        logger.debug("logging set to INFO")
Esempio n. 26
0
 def __init__(self, info, dry_run):
     self.dry_run = dry_run
     self.upstream_url = info["upstream_url"]
     self.downstream_name = info["downstream_name"]
     self.repo = None
     self.result = {"downstream_name": info["downstream_name"], "successful": False}
     self.operation = ""
     self.downstream_spec = ""
     self.packit_cfg = Config.get_user_config()
     self.packit_local_project = None
     self.packit_api = None
     self.pkg_cfg_path = ""
     self.pkg_cfg = None
     self.git_project = None
Esempio n. 27
0
def test_base_push_bad(upstream_distgit_remote):
    _, distgit, _ = upstream_distgit_remote
    b = PackitRepositoryBase(config=Config(), package_config=PackageConfig())
    b.local_project = LocalProject(
        working_dir=str(distgit),
        git_url="https://github.com/packit-service/lol")
    flexmock(
        LocalProject,
        push=lambda *args, **kwargs:
        [PushInfo(PushInfo.REMOTE_REJECTED, None, None, None, None)],
    )
    with pytest.raises(PackitException) as e:
        b.push("master")
    assert "unable to push" in str(e.value)
Esempio n. 28
0
def test_process_message(event):
    packit_yaml = ("{'specfile_path': '', 'synced_files': []"
                   ", jobs: [{trigger: release, job: propose_downstream}]}")
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    flexmock(
        GithubProject,
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="foo/bar",
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(PackitAPI, sync_release=lambda dist_git_branch, version: None)
    c = Config()
    s = SteveJobs(c)
    s.process_message(event)
Esempio n. 29
0
def test_existing_pr(title, description, branch, prs, exists):
    local_project = LocalProject(
        git_project=flexmock(service="something", get_pr_list=lambda: prs),
        refresh=False,
    )
    distgit = DistGit(
        config=flexmock(Config()),
        package_config=flexmock(PackageConfig()),
        local_project=local_project,
    )
    pr = distgit.existing_pr(title, description, branch)
    if exists:
        assert pr is not None
    else:
        assert pr is None
Esempio n. 30
0
def upstream_with_actions():
    return Upstream(
        config=flexmock(Config()),
        package_config=flexmock(
            PackageConfig(
                actions={
                    ActionName.pre_sync: "command --a",
                    ActionName.get_current_version: "command --b",
                })),
        local_project=flexmock(
            repo_name=flexmock(),
            refresh_the_arguments=lambda: None,
            git_project=flexmock(),
            git_service=flexmock(),
        ),
    )