Skip to content

Commit

Permalink
[vstest]: let redis decodes the response to be string instead of bytes
Browse files Browse the repository at this point in the history
python3 works on string instead of bytestring

Signed-off-by: Guohan Lu <[email protected]>
  • Loading branch information
lguohan committed Jul 7, 2020
1 parent c7c63ee commit 9c71203
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 72 deletions.
18 changes: 12 additions & 6 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion tests/port_dpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
95 changes: 48 additions & 47 deletions tests/test_crm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -701,225 +702,225 @@ 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
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv4_route_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv6_route_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv4_nexthop_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv6_nexthop_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv4_neighbor_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv6_neighbor_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'nexthop_group_member_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'nexthop_group_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_table_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_group_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_entry_high_threshold')
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
threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_counter_high_threshold')
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
Expand Down
6 changes: 4 additions & 2 deletions tests/test_port_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion tests/test_setro.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading

0 comments on commit 9c71203

Please sign in to comment.