Skip to content

Commit d821218

Browse files
committed
Added option for force persitent dvs if port < 32
Updated Readme Signed-off-by: Abhishek Dosi <[email protected]>
1 parent ea304d6 commit d821218

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

tests/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ For those developing new features for SWSS or the DVS framework, you might find
7171
```
7272
sudo pytest --dvsname=vs
7373
```
74+
By default if number of ports in persistent DVS < 32 (needed by testbed) then test will be aborted. To overcome that --force-dvs option can be used.
75+
76+
```
77+
sudo pytest --dvsname=vs --force-dvs
78+
```
79+
7480
7581
5. Additionally, if you need to simulate a specific hardware platform (e.g. Broadcom or Mellanox), you can add this environment variable when starting the DVS container:
7682

tests/conftest.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def ensure_system(cmd):
4141
def pytest_addoption(parser):
4242
parser.addoption("--dvsname", action="store", default=None,
4343
help="dvs name")
44+
45+
parser.addoption("--force-dvs", action="store_true", default=False,
46+
help="force persistent dvs when ports < 32 ")
47+
4448
parser.addoption("--keeptb", action="store_true", default=False,
4549
help="keep testbed after test")
4650
parser.addoption("--imgname", action="store", default="docker-sonic-vs",
@@ -170,7 +174,8 @@ def __init__(
170174
keeptb=False,
171175
fakeplatform=None,
172176
log_path=None,
173-
max_cpu=2
177+
max_cpu=2,
178+
force-dvs = None,
174179
):
175180
self.basicd = ['redis-server',
176181
'rsyslogd']
@@ -216,6 +221,14 @@ def __init__(
216221
if self.ctn == None:
217222
raise NameError("cannot find container %s" % name)
218223

224+
self.num_net_interfaces = self.net_interface_count()
225+
226+
if self.num_net_interfaces > NUM_PORTS:
227+
raise ValueError("persistent dvs is not valid for testbed with ports > %d" % NUM_PORTS)
228+
229+
if self.num_net_interfaces < NUM_PORTS and not force-dvs:
230+
raise ValueError("persistent dvs does not have %d ports needed by testbed" % NUM_PORTS)
231+
219232
# get base container
220233
for ctn in self.client.containers.list():
221234
if ctn.id == ctn_sw_id or ctn.name == ctn_sw_id:
@@ -410,6 +423,21 @@ def net_cleanup(self):
410423
print("remove extra link {}".format(pname))
411424
return
412425

426+
def net_interface_count(self):
427+
"""get the interface count in persistent DVS Container
428+
if not found or some error then return 0 as default"""
429+
430+
res = self.ctn.exec_run(['sh', '-c', 'ip link show | grep -oE eth[0-9]+ | grep -vc eth0'])
431+
if not res.exit_code:
432+
try:
433+
out = res.output.decode('utf-8')
434+
except AttributeError:
435+
return 0
436+
return int(out.rstrip('\n'))
437+
else:
438+
return 0
439+
440+
413441
def ctn_restart(self):
414442
self.ctn.restart()
415443

@@ -898,7 +926,7 @@ def remove_neighbor(self, interface, ip):
898926
def add_route(self, prefix, nexthop):
899927
self.runcmd("ip route add " + prefix + " via " + nexthop)
900928
time.sleep(1)
901-
929+
902930
def remove_route(self, prefix):
903931
self.runcmd("ip route del " + prefix)
904932
time.sleep(1)
@@ -1000,13 +1028,14 @@ def get_state_db(self):
10001028
@pytest.yield_fixture(scope="module")
10011029
def dvs(request) -> DockerVirtualSwitch:
10021030
name = request.config.getoption("--dvsname")
1031+
force-dvs = request.config.getoption("--force-dvs")
10031032
keeptb = request.config.getoption("--keeptb")
10041033
imgname = request.config.getoption("--imgname")
10051034
max_cpu = request.config.getoption("--max_cpu")
10061035
fakeplatform = getattr(request.module, "DVS_FAKE_PLATFORM", None)
10071036
log_path = name if name else request.module.__name__
10081037

1009-
dvs = DockerVirtualSwitch(name, imgname, keeptb, fakeplatform, log_path, max_cpu)
1038+
dvs = DockerVirtualSwitch(name, imgname, keeptb, fakeplatform, log_path, max_cpu, force-dvs)
10101039

10111040
yield dvs
10121041

0 commit comments

Comments
 (0)