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"
Example #2
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 #3
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 #4
0
def match_engine_masic():
    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")