Exemplo n.º 1
0
def primary_in_path_contains_only_packages(context, path):
    check_context_table(context, ["Name", "Epoch", "Version", "Release", "Architecture"])
    filepath = os.path.join(context.tempdir_manager.tempdir, path.lstrip('/'), "*-primary.xml.*")
    primary_filepath = glob.glob(filepath)[0]
    primary = xml_parse_repodata(primary_filepath, "{%s}package" % ns["pri_ns"], "primary")

    for name, epoch, version, release, architecture in context.table:
        nevra = build_nevra(name, epoch, version, release, architecture)
        found = False
        for key in primary.keys():
            pkg = primary.items[key]
            if (nevra == pkg.nevra()):
                del primary.items[key]
                found = True
                break

        if not found:
            print("primary.xml yet unmatched packages:")
            for key in primary.keys():
                pkg = primary.items[key]
                print("\t" + build_nevra(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch))
            raise AssertionError("Package " + nevra + " not found")

    if (len(primary.keys()) > 0):
        print("primary.xml contains additional packages:")
        for key in primary.keys():
            pkg = primary.items[key]
            print("\t" + build_nevra(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch))
        raise AssertionError("Additional packages in primary.xml")
Exemplo n.º 2
0
def primary_in_path_doesnt_contain_any_packages(context, path):
    filepath = os.path.join(context.tempdir_manager.tempdir, path.lstrip('/'), "*-primary.xml.*")
    primary_filepath = glob.glob(filepath)[0]
    primary = xml_parse_repodata(primary_filepath, "{%s}package" % ns["pri_ns"], "primary")

    if (len(primary.keys()) > 0):
        print("primary.xml contains additional packages:")
        for key in primary.keys():
            pkg = primary.items[key]
            print("\t" + build_nevra(pkg.name, pkg.epoch, pkg.version, pkg.release, pkg.arch))
        raise AssertionError("Additional packages in primary.xml")
Exemplo n.º 3
0
def repodata_are_consistent(context, path):
    repopath = os.path.join(context.tempdir_manager.tempdir, path.lstrip('/'))
    tmpdir = tempfile.mkdtemp()
    prim_path_sqlite = None

    # REPOMD
    md_path = os.path.join(repopath, "repomd.xml")
    if not os.path.exists(md_path):
        raise AssertionError("Error: repomd.xml is missing (%s)" % md_path)

    repomd = xml_parse_repodata(md_path, "{%s}data" % ns["md_ns"], "repomd")
    for key in repomd.keys():
        item = repomd.items[key]
        if not item.location_href:
            continue
        # Remove /repodata/ from path
        basename = os.path.basename(item.location_href)
        p = os.path.join(repopath, basename.lstrip('/'))
        if not os.path.isfile(p):
            raise AssertionError("Error: repomd.xml contains: \"%s\""
                                 "but it is not present in %s" % (p, repopath))

        decompressed_p = decompress_file_by_extension_to_dir(p, tmpdir)

        if "primary_db" == item.name:
            prim_path_sqlite = decompressed_p
        elif "filelists_db" == item.name:
            filelists_path_sqlite = decompressed_p
        elif "other_db" == item.name:
            other_path_sqlite = decompressed_p
        elif "primary" == item.name:
            prim_path = decompressed_p
        elif "filelists" == item.name:
            filelists_path = decompressed_p
        elif "other" == item.name:
            other_path = decompressed_p
        else:
            # Skip unsupported updateinfo, comps, etc..
            # TODO(amatej): we could technically check for updateinfo,
            # comps, modules and even verify some stuff
            continue

        verify_repomd_item_with_file(item, p, decompressed_p)

    # XML
    primary = xml_parse_repodata(prim_path, "{%s}package" % ns["pri_ns"], "primary")
    filelists = xml_parse_repodata(filelists_path, "{%s}package" % ns["fil_ns"], "filelists")
    other = xml_parse_repodata(other_path, "{%s}package" % ns["oth_ns"], "other")

    if set(primary.keys()) != set(filelists.keys()):
        raise AssertionError("XML files Primary and Filelists have different package sets")
    if set(primary.keys()) != set(other.keys()):
        raise AssertionError("XML files Primary and Other have different package sets")

    # SQLITE
    if prim_path_sqlite: # All three sqlite files have to be present at the same time
        primary_sql = load_sqlite(prim_path_sqlite, "primary")
        filelists_sql = load_sqlite(filelists_path_sqlite, "filelists")
        other_sql = load_sqlite(other_path_sqlite, "other")

        if set(primary_sql.keys()) != set(filelists_sql.keys()):
            raise AssertionError("SQLITE files Primary and Filelists have different package sets.")
        if set(primary_sql.keys()) != set(other_sql.keys()):
            raise AssertionError("SQLITE files Primary and Other have different package sets.")

        # Compare XML vs SQLITE packages by checksums
        if primary.keys() != primary_sql.keys():
            raise AssertionError("SQLITE Primary and XML Primary have different package sets.")
        if filelists.keys() != filelists_sql.keys():
            raise AssertionError("SQLITE Filelists and XML Filelists have different package sets.")
        if other.keys() != other_sql.keys():
            raise AssertionError("SQLITE Other and XML Other have different package sets.")

        # Compare XML vs SQLITE packages by name, names in SQLITE are only in Primary
        if primary.packages() != primary_sql.packages():
            raise AssertionError("SQLITE Primary and XML Primary have different package sets.")

        diff = primary.diff(primary_sql)
        if diff:
            raise AssertionError("SQLITE Primary and XML Primary are different.\n"
                                 "Difference: %s" % (diff))
        diff = filelists.diff(filelists_sql)
        if diff:
            raise AssertionError("SQLITE Filelists and XML Filelists are different.\n"
                                 "Difference: %s" % (diff))
        diff = other.diff(other_sql)
        if diff:
            raise AssertionError("SQLITE Filelists and XML Filelists are different.\n"
                                 "Difference: %s" % (diff))
    return
