示例#1
0
文件: utils.py 项目: nbashev/noc
def check_query(query: str, args: Dict[str, Any],
                expected: List[Dict[str, Any]]) -> bool:
    """
    ConfDB Query result order is undefined,
    so we need additional helper to check
    if all results matched

    :param query:
    :param args:
    :param expected:
    :return:
    """
    e = Engine()
    left: Dict[int, Dict[str,
                         Any]] = {dict_hash_int(ctx): ctx
                                  for ctx in expected}
    not_found: Set[Dict[str, Any]] = set()
    for ctx in e.query(query, **args):
        ctx_hash = dict_hash_int(ctx)
        if ctx_hash in left:
            del left[ctx_hash]
        else:
            not_found.add(ctx)
    for ctx_hash in not_found:
        print("Unexpected return result: %s" % not_found[ctx_hash])
    for ctx in left:
        print("Missed result:  %s" % ctx)
    return not left and not not_found
示例#2
0
文件: suppress.py 项目: nbashev/noc
 def event_hash(event: ActiveEvent) -> int:
     e_vars = {
         v.name: event.vars.get(v.name, "") or ""
         for v in event.event_class.vars if v.match_suppress
     }
     var_hash = dict_hash_int(event.vars) if e_vars else 0
     return hash_int(
         f"{event.managed_object.id}:{event.event_class.id}:{var_hash}")
示例#3
0
文件: dedup.py 项目: nbashev/noc
 def event_hash(event: ActiveEvent) -> int:
     var_hash = dict_hash_int(event.vars) if event.vars else 0
     return hash_int(
         f"{event.managed_object.id}:{event.event_class.id}:{var_hash}")
示例#4
0
文件: test_hash.py 项目: nbashev/noc
def test_dict_hash_int(value, expected):
    assert dict_hash_int(value) == expected