Skip to content

Commit

Permalink
[vstest]: fix string format compatibility issue for python2 and swig
Browse files Browse the repository at this point in the history
swig in python2 cannot take unicode format string

Signed-off-by: Guohan Lu <[email protected]>
  • Loading branch information
lguohan committed Jul 7, 2020
1 parent 26efbcf commit 8807b40
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,8 @@ def setReadOnlyAttr(self, obj, attr, val):
fvp = swsscommon.FieldValuePairs([(attr, val)])
key = "SAI_OBJECT_TYPE_SWITCH:" + swRid

ntf.send("set_ro", key, fvp)
# explicit convert unicode string to str for python2
ntf.send("set_ro", str(key), fvp)

def create_acl_table(self, table, type, ports):
tbl = swsscommon.Table(self.cdb, "ACL_TABLE")
Expand Down
10 changes: 6 additions & 4 deletions tests/port_dpb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from swsscommon import swsscommon
import redis
import time
import os
import pytest
Expand All @@ -26,8 +25,7 @@ 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,
encoding="utf-8", decode_responses=True)
self._counters_db = dvs.get_counters_db()
self._dvs_asic_db = dvs.get_asic_db()

def set_name(self, name):
Expand Down Expand Up @@ -173,7 +171,11 @@ def exists_in_app_db(self):
return status

def sync_oid(self):
self._oid = self._counters_db.hget("COUNTERS_PORT_NAME_MAP", self.get_name())
fvs = dict(self._counters_db.get_entry("COUNTERS_PORT_NAME_MAP", ""))
try:
self._oid = fvs[self.get_name()]
except KeyError:
self._oid = None

"""
Expectation of the caller is that the port does exist in ASIC DB.
Expand Down
3 changes: 2 additions & 1 deletion tests/test_setro.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def test_SetReadOnlyAttribute(self, dvs, testlog):

print(key)

ntf.send("set_ro", key, fvp)
# explicit convert unicode string to str for python2
ntf.send("set_ro", str(key), fvp)

# make action on appdb so orchagent will get RO value
# read asic db to see if orchagent behaved correctly
3 changes: 2 additions & 1 deletion tests/test_watermark.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def set_counter(self, dvs, obj_type, obj_id, attr, val):
fvp = swsscommon.FieldValuePairs([(attr, val)])
key = rid

ntf.send("set_stats", key, fvp)
# explicit convert unicode string to str for python2
ntf.send("set_stats", str(key), fvp)

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

Expand Down

0 comments on commit 8807b40

Please sign in to comment.