Exemplo n.º 4
0
def repodata_are_consistent(context, path):
    repopath = os.path.join(context.tempdir_manager.tempdir, path.lstrip('/'))
    tmpdir = tempfile.mkdtemp()
    prim_path_sqlite = None
    prim_zck_path = None

    # REPOMD
    md_path = os.path.join(repopath, "repomd.xml")
    if not os.path.exists(md_path):
        raise AssertionError("Error: repomd.xml is missing (%s)" % md_path)

    repomd = xml_parse_repodata(md_path, "{%s}data" % ns["md_ns"], "repomd")
    for key in repomd.keys():
        item = repomd.items[key]
        if not item.location_href:
            continue
        # Remove /repodata/ from path
        basename = os.path.basename(item.location_href)
        p = os.path.join(repopath, basename.lstrip('/'))
        if not os.path.isfile(p):
            raise AssertionError("Error: repomd.xml contains: \"%s\""
                                 "but it is not present in %s" % (p, repopath))

        decompressed_p = decompress_file_by_extension_to_dir(p, tmpdir)

        if item.name == "primary_db":
            prim_path_sqlite = decompressed_p
        elif item.name == "filelists_db":
            filelists_path_sqlite = decompressed_p
        elif item.name == "other_db":
            other_path_sqlite = decompressed_p
        elif item.name == "primary":
            prim_path = decompressed_p
        elif item.name == "filelists":
            filelists_path = decompressed_p
        elif item.name == "other":
            other_path = decompressed_p
        elif item.name == "primary_zck":
            prim_zck_path = decompressed_p
        elif item.name == "filelists_zck":
            filelists_zck_path = decompressed_p
        elif item.name == "other_zck":
            other_zck_path = decompressed_p
        else:
            # Skip unsupported updateinfo, comps, etc..
            # TODO(amatej): we could technically check for updateinfo,
            # comps, modules and even verify some stuff
            continue

        verify_repomd_item_with_file(item, p, decompressed_p)

    # XML
    primary = xml_parse_repodata(prim_path, "{%s}package" % ns["pri_ns"],
                                 "primary")
    filelists = xml_parse_repodata(filelists_path,
                                   "{%s}package" % ns["fil_ns"], "filelists")
    other = xml_parse_repodata(other_path, "{%s}package" % ns["oth_ns"],
                               "other")

    keys_do_not_differ(primary, filelists, other)

    # SQLITE
    if prim_path_sqlite:  # All three sqlite files have to be present at the same time
        primary_sql = load_sqlite(prim_path_sqlite, "primary")
        filelists_sql = load_sqlite(filelists_path_sqlite, "filelists")
        other_sql = load_sqlite(other_path_sqlite, "other")

        keys_do_not_differ(primary_sql, filelists_sql, other_sql)
        repodata_do_not_differ(primary, primary_sql, filelists, filelists_sql,
                               other, other_sql)

    # ZCK
    if prim_zck_path:  # All three zck files have to be present at the same time
        primary_zck = xml_parse_repodata(prim_zck_path,
                                         "{%s}package" % ns["pri_ns"],
                                         "primary")
        filelists_zck = xml_parse_repodata(filelists_zck_path,
                                           "{%s}package" % ns["fil_ns"],
                                           "filelists")
        other_zck = xml_parse_repodata(other_zck_path,
                                       "{%s}package" % ns["oth_ns"], "other")

        keys_do_not_differ(primary_zck, filelists_zck, other_zck)
        repodata_do_not_differ(primary, primary_zck, filelists, filelists_zck,
                               other, other_zck)

    return