Skip to content

Commit 9c71203

Browse files
committed
[vstest]: let redis decodes the response to be string instead of bytes
python3 works on string instead of bytestring Signed-off-by: Guohan Lu <[email protected]>
1 parent c7c63ee commit 9c71203

File tree

6 files changed

+84
-72
lines changed

6 files changed

+84
-72
lines changed

tests/conftest.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -451,13 +451,15 @@ def add_log_marker(self, file=None):
451451
return marker
452452

453453
def SubscribeAppDbObject(self, objpfx):
454-
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.APPL_DB)
454+
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.APPL_DB,
455+
encoding="utf-8", decode_responses=True)
455456
pubsub = r.pubsub()
456457
pubsub.psubscribe("__keyspace@0__:%s*" % objpfx)
457458
return pubsub
458459

459460
def SubscribeAsicDbObject(self, objpfx):
460-
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB)
461+
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB,
462+
encoding="utf-8", decode_responses=True)
461463
pubsub = r.pubsub()
462464
pubsub.psubscribe("__keyspace@1__:ASIC_STATE:%s*" % objpfx)
463465
return pubsub
@@ -486,7 +488,8 @@ def CountSubscribedObjects(self, pubsub, ignore=None, timeout=10):
486488
return (nadd, ndel)
487489

488490
def GetSubscribedAppDbObjects(self, pubsub, ignore=None, timeout=10):
489-
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.APPL_DB)
491+
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.APPL_DB,
492+
encoding="utf-8", decode_responses=True)
490493

491494
addobjs = []
492495
delobjs = []
@@ -529,7 +532,8 @@ def GetSubscribedAppDbObjects(self, pubsub, ignore=None, timeout=10):
529532

530533

531534
def GetSubscribedAsicDbObjects(self, pubsub, ignore=None, timeout=10):
532-
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB)
535+
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB,
536+
encoding="utf-8", decode_responses=True)
533537

534538
addobjs = []
535539
delobjs = []
@@ -560,7 +564,8 @@ def GetSubscribedAsicDbObjects(self, pubsub, ignore=None, timeout=10):
560564

561565
def SubscribeDbObjects(self, dbobjs):
562566
# assuming all the db object pairs are in the same db instance
563-
r = redis.Redis(unix_socket_path=self.redis_sock)
567+
r = redis.Redis(unix_socket_path=self.redis_sock, encoding="utf-8",
568+
decode_responses=True)
564569
pubsub = r.pubsub()
565570
substr = ""
566571
for db, obj in dbobjs:
@@ -852,7 +857,8 @@ def setReadOnlyAttr(self, obj, attr, val):
852857
assert len(keys) == 1
853858

854859
swVid = keys[0]
855-
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB)
860+
r = redis.Redis(unix_socket_path=self.redis_sock, db=swsscommon.ASIC_DB,
861+
encoding="utf-8", decode_responses=True)
856862
swRid = r.hget("VIDTORID", swVid)
857863

858864
assert swRid is not None

tests/port_dpb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def __init__(self, dvs, name = None):
2626
self._app_db_ptbl = swsscommon.Table(self._app_db, swsscommon.APP_PORT_TABLE_NAME)
2727
self._asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
2828
self._asic_db_ptbl = swsscommon.Table(self._asic_db, "ASIC_STATE:SAI_OBJECT_TYPE_PORT")
29-
self._counters_db = redis.Redis(unix_socket_path=self._dvs.redis_sock, db=swsscommon.COUNTERS_DB)
29+
self._counters_db = redis.Redis(unix_socket_path=self._dvs.redis_sock, db=swsscommon.COUNTERS_DB,
30+
encoding="utf-8", decode_responses=True)
3031
self._dvs_asic_db = dvs.get_asic_db()
3132

3233
def set_name(self, name):

tests/test_crm.py

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ def setReadOnlyAttr(dvs, obj, attr, val):
4646
assert len(keys) == 1
4747

4848
swVid = keys[0]
49-
r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB)
49+
r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB,
50+
encoding="utf-8", decode_responses=True)
5051
swRid = r.hget("VIDTORID", swVid)
5152

