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
Next Next commit
Fix the issue where persistent DVS is used to run pytest
and ports are created dynamically (ref pr:
sonic-net/sonic-buildimage#4499). There were two
issues:

a) since number of dynamic front port can be < 32 test case fails
   as it expect always 32. Make sure to udpate persitent DVS to always have
   32 ports/server link as part of test run and save the current config
   db

b) after test is done persistent DVS need to be moved to original state.
   Make dure to remove extra port/server link and restore back config db

Signed-off-by: Abhishek Dosi <[email protected]>
abdosi committed Jul 31, 2020
commit 7efd9685abc47068d4576397566326bb3a1c8054
19 changes: 18 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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():
@@ -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)

@@ -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,
@@ -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
# that were created
if self.persistent:
for s in self.servers:
s.destroy()
# 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))
@@ -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):