Example #1
0
def populate_fv(info, module, namespace):
    all_dbs = set()
    for id in info.keys():
        for db_name in info[id].keys():
            all_dbs.add(db_name)

    db_cfg_file = JsonSource()
    db_conn = ConnectionPool().initialize_connector(namespace)
    for db_name in all_dbs:
        if db_name == "CONFIG_FILE":
            db_cfg_file.connect(plugins.dump_modules[module].CONFIG_FILE,
                                namespace)
        else:
            db_conn.connect(db_name)

    final_info = {}
    for id in info.keys():
        final_info[id] = {}
        for db_name in info[id].keys():
            final_info[id][db_name] = {}
            final_info[id][db_name]["keys"] = []
            final_info[id][db_name]["tables_not_found"] = info[id][db_name][
                "tables_not_found"]
            for key in info[id][db_name]["keys"]:
                if db_name == "CONFIG_FILE":
                    fv = db_cfg_file.get(db_name, key)
                else:
                    fv = db_conn.get_all(db_name, key)
                final_info[id][db_name]["keys"].append({key: fv})

    return final_info
def match_engine():

    print("SETUP")
    os.environ["VERBOSE"] = "1"

    # Monkey Patch the SonicV2Connector Object
    from ...mock_tables import dbconnector
    db = SonicV2Connector()

    # popualate the db with mock data
    db_names = list(dedicated_dbs.keys())
    try:
        populate_mock(db, db_names, dedicated_dbs)
    except Exception as e:
        assert False, "Mock initialization failed: " + str(e)

    # Initialize connection pool
    conn_pool = ConnectionPool()
    conn_pool.fill(DEFAULT_NAMESPACE, db, db_names)

    # Initialize match_engine
    match_engine = MatchEngine(conn_pool)
    yield match_engine
    print("TEARDOWN")
    os.environ["VERBOSE"] = "0"
def match_engine():

    print("SETUP")
    os.environ["VERBOSE"] = "1"

    # Monkey Patch the SonicV2Connector Object
    from ...mock_tables import dbconnector
    db = SonicV2Connector()

    # popualate the db with mock data
    db_names = list(dedicated_dbs.keys())
    try:
        populate_mock(db, db_names, dedicated_dbs)
    except Exception as e:
        assert False, "Mock initialization failed: " + str(e)

    # Initialize connection pool
    conn_pool = ConnectionPool()
    DEF_NS = ''  # Default Namespace
    conn_pool.cache = {DEF_NS: {'conn': db, 'connected_to': set(db_names)}}

    # Initialize match_engine
    match_engine = MatchEngine(conn_pool)
    yield match_engine
    print("TEARDOWN")
    os.environ["VERBOSE"] = "0"
Example #4
0
def match_engine():
    print("SETUP")
    os.environ["VERBOSE"] = "1"

    dump_port_input = os.path.join(os.path.dirname(__file__), "../dump_input/dump/default")

    dedicated_dbs = {}
    dedicated_dbs['CONFIG_DB'] = os.path.join(dump_port_input, "config_db.json")
    dedicated_dbs['APPL_DB'] = os.path.join(dump_port_input, "appl_db.json")
    dedicated_dbs['STATE_DB'] = os.path.join(dump_port_input, "state_db.json")
    dedicated_dbs['ASIC_DB'] =  os.path.join(dump_port_input, "asic_db.json")
    
    conn = SonicV2Connector()
    # popualate the db ,with mock data
    db_names = list(dedicated_dbs.keys())
    try:
        populate_mock(conn, db_names, dedicated_dbs)
    except Exception as e:
        assert False, "Mock initialization failed: " + str(e)

    conn_pool = ConnectionPool()
    conn_pool.fill(DEFAULT_NAMESPACE, conn, db_names)
    match_engine = MatchEngine(conn_pool)

    yield match_engine
    print("TEARDOWN")
