Skip to content

Commit

Permalink
[vstest]: use eth1~32 as physical interface name in vs docker (sonic-…
Browse files Browse the repository at this point in the history
…net#700)

* [vstest]: use eth1~32 as physical interface name in vs docker

align with vs kvm image physical interface name ethXX instead of vEthernetXXX

* clean up network between test modules and various test fixes

Signed-off-by: Guohan Lu <gulv@microsoft.com>
  • Loading branch information
lguohan authored Nov 22, 2018
1 parent 6007e7f commit c74dc60
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 18 deletions.
49 changes: 38 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ def __init__(self, dvs):
self.neighTbl = swsscommon.Table(appl_db, "NEIGH_TABLE")

def __del__(self):
# Make sure no neighbors on vEthernet
keys = self.neighTbl.getKeys();
# Make sure no neighbors on physical interfaces
keys = self.neighTbl.getKeys()
for key in keys:
assert not key.startswith("vEthernet")
m = re.match("eth(\d+)", key)
if not m:
continue
assert int(m.group(1)) > 0

class VirtualServer(object):
def __init__(self, ctn_name, pid, i):
self.nsname = "%s-srv%d" % (ctn_name, i)
self.vifname = "vEthernet%d" % (i * 4)
self.pifname = "eth%d" % (i + 1)
self.cleanup = True

# create netns
Expand All @@ -97,21 +100,21 @@ def __init__(self, ctn_name, pid, i):
ensure_system("ip netns add %s" % self.nsname)

# create vpeer link
ensure_system("ip link add %s type veth peer name %s" % (self.nsname[0:12], self.vifname))
ensure_system("ip link add %s type veth peer name %s" % (self.nsname[0:12], self.pifname))
ensure_system("ip link set %s netns %s" % (self.nsname[0:12], self.nsname))
ensure_system("ip link set %s netns %d" % (self.vifname, pid))
ensure_system("ip link set %s netns %d" % (self.pifname, pid))

# bring up link in the virtual server
ensure_system("ip netns exec %s ip link set dev %s name eth0" % (self.nsname, self.nsname[0:12]))
ensure_system("ip netns exec %s ip link set dev eth0 up" % (self.nsname))
ensure_system("ip netns exec %s ethtool -K eth0 tx off" % (self.nsname))

# bring up link in the virtual switch
ensure_system("nsenter -t %d -n ip link set dev %s up" % (pid, self.vifname))
ensure_system("nsenter -t %d -n ip link set dev %s up" % (pid, self.pifname))

# disable arp, so no neigh on vEthernet(s)
ensure_system("nsenter -t %d -n ip link set arp off dev %s" % (pid, self.vifname))
ensure_system("nsenter -t %d -n sysctl -w net.ipv6.conf.%s.disable_ipv6=1" % (pid, self.vifname))
# disable arp, so no neigh on physical interfaces
ensure_system("nsenter -t %d -n ip link set arp off dev %s" % (pid, self.pifname))
ensure_system("nsenter -t %d -n sysctl -w net.ipv6.conf.%s.disable_ipv6=1" % (pid, self.pifname))

def destroy(self):
if self.cleanup:
Expand Down Expand Up @@ -188,6 +191,7 @@ def __init__(self, name=None, keeptb=False):

self.mount = "/var/run/redis-vs/{}".format(ctn_sw_name)

self.net_cleanup()
self.restart()
else:
self.ctn_sw = self.client.containers.run('debian:jessie', privileged=True, detach=True,
Expand Down Expand Up @@ -216,7 +220,7 @@ def __init__(self, name=None, keeptb=False):
# 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")
for i in range(0, 128, 4):
self.ctn.exec_run("sysctl -w net.ipv6.conf.vEthernet%d.disable_ipv6=1" % i)
self.ctn.exec_run("sysctl -w net.ipv6.conf.eth%d.disable_ipv6=1" % (i + 1))
self.check_ready()
self.init_asicdb_validator()
self.appldb = ApplDbValidator(self)
Expand Down Expand Up @@ -276,6 +280,29 @@ def check_ready(self, timeout=30):

time.sleep(1)

def net_cleanup(self):
"""clean up network, remove extra links"""

re_space = re.compile('\s+')

res = self.ctn.exec_run("ip link show")
try:
out = res.output
except AttributeError:
out = res
for l in out.split('\n'):
m = re.compile('^\d+').match(l)
if not m:
continue
fds = re_space.split(l)
if len(fds) > 1:
pname = fds[1].rstrip(":")
m = re.compile("(eth|lo|Bridge|Ethernet)").match(pname)
if not m:
self.ctn.exec_run("ip link del {}".format(pname))
print "remove extra link {}".format(pname)
return

def restart(self):
self.ctn.restart()

Expand Down
6 changes: 6 additions & 0 deletions tests/test_acl_portchannel.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ def test_PortChannelAfterAcl(self, dvs):
# create ACL table
self.create_acl_table(dvs, "LAG_ACL_TABLE", "PortChannel01")

time.sleep(1)

# check ASIC table
self.check_asic_table_existed(dvs)

Expand All @@ -154,6 +156,8 @@ def test_PortChannelBeforeAcl(self, dvs):
# create port channel
self.create_port_channel(dvs, "PortChannel01")

time.sleep(1)

# check ASIC table
self.check_asic_table_existed(dvs)

Expand All @@ -179,6 +183,8 @@ def test_AclOnPortChannelMember(self, dvs):
# create ACL table
self.create_acl_table(dvs, "LAG_ACL_TABLE", "Ethernet0")

time.sleep(1)

# check ASIC table
self.check_asic_table_absent(dvs)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_admin_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def test_PortChannelMemberAdminStatus(self, dvs, testlog):
self.check_admin_status(dvs, "Ethernet8", "up")

# remove port channel members
self.remove_port_channel_members(dvs, "PortCHannel6",
self.remove_port_channel_members(dvs, "PortChannel6",
["Ethernet0", "Ethernet4", "Ethernet8"])

# remove port channel
self.remove_port_channel(dvs, "PortCHannel6")
self.remove_port_channel(dvs, "PortChannel6")
7 changes: 2 additions & 5 deletions tests/test_speed.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,13 @@ def test_SpeedAndBufferSet(self, dvs, testlog):

buffer_profiles = cfg_buffer_profile_table.getKeys()
expected_buffer_profiles_num = len(buffer_profiles)
# buffers.json used for the test defines 7 static profiles:
# buffers.json used for the test defines 4 static profiles:
# "ingress_lossless_profile"
# "ingress_lossy_profile"
# "egress_lossless_profile"
# "egress_lossy_profile"
# "pg_lossy_profile"
# "q_lossless_profile"
# "q_lossy_profile"
# check if they get the DB
assert expected_buffer_profiles_num == 7
assert expected_buffer_profiles_num == 4
# and if they were successfully created on ASIC
assert len(asic_profile_table.getKeys()) == expected_buffer_profiles_num

Expand Down

0 comments on commit c74dc60

Please sign in to comment.