diff --git a/tests/conftest.py b/tests/conftest.py index 30ead8dd7087..b0c2a54cde27 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -451,13 +451,15 @@ def add_log_marker(self, file=None): return marker def SubscribeAppDbObject(self, objpfx): - r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.APPL_DB) + r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.APPL_DB, + encoding="utf-8", decode_responses=True) pubsub = r.pubsub() pubsub.psubscribe("__keyspace@0__:%s*" % objpfx) return pubsub def SubscribeAsicDbObject(self, objpfx): - r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB) + r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB, + encoding="utf-8", decode_responses=True) pubsub = r.pubsub() pubsub.psubscribe("__keyspace@1__:ASIC_STATE:%s*" % objpfx) return pubsub @@ -486,7 +488,8 @@ def CountSubscribedObjects(self, pubsub, ignore=None, timeout=10): return (nadd, ndel) def GetSubscribedAppDbObjects(self, pubsub, ignore=None, timeout=10): - r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.APPL_DB) + r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.APPL_DB, + encoding="utf-8", decode_responses=True) addobjs = [] delobjs = [] @@ -529,7 +532,8 @@ def GetSubscribedAppDbObjects(self, pubsub, ignore=None, timeout=10): def GetSubscribedAsicDbObjects(self, pubsub, ignore=None, timeout=10): - r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB) + r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB, + encoding="utf-8", decode_responses=True) addobjs = [] delobjs = [] @@ -560,7 +564,8 @@ def GetSubscribedAsicDbObjects(self, pubsub, ignore=None, timeout=10): def SubscribeDbObjects(self, dbobjs): # assuming all the db object pairs are in the same db instance - r = redis.Redis(unix_socket_path=self.redis_sock) + r = redis.Redis(unix_socket_path=self.redis_sock, encoding="utf-8", + decode_responses=True) pubsub = r.pubsub() substr = "" for db, obj in dbobjs: @@ -852,7 +857,8 @@ def setReadOnlyAttr(self, obj, attr, val): assert len(keys) == 1 swVid = keys[0] - r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB) + r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB, + encoding="utf-8", decode_responses=True) swRid = r.hget("VIDTORID", swVid) assert swRid is not None diff --git a/tests/port_dpb.py b/tests/port_dpb.py index 87d19b755e1a..6d0b07427ade 100644 --- a/tests/port_dpb.py +++ b/tests/port_dpb.py @@ -26,7 +26,8 @@ def __init__(self, dvs, name = None): self._app_db_ptbl = swsscommon.Table(self._app_db, swsscommon.APP_PORT_TABLE_NAME) self._asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) self._asic_db_ptbl = swsscommon.Table(self._asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT") - self._counters_db = redis.Redis(unix_socket_path=self._dvs.redis_sock, db=swsscommon.COUNTERS_DB) + self._counters_db = redis.Redis(unix_socket_path=self._dvs.redis_sock, db=swsscommon.COUNTERS_DB, + encoding="utf-8", decode_responses=True) self._dvs_asic_db = dvs.get_asic_db() def set_name(self, name): diff --git a/tests/test_crm.py b/tests/test_crm.py index 9d52550af155..41c06751e268 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -46,7 +46,8 @@ def setReadOnlyAttr(dvs, obj, attr, val): assert len(keys) == 1 swVid = keys[0] - r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB) + r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB, + encoding="utf-8", decode_responses=True) swRid = r.hget("VIDTORID", swVid) assert swRid is not None @@ -701,45 +702,45 @@ def test_CrmAcl(self, dvs, testlog): assert key not in keys def test_CrmAclGroup(self, dvs, testlog): - + db = swsscommon.DBConnector(4, dvs.redis_sock, 0) adb = swsscommon.DBConnector(1, dvs.redis_sock, 0) - + dvs.runcmd("crm config polling interval 1") bind_ports = ["Ethernet0", "Ethernet4", "Ethernet8"] - + # create ACL table tbl = swsscommon.Table(db, "ACL_TABLE") fvs = swsscommon.FieldValuePairs([("policy_desc", "testv6"), ("type", "L3V6"), ("ports", ",".join(bind_ports))]) tbl.set("test-aclv6", fvs) - + time.sleep(2) atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP") entry_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used') assert entry_used_counter == 3 - + # remove ACL table #tbl._del("test-aclv6") #time.sleep(2) #atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP") #table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used') #assert table_used_counter == 0 - + def test_Configure(self, dvs, testlog): - + #polling interval dvs.runcmd("crm config polling interval 10") time.sleep(2) polling_interval = getCrmConfigValue(dvs, 'Config', 'polling_interval') assert polling_interval == 10 - + def test_Configure_ipv4_route(self, dvs, testlog): - + #ipv4 route low/high threshold/type dvs.runcmd("crm config thresholds ipv4 route low 50") dvs.runcmd("crm config thresholds ipv4 route high 90") dvs.runcmd("crm config thresholds ipv4 route type percentage") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv4_route_low_threshold') assert threshold_low == 50 @@ -747,14 +748,14 @@ def test_Configure_ipv4_route(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv4_route_threshold_type') assert threshold_type == 'percentage' - + def test_Configure_ipv6_route(self, dvs, testlog): - + #ipv6 route low/high threshold/type dvs.runcmd("crm config thresholds ipv6 route low 50") dvs.runcmd("crm config thresholds ipv6 route high 90") dvs.runcmd("crm config thresholds ipv6 route type used") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv6_route_low_threshold') assert threshold_low == 50 @@ -762,14 +763,14 @@ def test_Configure_ipv6_route(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv6_route_threshold_type') assert threshold_type == 'used' - + def test_Configure_ipv4_nexthop(self, dvs, testlog): - + #ipv4 nexthop low/high threshold/type dvs.runcmd("crm config thresholds ipv4 nexthop low 50") dvs.runcmd("crm config thresholds ipv4 nexthop high 90") dvs.runcmd("crm config thresholds ipv4 nexthop type 'percentage'") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv4_nexthop_low_threshold') assert threshold_low == 50 @@ -777,14 +778,14 @@ def test_Configure_ipv4_nexthop(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv4_nexthop_threshold_type') assert threshold_type == 'percentage' - + def test_Configure_ipv6_nexthop(self, dvs, testlog): - + #ipv6 nexthop low/high threshold/type dvs.runcmd("crm config thresholds ipv6 nexthop low 50") dvs.runcmd("crm config thresholds ipv6 nexthop high 90") dvs.runcmd("crm config thresholds ipv6 nexthop type free") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv6_nexthop_low_threshold') assert threshold_low == 50 @@ -792,14 +793,14 @@ def test_Configure_ipv6_nexthop(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv6_nexthop_threshold_type') assert threshold_type == 'free' - + def test_Configure_ipv4_neighbor(self, dvs, testlog): - + #ipv4 neighbor low/high threshold/type dvs.runcmd("crm config thresholds ipv4 neighbor low 50") dvs.runcmd("crm config thresholds ipv4 neighbor high 90") dvs.runcmd("crm config thresholds ipv4 neighbor type percentage") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv4_neighbor_low_threshold') assert threshold_low == 50 @@ -807,14 +808,14 @@ def test_Configure_ipv4_neighbor(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv4_neighbor_threshold_type') assert threshold_type == 'percentage' - + def test_Configure_ipv6_neighbor(self, dvs, testlog): - + #ipv6 neighbor low/high threshold/type dvs.runcmd("crm config thresholds ipv6 neighbor low 50") dvs.runcmd("crm config thresholds ipv6 neighbor high 90") dvs.runcmd("crm config thresholds ipv6 neighbor type used") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv6_neighbor_low_threshold') assert threshold_low == 50 @@ -822,14 +823,14 @@ def test_Configure_ipv6_neighbor(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv6_neighbor_threshold_type') assert threshold_type == 'used' - + def test_Configure_group_member(self, dvs, testlog): - + #nexthop group member low/high threshold/type dvs.runcmd("crm config thresholds nexthop group member low 50") dvs.runcmd("crm config thresholds nexthop group member high 90") dvs.runcmd("crm config thresholds nexthop group member type percentage") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'nexthop_group_member_low_threshold') assert threshold_low == 50 @@ -837,14 +838,14 @@ def test_Configure_group_member(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'nexthop_group_member_threshold_type') assert threshold_type == 'percentage' - + def test_Configure_group_object(self, dvs, testlog): - + #nexthop group object low/high threshold/type dvs.runcmd("crm config thresholds nexthop group object low 50") dvs.runcmd("crm config thresholds nexthop group object high 90") dvs.runcmd("crm config thresholds nexthop group object type free") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'nexthop_group_low_threshold') assert threshold_low == 50 @@ -852,14 +853,14 @@ def test_Configure_group_object(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'nexthop_group_threshold_type') assert threshold_type == 'free' - + def test_Configure_acl_table(self, dvs, testlog): - + #thresholds acl table low/high threshold/type dvs.runcmd("crm config thresholds acl table low 50") dvs.runcmd("crm config thresholds acl table high 90") dvs.runcmd("crm config thresholds acl table type percentage") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_table_low_threshold') assert threshold_low == 50 @@ -867,14 +868,14 @@ def test_Configure_acl_table(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_table_threshold_type') assert threshold_type == 'percentage' - + def test_Configure_acl_group(self, dvs, testlog): - + #thresholds acl group low/high threshold/type dvs.runcmd("crm config thresholds acl group low 50") dvs.runcmd("crm config thresholds acl group high 90") dvs.runcmd("crm config thresholds acl group type used") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_group_low_threshold') assert threshold_low == 50 @@ -882,14 +883,14 @@ def test_Configure_acl_group(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_group_threshold_type') assert threshold_type == 'used' - + def test_Configure_acl_group_entry(self, dvs, testlog): - + #thresholds acl group entry low/high threshold/type dvs.runcmd("crm config thresholds acl group entry low 50") dvs.runcmd("crm config thresholds acl group entry high 90") dvs.runcmd("crm config thresholds acl group entry type percentage") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_entry_low_threshold') assert threshold_low == 50 @@ -897,14 +898,14 @@ def test_Configure_acl_group_entry(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_entry_threshold_type') assert threshold_type == 'percentage' - + def test_Configure_acl_group_counter(self, dvs, testlog): - + #thresholds acl group counter low/high threshold/type dvs.runcmd("crm config thresholds acl group counter low 50") dvs.runcmd("crm config thresholds acl group counter high 90") dvs.runcmd("crm config thresholds acl group counter type free") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_counter_low_threshold') assert threshold_low == 50 @@ -912,14 +913,14 @@ def test_Configure_acl_group_counter(self, dvs, testlog): assert threshold_high == 90 threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_counter_threshold_type') assert threshold_type == 'free' - + def test_Configure_fdb(self, dvs, testlog): - + #thresholds fdb low/high threshold/type dvs.runcmd("crm config thresholds fdb low 50") dvs.runcmd("crm config thresholds fdb high 90") dvs.runcmd("crm config thresholds fdb type percentage") - + time.sleep(2) threshold_low = getCrmConfigValue(dvs, 'Config', 'fdb_entry_low_threshold') assert threshold_low == 50 diff --git a/tests/test_port_config.py b/tests/test_port_config.py index 4698fde93c77..505ed3231b52 100644 --- a/tests/test_port_config.py +++ b/tests/test_port_config.py @@ -28,12 +28,14 @@ def getPortName(self, dvs, port_vid): def getPortOid(self, dvs, port_name): - cnt_r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.COUNTERS_DB) + cnt_r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.COUNTERS_DB, + encoding="utf-8", decode_responses=True) return cnt_r.hget("COUNTERS_PORT_NAME_MAP", port_name); def getVIDfromRID(self, dvs, port_rid): - asic_r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB) + asic_r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB, + encoding="utf-8", decode_responses=True) return asic_r.hget("RIDTOVID", port_rid); def test_port_hw_lane(self, dvs): diff --git a/tests/test_setro.py b/tests/test_setro.py index 6000f0fb8bfa..ceebe9cfbe7c 100644 --- a/tests/test_setro.py +++ b/tests/test_setro.py @@ -20,7 +20,8 @@ def test_SetReadOnlyAttribute(self, dvs, testlog): swVid = keys[0] - r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB) + r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB, + encoding="utf-8", decode_responses=True) swRid = r.hget("VIDTORID", swVid) diff --git a/tests/test_watermark.py b/tests/test_watermark.py index 40342c613cfc..5492944fd9ca 100644 --- a/tests/test_watermark.py +++ b/tests/test_watermark.py @@ -32,7 +32,7 @@ def setup_db(self, dvs): self.flex_db = dvs.get_flex_db() def enable_unittests(self, dvs, status): - db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL") fvp = swsscommon.FieldValuePairs() ntf.send("enable_unittests", status, fvp) @@ -42,7 +42,8 @@ def set_counter(self, dvs, obj_type, obj_id, attr, val): db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL") - r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB) + r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB, + encoding="utf-8", decode_responses=True) rid = r.hget("VIDTORID", obj_id) assert rid is not None @@ -60,7 +61,7 @@ def populate_asic(self, dvs, obj_type, attr, val): for obj_id in oids: self.set_counter(dvs, obj_type, obj_id, attr, val) - + def populate_asic_all(self, dvs, val): self.populate_asic(dvs, "SAI_OBJECT_TYPE_QUEUE", SaiWmStats.queue_shared, val) self.populate_asic(dvs, "SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP", SaiWmStats.pg_shared, val) @@ -71,7 +72,7 @@ def verify_value(self, dvs, obj_ids, table_name, watermark_name, expected_value) counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) table = swsscommon.Table(counters_db, table_name) - + for obj_id in obj_ids: ret = table.get(obj_id) @@ -93,7 +94,7 @@ def set_up_flex_counter(self, dvs): "QUEUE_WATERMARK_STAT_COUNTER:{}".format(q), queue_stats_entry) - pg_stats_entry = {"PG_COUNTER_ID_LIST": + pg_stats_entry = {"PG_COUNTER_ID_LIST": "SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES,SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES"} for pg in self.pgs: self.flex_db.create_entry("FLEX_COUNTER_TABLE", @@ -119,7 +120,7 @@ def set_up(self, dvs): self.pgs = self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP") db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "COUNTERS_QUEUE_TYPE_MAP") + tbl = swsscommon.Table(db, "COUNTERS_QUEUE_TYPE_MAP") self.uc_q = [] self.mc_q = [] @@ -156,7 +157,7 @@ def test_telemetry_period(self, dvs): self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_shared, "0") self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_headroom, "0") self.verify_value(dvs, self.qs, WmTables.periodic, SaiWmStats.queue_shared, "0") - + self.enable_unittests(dvs, "false") @pytest.mark.skip(reason="This test is not stable enough") @@ -173,7 +174,7 @@ def test_lua_plugins(self, dvs): self.verify_value(dvs, self.qs, table_name, SaiWmStats.queue_shared, "192") self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_headroom, "192") self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_shared, "192") - + self.populate_asic_all(dvs, "96") for table_name in [WmTables.user, WmTables.persistent]: @@ -182,7 +183,7 @@ def test_lua_plugins(self, dvs): self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_shared, "192") self.populate_asic_all(dvs, "288") - + for table_name in [WmTables.user, WmTables.persistent]: self.verify_value(dvs, self.qs, table_name, SaiWmStats.queue_shared, "288") self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_headroom, "288") @@ -209,9 +210,9 @@ def test_clear(self, dvs): # make sure the rest is untouched - self.verify_value(dvs, self.pgs, WmTables.user, SaiWmStats.pg_headroom, "288") - self.verify_value(dvs, self.pgs, WmTables.persistent, SaiWmStats.pg_shared, "288") - self.verify_value(dvs, self.pgs, WmTables.persistent, SaiWmStats.pg_headroom, "288") + self.verify_value(dvs, self.pgs, WmTables.user, SaiWmStats.pg_headroom, "288") + self.verify_value(dvs, self.pgs, WmTables.persistent, SaiWmStats.pg_shared, "288") + self.verify_value(dvs, self.pgs, WmTables.persistent, SaiWmStats.pg_headroom, "288") # clear queue unicast persistent watermark, and verify that multicast watermark and user watermarks are not affected @@ -224,8 +225,8 @@ def test_clear(self, dvs): # make sure the rest is untouched - self.verify_value(dvs, self.mc_q, WmTables.persistent, SaiWmStats.queue_shared, "288") - self.verify_value(dvs, self.uc_q, WmTables.user, SaiWmStats.queue_shared, "288") - self.verify_value(dvs, self.mc_q, WmTables.user, SaiWmStats.queue_shared, "288") + self.verify_value(dvs, self.mc_q, WmTables.persistent, SaiWmStats.queue_shared, "288") + self.verify_value(dvs, self.uc_q, WmTables.user, SaiWmStats.queue_shared, "288") + self.verify_value(dvs, self.mc_q, WmTables.user, SaiWmStats.queue_shared, "288") self.enable_unittests(dvs, "false")