diff --git a/tests/README.md b/tests/README.md index b12d46faa9b3..85741a252a27 100644 --- a/tests/README.md +++ b/tests/README.md @@ -14,9 +14,9 @@ SWSS, Redis, and all the other required components run inside a virtual switch D ``` sudo modprobe team sudo apt install net-tools ethtool vlan - sudo pip install docker zipp==2.2.1 pytest==4.6.9 flaky redis + sudo pip3 install docker zipp==2.2.1 pytest==4.6.9 flaky redis distro==1.4.0 ``` -3. Install `python-swsscommon_1.0.0_amd64.deb`. You will need to install all the dependencies as well in the following order: +3. Install `python3-swsscommon_1.0.0_amd64.deb`. You will need to install all the dependencies as well in the following order: ``` sudo dpkg -i libnl-3-200_3.5.0-1_amd64.deb @@ -30,7 +30,10 @@ SWSS, Redis, and all the other required components run inside a virtual switch D You can find the dependencies [here](https://sonic-jenkins.westus2.cloudapp.azure.com/job/vs/job/buildimage-vs-all/lastSuccessfulBuild/artifact/target/debs/stretch/), and get this package by: - [Building it from scratch](https://github.com/Azure/sonic-swss-common) - - [Downloading the latest build from Jenkins](https://sonic-jenkins.westus2.cloudapp.azure.com/job/common/job/sonic-swss-common-build/lastSuccessfulBuild/artifact/target/) + - Downloading the latest build from Jenkins + - [Debian](https://sonic-jenkins.westus2.cloudapp.azure.com/job/common/job/sonic-swss-common-build/lastSuccessfulBuild/artifact/target/) + - [Ubuntu 18.04](https://sonic-jenkins.westus2.cloudapp.azure.com/job/common/job/sonic-swss-common-build-ubuntu/lastSuccessfulBuild/artifact/target/) + - [Ubuntu 20.04](https://sonic-jenkins.westus2.cloudapp.azure.com/job/common/job/sonic-swss-common-build-ubuntu-20_04/lastSuccessfulBuild/artifact/target/) 4. Load the `docker-sonic-vs.gz` file into docker. You can get the image by: - [Building it from scratch](https://github.com/Azure/sonic-buildimage) - [Downloading the latest build from Jenkins](https://sonic-jenkins.westus2.cloudapp.azure.com/job/vs/job/buildimage-vs-all/lastSuccessfulBuild/artifact/target/) diff --git a/tests/conftest.py b/tests/conftest.py index c8d676f8b79f..577d5602a65b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -6,10 +6,12 @@ import redis import docker import pytest -import commands import tarfile -import StringIO +import io import subprocess +import sys +if sys.version_info < (3, 0): + import commands from datetime import datetime from swsscommon import swsscommon @@ -21,7 +23,10 @@ from dvslib import dvs_policer def ensure_system(cmd): - (rc, output) = commands.getstatusoutput(cmd) + if sys.version_info < (3, 0): + (rc, output) = commands.getstatusoutput(cmd) + else: + (rc, output) = subprocess.getstatusoutput(cmd) if rc: raise RuntimeError('Failed to run command: %s. rc=%d. output: %s' % (cmd, rc, output)) @@ -138,9 +143,9 @@ def runcmd(self, cmd): try: out = subprocess.check_output("ip netns exec %s %s" % (self.nsname, cmd), stderr=subprocess.STDOUT, shell=True) except subprocess.CalledProcessError as e: - print "------rc={} for cmd: {}------".format(e.returncode, e.cmd) - print e.output.rstrip() - print "------" + print("------rc={} for cmd: {}------".format(e.returncode, e.cmd)) + print(e.output.rstrip()) + print("------") return e.returncode return 0 @@ -148,7 +153,7 @@ def runcmd_async(self, cmd): return subprocess.Popen("ip netns exec %s %s" % (self.nsname, cmd), shell=True) def runcmd_output(self, cmd): - return subprocess.check_output("ip netns exec %s %s" % (self.nsname, cmd), shell=True) + return subprocess.check_output("ip netns exec %s %s" % (self.nsname, cmd), shell=True).decode('utf-8') class DockerVirtualSwitch(object): APP_DB_ID = 0 @@ -189,7 +194,10 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None): for ctn in self.client.containers.list(): if ctn.name == name: self.ctn = ctn - (status, output) = commands.getstatusoutput("docker inspect --format '{{.HostConfig.NetworkMode}}' %s" % name) + if sys.version_info < (3, 0): + (status, output) = commands.getstatusoutput("docker inspect --format '{{.HostConfig.NetworkMode}}' %s" % name) + else: + (status, output) = subprocess.getstatusoutput("docker inspect --format '{{.HostConfig.NetworkMode}}' %s" % name) ctn_sw_id = output.split(':')[1] self.cleanup = False if self.ctn == None: @@ -200,7 +208,10 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None): if ctn.id == ctn_sw_id or ctn.name == ctn_sw_id: ctn_sw_name = ctn.name - (status, output) = commands.getstatusoutput("docker inspect --format '{{.State.Pid}}' %s" % ctn_sw_name) + if sys.version_info < (3, 0): + (status, output) = commands.getstatusoutput("docker inspect --format '{{.State.Pid}}' %s" % ctn_sw_name) + else: + (status, output) = subprocess.getstatusoutput("docker inspect --format '{{.State.Pid}}' %s" % ctn_sw_name) self.ctn_sw_pid = int(output) # create virtual servers @@ -216,7 +227,10 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None): else: self.ctn_sw = self.client.containers.run('debian:jessie', privileged=True, detach=True, command="bash", stdin_open=True) - (status, output) = commands.getstatusoutput("docker inspect --format '{{.State.Pid}}' %s" % self.ctn_sw.name) + if sys.version_info < (3, 0): + (status, output) = commands.getstatusoutput("docker inspect --format '{{.State.Pid}}' %s" % self.ctn_sw.name) + else: + (status, output) = subprocess.getstatusoutput("docker inspect --format '{{.State.Pid}}' %s" % self.ctn_sw.name) self.ctn_sw_pid = int(output) # create virtual server @@ -286,7 +300,7 @@ def check_ready(self, timeout=30): # get process status res = self.ctn.exec_run("supervisorctl status") try: - out = res.output + out = res.output.decode('utf-8') except AttributeError: out = res for l in out.split('\n'): @@ -324,7 +338,7 @@ def net_cleanup(self): res = self.ctn.exec_run("ip link show") try: - out = res.output + out = res.output.decode('utf-8') except AttributeError: out = res for l in out.split('\n'): @@ -337,7 +351,7 @@ def net_cleanup(self): m = re.compile("(eth|lo|Bridge|Ethernet)").match(pname) if not m: self.ctn.exec_run("ip link del {}".format(pname)) - print "remove extra link {}".format(pname) + print("remove extra link {}".format(pname)) return def ctn_restart(self): @@ -391,19 +405,19 @@ def runcmd(self, cmd): res = self.ctn.exec_run(cmd) try: exitcode = res.exit_code - out = res.output + out = res.output.decode('utf-8') except AttributeError: exitcode = 0 out = res if exitcode != 0: - print "-----rc={} for cmd {}-----".format(exitcode, cmd) - print out.rstrip() - print "-----" + print("-----rc={} for cmd {}-----".format(exitcode, cmd)) + print(out.rstrip()) + print("-----") return (exitcode, out) def copy_file(self, path, filename): - tarstr = StringIO.StringIO() + tarstr = io.StringIO() tar = tarfile.open(fileobj=tarstr, mode="w") tar.add(filename, os.path.basename(filename)) tar.close() @@ -439,13 +453,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 @@ -457,7 +473,7 @@ def CountSubscribedObjects(self, pubsub, ignore=None, timeout=10): while True and idle < timeout: message = pubsub.get_message() if message: - print message + print(message) if ignore: fds = message['channel'].split(':') if fds[2] in ignore: @@ -474,7 +490,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 = [] @@ -484,7 +501,7 @@ def GetSubscribedAppDbObjects(self, pubsub, ignore=None, timeout=10): while True and idle < timeout: message = pubsub.get_message() if message: - print message + print(message) key = message['channel'].split(':', 1)[1] # In producer/consumer_state_table scenarios, every entry will # show up twice for every push/pop operation, so skip the second @@ -517,7 +534,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 = [] @@ -526,7 +544,7 @@ def GetSubscribedAsicDbObjects(self, pubsub, ignore=None, timeout=10): while True and idle < timeout: message = pubsub.get_message() if message: - print message + print(message) key = message['channel'].split(':', 1)[1] if ignore: fds = message['channel'].split(':') @@ -548,7 +566,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: @@ -860,7 +879,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 @@ -871,7 +891,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/dvslib/dvs_vlan.py b/tests/dvslib/dvs_vlan.py index b22ac9cf1218..adca18b0e72b 100644 --- a/tests/dvslib/dvs_vlan.py +++ b/tests/dvslib/dvs_vlan.py @@ -1,4 +1,4 @@ -from dvs_database import DVSDatabase +from .dvs_database import DVSDatabase class DVSVlan(object): def __init__(self, adb, cdb, sdb, cntrdb, appdb): diff --git a/tests/port_dpb.py b/tests/port_dpb.py index 5a5217ca6077..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,7 +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) + self._counters_db = dvs.get_counters_db() self._dvs_asic_db = dvs.get_asic_db() def set_name(self, name): @@ -87,7 +86,7 @@ def get_oid(self): return self._oid def print_port(self): - print "Port: %s Lanes: %s Speed: %d, Index: %d"%(self._name, self._lanes, self._speed, self._index) + print("Port: %s Lanes: %s Speed: %d, Index: %d"%(self._name, self._lanes, self._speed, self._index)) def port_merge(self, child_ports): child_ports.sort(key=lambda x: x.get_port_num()) @@ -111,7 +110,7 @@ def port_split(self, child_ports): child_port_list = [] port_num = self.get_port_num() num_lanes = len(self._lanes) - offset = num_lanes/child_ports; + offset = num_lanes//child_ports lanes_per_child = offset for i in range(child_ports): child_port_num = port_num + (i * offset) @@ -120,7 +119,7 @@ def port_split(self, child_ports): child_port_lanes = [] for j in range(lanes_per_child): child_port_lanes.append(self._lanes[(i*offset)+j]) - child_port_speed = self._speed/child_ports + child_port_speed = self._speed//child_ports child_port_index = self._index child_port = Port(self._dvs, child_port_name) @@ -172,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. @@ -218,7 +221,7 @@ def verify_asic_db(self): (status, fvs) = self._asic_db_ptbl.get(self.get_oid()) assert(status == True) fvs_dict = self.get_fvs_dict(fvs) - if (fvs_dict.has_key("SAI_PORT_ATTR_HW_LANE_LIST")): + if "SAI_PORT_ATTR_HW_LANE_LIST" in fvs_dict: assert(fvs_dict['SAI_PORT_ATTR_HW_LANE_LIST'] == self.get_lanes_asic_db_str()) assert(fvs_dict['SAI_PORT_ATTR_SPEED'] == str(self.get_speed())) diff --git a/tests/test_crm.py b/tests/test_crm.py index 9d52550af155..8059507201b7 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -2,7 +2,6 @@ import re import time import json -import redis import pytest from swsscommon import swsscommon @@ -37,28 +36,6 @@ def getCrmConfigStr(dvs, key, counter): return k[1] return "" -def setReadOnlyAttr(dvs, obj, attr, val): - - db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "ASIC_STATE:{0}".format(obj)) - keys = tbl.getKeys() - - assert len(keys) == 1 - - swVid = keys[0] - r = redis.Redis(unix_socket_path=dvs.redis_sock, db=swsscommon.ASIC_DB) - swRid = r.hget("VIDTORID", swVid) - - assert swRid is not None - - ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL") - fvp = swsscommon.FieldValuePairs() - ntf.send("enable_unittests", "true", fvp) - fvp = swsscommon.FieldValuePairs([(attr, val)]) - key = "SAI_OBJECT_TYPE_SWITCH:" + swRid - - ntf.send("set_ro", key, fvp) - def check_syslog(dvs, marker, err_log, expected_cnt): (exitcode, num) = dvs.runcmd(['sh', '-c', "awk \'/%s/,ENDFILE {print;}\' /var/log/syslog | grep \"%s\" | wc -l" % (marker, err_log)]) assert num.strip() >= str(expected_cnt) @@ -73,7 +50,7 @@ def test_CrmFdbEntry(self, dvs, testlog): dvs.servers[2].runcmd("sysctl -w net.ipv6.conf.eth0.disable_ipv6=1") dvs.runcmd("crm config polling interval 1") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') time.sleep(2) @@ -100,7 +77,7 @@ def test_CrmFdbEntry(self, dvs, testlog): tbl.set("Vlan2|Ethernet8", fvs) # update available counter - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '999') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '999') time.sleep(2) @@ -112,7 +89,7 @@ def test_CrmFdbEntry(self, dvs, testlog): assert avail_counter - new_avail_counter == 1 # update available counter - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_FDB_ENTRY', '1000') time.sleep(2) @@ -142,7 +119,7 @@ def test_CrmIpv4Route(self, dvs, testlog): dvs.runcmd("crm config polling interval 1") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') # add static neighbor dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") @@ -159,7 +136,7 @@ def test_CrmIpv4Route(self, dvs, testlog): # add route and update available counter ps.set("2.2.2.0/24", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '999') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '999') time.sleep(2) @@ -173,7 +150,7 @@ def test_CrmIpv4Route(self, dvs, testlog): # remove route and update available counter ps._del("2.2.2.0/24") dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_ROUTE_ENTRY', '1000') time.sleep(2) @@ -212,7 +189,7 @@ def test_CrmIpv6Route(self, dvs, testlog): dvs.runcmd("crm config polling interval 1") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') # get neighbor and arp entry dvs.servers[0].runcmd("ping6 -c 4 fc00::1") @@ -229,7 +206,7 @@ def test_CrmIpv6Route(self, dvs, testlog): # add route and update available counter ps.set("2001::/64", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '999') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '999') time.sleep(2) @@ -243,7 +220,7 @@ def test_CrmIpv6Route(self, dvs, testlog): # remove route and update available counter ps._del("2001::/64") dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_ROUTE_ENTRY', '1000') time.sleep(2) @@ -275,7 +252,7 @@ def test_CrmIpv4Nexthop(self, dvs, testlog): dvs.runcmd("crm config polling interval 1") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') time.sleep(2) @@ -285,7 +262,7 @@ def test_CrmIpv4Nexthop(self, dvs, testlog): # add nexthop and update available counter dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '999') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '999') time.sleep(2) @@ -298,7 +275,7 @@ def test_CrmIpv4Nexthop(self, dvs, testlog): # remove nexthop and update available counter dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEXTHOP_ENTRY', '1000') time.sleep(2) @@ -334,7 +311,7 @@ def test_CrmIpv6Nexthop(self, dvs, testlog): dvs.runcmd("crm config polling interval 1") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') time.sleep(2) @@ -344,7 +321,7 @@ def test_CrmIpv6Nexthop(self, dvs, testlog): # add nexthop and update available counter dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '999') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '999') time.sleep(2) @@ -357,7 +334,7 @@ def test_CrmIpv6Nexthop(self, dvs, testlog): # remove nexthop and update available counter dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEXTHOP_ENTRY', '1000') time.sleep(2) @@ -389,7 +366,7 @@ def test_CrmIpv4Neighbor(self, dvs, testlog): dvs.runcmd("crm config polling interval 1") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') time.sleep(2) @@ -399,7 +376,7 @@ def test_CrmIpv4Neighbor(self, dvs, testlog): # add neighbor and update available counter dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '999') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '999') time.sleep(2) @@ -412,7 +389,7 @@ def test_CrmIpv4Neighbor(self, dvs, testlog): # remove neighbor and update available counter dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV4_NEIGHBOR_ENTRY', '1000') time.sleep(2) @@ -448,7 +425,7 @@ def test_CrmIpv6Neighbor(self, dvs, testlog): dvs.runcmd("crm config polling interval 1") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') time.sleep(2) @@ -458,7 +435,7 @@ def test_CrmIpv6Neighbor(self, dvs, testlog): # add neighbor and update available counter dvs.runcmd("ip -6 neigh replace fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '999') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '999') time.sleep(2) @@ -471,7 +448,7 @@ def test_CrmIpv6Neighbor(self, dvs, testlog): # remove neighbor and update available counter dvs.runcmd("ip -6 neigh del fc00::2 lladdr 11:22:33:44:55:66 dev Ethernet0") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_IPV6_NEIGHBOR_ENTRY', '1000') time.sleep(2) @@ -506,7 +483,7 @@ def test_CrmNexthopGroup(self, dvs, testlog): dvs.runcmd("crm config polling interval 1") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') # add neighbors dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") @@ -524,7 +501,7 @@ def test_CrmNexthopGroup(self, dvs, testlog): # add route and update available counter ps.set("2.2.2.0/24", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '999') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '999') time.sleep(2) @@ -539,7 +516,7 @@ def test_CrmNexthopGroup(self, dvs, testlog): ps._del("2.2.2.0/24") dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_ENTRY', '1000') time.sleep(2) @@ -581,7 +558,7 @@ def test_CrmNexthopGroupMember(self, dvs, testlog): dvs.runcmd("crm config polling interval 1") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') # add neighbors dvs.runcmd("ip neigh replace 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") @@ -599,7 +576,7 @@ def test_CrmNexthopGroupMember(self, dvs, testlog): # add route and update available counter ps.set("2.2.2.0/24", fvs) - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '998') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '998') time.sleep(2) @@ -614,7 +591,7 @@ def test_CrmNexthopGroupMember(self, dvs, testlog): ps._del("2.2.2.0/24") dvs.runcmd("ip neigh del 10.0.0.1 lladdr 11:22:33:44:55:66 dev Ethernet0") dvs.runcmd("ip neigh del 10.0.0.3 lladdr 11:22:33:44:55:66 dev Ethernet4") - setReadOnlyAttr(dvs, 'SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') + dvs.setReadOnlyAttr('SAI_OBJECT_TYPE_SWITCH', 'SAI_SWITCH_ATTR_AVAILABLE_NEXT_HOP_GROUP_MEMBER_ENTRY', '1000') time.sleep(2) @@ -701,45 +678,45 @@ 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 @@ -747,14 +724,14 @@ def test_Configure_ipv4_route(self, dvs, testlog): 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 @@ -762,14 +739,14 @@ def test_Configure_ipv6_route(self, dvs, testlog): 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 @@ -777,14 +754,14 @@ def test_Configure_ipv4_nexthop(self, dvs, testlog): 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 @@ -792,14 +769,14 @@ def test_Configure_ipv6_nexthop(self, dvs, testlog): 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 @@ -807,14 +784,14 @@ def test_Configure_ipv4_neighbor(self, dvs, testlog): 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 @@ -822,14 +799,14 @@ def test_Configure_ipv6_neighbor(self, dvs, testlog): 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 @@ -837,14 +814,14 @@ def test_Configure_group_member(self, dvs, testlog): 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 @@ -852,14 +829,14 @@ def test_Configure_group_object(self, dvs, testlog): 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 @@ -867,14 +844,14 @@ def test_Configure_acl_table(self, dvs, testlog): 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 @@ -882,14 +859,14 @@ def test_Configure_acl_group(self, dvs, testlog): 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 @@ -897,14 +874,14 @@ def test_Configure_acl_group_entry(self, dvs, testlog): 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 @@ -912,14 +889,14 @@ def test_Configure_acl_group_counter(self, dvs, testlog): 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 diff --git a/tests/test_mirror.py b/tests/test_mirror.py index 687315d55d4e..af14ca9d9175 100644 --- a/tests/test_mirror.py +++ b/tests/test_mirror.py @@ -1,5 +1,5 @@ # This test suite covers the functionality of mirror feature in SwSS -import platform +import distro import pytest import time @@ -235,7 +235,7 @@ def remove_fdb(self, vlan, mac): # Ignore testcase in Debian Jessie # TODO: Remove this skip if Jessie support is no longer needed - @pytest.mark.skipif(StrictVersion(platform.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") + @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") def test_MirrorToVlanAddRemove(self, dvs, testlog): """ This test covers basic mirror session creation and removal operation @@ -442,7 +442,7 @@ def test_MirrorToLagAddRemove(self, dvs, testlog): # Ignore testcase in Debian Jessie # TODO: Remove this skip if Jessie support is no longer needed - @pytest.mark.skipif(StrictVersion(platform.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") + @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") def test_MirrorDestMoveVlan(self, dvs, testlog): """ This test tests mirror session destination move from non-VLAN to VLAN diff --git a/tests/test_mirror_ipv6_separate.py b/tests/test_mirror_ipv6_separate.py index 6696b26d2145..966d1217c906 100644 --- a/tests/test_mirror_ipv6_separate.py +++ b/tests/test_mirror_ipv6_separate.py @@ -284,7 +284,7 @@ def test_CreateMirrorIngressAndEgress(self, dvs, testlog): self.create_acl_table(ingress_table, ports, "MIRROR") # Check that the table has been created - table_ids = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE", + table_ids = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE", len(asic_db.default_acl_tables) + 1) table_entries = [oid for oid in table_ids if oid not in asic_db.default_acl_tables] original_entry = table_entries[0] @@ -293,7 +293,7 @@ def test_CreateMirrorIngressAndEgress(self, dvs, testlog): self.create_acl_table(duplicate_ingress_table, ports, "MIRROR") # Check that there is still only one table, and that it is the original table - table_ids = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE", + table_ids = asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE", len(asic_db.default_acl_tables) + 1) table_entries = [oid for oid in table_ids if oid not in asic_db.default_acl_tables] assert table_entries[0] == original_entry @@ -305,14 +305,14 @@ def test_CreateMirrorIngressAndEgress(self, dvs, testlog): self.create_acl_table(egress_table, ports, "MIRROR", "egress") # Check that there are two tables - asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE", + asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE", len(asic_db.default_acl_tables) + 2) # Attempt to create another MIRROR table with egress ACLs self.create_acl_table(duplicate_egress_table, ports, "MIRROR", "egress") # Check that there are still only two tables - asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE", + asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ACL_TABLE", len(asic_db.default_acl_tables) + 2) self.remove_acl_table(ingress_table) diff --git a/tests/test_nhg.py b/tests/test_nhg.py index 4a12590d9af5..91692addd449 100644 --- a/tests/test_nhg.py +++ b/tests/test_nhg.py @@ -1,5 +1,6 @@ import os import re +import sys import time import json import pytest @@ -206,7 +207,7 @@ def asic_route_nhg_fvs(k): if not fvs: return None - print fvs + print(fvs) nhgid = fvs.get("SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID") if nhgid is None: return None @@ -216,7 +217,10 @@ def asic_route_nhg_fvs(k): MAX_ECMP_COUNT = 512 MAX_PORT_COUNT = 10 - IP_INTEGER_BASE = int(ipaddress.IPv4Address(unicode("2.2.2.0"))) + if sys.version_info < (3, 0): + IP_INTEGER_BASE = int(ipaddress.IPv4Address(unicode("2.2.2.0"))) + else: + IP_INTEGER_BASE = int(ipaddress.IPv4Address(str("2.2.2.0"))) config_db = dvs.get_config_db() fvs = {"NULL": "NULL"} diff --git a/tests/test_port_config.py b/tests/test_port_config.py index 4698fde93c77..505ed3231b52 100644 --- a/tests/test_port_config.py +++ b/tests/test_port_config.py @@ -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): diff --git a/tests/test_port_dpb.py b/tests/test_port_dpb.py index 6c72dfda8e69..66ed2bf62730 100644 --- a/tests/test_port_dpb.py +++ b/tests/test_port_dpb.py @@ -63,7 +63,7 @@ def test_port_breakout_one(self, dvs): #print "**** 4X10G --> 4X25G passed ****" dpb.breakin(dvs, ["Ethernet0", "Ethernet1", "Ethernet2", "Ethernet3"]) #print "**** 4X25G --> 1X100G passed ****" - dpb.breakout(dvs, "Ethernet0", maxBreakOut/2) + dpb.breakout(dvs, "Ethernet0", maxBreakOut//2) #print "**** 1X100G --> 2X50G passed ****" dpb.breakin(dvs, ["Ethernet0", "Ethernet2"]) #print "**** 2X50G --> 1X100G passed ****" diff --git a/tests/test_port_mac_learn.py b/tests/test_port_mac_learn.py index b2f1dccceb1b..6731ed7b54cf 100644 --- a/tests/test_port_mac_learn.py +++ b/tests/test_port_mac_learn.py @@ -60,7 +60,7 @@ def check_learn_mode_in_asicdb(self, interface_oid, learn_mode): return True else: return False - + def test_PortMacLearnMode(self, dvs, testlog): self.setup_db(dvs) @@ -126,7 +126,7 @@ def test_PortchannelMacLearnMode(self, dvs, testlog): ("mtu", "9100")]) tbl.set("PortChannel001", fvs) time.sleep(1) - + # create vlan tbl = swsscommon.Table(self.cdb, "VLAN") fvs = swsscommon.FieldValuePairs([("vlanid", "3")]) diff --git a/tests/test_setro.py b/tests/test_setro.py index 896d0c1facb8..50d66360049b 100644 --- a/tests/test_setro.py +++ b/tests/test_setro.py @@ -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) @@ -36,9 +37,10 @@ def test_SetReadOnlyAttribute(self, dvs, testlog): key = "SAI_OBJECT_TYPE_SWITCH:" + swRid - print key + 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_tunnel.py b/tests/test_tunnel.py index bd8273e703d4..d3d5811adb58 100644 --- a/tests/test_tunnel.py +++ b/tests/test_tunnel.py @@ -134,7 +134,7 @@ def remove_and_test_tunnel(self, db, asicdb, tunnel_name): status, fvs = tunnel_table.get(tunnel_sai_obj) # get overlay loopback interface oid to check if it is deleted with the tunnel - overlay_infs_id = {f:v for f,v in fvs}["SAI_TUNNEL_ATTR_OVERLAY_INTERFACE"] + overlay_infs_id = {f:v for f,v in fvs}["SAI_TUNNEL_ATTR_OVERLAY_INTERFACE"] ps = swsscommon.ProducerStateTable(db, self.APP_TUNNEL_DECAP_TABLE_NAME) ps.set(tunnel_name, create_fvs(), 'DEL') diff --git a/tests/test_vlan.py b/tests/test_vlan.py index 39b9bf76555a..79b76f73ceb9 100644 --- a/tests/test_vlan.py +++ b/tests/test_vlan.py @@ -1,4 +1,4 @@ -import platform +import distro import pytest from distutils.version import StrictVersion @@ -158,7 +158,7 @@ def test_VlanIncrementalConfig(self, dvs): self.dvs_vlan.remove_vlan(vlan) self.dvs_vlan.get_and_verify_vlan_ids(0) - @pytest.mark.skipif(StrictVersion(platform.linux_distribution()[1]) <= StrictVersion('8.9'), + @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") @pytest.mark.parametrize("test_input, expected", [ (["Vla", "2"], 0), @@ -185,7 +185,7 @@ def test_AddVlanWithIncorrectKeyPrefix(self, dvs, test_input, expected): self.dvs_vlan.remove_vlan(vlan_id) self.dvs_vlan.get_and_verify_vlan_ids(0) - @pytest.mark.skipif(StrictVersion(platform.linux_distribution()[1]) <= StrictVersion('8.9'), + @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") @pytest.mark.parametrize("test_input, expected", [ (["Vlan", "abc"], 0), @@ -277,7 +277,7 @@ def test_RemoveNonexistentVlan(self, dvs): self.dvs_vlan.remove_vlan(vlan) self.dvs_vlan.get_and_verify_vlan_ids(0) - @pytest.mark.skipif(StrictVersion(platform.linux_distribution()[1]) <= StrictVersion('8.9'), + @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") @pytest.mark.parametrize("test_input, expected", [ (["tagging_mode", "untagged"], [1, "SAI_VLAN_TAGGING_MODE_UNTAGGED"]), @@ -385,7 +385,7 @@ def test_VlanDbData(self, dvs): self.dvs_vlan.remove_vlan(vlan) - @pytest.mark.skipif(StrictVersion(platform.linux_distribution()[1]) <= StrictVersion('8.9'), + @pytest.mark.skipif(StrictVersion(distro.linux_distribution()[1]) <= StrictVersion('8.9'), reason="Debian 8.9 or before has no support") @pytest.mark.parametrize("test_input, expected", [ (["untagged"], ["SAI_VLAN_TAGGING_MODE_UNTAGGED"]), diff --git a/tests/test_vrf.py b/tests/test_vrf.py index 6b04ce63f273..f3d11c57756e 100644 --- a/tests/test_vrf.py +++ b/tests/test_vrf.py @@ -44,7 +44,7 @@ def is_vrf_attributes_correct(self, db, table, key, expected_attributes): assert status, "Got an error when get a key" # filter the fake 'NULL' attribute out - fvs = filter(lambda x : x != ('NULL', 'NULL'), fvs) + fvs = [x for x in fvs if x != ('NULL', 'NULL')] attr_keys = {entry[0] for entry in fvs} assert attr_keys == set(expected_attributes.keys()) @@ -78,7 +78,7 @@ def vrf_create(self, dvs, vrf_name, attributes, expected_attributes): assert len(intf_entries) == 1 assert intf_entries[0] == vrf_name exp_attr = {} - for an in xrange(len(attributes)): + for an in range(len(attributes)): exp_attr[attributes[an][0]] = attributes[an][1] self.is_vrf_attributes_correct(self.pdb, "VRF_TABLE", vrf_name, exp_attr) @@ -142,7 +142,7 @@ def boolean_gen(self): def mac_addr_gen(self): - ns = [random.randint(0, 255) for _ in xrange(6)] + ns = [random.randint(0, 255) for _ in range(6)] ns[0] &= 0xfe mac = ':'.join("%02x" % n for n in ns) return mac, mac.upper() @@ -175,15 +175,15 @@ def test_VRFMgr_Comprehensive(self, dvs, testlog): ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', self.packet_action_gen), ] - random.seed(int(time.clock())) + random.seed(int(time.time())) - for n in xrange(2**len(attributes)): + for n in range(2**len(attributes)): # generate testcases for all combinations of attributes req_attr = [] exp_attr = {} vrf_name = "Vrf_%d" % n bmask = 0x1 - for an in xrange(len(attributes)): + for an in range(len(attributes)): if (bmask & n) > 0: req_res, exp_res = attributes[an][2]() req_attr.append((attributes[an][0], req_res)) @@ -228,7 +228,7 @@ def test_VRFMgr_Update(self, dvs, testlog): ('l3_mc_action', 'SAI_VIRTUAL_ROUTER_ATTR_UNKNOWN_L3_MULTICAST_PACKET_ACTION', self.packet_action_gen), ] - random.seed(int(time.clock())) + random.seed(int(time.time())) state = self.vrf_create(dvs, "Vrf_a", [ diff --git a/tests/test_warm_reboot.py b/tests/test_warm_reboot.py index 8d327873f3ab..5ad0bc7b9b14 100644 --- a/tests/test_warm_reboot.py +++ b/tests/test_warm_reboot.py @@ -209,31 +209,31 @@ def setup_initial_neighbors(dvs): for i in range(8, 8+NUM_INTF): for j in range(NUM_NEIGH_PER_INTF): dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+2)) - dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+2)) + dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4, j+2)) time.sleep(1) for i in range(8, 8+NUM_INTF): for j in range(NUM_NEIGH_PER_INTF): - dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+2)]) - dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+2)]) + dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4, j+2)]) + dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4, j+2)]) # Del half of the ips and a new half of the ips # note: the first ipv4 can not be deleted only def del_and_add_neighbors(dvs): for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.servers[i].runcmd("ip addr del {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF/2+2)) - dvs.servers[i].runcmd("ip -6 addr del {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF/2+2)) + for j in range(NUM_NEIGH_PER_INTF//2): + dvs.servers[i].runcmd("ip addr del {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF//2+2)) + dvs.servers[i].runcmd("ip -6 addr del {}00::{}/64 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF//2+2)) dvs.servers[i].runcmd("ip addr add {}.0.0.{}/24 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF+2)) - dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4,j+NUM_NEIGH_PER_INTF+2)) + dvs.servers[i].runcmd("ip -6 addr add {}00::{}/64 dev eth0".format(i*4, j+NUM_NEIGH_PER_INTF+2)) #ping new IPs def ping_new_ips(dvs): for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) - dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)]) + for j in range(NUM_NEIGH_PER_INTF//2): + dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4, j+NUM_NEIGH_PER_INTF+2)]) + dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4, j+NUM_NEIGH_PER_INTF+2)]) class TestWarmReboot(object): @@ -488,10 +488,10 @@ def test_swss_neighbor_syncup(self, dvs, testlog): macs = ["00:00:00:00:24:02", "00:00:00:00:24:03", "00:00:00:00:28:02", "00:00:00:00:28:03"] for i in range(len(ips)): - dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i//2], macs[i])) for i in range(len(v6ips)): - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i//2], macs[i])) time.sleep(1) @@ -500,7 +500,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): tbl = swsscommon.Table(db, "NEIGH_TABLE") for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == True for v in fvs: @@ -510,7 +510,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): assert v[1] == "IPv4" for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == True for v in fvs: @@ -539,7 +539,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # Check the neighbor entries are still in appDB correctly for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == True for v in fvs: @@ -549,7 +549,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): assert v[1] == "IPv4" for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == True for v in fvs: @@ -586,10 +586,10 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # delete even nummber of ipv4/ipv6 neighbor entries from each interface for i in range(0, len(ips), 2): - dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) + dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i//2])) for i in range(0, len(v6ips), 2): - dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) + dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i//2])) # start neighsyncd again start_neighsyncd(dvs) @@ -598,7 +598,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # check ipv4 and ipv6 neighbors for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) #should not see deleted neighbor entries if i % 2 == 0: assert status == False @@ -614,7 +614,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): assert v[1] == "IPv4" for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) #should not see deleted neighbor entries if i % 2 == 0: assert status == False @@ -661,19 +661,19 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # use "change" if neighbor is in FAILED state for i in range(0, len(ips), 2): (rc, output) = dvs.runcmd(['sh', '-c', "ip -4 neigh | grep {}".format(ips[i])]) - print output + print(output) if output: - dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i//2], macs[i])) else: - dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip neigh add {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i//2], macs[i])) for i in range(0, len(v6ips), 2): (rc, output) = dvs.runcmd(['sh', '-c', "ip -6 neigh | grep {}".format(v6ips[i])]) - print output + print(output) if output: - dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i//2], macs[i])) else: - dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], macs[i])) + dvs.runcmd("ip -6 neigh add {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i//2], macs[i])) # start neighsyncd again start_neighsyncd(dvs) @@ -685,7 +685,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # check ipv4 and ipv6 neighbors, should see all neighbors for i in range(len(ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == True for v in fvs: if v[0] == "neigh": @@ -694,7 +694,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): assert v[1] == "IPv4" for i in range(len(v6ips)): - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == True for v in fvs: if v[0] == "neigh": @@ -740,15 +740,15 @@ def test_swss_neighbor_syncup(self, dvs, testlog): for i in range(len(ips)): if i % 2 == 0: - dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i/2], newmacs[i])) + dvs.runcmd("ip neigh change {} dev {} lladdr {} nud reachable".format(ips[i], intfs[i//2], newmacs[i])) else: - dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i/2])) + dvs.runcmd("ip neigh del {} dev {}".format(ips[i], intfs[i//2])) for i in range(len(v6ips)): if i % 2 == 0: - dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i/2], newmacs[i])) + dvs.runcmd("ip -6 neigh change {} dev {} lladdr {} nud reachable".format(v6ips[i], intfs[i//2], newmacs[i])) else: - dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i/2])) + dvs.runcmd("ip -6 neigh del {} dev {}".format(v6ips[i], intfs[i//2])) # start neighsyncd again start_neighsyncd(dvs) @@ -765,7 +765,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): # check ipv4 and ipv6 neighbors, should see all neighbors with updated info for i in range(len(ips)): if i % 2 == 0: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == True for v in fvs: if v[0] == "neigh": @@ -773,12 +773,12 @@ def test_swss_neighbor_syncup(self, dvs, testlog): if v[0] == "family": assert v[1] == "IPv4" else: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], ips[i])) assert status == False for i in range(len(v6ips)): if i % 2 == 0: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == True for v in fvs: if v[0] == "neigh": @@ -786,7 +786,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): if v[0] == "family": assert v[1] == "IPv6" else: - (status, fvs) = tbl.get("{}:{}".format(intfs[i/2], v6ips[i])) + (status, fvs) = tbl.get("{}:{}".format(intfs[i//2], v6ips[i])) assert status == False time.sleep(2) @@ -995,9 +995,9 @@ def test_swss_port_state_syncup(self, dvs, testlog): # appDB port table operation orchStateCount = 0 for message in pubsubMessages: - print message + print(message) key = message['channel'].split(':', 1)[1] - print key + print(key) if message['data'] != 'hset' and message['data'] != 'del': continue if key.find(swsscommon.APP_PORT_TABLE_NAME)==0: @@ -1947,11 +1947,11 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): # should finish the store within 10 seconds time.sleep(10) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS//2) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS//2) - check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_stale_v4_neigh_num(dvs, NUM_OF_NEIGHS//2) + check_kernel_stale_v6_neigh_num(dvs, NUM_OF_NEIGHS//2) # check syslog and sairedis.rec file for activities check_syslog_for_neighbor_entry(dvs, marker, 0, 0, "ipv4") @@ -1972,7 +1972,7 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS) check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS) - check_redis_neigh_entries(dvs, tbl, 2*(NUM_OF_NEIGHS+NUM_OF_NEIGHS/2)) + check_redis_neigh_entries(dvs, tbl, 2*(NUM_OF_NEIGHS+NUM_OF_NEIGHS//2)) (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) assert nadd == NUM_OF_NEIGHS #ipv4 and ipv6 @@ -1980,9 +1980,9 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): # Remove stale entries manually for i in range(8, 8+NUM_INTF): - for j in range(NUM_NEIGH_PER_INTF/2): - dvs.runcmd(['sh', '-c', "ip neigh del {}.0.0.{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) - dvs.runcmd(['sh', '-c', "ip -6 neigh del {}00::{} dev Ethernet{}".format(i*4,j+NUM_NEIGH_PER_INTF/2+2, i*4)]) + for j in range(NUM_NEIGH_PER_INTF//2): + dvs.runcmd(['sh', '-c', "ip neigh del {}.0.0.{} dev Ethernet{}".format(i*4, j+NUM_NEIGH_PER_INTF//2+2, i*4)]) + dvs.runcmd(['sh', '-c', "ip -6 neigh del {}00::{} dev Ethernet{}".format(i*4, j+NUM_NEIGH_PER_INTF//2+2, i*4)]) time.sleep(5) @@ -2022,7 +2022,7 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): check_kernel_reachable_neigh_num(dvs, 0) # bring down half of the links - for i in range(8, 8+NUM_INTF/2): + for i in range(8, 8+NUM_INTF//2): dvs.runcmd("ip link set down dev Ethernet{}".format(i*4)) # start neighsyncd and restore_neighbors @@ -2032,15 +2032,15 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): # restore for up interfaces should be done within 10 seconds time.sleep(10) - check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS/2) - check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS/2) + check_kernel_reachable_v4_neigh_num(dvs, NUM_OF_NEIGHS//2) + check_kernel_reachable_v6_neigh_num(dvs, NUM_OF_NEIGHS//2) restoretbl = swsscommon.Table(state_db, swsscommon.STATE_NEIGH_RESTORE_TABLE_NAME) # waited 10 above already i = 10 while (not kernel_restore_neighs_done(restoretbl)): - print "Waiting for kernel neighbors restore process done: {} seconds".format(i) + print("Waiting for kernel neighbors restore process done: {} seconds".format(i)) time.sleep(10) i += 10 @@ -2048,8 +2048,8 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): # check syslog and sairedis.rec file for activities - #check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv4") - #check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS/2, "ipv6") + #check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS//2, "ipv4") + #check_syslog_for_neighbor_entry(dvs, marker, 0, NUM_OF_NEIGHS//2, "ipv6") (nadd, ndel) = dvs.CountSubscribedObjects(pubsub) assert nadd == 0 assert ndel == NUM_OF_NEIGHS diff --git a/tests/test_watermark.py b/tests/test_watermark.py index 40342c613cfc..3a3133e03e33 100644 --- a/tests/test_watermark.py +++ b/tests/test_watermark.py @@ -32,7 +32,7 @@ def setup_db(self, dvs): self.flex_db = dvs.get_flex_db() def enable_unittests(self, dvs, status): - db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) + db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL") fvp = swsscommon.FieldValuePairs() ntf.send("enable_unittests", status, fvp) @@ -42,7 +42,8 @@ def set_counter(self, dvs, obj_type, obj_id, attr, val): db = swsscommon.DBConnector(swsscommon.ASIC_DB, dvs.redis_sock, 0) ntf = swsscommon.NotificationProducer(db, "SAI_VS_UNITTEST_CHANNEL") - 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) rid = r.hget("VIDTORID", obj_id) assert rid is not None @@ -50,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): @@ -60,7 +62,7 @@ def populate_asic(self, dvs, obj_type, attr, val): for obj_id in oids: self.set_counter(dvs, obj_type, obj_id, attr, val) - + def populate_asic_all(self, dvs, val): self.populate_asic(dvs, "SAI_OBJECT_TYPE_QUEUE", SaiWmStats.queue_shared, val) self.populate_asic(dvs, "SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP", SaiWmStats.pg_shared, val) @@ -71,7 +73,7 @@ def verify_value(self, dvs, obj_ids, table_name, watermark_name, expected_value) counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) table = swsscommon.Table(counters_db, table_name) - + for obj_id in obj_ids: ret = table.get(obj_id) @@ -93,7 +95,7 @@ def set_up_flex_counter(self, dvs): "QUEUE_WATERMARK_STAT_COUNTER:{}".format(q), queue_stats_entry) - pg_stats_entry = {"PG_COUNTER_ID_LIST": + pg_stats_entry = {"PG_COUNTER_ID_LIST": "SAI_INGRESS_PRIORITY_GROUP_STAT_SHARED_WATERMARK_BYTES,SAI_INGRESS_PRIORITY_GROUP_STAT_XOFF_ROOM_WATERMARK_BYTES"} for pg in self.pgs: self.flex_db.create_entry("FLEX_COUNTER_TABLE", @@ -119,7 +121,7 @@ def set_up(self, dvs): self.pgs = self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_INGRESS_PRIORITY_GROUP") db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, dvs.redis_sock, 0) - tbl = swsscommon.Table(db, "COUNTERS_QUEUE_TYPE_MAP") + tbl = swsscommon.Table(db, "COUNTERS_QUEUE_TYPE_MAP") self.uc_q = [] self.mc_q = [] @@ -156,7 +158,7 @@ def test_telemetry_period(self, dvs): self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_shared, "0") self.verify_value(dvs, self.pgs, WmTables.periodic, SaiWmStats.pg_headroom, "0") self.verify_value(dvs, self.qs, WmTables.periodic, SaiWmStats.queue_shared, "0") - + self.enable_unittests(dvs, "false") @pytest.mark.skip(reason="This test is not stable enough") @@ -173,7 +175,7 @@ def test_lua_plugins(self, dvs): self.verify_value(dvs, self.qs, table_name, SaiWmStats.queue_shared, "192") self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_headroom, "192") self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_shared, "192") - + self.populate_asic_all(dvs, "96") for table_name in [WmTables.user, WmTables.persistent]: @@ -182,7 +184,7 @@ def test_lua_plugins(self, dvs): self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_shared, "192") self.populate_asic_all(dvs, "288") - + for table_name in [WmTables.user, WmTables.persistent]: self.verify_value(dvs, self.qs, table_name, SaiWmStats.queue_shared, "288") self.verify_value(dvs, self.pgs, table_name, SaiWmStats.pg_headroom, "288") @@ -209,9 +211,9 @@ def test_clear(self, dvs): # make sure the rest is untouched - self.verify_value(dvs, self.pgs, WmTables.user, SaiWmStats.pg_headroom, "288") - self.verify_value(dvs, self.pgs, WmTables.persistent, SaiWmStats.pg_shared, "288") - self.verify_value(dvs, self.pgs, WmTables.persistent, SaiWmStats.pg_headroom, "288") + self.verify_value(dvs, self.pgs, WmTables.user, SaiWmStats.pg_headroom, "288") + self.verify_value(dvs, self.pgs, WmTables.persistent, SaiWmStats.pg_shared, "288") + self.verify_value(dvs, self.pgs, WmTables.persistent, SaiWmStats.pg_headroom, "288") # clear queue unicast persistent watermark, and verify that multicast watermark and user watermarks are not affected @@ -224,8 +226,8 @@ def test_clear(self, dvs): # make sure the rest is untouched - self.verify_value(dvs, self.mc_q, WmTables.persistent, SaiWmStats.queue_shared, "288") - self.verify_value(dvs, self.uc_q, WmTables.user, SaiWmStats.queue_shared, "288") - self.verify_value(dvs, self.mc_q, WmTables.user, SaiWmStats.queue_shared, "288") + self.verify_value(dvs, self.mc_q, WmTables.persistent, SaiWmStats.queue_shared, "288") + self.verify_value(dvs, self.uc_q, WmTables.user, SaiWmStats.queue_shared, "288") + self.verify_value(dvs, self.mc_q, WmTables.user, SaiWmStats.queue_shared, "288") self.enable_unittests(dvs, "false")