From 8807b4060605eaad32997bdc302c3e3b999c92d3 Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sun, 5 Jul 2020 03:15:03 +0000 Subject: [PATCH] [vstest]: fix string format compatibility issue for python2 and swig swig in python2 cannot take unicode format string Signed-off-by: Guohan Lu --- tests/conftest.py | 3 ++- tests/port_dpb.py | 10 ++++++---- tests/test_setro.py | 3 ++- tests/test_watermark.py | 3 ++- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index b0c2a54cde27..2bd5972ceabd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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") diff --git a/tests/port_dpb.py b/tests/port_dpb.py index 7688c3f67d67..6c3ddee3eac4 100644 --- a/tests/port_dpb.py +++ b/tests/port_dpb.py @@ -1,5 +1,4 @@ from swsscommon import swsscommon -import redis import time import os import pytest @@ -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): @@ -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. diff --git a/tests/test_setro.py b/tests/test_setro.py index ceebe9cfbe7c..50d66360049b 100644 --- a/tests/test_setro.py +++ b/tests/test_setro.py @@ -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 diff --git a/tests/test_watermark.py b/tests/test_watermark.py index 5492944fd9ca..3a3133e03e33 100644 --- a/tests/test_watermark.py +++ b/tests/test_watermark.py @@ -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):