Esempio n. 1
0
def test_dist_git_push_release_handle(github_release_webhook):
    packit_yaml = (
        "{'specfile_path': 'hello-world.spec', 'synced_files': []"
        ", jobs: [{trigger: release, job: propose_downstream, metadata: {targets:[]}}]}"
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
        get_web_url=lambda: "https://github.com/packit-service/hello-world",
        is_private=lambda: False,
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="master", version="0.3.0"
    ).once()

    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release)
    )

    results = SteveJobs().process_message(github_release_webhook)
    assert first_dict_value(results["jobs"])["success"]
    assert results["event"]["trigger"] == "release"
def test_dist_git_push_release_handle_one_failed(
    github_release_webhook, fedora_branches
):
    packit_yaml = (
        "{'specfile_path': 'hello-world.spec', 'synced_files': []"
        ", jobs: [{trigger: release, job: propose_downstream, "
        "metadata: {targets:[], dist-git-branch: fedora-all}}]}"
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = (
        flexmock(
            get_file_content=lambda path, ref: packit_yaml,
            full_repo_name="packit-service/hello-world",
            repo="hello-world",
            get_files=lambda ref, filter_regex: [],
            get_sha_from_tag=lambda tag_name: "123456",
            get_web_url=lambda: "https://github.com/packit/hello-world",
            is_private=lambda: False,
        )
        .should_receive("create_issue")
        .once()
        .mock()
    )
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(config)
    # it would make sense to make LocalProject offline
    for i, branch in enumerate(fedora_branches):
        sync_release = (
            flexmock(PackitAPI)
            .should_receive("sync_release")
            .with_args(dist_git_branch=branch, version="0.3.0")
            .once()
        )
        if i == 1:
            sync_release.and_raise(Exception, f"Failed {branch}").once()

    flexmock(FedPKG).should_receive("clone").and_return(None)

    flexmock(sentry_integration).should_receive("send_to_sentry").and_return().once()
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release, id=123)
    )

    flexmock(Signature).should_receive("apply_async").once()
    processing_results = SteveJobs().process_message(github_release_webhook)
    assert processing_results["details"]["event"]["trigger"] == "release"
    event_dict, package_config, job = get_parameters_from_results(processing_results)

    results = run_propose_downstream_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job,
    )
    assert not first_dict_value(results["job"])["success"]
def test_dist_git_push_release_handle_all_failed(github_release_webhook,
                                                 fedora_branches):
    packit_yaml = ("{'specfile_path': 'hello-world.spec', 'synced_files': []"
                   ", jobs: [{trigger: release, job: propose_downstream, "
                   "metadata: {targets:[], dist-git-branch: fedora-all}}]}")
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    table_content = ""
    for branch in fedora_branches:
        table_content += f"| `{branch}` | `Failed` |\n"
    project = (flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
        get_web_url=lambda: "https://github.com/packit/hello-world",
        is_private=lambda: False,
        default_branch="main",
    ).should_receive("create_issue").with_args(
        title="[packit] Propose downstream failed for release 0.3.0",
        body="Packit failed on creating pull-requests in dist-git:\n\n"
        "| dist-git branch | error |\n"
        "| --------------- | ----- |\n"
        f"{table_content}\n\n"
        "You can retrigger the update by adding a comment (`/packit propose-downstream`)"
        " into this issue.\n",
    ).once().mock())
    lp = flexmock(LocalProject, refresh_the_arguments=lambda: None)
    lp.git_project = project
    flexmock(DistGit).should_receive("local_project").and_return(lp)

    flexmock(Allowlist, check_and_report=True)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").and_raise(
        Exception, "Failed").times(len(fedora_branches))
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release, id=123))

    flexmock(sentry_integration).should_receive(
        "send_to_sentry").and_return().times(len(fedora_branches))
    flexmock(Signature).should_receive("apply_async").once()

    processing_results = SteveJobs().process_message(github_release_webhook)
    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results)

    results = run_propose_downstream_handler(
        package_config=package_config,
        event=event_dict,
        job_config=job_config,
    )
    assert not first_dict_value(results["job"])["success"]
