Skip to content

Commit

Permalink
Fix test case issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vasant17 authored and zhenggen-xu committed Nov 9, 2019
1 parent 97da0d2 commit 8bae555
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 48 deletions.
60 changes: 26 additions & 34 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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'''
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
22 changes: 13 additions & 9 deletions tests/port_dpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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(" ", "")

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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),
Expand All @@ -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

Expand All @@ -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)
Expand Down
1 change: 0 additions & 1 deletion tests/test_acl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import re
import json


class BaseTestAcl(object):
""" base class with helpers for Test classes """
def setup_db(self, dvs):
Expand Down
6 changes: 2 additions & 4 deletions tests/test_port_dpb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 8bae555

Please sign in to comment.