Esempio n. 1
0
def test_distro2compose_for_aarch64(distro, arch, compose, use_internal_tf):
    job_helper = TFJobHelper(
        service_config=flexmock(
            testing_farm_api_url="xyz",
        ),
        package_config=flexmock(jobs=[]),
        project=flexmock(),
        metadata=flexmock(),
        db_trigger=flexmock(),
        job_config=JobConfig(
            type=JobType.tests,
            trigger=JobConfigTriggerType.pull_request,
            metadata=JobMetadataConfig(use_internal_tf=use_internal_tf),
        ),
    )
    job_helper = flexmock(job_helper)

    response = flexmock(
        status_code=200, json=lambda: {"composes": [{"name": "Fedora-33"}]}
    )
    job_helper.should_receive("send_testing_farm_request").and_return(response).times(
        0 if use_internal_tf else 1
    )

    assert job_helper.distro2compose(distro, arch=arch) == compose
def test_trigger_payload(
    tf_token,
    ps_deployment,
    repo,
    namespace,
    commit_sha,
    project_url,
    git_ref,
    copr_owner,
    copr_project,
    pipeline_id,
    chroot,
):
    # Soo many things are happening in a single constructor!!!!
    config = flexmock(
        testing_farm_secret=tf_token,
        deployment=ps_deployment,
        command_handler_work_dir="/tmp",
    )
    package_config = flexmock(jobs=[])
    project = flexmock(
        repo=repo,
        namespace=namespace,
        service="GitHub",
        get_git_urls=lambda: {"git": f"{project_url}.git"},
    )
    metadata = flexmock(
        trigger=flexmock(),
        commit_sha=commit_sha,
        git_ref=git_ref,
        project_url=project_url,
    )
    db_trigger = flexmock()

    job_helper = TFJobHelper(config, package_config, project, metadata,
                             db_trigger, flexmock())
    job_helper = flexmock(job_helper)

    job_helper.should_receive("job_owner").and_return(copr_owner)
    job_helper.should_receive("job_project").and_return(copr_project)
    payload = job_helper._trigger_payload(pipeline_id, chroot)

    assert payload["pipeline"]["id"] == pipeline_id
    assert payload["api"]["token"] == tf_token
    assert "packit.dev/api" in payload["response-url"]
    assert payload["artifact"] == {
        "repo-name": repo,
        "repo-namespace": namespace,
        "copr-repo-name": f"{copr_owner}/{copr_project}",
        "copr-chroot": chroot,
        "commit-sha": commit_sha,
        "git-url": f"{project_url}.git",
        "git-ref": git_ref,
    }
Esempio n. 3
0
def test_chroot2distro_arch(chroot, distro, arch, use_internal_tf):
    job_helper = TFJobHelper(
        service_config=flexmock(
            testing_farm_api_url="xyz",
        ),
        package_config=flexmock(jobs=[]),
        project=flexmock(),
        metadata=flexmock(),
        db_trigger=flexmock(),
        job_config=JobConfig(
            type=JobType.tests,
            trigger=JobConfigTriggerType.pull_request,
            metadata=JobMetadataConfig(use_internal_tf=use_internal_tf),
        ),
    )
    job_helper = flexmock(job_helper)

    assert job_helper.chroot2distro_arch(chroot) == (distro, arch)
def test_get_compose_arch(chroot, compose, arch):
    job_helper = TFJobHelper(
        service_config=flexmock(
            testing_farm_api_url="xyz",
        ),
        package_config=flexmock(jobs=[]),
        project=flexmock(),
        metadata=flexmock(),
        db_trigger=flexmock(),
        job_config=JobConfig(
            type=JobType.tests, trigger=JobConfigTriggerType.pull_request
        ),
    )
    job_helper = flexmock(job_helper)

    response = flexmock(
        status_code=200, json=lambda: {"composes": [{"name": "Fedora-33"}]}
    )
    job_helper.should_receive("send_testing_farm_request").and_return(response)

    compose_, arch_ = job_helper.get_compose_arch(chroot)
    assert compose_ == compose
    assert arch_ == arch
