Skip to content

Commit

Permalink
add --keeptb option to keep testbed after test
Browse files Browse the repository at this point in the history
Signed-off-by: Guohan Lu <gulv@microsoft.com>
  • Loading branch information
lguohan committed Oct 22, 2018
1 parent 6ee779c commit 7d1b09e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ def ensure_system(cmd):
def pytest_addoption(parser):
parser.addoption("--dvsname", action="store", default=None,
help="dvs name")
parser.addoption("--keeptb", action="store_true", default=False,
help="keep testbed after test")

class AsicDbValidator(object):
def __init__(self, dvs):
Expand Down Expand Up @@ -127,7 +129,7 @@ def runcmd_async(self, cmd):
return subprocess.Popen("ip netns exec %s %s" % (self.nsname, cmd), shell=True)

class DockerVirtualSwitch(object):
def __init__(self, name=None):
def __init__(self, name=None, keeptb=False):
self.basicd = ['redis-server',
'rsyslogd']
self.swssd = ['orchagent',
Expand All @@ -147,7 +149,10 @@ def __init__(self, name=None):
self.client = docker.from_env()

self.ctn = None
self.cleanup = True
if keeptb:
self.cleanup = False
else:
self.cleanup = True
if name != None:
# get virtual switch container
for ctn in self.client.containers.list():
Expand Down Expand Up @@ -556,7 +561,8 @@ def setReadOnlyAttr(self, obj, attr, val):
@pytest.yield_fixture(scope="module")
def dvs(request):
name = request.config.getoption("--dvsname")
dvs = DockerVirtualSwitch(name)
keeptb = request.config.getoption("--keeptb")
dvs = DockerVirtualSwitch(name, keeptb)
yield dvs
if name == None:
dvs.get_logs(request.module.__name__)
Expand Down

0 comments on commit 7d1b09e

Please sign in to comment.