From d7ff1ad363da96819cff650643a25ec3649bc69e Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sat, 27 Jun 2020 09:31:27 +0000 Subject: [PATCH 1/8] [vstest]: upgrade swss vs tests to python3 this pr mainly contains the changes made by 2to3 conversion tool --- tests/conftest.py | 56 +++++++++++++++++++----------- tests/dvslib/dvs_vlan.py | 2 +- tests/port_dpb.py | 4 +-- tests/test_mirror_ipv6_separate.py | 8 ++--- tests/test_nhg.py | 8 +++-- tests/test_port_mac_learn.py | 4 +-- tests/test_setro.py | 2 +- tests/test_tunnel.py | 2 +- tests/test_vrf.py | 10 +++--- tests/test_warm_reboot.py | 10 +++--- 10 files changed, 62 insertions(+), 44 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index fac32b321768..30ead8dd7087 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 @@ -19,7 +21,10 @@ from dvslib import dvs_lag 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)) @@ -136,9 +141,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 @@ -146,7 +151,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 @@ -187,7 +192,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: @@ -198,7 +206,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 @@ -214,7 +225,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 @@ -284,7 +298,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'): @@ -322,7 +336,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'): @@ -335,7 +349,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): @@ -389,19 +403,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() @@ -455,7 +469,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: @@ -482,7 +496,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 @@ -524,7 +538,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(':') 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..87d19b755e1a 100644 --- a/tests/port_dpb.py +++ b/tests/port_dpb.py @@ -87,7 +87,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()) @@ -218,7 +218,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_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_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..6000f0fb8bfa 100644 --- a/tests/test_setro.py +++ b/tests/test_setro.py @@ -36,7 +36,7 @@ def test_SetReadOnlyAttribute(self, dvs, testlog): key = "SAI_OBJECT_TYPE_SWITCH:" + swRid - print key + print(key) ntf.send("set_ro", key, fvp) 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_vrf.py b/tests/test_vrf.py index 6b04ce63f273..f68d80775be6 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() @@ -177,13 +177,13 @@ def test_VRFMgr_Comprehensive(self, dvs, testlog): random.seed(int(time.clock())) - 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)) diff --git a/tests/test_warm_reboot.py b/tests/test_warm_reboot.py index 8d327873f3ab..87f02272e0ea 100644 --- a/tests/test_warm_reboot.py +++ b/tests/test_warm_reboot.py @@ -661,7 +661,7 @@ 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])) else: @@ -669,7 +669,7 @@ def test_swss_neighbor_syncup(self, dvs, testlog): 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])) else: @@ -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: @@ -2040,7 +2040,7 @@ def test_system_warmreboot_neighbor_syncup(self, dvs, testlog): # 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 From c7c63ee4b975cdb5e9cb5b6527209b0987f273e1 Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sat, 27 Jun 2020 09:40:00 +0000 Subject: [PATCH 2/8] [vstest]: change from platform to distro platform.linux_distribution is no longer supported 3.8+ Signed-off-by: Guohan Lu --- tests/test_mirror.py | 6 +++--- tests/test_vlan.py | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) 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_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"]), From 9c71203a5fa9ca2bfd746c3215f46c7fcfb8cebb Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sat, 4 Jul 2020 06:10:53 +0000 Subject: [PATCH 3/8] [vstest]: let redis decodes the response to be string instead of bytes python3 works on string instead of bytestring Signed-off-by: Guohan Lu --- tests/conftest.py | 18 +++++--- tests/port_dpb.py | 3 +- tests/test_crm.py | 95 ++++++++++++++++++++------------------- tests/test_port_config.py | 6 ++- tests/test_setro.py | 3 +- tests/test_watermark.py | 31 ++++++------- 6 files changed, 84 insertions(+), 72 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 30ead8dd7087..b0c2a54cde27 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -451,13 +451,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 @@ -486,7 +488,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 = [] @@ -529,7 +532,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 = [] @@ -560,7 +564,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: @@ -852,7 +857,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 diff --git a/tests/port_dpb.py b/tests/port_dpb.py index 87d19b755e1a..6d0b07427ade 100644 --- a/tests/port_dpb.py +++ b/tests/port_dpb.py @@ -26,7 +26,8 @@ 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 = redis.Redis(unix_socket_path=self._dvs.redis_sock, db=swsscommon.COUNTERS_DB, + encoding="utf-8", decode_responses=True) self._dvs_asic_db = dvs.get_asic_db() def set_name(self, name): diff --git a/tests/test_crm.py b/tests/test_crm.py index 9d52550af155..41c06751e268 100644 --- a/tests/test_crm.py +++ b/tests/test_crm.py @@ -46,7 +46,8 @@ def setReadOnlyAttr(dvs, obj, attr, val): assert len(keys) == 1 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) assert swRid is not None @@ -701,45 +702,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 +748,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 +763,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 +778,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 +793,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 +808,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 +823,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 +838,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 +853,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 +868,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 +883,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 +898,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 +913,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_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_setro.py b/tests/test_setro.py index 6000f0fb8bfa..ceebe9cfbe7c 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) diff --git a/tests/test_watermark.py b/tests/test_watermark.py index 40342c613cfc..5492944fd9ca 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 @@ -60,7 +61,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 +72,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 +94,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 +120,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 +157,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 +174,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 +183,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 +210,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 +225,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") From 6adaf2ec05fb4b8f4e983280600ee8b92efc3a1f Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sat, 4 Jul 2020 08:10:50 +0000 Subject: [PATCH 4/8] [vstest]: change time.clock() to time.time() time.clock() is removed from python 3.3 Signed-off-by: Guohan Lu --- tests/test_vrf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_vrf.py b/tests/test_vrf.py index f68d80775be6..f3d11c57756e 100644 --- a/tests/test_vrf.py +++ b/tests/test_vrf.py @@ -175,7 +175,7 @@ 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 range(2**len(attributes)): # generate testcases for all combinations of attributes @@ -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", [ From 26efbcf533081d61fc72d964ecb52f7ebb624fd8 Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sat, 4 Jul 2020 12:25:05 +0000 Subject: [PATCH 5/8] [vstest]: change float division to integer division Signed-off-by: Guohan Lu --- tests/port_dpb.py | 6 +-- tests/test_port_dpb.py | 2 +- tests/test_warm_reboot.py | 94 +++++++++++++++++++-------------------- 3 files changed, 51 insertions(+), 51 deletions(-) diff --git a/tests/port_dpb.py b/tests/port_dpb.py index 6d0b07427ade..7688c3f67d67 100644 --- a/tests/port_dpb.py +++ b/tests/port_dpb.py @@ -112,7 +112,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) @@ -121,7 +121,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) @@ -219,7 +219,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 ("SAI_PORT_ATTR_HW_LANE_LIST" in fvs_dict): + 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_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_warm_reboot.py b/tests/test_warm_reboot.py index 87f02272e0ea..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 @@ -663,17 +663,17 @@ def test_swss_neighbor_syncup(self, dvs, testlog): (rc, output) = dvs.runcmd(['sh', '-c', "ip -4 neigh | grep {}".format(ips[i])]) 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) 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) @@ -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,8 +2032,8 @@ 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) @@ -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 From 8807b4060605eaad32997bdc302c3e3b999c92d3 Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sun, 5 Jul 2020 03:15:03 +0000 Subject: [PATCH 6/8] [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): From c90b28101942ee6e675f93dc3015eb3fc4ce6c2b Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sun, 5 Jul 2020 04:50:27 +0000 Subject: [PATCH 7/8] [vstest]: reuse dvs setReadOnlyAttr in test_crm.py Signed-off-by: Guohan Lu --- tests/test_crm.py | 78 ++++++++++++++++------------------------------- 1 file changed, 27 insertions(+), 51 deletions(-) diff --git a/tests/test_crm.py b/tests/test_crm.py index 41c06751e268..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,29 +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, - encoding="utf-8", decode_responses=True) - 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) @@ -74,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) @@ -101,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) @@ -113,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) @@ -143,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") @@ -160,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) @@ -174,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) @@ -213,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") @@ -230,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) @@ -244,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) @@ -276,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) @@ -286,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) @@ -299,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) @@ -335,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) @@ -345,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) @@ -358,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) @@ -390,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) @@ -400,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) @@ -413,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) @@ -449,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) @@ -459,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) @@ -472,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) @@ -507,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") @@ -525,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) @@ -540,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) @@ -582,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") @@ -600,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) @@ -615,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) From ff04e6d787bd8c679af8eaec3c3d698b5c54d278 Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sat, 27 Jun 2020 09:35:44 +0000 Subject: [PATCH 8/8] [doc]: update instruction to run vstest under python3 Signed-off-by: Guohan Lu --- tests/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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/)