Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue when persistent DVS is used to run pytest which has number of front-panel ports < 32 #1373

Merged
merged 8 commits into from
Aug 18, 2020
19 changes: 18 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
self.cleanup = False
else:
self.cleanup = True
self.persistent = False
if name != None:
# get virtual switch container
for ctn in self.client.containers.list():
Expand All @@ -203,7 +204,9 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
else:
(status, output) = subprocess.getstatusoutput("docker inspect --format '{{.HostConfig.NetworkMode}}' %s" % name)
ctn_sw_id = output.split(':')[1]
# Persistent DVS is available.
self.cleanup = False
self.persistent = True
if self.ctn == None:
raise NameError("cannot find container %s" % name)

Expand All @@ -227,6 +230,10 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
self.mount = "/var/run/redis-vs/{}".format(ctn_sw_name)

self.net_cleanup()
# As part of https://github.com/Azure/sonic-buildimage/pull/4499
# VS support dynamically create Front-panel ports so save the orginal
# config db for persistent DVS
self.runcmd("mv /etc/sonic/config_db.json /etc/sonic/config_db.json.orig")
self.ctn_restart()
else:
self.ctn_sw = self.client.containers.run('debian:jessie', privileged=True, detach=True,
Expand Down Expand Up @@ -271,7 +278,13 @@ def __init__(self, name=None, imgname=None, keeptb=False, fakeplatform=None):
def destroy(self):
if self.appldb:
del self.appldb
if self.cleanup:
# In case persisten dvs was used removed all the extra server link
daall marked this conversation as resolved.
Show resolved Hide resolved
# that were created
if self.persistent:
for s in self.servers:
s.destroy()
daall marked this conversation as resolved.
Show resolved Hide resolved
# persistent and clean-up flag are mutually exclusive
elif self.cleanup:
self.ctn.remove(force=True)
self.ctn_sw.remove(force=True)
os.system("rm -rf {}".format(self.mount))
Expand Down Expand Up @@ -1043,6 +1056,10 @@ def dvs(request):
else:
dvs.get_logs()
dvs.destroy()
# restore original config db
if dvs.persistent:
dvs.runcmd("mv /etc/sonic/config_db.json.orig /etc/sonic/config_db.json")
dvs.ctn_restart()

@pytest.yield_fixture
def testlog(request, dvs):
Expand Down