From 8bae55589e9a499689c84904a9a02676f5512125 Mon Sep 17 00:00:00 2001 From: Vasant Patil <36455926+vasant17@users.noreply.github.com> Date: Fri, 8 Nov 2019 15:43:30 -0800 Subject: [PATCH] Fix test case issues --- tests/conftest.py | 60 ++++++++++++++++++------------------------ tests/port_dpb.py | 22 +++++++++------- tests/test_acl.py | 1 - tests/test_port_dpb.py | 6 ++--- 4 files changed, 41 insertions(+), 48 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 2f534c4bcd4..4f3245deb5f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,8 +77,8 @@ def __init__(self, dvs): class ApplDbValidator(object): def __init__(self, dvs): - appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) - self.neighTbl = swsscommon.Table(appl_db, "NEIGH_TABLE") + self.appl_db = swsscommon.DBConnector(swsscommon.APPL_DB, dvs.redis_sock, 0) + self.neighTbl = swsscommon.Table(self.appl_db, "NEIGH_TABLE") def __del__(self): # Make sure no neighbors on physical interfaces @@ -155,10 +155,11 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None): 'vrfmgrd', 'portmgrd'] self.syncd = ['syncd'] - self.rtd = ['fpmsyncd', 'zebra'] + self.rtd = ['fpmsyncd', 'zebra', 'staticd'] self.teamd = ['teamsyncd', 'teammgrd'] self.alld = self.basicd + self.swssd + self.syncd + self.rtd + self.teamd self.client = docker.from_env() + self.appldb = None if subprocess.check_call(["/sbin/modprobe", "team"]) != 0: raise NameError("cannot install kernel team module") @@ -196,7 +197,7 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None): self.mount = "/var/run/redis-vs/{}".format(ctn_sw_name) self.net_cleanup() - self.restart() + self.ctn_restart() else: self.ctn_sw = self.client.containers.run('debian:jessie', privileged=True, detach=True, command="bash", stdin_open=True) @@ -221,8 +222,20 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None): network_mode="container:%s" % self.ctn_sw.name, volumes={ self.mount: { 'bind': '/var/run/redis', 'mode': 'rw' } }) - self.appldb = None self.redis_sock = self.mount + '/' + "redis.sock" + self.check_ctn_status_and_db_connect() + + def destroy(self): + if self.appldb: + del self.appldb + if self.cleanup: + self.ctn.remove(force=True) + self.ctn_sw.remove(force=True) + os.system("rm -rf {}".format(self.mount)) + for s in self.servers: + s.destroy() + + def check_ctn_status_and_db_connect(self): try: # temp fix: remove them once they are moved to vs start.sh self.ctn.exec_run("sysctl -w net.ipv6.conf.default.disable_ipv6=0") @@ -235,15 +248,6 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None): self.destroy() raise - def destroy(self): - if self.appldb: - del self.appldb - if self.cleanup: - self.ctn.remove(force=True) - self.ctn_sw.remove(force=True) - os.system("rm -rf {}".format(self.mount)) - for s in self.servers: - s.destroy() def check_ready(self, timeout=30): '''check if all processes in the dvs is ready''' @@ -310,21 +314,21 @@ def net_cleanup(self): print "remove extra link {}".format(pname) return - def restart(self): + def ctn_restart(self): self.ctn.restart() + def restart(self): + if self.appldb: + del self.appldb + self.ctn_restart() + self.check_ctn_status_and_db_connect() + # start processes in SWSS def start_swss(self): cmd = "" for pname in self.swssd: cmd += "supervisorctl start {}; ".format(pname) self.runcmd(['sh', '-c', cmd]) - - def stop_all_daemons(self): - cmd = "" - for pname in self.alld: - cmd += "supervisorctl stop {}; ".format(pname) - self.runcmd(['sh', '-c', cmd]) time.sleep(5) # stop processes in SWSS @@ -836,19 +840,7 @@ def remove_dpb_config_file(dvs): @pytest.yield_fixture(scope="module") def dpb_setup_fixture(dvs): - start_cmd = "/usr/bin/start.sh" - - print "Set Up" create_dpb_config_file(dvs) - #dvs.restart() - dvs.stop_all_daemons() - dvs.runcmd(start_cmd) - time.sleep(10) - + dvs.restart() yield - - print "Tear Down" remove_dpb_config_file(dvs) - #dvs.restart() - #dvs.stop_all_daemons() - #dvs.runcmd(start_cmd) diff --git a/tests/port_dpb.py b/tests/port_dpb.py index 24a73b7a502..87d4f853900 100644 --- a/tests/port_dpb.py +++ b/tests/port_dpb.py @@ -11,7 +11,7 @@ class Port(): def __init__(self, dvs, name = None): self._name = name if name != None: - self._port_num = int(re.compile(r'(\d+)$').search(self._name).group(1)) + self._port_num = int(re.compile(r'(\d+)$').search(self._name).group(1)) self._alias = None self._speed = None self._lanes = [] @@ -44,6 +44,7 @@ def set_lanes(self, lanes): lanes_list.append(int(lane)) lanes_list.sort() self._lanes_db_str = str(lanes_list)[1:-1] + self._lanes_db_str = self._lanes_db_str.replace(" ","") self._lanes_asic_db_str = str(len(lanes)) + ":" + self._lanes_db_str self._lanes_asic_db_str = self._lanes_asic_db_str.replace(" ", "") @@ -81,7 +82,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()) @@ -109,7 +110,7 @@ def port_split(self, child_ports): lanes_per_child = offset for i in range(child_ports): child_port_num = port_num + (i * offset) - child_port_name = "Ethernet%d"%(child_port_num) + child_port_name = "Ethernet%d"%(child_port_num) child_port_alias = "Eth%d/%d"%(port_num, child_port_num) child_port_lanes = [] for j in range(lanes_per_child): @@ -139,9 +140,9 @@ def sync_from_config_db(self): self.set_index(int(fvs_dict['index'])) def write_to_config_db(self): - lanes_str = self.get_lanes_db_str() + lanes_str = self.get_lanes_db_str() index_str = str(self.get_index()) - alias_str = self.get_alias() + alias_str = self.get_alias() speed_str = str(self.get_speed()) fvs = swsscommon.FieldValuePairs([("alias", alias_str), ("lanes", lanes_str), @@ -163,12 +164,15 @@ def exists_in_app_db(self): (status, _) = self._app_db_ptbl.get(self.get_name()) return status - def exists_in_asic_db(self): + def sync_oid(self): if self._oid is None: counter_redis_conn = redis.Redis(unix_socket_path=self._dvs.redis_sock, db=swsscommon.COUNTERS_DB) self._oid = counter_redis_conn.hget("COUNTERS_PORT_NAME_MAP", self.get_name()) - if self._oid is None: - return False + + def exists_in_asic_db(self): + self.sync_oid() + if self._oid is None: + return False (status, _) = self._asic_db_ptbl.get(self._oid) return status @@ -191,7 +195,7 @@ def verify_app_db(self): assert(fvs_dict['index'] == str(self.get_index())) def verify_asic_db(self): - self.exists_in_asic_db() + self.sync_oid() (status, fvs) = self._asic_db_ptbl.get(self.get_oid()) assert(status == True) fvs_dict = self.get_fvs_dict(fvs) diff --git a/tests/test_acl.py b/tests/test_acl.py index 5cfeb49b4e2..69cf06165ee 100644 --- a/tests/test_acl.py +++ b/tests/test_acl.py @@ -3,7 +3,6 @@ import re import json - class BaseTestAcl(object): """ base class with helpers for Test classes """ def setup_db(self, dvs): diff --git a/tests/test_port_dpb.py b/tests/test_port_dpb.py index 3338a0258c5..64c2789c0c6 100644 --- a/tests/test_port_dpb.py +++ b/tests/test_port_dpb.py @@ -34,7 +34,7 @@ def breakin(self, dvs, port_names): assert(cp.exists_in_asic_db() == False) print "Verified child ports are deleted from all DBs" - p = Port(dvs) + p = Port(dvs) p.port_merge(child_ports) p.write_to_config_db() print "Added port:%s to config DB"%p.get_name() @@ -67,7 +67,7 @@ def breakout(self, dvs, port_name, num_child_ports): assert(p.exists_in_asic_db() == False) # Create child ports and write to config DB - child_ports = p.port_split(num_child_ports) + child_ports = p.port_split(num_child_ports) child_port_names = [] for cp in child_ports: cp.write_to_config_db() @@ -161,9 +161,7 @@ def test_port_breakout_multiple(self, dvs): self.breakin(dvs, ["Ethernet64", "Ethernet65", "Ethernet66", "Ethernet67"]) self.breakin(dvs, ["Ethernet112", "Ethernet113", "Ethernet114", "Ethernet115"]) - ''' @pytest.mark.skip() - ''' def test_port_breakout_all(self, dvs): port_names = [] for i in range(32):