Skip to content

Commit 8807b40

Browse files
committed
[vstest]: fix string format compatibility issue for python2 and swig
swig in python2 cannot take unicode format string Signed-off-by: Guohan Lu <[email protected]>
1 parent 26efbcf commit 8807b40

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

tests/conftest.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,8 @@ def setReadOnlyAttr(self, obj, attr, val):
869869
fvp = swsscommon.FieldValuePairs([(attr, val)])
870870
key = "SAI_OBJECT_TYPE_SWITCH:" + swRid
871871

872-
ntf.send("set_ro", key, fvp)
872+
# explicit convert unicode string to str for python2
873+
ntf.send("set_ro", str(key), fvp)
873874

874875
def create_acl_table(self, table, type, ports):
875876
tbl = swsscommon.Table(self.cdb, "ACL_TABLE")

tests/port_dpb.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from swsscommon import swsscommon
2-
import redis
32
import time
43
import os
54
import pytest
@@ -26,8 +25,7 @@ def __init__(self, dvs, name = None):
2625
self._app_db_ptbl = swsscommon.Table(self._app_db, swsscommon.APP_PORT_TABLE_NAME)
2726
self._asic_db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0)
2827
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,
30-
encoding="utf-8", decode_responses=True)
28+
self._counters_db = dvs.get_counters_db()
3129
self._dvs_asic_db = dvs.get_asic_db()
3230

3331
def set_name(self, name):
@@ -173,7 +171,11 @@ def exists_in_app_db(self):
173171
return status
174172

175173
def sync_oid(self):
176-
self._oid = self._counters_db.hget("COUNTERS_PORT_NAME_MAP", self.get_name())
174+
fvs = dict(self._counters_db.get_entry("COUNTERS_PORT_NAME_MAP", ""))
175+
try:
176+
self._oid = fvs[self.get_name()]
177+
except KeyError:
178+
self._oid = None
177179

178180
"""
179181
Expectation of the caller is that the port does exist in ASIC DB.

tests/test_setro.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def test_SetReadOnlyAttribute(self, dvs, testlog):
3939

4040
print(key)
4141

42-
ntf.send("set_ro", key, fvp)
42+
# explicit convert unicode string to str for python2
43+
ntf.send("set_ro", str(key), fvp)
4344

4445
# make action on appdb so orchagent will get RO value
4546
# read asic db to see if orchagent behaved correctly

tests/test_watermark.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def set_counter(self, dvs, obj_type, obj_id, attr, val):
5151
fvp = swsscommon.FieldValuePairs([(attr, val)])
5252
key = rid
5353

54-
ntf.send("set_stats", key, fvp)
54+
# explicit convert unicode string to str for python2
55+
ntf.send("set_stats", str(key), fvp)
5556

5657
def populate_asic(self, dvs, obj_type, attr, val):
5758

0 commit comments

Comments
 (0)