Ejemplo n.º 1
0
def check_rpmdb_transaction(context, mode):
    check_context_table(context, ["Action", "Package"])

    if not "rpmdb_pre" in context.dnf:
        raise ValueError("RPMDB snapshot wasn't created before running this step.")

    context.dnf["rpmdb_post"] = get_rpmdb_rpms(context.dnf.installroot)

    checked_rpmdb = {}

    # check changes in RPMDB
    rpmdb_transaction = diff_rpm_lists(context.dnf["rpmdb_pre"], context.dnf["rpmdb_post"])
    for action, nevras in context.table:
        if action in ["broken"]:
            continue
        for nevra in nevras.split(", "):
            checked_rpmdb.setdefault(action, set()).add(nevra)
            if action.startswith('group-'):
                continue
            if action.startswith('module-'):
                continue
            rpm = RPM(nevra)
            if action == "reinstall" and rpm not in rpmdb_transaction["reinstall"]:
                action = "unchanged"
            if (action == "remove" and rpm not in rpmdb_transaction["remove"]
                and rpm in rpmdb_transaction["obsoleted"]):
                action = "obsoleted"
            elif (action == "obsoleted" and rpm not in rpmdb_transaction["obsoleted"]
                  and rpm in rpmdb_transaction["remove"]):
                action = "remove"
            if action == "absent":
                if rpm in rpmdb_transaction["present"]:
                    raise AssertionError("[rpmdb] Package %s not '%s'" % (rpm, action))
                continue
            if rpm not in rpmdb_transaction[action]:
                candidates = ", ".join([str(i) for i in sorted(rpmdb_transaction[action])])
                raise AssertionError("[rpmdb] Package %s not '%s'; Possible candidates: %s" % (
                                     rpm, action, candidates))

    if mode == 'exact_match':
        context_table = parse_context_table(context)
        for action in ["install", "remove", "upgrade", "downgrade"]:
            delta = []
            for nevra in context_table[action].copy():
                if nevra in rpmdb_transaction[action]:
                    rpmdb_transaction[action].remove(nevra)
                elif action == "remove": # and nevra in rpmdb_transaction["obsolete"]:
                    rpmdb_transaction["obsoleted"].remove(nevra)
                else:
                    delta.append(nevra)
            if delta:
                raise AssertionError(
                    "[rpmdb] Following packages weren't captured in the table for action '%s': %s" % (
                    action, ", ".join([str(rpm) for rpm in sorted(delta)])))
Ejemplo n.º 2
0
def then_RPMDB_transaction_is_empty(context):
    if not "rpmdb_pre" in context.dnf:
        raise ValueError("RPMDB snapshot wasn't created before running this step.")

    context.dnf["rpmdb_post"] = get_rpmdb_rpms(context.dnf.installroot)

    # check changes in RPMDB
    rpmdb_transaction = diff_rpm_lists(context.dnf["rpmdb_pre"], context.dnf["rpmdb_post"])
    if rpmdb_transaction["changed"]:
        changes = ", ".join([str(i) for i in sorted(rpmdb_transaction["changed"])])
        raise AssertionError("[rpmdb] Packages have changed: {}".format(changes))