Esempio n. 5
0
def test_test_repo(fmf_url, fmf_ref, result_url, result_ref):
    tf_api = "https://api.dev.testing-farm.io/v0.1/"
    tf_token = "very-secret"
    ps_deployment = "test"
    repo = "packit"
    project_url = "https://github.com/packit/packit"
    git_ref = "master"
    namespace = "packit-service"
    commit_sha = "feb41e5"
    copr_owner = "me"
    copr_project = "cool-project"
    chroot = "centos-stream-x86_64"
    compose = "Fedora-Rawhide"

    config = flexmock(
        testing_farm_api_url=tf_api,
        testing_farm_secret=tf_token,
        deployment=ps_deployment,
        command_handler_work_dir="/tmp",
    )
    package_config = flexmock(jobs=[])
    pr = flexmock(source_project=flexmock(get_web_url=lambda: project_url))
    project = flexmock(
        repo=repo,
        namespace=namespace,
        service="GitHub",
        get_git_urls=lambda: {"git": f"{project_url}.git"},
        get_pr=lambda id_: pr,
        full_repo_name=f"{namespace}/{repo}",
    )
    metadata = flexmock(
        trigger=flexmock(),
        commit_sha=commit_sha,
        git_ref=git_ref,
        project_url=project_url,
        pr_id=123,
    )
    db_trigger = flexmock()

    job_helper = TFJobHelper(
        service_config=config,
        package_config=package_config,
        project=project,
        metadata=metadata,
        db_trigger=db_trigger,
        job_config=JobConfig(
            type=JobType.tests,
            trigger=JobConfigTriggerType.pull_request,
            metadata=JobMetadataConfig(fmf_url=fmf_url, fmf_ref=fmf_ref),
        ),
    )
    job_helper = flexmock(job_helper)

    job_helper.should_receive("job_owner").and_return(copr_owner)
    job_helper.should_receive("job_project").and_return(copr_project)
    job_helper.should_receive("distro2compose").and_return(compose)

    build_id = 1
    # URLs shortened for clarity
    log_url = "https://copr-be.cloud.fedoraproject.org/results/.../builder-live.log.gz"
    srpm_url = (
        f"https://download.copr.fedorainfracloud.org/results/.../{repo}-0.1-1.src.rpm"
    )
    copr_build = flexmock(
        id=build_id,
        built_packages=[
            {
                "name": repo,
                "version": "0.1",
                "release": "1",
                "arch": "noarch",
                "epoch": "0",
            }
        ],
        build_logs_url=log_url,
    )
    copr_build.should_receive("get_srpm_build").and_return(flexmock(url=srpm_url))

    payload = job_helper._payload(chroot, build=copr_build)
    assert payload.get("test")
    assert payload["test"].get("fmf")
    assert payload["test"]["fmf"].get("url") == result_url
    assert payload["test"]["fmf"].get("ref") == result_ref