Example #5
0
def get_port_acl_binding(db_wrap, port, ns):
    """
    Verify if the port is not bound to any ACL Table
    
    Args:
        db_wrap: utilities_common.Db() object
        port: Iface name
        ns: namespace

    Returns:
        list: ACL_TABLE names if found, 
                otherwise empty
    """
    ACL = "ACL_TABLE"  # Table to look for port bindings
    if not isinstance(db_wrap, Db):
        raise Exception("db_wrap object is not of type utilities_common.Db")

    conn_pool = ConnectionPool()
    conn_pool.fill(ns, db_wrap.db_clients[ns], db_wrap.db_list)
    m_engine = MatchEngine(conn_pool)
    req = MatchRequest(db="CONFIG_DB",
                       table=ACL,
                       key_pattern="*",
                       field="ports@",
                       value=port,
                       ns=ns,
                       match_entire_list=False)
    ret = m_engine.fetch(req)
    acl_tables, _ = get_matched_keys(ret)
    return acl_tables
Example #6
0
def extract_rid(info, ns):
    r = RedisSource(ConnectionPool())
    r.connect("ASIC_DB", ns)
    vidtorid = {}
    vid_cache = {}  # Cache Entries to reduce number of Redis Calls
    for arg in info.keys():
        mp = get_v_r_map(r, info[arg], vid_cache)
        if mp:
            vidtorid[arg] = mp
    return vidtorid
Example #7
0
def match_engine():
    print("SETUP")
    os.environ["VERBOSE"] = "1"

    from ..mock_tables import mock_multi_asic
    reload(mock_multi_asic)
    from ..mock_tables import dbconnector
    dbconnector.load_namespace_config()

    dump_input = os.path.join(os.path.dirname(__file__), "../dump_input/")
    dedicated_dbs = {}

    conn = SonicV2Connector()
    # popualate the db ,with mock data
    db_names = list(dedicated_dbs.keys())
    try:
        populate_mock(conn, db_names, dedicated_dbs)
    except Exception as e:
        assert False, "Mock initialization failed: " + str(e)

    conn_pool = ConnectionPool()
    dedicated_dbs['CONFIG_DB'] = os.path.join(dump_input,
                                              "dump/default/config_db.json")
    dedicated_dbs['APPL_DB'] = os.path.join(dump_input,
                                            "dump/default/appl_db.json")
    dedicated_dbs['STATE_DB'] = os.path.join(dump_input,
                                             "dump/default/state_db.json")
    dedicated_dbs['ASIC_DB'] = os.path.join(dump_input,
                                            "dump/default/asic_db.json")
    conn_pool.fill(DEFAULT_NAMESPACE,
                   conn_pool.initialize_connector(DEFAULT_NAMESPACE),
                   list(dedicated_dbs.keys()))
    populate_mock(conn_pool.cache[DEFAULT_NAMESPACE][CONN],
                  list(dedicated_dbs.keys()), dedicated_dbs)

    dedicated_dbs['CONFIG_DB'] = os.path.join(dump_input,
                                              "dump/asic0/config_db.json")
    dedicated_dbs['APPL_DB'] = os.path.join(dump_input,
                                            "dump/asic0/appl_db.json")
    dedicated_dbs['STATE_DB'] = os.path.join(dump_input,
                                             "dump/asic0/state_db.json")
    dedicated_dbs['ASIC_DB'] = os.path.join(dump_input,
                                            "dump/asic0/asic_db.json")
    conn_pool.fill("asic0", conn_pool.initialize_connector("asic0"),
                   list(dedicated_dbs.keys()))
    populate_mock(conn_pool.cache["asic0"][CONN], list(dedicated_dbs.keys()),
                  dedicated_dbs)

    dedicated_dbs['CONFIG_DB'] = os.path.join(dump_input,
                                              "dump/asic1/config_db.json")
    dedicated_dbs['APPL_DB'] = os.path.join(dump_input,
                                            "dump/asic1/appl_db.json")
    dedicated_dbs['STATE_DB'] = os.path.join(dump_input,
                                             "dump/asic1/state_db.json")
    dedicated_dbs['ASIC_DB'] = os.path.join(dump_input,
                                            "dump/asic1/asic_db.json")
    conn_pool.fill("asic1", conn_pool.initialize_connector("asic1"),
                   list(dedicated_dbs.keys()))
    populate_mock(conn_pool.cache["asic1"][CONN], list(dedicated_dbs.keys()),
                  dedicated_dbs)

    match_engine = MatchEngine(conn_pool)
    yield match_engine
    print("TEARDOWN")