Exemplo n.º 1
0
def test_create_repo(mock_download_file):
    """ Test to create a rpm repository of out a dir. """
    tmp_dir = tempfile.TemporaryDirectory()
    config = Config("koji_fake_url", "koji_fake_storage", "x86_64", ".")

    build = load_test_data("pki_core_build")
    tags = load_test_data("pki_core_tags")
    build_tag_md = load_test_data("pki_core_build_tag")

    mock_session = mock.Mock()

    mock_session.getBuild.return_value = build
    mock_session.listTags.return_value = tags
    mock_session.listTaggedRPMS.return_value = build_tag_md

    def download_file(url, target_pkg_dir, filename):
        """ Mock function which fakes rpm downloads """
        abs_file_path = "/".join([target_pkg_dir, filename])
        open(abs_file_path, "w").close()

    mock_download_file.side_effect = download_file

    pkgs = get_buildrequire_pkgs_from_build("1234", mock_session, config)
    pkgs, rpm_num = add_rpm_urls(pkgs, config)
    rpm_bulk_download(pkgs, rpm_num, tmp_dir.name)
    create_repo(tmp_dir.name)
    assert os.path.exists(tmp_dir.name + "/repodata")
Exemplo n.º 2
0
def test_rpm_bulk_download_pkg_exist(mock_download_file):
    """ Test if we create each pkg dir only once. """

    tmp_dir = tempfile.TemporaryDirectory()
    config = Config("koji_fake_url", "koji_fake_storage", "x86_64", ".")

    build = load_test_data("pki_core_build")
    tags = load_test_data("pki_core_tags")
    build_tag_md = load_test_data("pki_core_build_tag")

    mock_session = mock.Mock()

    mock_session.getBuild.return_value = build
    mock_session.listTags.return_value = tags
    mock_session.listTaggedRPMS.return_value = build_tag_md

    def download_file(url, target_pkg_dir, filename):
        """ Mock function which fakes rpm downloads """
        abs_file_path = "/".join([target_pkg_dir, filename])
        open(abs_file_path, "w").close()

    mock_download_file.side_effect = download_file

    pkgs = get_buildrequire_pkgs_from_build("1234", mock_session, config)
    pkgs, rpm_num = add_rpm_urls(pkgs, config)
    rpm_bulk_download(pkgs, rpm_num, tmp_dir.name)

    with mock.patch("modulemd_tools.bld2repo.os.makedirs") as mock_makedirs:
        rpm_bulk_download(pkgs, rpm_num, tmp_dir.name)

    assert not mock_makedirs.call_count
Exemplo n.º 3
0
def test_rpm_bulk_download_rpm_file_exists(mock_download_file):
    """ Test if we download each rpm file only once. If the file exists we skip it. """

    tmp_dir = tempfile.TemporaryDirectory()
    config = Config("koji_fake_url", "koji_fake_storage", "x86_64", ".")

    build = load_test_data("pki_core_build")
    tags = load_test_data("pki_core_tags")
    build_tag_md = load_test_data("pki_core_build_tag")

    mock_session = mock.Mock()

    mock_session.getBuild.return_value = build
    mock_session.listTags.return_value = tags
    mock_session.listTaggedRPMS.return_value = build_tag_md

    def download_file(url, target_pkg_dir, filename):
        """ Mock function which fakes rpm downloads """
        abs_file_path = "/".join([target_pkg_dir, filename])
        open(abs_file_path, "w").close()

    mock_download_file.side_effect = download_file

    pkgs = get_buildrequire_pkgs_from_build("1234", mock_session, config)
    pkgs, rpm_num = add_rpm_urls(pkgs, config)
    rpm_bulk_download(pkgs, rpm_num, tmp_dir.name)

    rpm_bulk_download(pkgs, rpm_num, tmp_dir.name)

    # the call_count should be the same as the number of rpms in the metadata.
    # we called the rpm_bulk_download function twice, but the second time the download
    # part should be skipped for the same dir.
    assert mock_download_file.call_count == rpm_num
Exemplo n.º 4
0
def test_rpm_bulk_download(mock_download_file):
    """ Test if the rpm files are downloaded. """

    tmp_dir = tempfile.TemporaryDirectory()
    config = Config("koji_fake_url", "koji_fake_storage", "x86_64", ".")

    build = load_test_data("pki_core_build")
    tags = load_test_data("pki_core_tags")
    build_tag_md = load_test_data("pki_core_build_tag")

    mock_session = mock.Mock()

    mock_session.getBuild.return_value = build
    mock_session.listTags.return_value = tags
    mock_session.listTaggedRPMS.return_value = build_tag_md

    def download_file(url, target_pkg_dir, filename):
        """ Mock function which fakes rpm downloads """
        abs_file_path = "/".join([target_pkg_dir, filename])
        open(abs_file_path, "w").close()

    mock_download_file.side_effect = download_file

    pkgs = get_buildrequire_pkgs_from_build("1234", mock_session, config)
    pkgs, rpm_num = add_rpm_urls(pkgs, config)
    rpm_bulk_download(pkgs, rpm_num, tmp_dir.name)

    # we gather all the files created on disk
    created_rpm_files = []
    for _, _, f in os.walk(tmp_dir.name):
        created_rpm_files += f

    # test if the number of created files is the same as provided by the metadata
    assert len(created_rpm_files) == rpm_num

    # test if the filenames are the same as described in the metadata
    for pkg in pkgs:
        for rpm_url in pkg["rpm_urls"]:
            rpm = rpm_url.split("/")[-1]
            assert rpm in created_rpm_files
Exemplo n.º 5
0
def main():
    parser = get_arg_parser()
    args = parser.parse_args()

    koji_host_dflt = parser.get_default("koji_host")

    if args.koji_host != koji_host_dflt:
        koji_storage_dflt = parser.get_default("koji_storage_host")
        if args.koji_storage_host == koji_storage_dflt:
            parser.error(
                "--koji-host and --koji-storage-host need to be used to together."
            )

    config = Config(args.koji_host, args.koji_storage_host, args.arch,
                    args.result_dir)
    session = get_koji_session(config)

    pkgs = get_buildrequire_pkgs_from_build(args.build_id, session, config)

    pkgs, rpm_num = add_rpm_urls(pkgs, config)

    rpm_bulk_download(pkgs, rpm_num, config.result_dir)

    create_repo(config.result_dir)