5253
assert swRid is not None
@@ -701,225 +702,225 @@ def test_CrmAcl(self, dvs, testlog):
701702
assert key not in keys
702703

703704
def test_CrmAclGroup(self, dvs, testlog):
704-
705+
705706
db = swsscommon.DBConnector(4, dvs.redis_sock, 0)
706707
adb = swsscommon.DBConnector(1, dvs.redis_sock, 0)
707-
708+
708709
dvs.runcmd("crm config polling interval 1")
709710
bind_ports = ["Ethernet0", "Ethernet4", "Ethernet8"]
710-
711+
711712
# create ACL table
712713
tbl = swsscommon.Table(db, "ACL_TABLE")
713714
fvs = swsscommon.FieldValuePairs([("policy_desc", "testv6"), ("type", "L3V6"), ("ports", ",".join(bind_ports))])
714715
tbl.set("test-aclv6", fvs)
715-
716+
716717
time.sleep(2)
717718
atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP")
718719
entry_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used')
719720
assert entry_used_counter == 3
720-
721+
721722
# remove ACL table
722723
#tbl._del("test-aclv6")
723724
#time.sleep(2)
724725
#atbl = swsscommon.Table(adb, "ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE_GROUP")
725726
#table_used_counter = getCrmCounterValue(dvs, 'ACL_STATS:INGRESS:PORT', 'crm_stats_acl_group_used')
726727
#assert table_used_counter == 0
727-
728+
728729
def test_Configure(self, dvs, testlog):
729-
730+
730731
#polling interval
731732
dvs.runcmd("crm config polling interval 10")
732733
time.sleep(2)
733734
polling_interval = getCrmConfigValue(dvs, 'Config', 'polling_interval')
734735
assert polling_interval == 10
735-
736+
736737
def test_Configure_ipv4_route(self, dvs, testlog):
737-
738+
738739
#ipv4 route low/high threshold/type
739740
dvs.runcmd("crm config thresholds ipv4 route low 50")
740741
dvs.runcmd("crm config thresholds ipv4 route high 90")
741742
dvs.runcmd("crm config thresholds ipv4 route type percentage")
742-
743+
743744
time.sleep(2)
744745
threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv4_route_low_threshold')
745746
assert threshold_low == 50
746747
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv4_route_high_threshold')
747748
assert threshold_high == 90
748749
threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv4_route_threshold_type')
749750
assert threshold_type == 'percentage'
750-
751+
751752
def test_Configure_ipv6_route(self, dvs, testlog):
752-
753+
753754
#ipv6 route low/high threshold/type
754755
dvs.runcmd("crm config thresholds ipv6 route low 50")
755756
dvs.runcmd("crm config thresholds ipv6 route high 90")
756757
dvs.runcmd("crm config thresholds ipv6 route type used")
757-
758+
758759
time.sleep(2)
759760
threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv6_route_low_threshold')
760761
assert threshold_low == 50
761762
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv6_route_high_threshold')
762763
assert threshold_high == 90
763764
threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv6_route_threshold_type')
764765
assert threshold_type == 'used'
765-
766+
766767
def test_Configure_ipv4_nexthop(self, dvs, testlog):
767-
768+
768769
#ipv4 nexthop low/high threshold/type
769770
dvs.runcmd("crm config thresholds ipv4 nexthop low 50")
770771
dvs.runcmd("crm config thresholds ipv4 nexthop high 90")
771772
dvs.runcmd("crm config thresholds ipv4 nexthop type 'percentage'")
772-
773+
773774
time.sleep(2)
774775
threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv4_nexthop_low_threshold')
775776
assert threshold_low == 50
776777
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv4_nexthop_high_threshold')
777778
assert threshold_high == 90
778779
threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv4_nexthop_threshold_type')
779780
assert threshold_type == 'percentage'
780-
781+
781782
def test_Configure_ipv6_nexthop(self, dvs, testlog):
782-
783+
783784
#ipv6 nexthop low/high threshold/type
784785
dvs.runcmd("crm config thresholds ipv6 nexthop low 50")
785786
dvs.runcmd("crm config thresholds ipv6 nexthop high 90")
786787
dvs.runcmd("crm config thresholds ipv6 nexthop type free")
787-
788+
788789
time.sleep(2)
789790
threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv6_nexthop_low_threshold')
790791
assert threshold_low == 50
791792
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv6_nexthop_high_threshold')
792793
assert threshold_high == 90
793794
threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv6_nexthop_threshold_type')
794795
assert threshold_type == 'free'
795-
796+
796797
def test_Configure_ipv4_neighbor(self, dvs, testlog):
797-
798+
798799
#ipv4 neighbor low/high threshold/type
799800
dvs.runcmd("crm config thresholds ipv4 neighbor low 50")
800801
dvs.runcmd("crm config thresholds ipv4 neighbor high 90")
801802
dvs.runcmd("crm config thresholds ipv4 neighbor type percentage")
802-
803+
803804
time.sleep(2)
804805
threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv4_neighbor_low_threshold')
805806
assert threshold_low == 50
806807
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv4_neighbor_high_threshold')
807808
assert threshold_high == 90
808809
threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv4_neighbor_threshold_type')
809810
assert threshold_type == 'percentage'
810-
811+
811812
def test_Configure_ipv6_neighbor(self, dvs, testlog):
812-
813+
813814
#ipv6 neighbor low/high threshold/type
814815
dvs.runcmd("crm config thresholds ipv6 neighbor low 50")
815816
dvs.runcmd("crm config thresholds ipv6 neighbor high 90")
816817
dvs.runcmd("crm config thresholds ipv6 neighbor type used")
817-
818+
818819
time.sleep(2)
819820
threshold_low = getCrmConfigValue(dvs, 'Config', 'ipv6_neighbor_low_threshold')
820821
assert threshold_low == 50
821822
threshold_high = getCrmConfigValue(dvs, 'Config', 'ipv6_neighbor_high_threshold')
822823
assert threshold_high == 90
823824
threshold_type = getCrmConfigStr(dvs, 'Config', 'ipv6_neighbor_threshold_type')
824825
assert threshold_type == 'used'
825-
826+
826827
def test_Configure_group_member(self, dvs, testlog):
827-
828+
828829
#nexthop group member low/high threshold/type
829830
dvs.runcmd("crm config thresholds nexthop group member low 50")
830831
dvs.runcmd("crm config thresholds nexthop group member high 90")
831832
dvs.runcmd("crm config thresholds nexthop group member type percentage")
832-
833+
833834
time.sleep(2)
834835
threshold_low = getCrmConfigValue(dvs, 'Config', 'nexthop_group_member_low_threshold')
835836
assert threshold_low == 50
836837
threshold_high = getCrmConfigValue(dvs, 'Config', 'nexthop_group_member_high_threshold')
837838
assert threshold_high == 90
838839
threshold_type = getCrmConfigStr(dvs, 'Config', 'nexthop_group_member_threshold_type')
839840
assert threshold_type == 'percentage'
840-
841+
841842
def test_Configure_group_object(self, dvs, testlog):
842-
843+
843844
#nexthop group object low/high threshold/type
844845
dvs.runcmd("crm config thresholds nexthop group object low 50")
845846
dvs.runcmd("crm config thresholds nexthop group object high 90")
846847
dvs.runcmd("crm config thresholds nexthop group object type free")
847-
848+
848849
time.sleep(2)
849850
threshold_low = getCrmConfigValue(dvs, 'Config', 'nexthop_group_low_threshold')
850851
assert threshold_low == 50
851852
threshold_high = getCrmConfigValue(dvs, 'Config', 'nexthop_group_high_threshold')
852853
assert threshold_high == 90
853854
threshold_type = getCrmConfigStr(dvs, 'Config', 'nexthop_group_threshold_type')
854855
assert threshold_type == 'free'
855-
856+
856857
def test_Configure_acl_table(self, dvs, testlog):
857-
858+
858859
#thresholds acl table low/high threshold/type
859860
dvs.runcmd("crm config thresholds acl table low 50")
860861
dvs.runcmd("crm config thresholds acl table high 90")
861862
dvs.runcmd("crm config thresholds acl table type percentage")
862-
863+
863864
time.sleep(2)
864865
threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_table_low_threshold')
865866
assert threshold_low == 50
866867
threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_table_high_threshold')
867868
assert threshold_high == 90
868869
threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_table_threshold_type')
869870
assert threshold_type == 'percentage'
870-
871+
871872
def test_Configure_acl_group(self, dvs, testlog):
872-
873+
873874
#thresholds acl group low/high threshold/type
874875
dvs.runcmd("crm config thresholds acl group low 50")
875876
dvs.runcmd("crm config thresholds acl group high 90")
876877
dvs.runcmd("crm config thresholds acl group type used")
877-
878+
878879
time.sleep(2)
879880
threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_group_low_threshold')
880881
assert threshold_low == 50
881882
threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_group_high_threshold')
882883
assert threshold_high == 90
883884
threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_group_threshold_type')
884885
assert threshold_type == 'used'
885-
886+
886887
def test_Configure_acl_group_entry(self, dvs, testlog):
887-
888+
888889
#thresholds acl group entry low/high threshold/type
889890
dvs.runcmd("crm config thresholds acl group entry low 50")
890891
dvs.runcmd("crm config thresholds acl group entry high 90")
891892
dvs.runcmd("crm config thresholds acl group entry type percentage")
892-
893+
893894
time.sleep(2)
894895
threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_entry_low_threshold')
895896
assert threshold_low == 50
896897
threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_entry_high_threshold')
897898
assert threshold_high == 90
898899
threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_entry_threshold_type')
899900
assert threshold_type == 'percentage'
900-
901+
901902
def test_Configure_acl_group_counter(self, dvs, testlog):
902-
903+
903904
#thresholds acl group counter low/high threshold/type
904905
dvs.runcmd("crm config thresholds acl group counter low 50")
905906
dvs.runcmd("crm config thresholds acl group counter high 90")
906907
dvs.runcmd("crm config thresholds acl group counter type free")
907-
908+
908909
time.sleep(2)
909910
threshold_low = getCrmConfigValue(dvs, 'Config', 'acl_counter_low_threshold')
910911
assert threshold_low == 50
911912
threshold_high = getCrmConfigValue(dvs, 'Config', 'acl_counter_high_threshold')
912913
assert threshold_high == 90
913914
threshold_type = getCrmConfigStr(dvs, 'Config', 'acl_counter_threshold_type')
914915
assert threshold_type == 'free'
915-
916+
916917
def test_Configure_fdb(self, dvs, testlog):
917-
918+
918919
#thresholds fdb low/high threshold/type
919920
dvs.runcmd("crm config thresholds fdb low 50")
920921
dvs.runcmd("crm config thresholds fdb high 90")
921922
dvs.runcmd("crm config thresholds fdb type percentage")
922-
923+
923924
time.sleep(2)
924925
threshold_low = getCrmConfigValue(dvs, 'Config', 'fdb_entry_low_threshold')
925926
assert threshold_low == 50

tests/test_port_config.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@ def getPortName(self, dvs, port_vid):
2828

2929

3030
def getPortOid(self, dvs, port_name):
31-
cnt_r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.COUNTERS_DB)
31+
cnt_r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.COUNTERS_DB,
32+
encoding="utf-8", decode_responses=True)
3233
return cnt_r.hget("COUNTERS_PORT_NAME_MAP", port_name);
3334

3435

3536
def getVIDfromRID(self, dvs, port_rid):
36-
asic_r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB)
37+
asic_r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB,
38+
encoding="utf-8", decode_responses=True)
3739
return asic_r.hget("RIDTOVID", port_rid);
3840

3941
def test_port_hw_lane(self, dvs):

tests/test_setro.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def test_SetReadOnlyAttribute(self, dvs, testlog):
2020

2121
swVid = keys[0]
2222

23-
r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB)
23+
r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB,
24+
encoding="utf-8", decode_responses=True)
2425

2526
swRid = r.hget("VIDTORID", swVid)
2627

0 commit comments

Comments
 (0)