Skip to content

Commit

Permalink
test-network: add tests for SR-IOV
Browse files Browse the repository at this point in the history
This also adjusts test_sysctl_disable_ipv6(), as rt_trap flag may be
added to routes on some environments.
  • Loading branch information
yuwata committed Jun 23, 2020
1 parent 3da8615 commit 0bacad6
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
37 changes: 37 additions & 0 deletions test/test-network/conf/25-sriov.network
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[Match]
Name=eni99np1

[Network]
Address=192.168.100.100/24

[SRIOV]
VirtualFunction=0
VLANId=5
VLANProtocol=802.1ad
QualityOfService=1
MACSpoofCheck=yes
QueryReceiveSideScaling=yes
Trust=yes
LinkState=yes
MACAddress=00:11:22:33:44:55

[SRIOV]
VirtualFunction=1
VLANId=6
VLANProtocol=802.1Q
QualityOfService=2
MACSpoofCheck=no
QueryReceiveSideScaling=no
Trust=no
LinkState=no
MACAddress=00:11:22:33:44:56

[SRIOV]
VirtualFunction=2
VLANId=7
QualityOfService=3
MACSpoofCheck=no
QueryReceiveSideScaling=no
Trust=no
LinkState=auto
MACAddress=00:11:22:33:44:57
58 changes: 56 additions & 2 deletions test/test-network/systemd-networkd-tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,33 @@ def f(func):

return f

def expectedFailureIfNetdevsimWithSRIOVIsNotAvailable():
def f(func):
call('rmmod netdevsim', stderr=subprocess.DEVNULL)
rc = call('modprobe netdevsim', stderr=subprocess.DEVNULL)
if rc != 0:
return unittest.expectedFailure(func)

try:
with open('/sys/bus/netdevsim/new_device', mode='w') as f:
f.write('99 1')
except Exception as error:
return unittest.expectedFailure(func)

call('udevadm settle')
call('udevadm info -w10s /sys/devices/netdevsim99/net/eni99np1', stderr=subprocess.DEVNULL)
try:
with open('/sys/class/net/eni99np1/device/sriov_numvfs', mode='w') as f:
f.write('3')
except Exception as error:
call('rmmod netdevsim', stderr=subprocess.DEVNULL)
return unittest.expectedFailure(func)

call('rmmod netdevsim', stderr=subprocess.DEVNULL)
return func

return f

def expectedFailureIfCAKEIsNotAvailable():
def f(func):
call('ip link add dummy98 type dummy', stderr=subprocess.DEVNULL)
Expand Down Expand Up @@ -1682,6 +1709,7 @@ class NetworkdNetworkTests(unittest.TestCase, Utilities):
'25-route-vrf.network',
'25-gateway-static.network',
'25-gateway-next-static.network',
'25-sriov.network',
'25-sysctl-disable-ipv6.network',
'25-sysctl.network',
'25-test1.network',
Expand Down Expand Up @@ -2224,7 +2252,7 @@ def test_sysctl_disable_ipv6(self):
self.assertRegex(output, 'inet6 .* scope link')
output = check_output('ip -4 route show dev dummy98')
print(output)
self.assertEqual(output, '10.2.0.0/16 proto kernel scope link src 10.2.3.4')
self.assertRegex(output, '10.2.0.0/16 proto kernel scope link src 10.2.3.4')
output = check_output('ip -6 route show dev dummy98')
print(output)
self.assertRegex(output, 'default via 2607:5300:203:39ff:ff:ff:ff:ff proto static')
Expand All @@ -2247,7 +2275,7 @@ def test_sysctl_disable_ipv6(self):
self.assertRegex(output, 'inet6 .* scope link')
output = check_output('ip -4 route show dev dummy98')
print(output)
self.assertEqual(output, '10.2.0.0/16 proto kernel scope link src 10.2.3.4')
self.assertRegex(output, '10.2.0.0/16 proto kernel scope link src 10.2.3.4')
output = check_output('ip -6 route show dev dummy98')
print(output)
self.assertRegex(output, 'default via 2607:5300:203:39ff:ff:ff:ff:ff proto static')
Expand Down Expand Up @@ -2480,6 +2508,32 @@ def test_qdisc_hhf(self):
self.assertRegex(output, 'qdisc hhf 3a: root')
self.assertRegex(output, 'limit 1022p')

@expectedFailureIfNetdevsimWithSRIOVIsNotAvailable()
def test_sriov(self):
call('rmmod netdevsim', stderr=subprocess.DEVNULL)
call('modprobe netdevsim', stderr=subprocess.DEVNULL)
with open('/sys/bus/netdevsim/new_device', mode='w') as f:
f.write('99 1')

call('udevadm settle')
call('udevadm info -w10s /sys/devices/netdevsim99/net/eni99np1', stderr=subprocess.DEVNULL)
with open('/sys/class/net/eni99np1/device/sriov_numvfs', mode='w') as f:
f.write('3')

copy_unit_to_networkd_unit_path('25-sriov.network')
start_networkd()
self.wait_online(['eni99np1:routable'])

output = check_output('ip link show dev eni99np1')
print(output)
self.assertRegex(output,
'vf 0 .*00:11:22:33:44:55.*vlan 5, qos 1, vlan protocol 802.1ad, spoof checking on, link-state enable, trust on, query_rss on\n *'
'vf 1 .*00:11:22:33:44:56.*vlan 6, qos 2, spoof checking off, link-state disable, trust off, query_rss off\n *'
'vf 2 .*00:11:22:33:44:57.*vlan 7, qos 3, spoof checking off, link-state auto, trust off, query_rss off'
)

call('rmmod netdevsim', stderr=subprocess.DEVNULL)

class NetworkdStateFileTests(unittest.TestCase, Utilities):
links = [
'dummy98',
Expand Down

0 comments on commit 0bacad6

Please sign in to comment.