def test_ConfigDBPipeConnector(): config_db = ConfigDBPipeConnector() config_db.connect(wait_for_init=False) config_db.get_redis_client(config_db.CONFIG_DB).flushdb() config_db.set_entry("TEST_PORT", "Ethernet112", {"alias": "etp1x"}) allconfig = config_db.get_config() assert allconfig["TEST_PORT"]["Ethernet112"]["alias"] == "etp1x" config_db.set_entry("TEST_PORT", "Ethernet112", {"mtu": "12345"}) allconfig = config_db.get_config() assert "alias" not in allconfig["TEST_PORT"]["Ethernet112"] assert allconfig["TEST_PORT"]["Ethernet112"]["mtu"] == "12345" config_db.mod_config(allconfig) allconfig["TEST_PORT"]["Ethernet113"] = None allconfig["TEST_VLAN"] = None config_db.mod_config(allconfig) allconfig.setdefault("ACL_TABLE", {}).setdefault( "EVERFLOW", {})["ports"] = ["Ethernet0", "Ethernet4", "Ethernet8"] config_db.mod_config(allconfig) allconfig = config_db.get_config() config_db.delete_table("TEST_PORT") config_db.delete_table("ACL_TABLE") allconfig = config_db.get_config() assert len(allconfig) == 0
def test_ConfigDBPipeConnectorSeparator(): db = swsscommon.DBConnector("CONFIG_DB", 0, True) config_db = ConfigDBPipeConnector() config_db.db_connect("CONFIG_DB", False, False) config_db.get_redis_client(config_db.CONFIG_DB).flushdb() config_db.set_entry("TEST_PORT", "Ethernet222", {"alias": "etp2x"}) db.set("ItemWithoutSeparator", "item11") allconfig = config_db.get_config() assert "TEST_PORT" in allconfig assert "ItemWithoutSeparator" not in allconfig alltable = config_db.get_table("*") assert "Ethernet222" in alltable config_db.delete_table("TEST_PORT") db.delete("ItemWithoutSeparator") allconfig = config_db.get_config() assert len(allconfig) == 0
def test_ConfigDBScan(): config_db = ConfigDBPipeConnector() config_db.connect(wait_for_init=False) n = 1000 for i in range(0, n): s = str(i) config_db.mod_entry("TEST_TYPE" + s, "Ethernet" + s, {"alias" + s: "etp" + s}) allconfig = config_db.get_config() assert len(allconfig) == n config_db = ConfigDBConnector() config_db.connect(wait_for_init=False) allconfig = config_db.get_config() assert len(allconfig) == n for i in range(0, n): s = str(i) config_db.delete_table("TEST_TYPE" + s)