def test_dont_retry_propose_downstream_task(github_release_webhook):
    packit_yaml = (
        "{'specfile_path': 'hello-world.spec', 'synced_files': []"
        ", jobs: [{trigger: release, job: propose_downstream, metadata: {targets:[]}}]}"
    )
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
        get_web_url=lambda: "https://github.com/packit/hello-world",
        is_private=lambda: False,
        default_branch="main",
    )

    lp = flexmock(LocalProject, refresh_the_arguments=lambda: None)
    lp.git_project = project
    flexmock(DistGit).should_receive("local_project").and_return(lp)

    flexmock(Allowlist, check_and_report=True)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    # it would make sense to make LocalProject offline

    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release, id=123))
    flexmock(Signature).should_receive("apply_async").once()

    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="main", tag="0.3.0").and_raise(
            RebaseHelperError,
            "Failed to download file from URL example.com").once()
    flexmock(Context, retries=2)
    flexmock(Task).should_receive("retry").never()
    flexmock(project).should_receive("create_issue").once()

    processing_results = SteveJobs().process_message(github_release_webhook)
    event_dict, job, job_config, package_config = get_parameters_from_results(
        processing_results)

    results = run_propose_downstream_handler(event_dict, package_config,
                                             job_config)

    assert not first_dict_value(results["job"])["success"]
Esempio n. 5
0
def test_dist_git_push_release_handle_all_failed(release_event):
    packit_yaml = ("{'specfile_path': 'hello-world.spec', 'synced_files': []"
                   ", jobs: [{trigger: release, job: propose_downstream, "
                   "metadata: {targets:[], dist-git-branch: fedora-all}}]}")
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = (flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
    ).should_receive("create_issue").with_args(
        title="[packit] Propose update failed for release 0.3.0",
        body="Packit failed on creating pull-requests in dist-git:\n\n"
        "| dist-git branch | error |\n"
        "| --------------- | ----- |\n"
        "| `f30` | `Failed` |\n"
        "| `f31` | `Failed` |\n"
        "| `f32` | `Failed` |\n"
        "| `master` | `Failed` |\n\n\n"
        "You can re-trigger the update by adding `/packit propose-update`"
        " to the issue comment.\n",
    ).once().mock())
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    flexmock(SteveJobs, _is_private=False)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").and_raise(
        Exception, "Failed").times(4)
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release))

    # 4 = master, f32, 31, 30
    flexmock(sentry_integration).should_receive(
        "send_to_sentry").and_return().times(4)

    results = SteveJobs().process_message(release_event)
    assert not results["jobs"]["propose_downstream"]["success"]
    assert results["event"]["trigger"] == "release"
Esempio n. 6
0
def test_dist_git_push_release_handle_one_failed(release_event):
    packit_yaml = ("{'specfile_path': 'hello-world.spec', 'synced_files': []"
                   ", jobs: [{trigger: release, job: propose_downstream, "
                   "metadata: {targets:[], dist-git-branch: fedora-all}}]}")
    flexmock(Github, get_repo=lambda full_name_or_id: None)
    project = (flexmock(
        get_file_content=lambda path, ref: packit_yaml,
        full_repo_name="packit-service/hello-world",
        repo="hello-world",
        get_files=lambda ref, filter_regex: [],
        get_sha_from_tag=lambda tag_name: "123456",
    ).should_receive("create_issue").once().mock())
    flexmock(LocalProject, refresh_the_arguments=lambda: None)
    flexmock(Whitelist, check_and_report=True)
    flexmock(SteveJobs, _is_private=False)
    config = ServiceConfig()
    config.command_handler_work_dir = SANDCASTLE_WORK_DIR
    config.get_project = lambda url: project
    flexmock(ServiceConfig).should_receive("get_service_config").and_return(
        config)
    # it would make sense to make LocalProject offline
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="master", version="0.3.0").once()

    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="f32",
        version="0.3.0").and_raise(Exception, "Failed f30").once()
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="f31", version="0.3.0").once()
    flexmock(PackitAPI).should_receive("sync_release").with_args(
        dist_git_branch="f30", version="0.3.0").once()

    flexmock(FedPKG).should_receive("clone").and_return(None)

    flexmock(sentry_integration).should_receive(
        "send_to_sentry").and_return().once()
    flexmock(AddReleaseDbTrigger).should_receive("db_trigger").and_return(
        flexmock(job_config_trigger_type=JobConfigTriggerType.release))

    results = SteveJobs().process_message(release_event)
    assert not results["jobs"]["propose_downstream"]["success"]
    assert results["event"]["trigger"] == "release"