Esempio n. 6
0
def test_payload(
    tf_api,
    tf_token,
    internal_tf_token,
    use_internal_tf,
    ps_deployment,
    repo,
    namespace,
    commit_sha,
    project_url,
    git_ref,
    copr_owner,
    copr_project,
    build_id,
    chroot,
    built_packages,
    distro,
    compose,
    arch,
    packages_to_send,
):
    # Soo many things are happening in a single constructor!!!!
    config = flexmock(
        testing_farm_api_url=tf_api,
        testing_farm_secret=tf_token,
        internal_testing_farm_secret=internal_tf_token,
        deployment=ps_deployment,
        command_handler_work_dir="/tmp",
    )
    package_config = flexmock(jobs=[])
    pr = flexmock(source_project=flexmock(get_web_url=lambda: project_url))
    project = flexmock(
        repo=repo,
        namespace=namespace,
        service="GitHub",
        get_git_urls=lambda: {"git": f"{project_url}.git"},
        get_pr=lambda id_: pr,
        full_repo_name=f"{namespace}/{repo}",
    )
    metadata = flexmock(
        trigger=flexmock(),
        commit_sha=commit_sha,
        git_ref=git_ref,
        project_url=project_url,
        pr_id=123,
    )
    db_trigger = flexmock()

    job_helper = TFJobHelper(
        service_config=config,
        package_config=package_config,
        project=project,
        metadata=metadata,
        db_trigger=db_trigger,
        job_config=JobConfig(
            type=JobType.tests,
            trigger=JobConfigTriggerType.pull_request,
            metadata=JobMetadataConfig(use_internal_tf=use_internal_tf),
        ),
    )

    token_to_use = internal_tf_token if use_internal_tf else tf_token
    assert job_helper.tft_token == token_to_use

    job_helper = flexmock(job_helper)

    job_helper.should_receive("job_owner").and_return(copr_owner)
    job_helper.should_receive("job_project").and_return(copr_project)
    job_helper.should_receive("distro2compose").and_return(compose)
    artifact = {"id": f"{build_id}:{chroot}", "type": "fedora-copr-build"}

    if packages_to_send:
        artifact["packages"] = packages_to_send

    # URLs shortened for clarity
    log_url = "https://copr-be.cloud.fedoraproject.org/results/.../builder-live.log.gz"
    srpm_url = (
        f"https://download.copr.fedorainfracloud.org/results/.../{repo}-0.1-1.src.rpm"
    )
    copr_build = flexmock(
        id=build_id,
        built_packages=[
            {
                "name": repo,
                "version": "0.1",
                "release": "1",
                "arch": "noarch",
                "epoch": "0",
            }
        ],
        build_logs_url=log_url,
    )
    copr_build.should_receive("get_srpm_build").and_return(flexmock(url=srpm_url))

    payload = job_helper._payload(chroot, artifact, copr_build)

    assert payload["api_key"] == token_to_use
    assert payload["test"]["fmf"] == {
        "url": project_url,
        "ref": commit_sha,
    }

    assert payload["environments"] == [
        {
            "arch": arch,
            "os": {"compose": compose},
            "artifacts": [artifact],
            "tmt": {"context": {"distro": distro, "arch": arch, "trigger": "commit"}},
            "variables": {
                "PACKIT_FULL_REPO_NAME": f"{namespace}/{repo}",
                "PACKIT_COMMIT_SHA": commit_sha,
                "PACKIT_PACKAGE_NVR": f"{repo}-0.1-1",
                "PACKIT_BUILD_LOG_URL": log_url,
                "PACKIT_SRPM_URL": srpm_url,
            },
        }
    ]
    assert payload["notification"]["webhook"]["url"].endswith("/testing-farm/results")
def test_payload(
    tf_api,
    tf_token,
    ps_deployment,
    repo,
    namespace,
    commit_sha,
    project_url,
    git_ref,
    copr_owner,
    copr_project,
    build_id,
    chroot,
    compose,
    arch,
):
    # Soo many things are happening in a single constructor!!!!
    config = flexmock(
        testing_farm_api_url=tf_api,
        testing_farm_secret=tf_token,
        deployment=ps_deployment,
        command_handler_work_dir="/tmp",
    )
    package_config = flexmock(jobs=[])
    pr = flexmock(source_project=flexmock(get_web_url=lambda: project_url))
    project = flexmock(
        repo=repo,
        namespace=namespace,
        service="GitHub",
        get_git_urls=lambda: {"git": f"{project_url}.git"},
        get_pr=lambda id_: pr,
    )
    metadata = flexmock(
        trigger=flexmock(),
        commit_sha=commit_sha,
        git_ref=git_ref,
        project_url=project_url,
        pr_id=123,
    )
    db_trigger = flexmock()

    job_helper = TFJobHelper(
        service_config=config,
        package_config=package_config,
        project=project,
        metadata=metadata,
        db_trigger=db_trigger,
        job_config=JobConfig(
            type=JobType.tests, trigger=JobConfigTriggerType.pull_request
        ),
    )
    job_helper = flexmock(job_helper)

    job_helper.should_receive("job_owner").and_return(copr_owner)
    job_helper.should_receive("job_project").and_return(copr_project)
    job_helper.should_receive("get_compose_arch").and_return(compose, arch)
    payload = job_helper._payload(build_id, chroot)

    assert payload["api_key"] == tf_token
    assert payload["test"]["fmf"] == {
        "url": project_url,
        "ref": commit_sha,
    }
    assert payload["environments"] == [
        {
            "arch": arch,
            "os": {"compose": compose},
            "artifacts": [{"id": f"{build_id}:{chroot}", "type": "fedora-copr-build"}],
        }
    ]
    assert payload["notification"]["webhook"]["url"].endswith("/testing-farm/results")