def compare(reference, new, ignored_keys=None):
    """Compare two dictionaries and return annotated difference.

    Positional arguments:
    reference -- the reference dictionary
    new -- the new dictionary

    Keyword arguments:
    ignored_keys -- keys to ignore in reference and new
    """
    missing_from_new = {}
    different = {}
    modified = {}
    ret = {}
    if ignored_keys is None:
        ignored_keys = set()
    for key1, value1 in reference.viewitems():
        if key1 in ignored_keys:
            try:
                del new[key1]
            except __HOLE__:
                pass
            continue
        else:
            try:
                value2 = new[key1]
            except KeyError:
                missing_from_new[key1] = value1
            else:
                try:
                    rec_comp = compare(value1, value2,
                                       ignored_keys=ignored_keys)
                    if rec_comp:
                        modified[key1] = rec_comp
                except AttributeError:
                    if value1 != value2:
                        different[key1] = {'reference': value1, 'new': value2}
                del new[key1]
    missing_from_reference = new
    for k, v in {'different': different,
                 'missing_from_reference': missing_from_reference,
                 'missing_from_new': missing_from_new,
                 'modified': modified}.viewitems():
        if v:
            ret[k] = v
    return ret
dataset/ETHPy150Open rcbops/rpc-openstack/maas/testing/compare-definitions.py/compare