예제 #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
 def clean(self, data):
     data = super(ConfDBQueryApplication, self).clean(data)
     src = data.get("source", "")
     try:
         Engine().compile(src)
     except SyntaxError as e:
         raise ValueError("Syntax error: %s", e)
     return data
예제 #3
0
파일: test_match.py 프로젝트: nbashev/noc
def test_match(conf, query, output):
    e = Engine()
    e.insert_bulk(conf)
    assert list(e.query(query)) == output
예제 #4
0
def test_collapse_join(conf, query, result):
    e = Engine()
    e.insert_bulk(CONF1)
    list(e.query(query))
    assert e.dump("indent") == result
예제 #5
0
def test_not(input, query, output):
    e = Engine()
    assert list(e.query(query, **input)) == output
예제 #6
0
def test_match_any_vlan(input, query, output):
    e = Engine()
    assert list(e.query(query, **input)) == output
예제 #7
0
def test_prepared_query(query):
    e = Engine()
    q = e.compile(query)
    e.query(q)
예제 #8
0
def test_invalid(query):
    e = Engine()
    with pytest.raises(SyntaxError):
        e.compile(query)
예제 #9
0
def test_valid(query):
    e = Engine()
    e.compile(query)
예제 #10
0
def test_match_prefix(input, query, output):
    e = Engine()
    assert list(e.query(query, **input)) == output
예제 #11
0
def test_match(conf, query, output):
    db = ConfDB()
    db.insert_bulk(conf)
    e = Engine().with_db(db)
    assert list(e.query(query)) == output
예제 #12
0
def test_fact(conf, input, query, out_conf, output):
    db = ConfDB()
    db.insert_bulk(CONF1)
    e = Engine().with_db(db)
    assert list(e.query(query, **input)) == output
    assert db.marshall("indent") == out_conf