iproute/tests/ip-link-sanity-test/ip-link-tests.py
Susant Sahani 84d80eb1b5 CI: Add ip link kind and set dev tests
justification
Adds tests according to the CI wiki specifically the standard test interface in the spec.
The playbook includes Tier1 level test cases that have been tested in the following contexts and
is passing reliably: Classic. Test logs are stored in the artifacts directory.
The following steps are used to execute the tests using the standard test interface:

Test enveronment
Make sure you have installed packages from the spec
```
ansible-2.4.1.0-2.fc28.noarch
python2-dnf-2.7.5-1.fc28.noarch
libselinux-python-2.7-2.fc28.x86_64
standard-test-roles-2.5-1.fc28.noarch
Run tests for Classic
Snip of the example test run for Classic tests:
```

```
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Setup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

iproute-4.15.0-1.fc28.x86_64
:: [ 16:56:03 ] :: [   PASS   ] :: Checking for the presence of iproute rpm
:: [ 16:56:03 ] :: [   LOG    ] :: Package versions:
:: [ 16:56:04 ] :: [   LOG    ] ::   iproute-4.15.0-1.fc28.x86_64
:: [ 16:56:04 ] :: [  BEGIN   ] :: Running 'cp ip-link-tests.py /usr/bin'
:: [ 16:56:04 ] :: [   PASS   ] :: Command 'cp ip-link-tests.py /usr/bin' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Duration: 1s
::   Assertions: 2 good, 0 bad
::   RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 16:56:04 ] :: [   LOG    ] :: ip link tests
:: [ 16:56:04 ] :: [  BEGIN   ] :: Running '/usr/bin/python3 /usr/bin/ip-link-tests.py'
test_add_bond (__main__.IPLinkKindTests) ... ok
test_add_bridge (__main__.IPLinkKindTests) ... ok
test_add_dummy (__main__.IPLinkKindTests) ... ok
test_add_erspan_tunnel (__main__.IPLinkKindTests) ... ok
test_add_geneve_tunnel (__main__.IPLinkKindTests) ... ok
test_add_gre_tunnel (__main__.IPLinkKindTests) ... ok
test_add_gretap_tunnel (__main__.IPLinkKindTests) ... ok
test_add_ip6erspan_tunnel (__main__.IPLinkKindTests) ... ok
test_add_ip6gre_tunnel (__main__.IPLinkKindTests) ... ok
test_add_ip6gretap_tunnel (__main__.IPLinkKindTests) ... ok
test_add_ipip_tunnel (__main__.IPLinkKindTests) ... ok
test_add_ipvlan (__main__.IPLinkKindTests) ... ok
test_add_macsec (__main__.IPLinkKindTests) ... ok
test_add_macvlan (__main__.IPLinkKindTests) ... ok
test_add_macvtap (__main__.IPLinkKindTests) ... ok
test_add_sit_tunnel (__main__.IPLinkKindTests) ... ok
test_add_team (__main__.IPLinkKindTests) ... ok
test_add_vcan (__main__.IPLinkKindTests) ... ok
test_add_veth_pair (__main__.IPLinkKindTests) ... ok
test_add_vlan (__main__.IPLinkKindTests) ... ok
test_add_vrf (__main__.IPLinkKindTests) ... ok
test_add_vti_tunnel (__main__.IPLinkKindTests) ... ok
test_add_vxcan (__main__.IPLinkKindTests) ... ok
test_add_vxlan (__main__.IPLinkKindTests) ... ok
test_set_dev_address (__main__.IPLinkSetDevTests) ... ok
test_set_dev_alias (__main__.IPLinkSetDevTests) ... ok
test_set_dev_all_multicast (__main__.IPLinkSetDevTests) ... ok
test_set_dev_mtu (__main__.IPLinkSetDevTests) ... ok
test_set_dev_multicast (__main__.IPLinkSetDevTests) ... ok
test_set_dev_name (__main__.IPLinkSetDevTests) ... ok
test_set_dev_up_down (__main__.IPLinkSetDevTests) ... ok

----------------------------------------------------------------------
Ran 31 tests in 0.966s

OK
:: [ 16:56:05 ] :: [   PASS   ] :: Command '/usr/bin/python3 /usr/bin/ip-link-tests.py' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Duration: 1s
::   Assertions: 1 good, 0 bad
::   RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Cleanup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 16:56:05 ] :: [  BEGIN   ] :: Running 'rm /usr/bin/ip-link-tests.py'
:: [ 16:56:05 ] :: [   PASS   ] :: Command 'rm /usr/bin/ip-link-tests.py' (Expected 0, got 0)
:: [ 16:56:05 ] :: [   LOG    ] :: ip link tests done
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Duration: 0s
::   Assertions: 1 good, 0 bad
::   RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   TEST PROTOCOL
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

    Package       : iproute
    Installed     : iproute-4.15.0-1.fc28.x86_64
    beakerlib RPM : beakerlib-1.17-13.fc28.noarch
    Test started  : 2018-06-17 16:56:03 IST
    Test finished : 2018-06-17 16:56:05 IST (still running)
    Test duration : 2 seconds
    Test name     : unknown
    Distro        : Fedora release 28 (Twenty Eight)
    Hostname      : Zeus
    Architecture  : x86_64
    CPUs          : 8 x Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
    RAM size      : 31542 MB
    HDD size      : 452.94 GB

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Test description
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

PURPOSE of /CoreOS/iproute/Sanity/ip-link-sanity-test
Description: Test basic ip link funcionality
Author: Susant Sahani <susant@redhat.com>

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Setup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 16:56:03 ] :: [   PASS   ] :: Checking for the presence of iproute rpm
:: [ 16:56:03 ] :: [   LOG    ] :: Package versions:
:: [ 16:56:04 ] :: [   LOG    ] ::   iproute-4.15.0-1.fc28.x86_64
:: [ 16:56:04 ] :: [   PASS   ] :: Command 'cp ip-link-tests.py /usr/bin' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Duration: 1s
::   Assertions: 2 good, 0 bad
::   RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 16:56:04 ] :: [   LOG    ] :: ip link tests
:: [ 16:56:05 ] :: [   PASS   ] :: Command '/usr/bin/python3 /usr/bin/ip-link-tests.py' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Duration: 1s
::   Assertions: 1 good, 0 bad
::   RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Cleanup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 16:56:05 ] :: [   PASS   ] :: Command 'rm /usr/bin/ip-link-tests.py' (Expected 0, got 0)
:: [ 16:56:05 ] :: [   LOG    ] :: ip link tests done
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Duration: 0s
::   Assertions: 1 good, 0 bad
::   RESULT: PASS

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   unknown
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 16:56:05 ] :: [   LOG    ] :: JOURNAL XML: /var/tmp/beakerlib-zsCyOCP/journal.xml
:: [ 16:56:05 ] :: [   LOG    ] :: JOURNAL TXT: /var/tmp/beakerlib-zsCyOCP/journal.txt
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::   Duration: 2s
::   Phases: 3 good, 0 bad
::   OVERALL RESULT: PASS
```
2018-06-17 17:02:31 +05:30

343 lines
12 KiB
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1+
# ~~~
# runtest.sh of /CoreOS/iproute/Sanity/ip-link-sanity-test
# Description: Test basic ip link funcionality
#
# Author: Susant Sahani <susant@redhat.com>
# Copyright (c) 2018 Red Hat, Inc.
# ~~~
import errno
import os
import sys
import time
import unittest
import subprocess
import signal
import shutil
def setUpModule():
if shutil.which('ip') is None:
raise OSError(errno.ENOENT, 'ip not found')
class IPLinkUtilities():
def read_attr(self, link, attribute):
"""Read a link attributed from the sysfs."""
with open(os.path.join('/sys/class/net', link, attribute)) as f:
return f.readline().strip()
def link_exists(self, link):
self.assertTrue(os.path.exists(os.path.join('/sys/class/net', link)))
class IPLinkSetDevTests(unittest.TestCase, IPLinkUtilities):
def setUp(self):
""" Setup """
subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy'])
self.link_exists('dummy-test')
def tearDown(self):
subprocess.check_output(['ip', 'link', 'del', 'dummy-test'])
def test_set_dev_mtu(self):
subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'mtu', '9000'])
self.assertEqual('9000', self.read_attr('dummy-test', 'mtu'))
def test_set_dev_up_down(self):
subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'up'])
output=subprocess.check_output(['ip', 'link', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8')
self.assertRegex(output, 'UP,LOWER_UP')
subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'down'])
output=subprocess.check_output(['ip', 'link', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8')
self.assertNotRegex(output, 'UP,LOWER_UP')
def test_set_dev_address(self):
subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'address', '02:01:02:03:04:08'])
output=subprocess.check_output(['ip', 'link', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8')
self.assertRegex(output, 'link/ether 02:01:02:03:04:08')
def test_set_dev_alias(self):
subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'alias', 'test-test'])
output=subprocess.check_output(['ip', 'link', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8')
self.assertRegex(output, 'test-test')
def test_set_dev_name(self):
subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'name', 'test-test'])
output=subprocess.check_output(['ip', 'link', 'show', 'dev', 'test-test']).rstrip().decode('utf-8')
self.assertRegex(output, 'test-test')
subprocess.check_output(['ip', 'link', 'set', 'dev', 'test-test', 'name', 'dummy-test'])
def test_set_dev_multicast(self):
subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'multicast', 'on'])
output=subprocess.check_output(['ip', 'link', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8')
self.assertRegex(output, 'MULTICAST')
def test_set_dev_all_multicast(self):
subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'allmulticast', 'on'])
output=subprocess.check_output(['ip', 'link', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8')
self.assertRegex(output, 'ALLMULTI')
class IPLinkKindTests(unittest.TestCase, IPLinkUtilities):
def setUp(self):
""" Setup """
pass
def tearDown(self):
pass
def test_add_veth_pair(self):
subprocess.check_output(['ip', 'link', 'add', 'veth-test', 'type', 'veth', 'peer', 'name', 'veth-peer-test'])
self.link_exists('veth-test')
self.link_exists('veth-peer-test')
subprocess.check_output(['ip', 'link', 'del', 'veth-test'])
def test_add_dummy(self):
subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy'])
self.link_exists('dummy-test')
subprocess.check_output(['ip', 'link', 'del', 'dummy-test'])
def test_add_vcan(self):
subprocess.check_output(['ip', 'link', 'add', 'vcan-test', 'type', 'vcan'])
self.link_exists('vcan-test')
subprocess.check_output(['ip', 'link', 'del', 'vcan-test'])
def test_add_vxcan(self):
subprocess.check_output(['ip', 'link', 'add', 'vxcan-test', 'type', 'vxcan'])
self.link_exists('vxcan-test')
subprocess.check_output(['ip', 'link', 'del', 'vxcan-test'])
def test_add_vlan(self):
subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy'])
self.link_exists('dummy-test')
subprocess.check_output(['ip', 'link', 'add', 'link', 'dummy-test', 'name', 'vlantest.100', 'type', 'vlan', 'id', '100'])
self.link_exists('vlantest.100')
subprocess.check_output(['ip', 'link', 'del', 'vlantest.100'])
subprocess.check_output(['ip', 'link', 'del', 'dummy-test'])
def test_add_macvlan(self):
subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy'])
self.link_exists('dummy-test')
subprocess.check_output(['ip', 'link', 'add', 'link', 'dummy-test', 'macvlan-test', 'type', 'macvlan', 'mode', 'bridge'])
self.link_exists('macvlan-test')
subprocess.check_output(['ip', 'link', 'del', 'macvlan-test'])
subprocess.check_output(['ip', 'link', 'del', 'dummy-test'])
def test_add_macvtap(self):
subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy'])
self.link_exists('dummy-test')
subprocess.check_output(['ip', 'link', 'add', 'link', 'dummy-test', 'macvtap-test', 'type', 'macvtap', 'mode', 'bridge'])
self.link_exists('macvtap-test')
subprocess.check_output(['ip', 'link', 'del', 'macvtap-test'])
subprocess.check_output(['ip', 'link', 'del', 'dummy-test'])
def test_add_bridge(self):
subprocess.check_output(['ip', 'link', 'add', 'bridge-test', 'type', 'bridge'])
self.link_exists('bridge-test')
subprocess.check_output(['ip', 'link', 'del', 'bridge-test'])
def test_add_bond(self):
subprocess.check_output(['ip', 'link', 'add', 'bond-test', 'type', 'bond'])
self.link_exists('bond-test')
subprocess.check_output(['ip', 'link', 'del', 'bond-test'])
def test_add_team(self):
subprocess.check_output(['ip', 'link', 'add', 'team-test', 'type', 'team'])
self.link_exists('team-test')
subprocess.check_output(['ip', 'link', 'del', 'team-test'])
def test_add_ipip_tunnel(self):
subprocess.check_output(['ip', 'tunnel', 'add', 'test-ipiptun', 'mode', 'ipip', 'remote', '10.3.3.3', 'local', '10.4.4.4', 'ttl' ,'64'])
self.link_exists('test-ipiptun')
subprocess.check_output(['ip', 'link', 'del', 'test-ipiptun'])
def test_add_gre_tunnel(self):
subprocess.check_output(['ip', 'tunnel', 'add', 'test-gretun', 'mode', 'gre', 'remote', '10.3.3.3', 'local', '10.4.4.4', 'ttl' ,'64'])
self.link_exists('test-gretun')
subprocess.check_output(['ip', 'link', 'del', 'test-gretun'])
def test_add_gretap_tunnel(self):
subprocess.check_output(['ip', 'link', 'add', 'test-gretap', 'type', 'gretap', 'remote', '10.3.3.3', 'local', '10.4.4.4'])
self.link_exists('test-gretap')
subprocess.check_output(['ip', 'link', 'del', 'test-gretap'])
def test_add_ip6gre_tunnel(self):
subprocess.check_output(['ip', 'link', 'add', 'test-ip6gre', 'type', 'ip6gre', 'remote', '2a00:ffde:4567:edde::4987', 'local', '2001:473:fece:cafe::5179'])
self.link_exists('test-ip6gre')
subprocess.check_output(['ip', 'link', 'del', 'test-ip6gre'])
def test_add_ip6gretap_tunnel(self):
subprocess.check_output(['ip', 'link', 'add', 'test-ip6gretap', 'type', 'ip6gretap', 'remote', '2a00:ffde:4567:edde::4987', 'local', '2001:473:fece:cafe::5179'])
self.link_exists('test-ip6gretap')
subprocess.check_output(['ip', 'link', 'del', 'test-ip6gretap'])
def test_add_erspan_tunnel(self):
subprocess.check_output(['ip', 'link', 'add', 'dev', 'test-erspan', 'type', 'erspan', 'seq', 'key', '100','erspan', '123', 'remote', '10.3.3.3', 'local', '10.4.4.4'])
self.link_exists('test-erspan')
subprocess.check_output(['ip', 'link', 'del', 'test-erspan'])
def test_add_ip6erspan_tunnel(self):
subprocess.check_output(['ip', 'link', 'add', 'dev', 'test-ip6erspan', 'type', 'erspan', 'seq', 'key', '101','erspan', '1234', 'remote', '10.3.3.3', 'local', '10.4.4.4'])
self.link_exists('test-ip6erspan')
subprocess.check_output(['ip', 'link', 'del', 'test-ip6erspan'])
def test_add_sit_tunnel(self):
subprocess.check_output(['ip', 'tunnel', 'add', 'test-sittun', 'mode', 'sit', 'remote', '10.3.3.3', 'local', '10.4.4.4', 'ttl' ,'64'])
self.link_exists('test-sittun')
subprocess.check_output(['ip', 'link', 'del', 'test-sittun'])
def test_add_vti_tunnel(self):
subprocess.check_output(['ip', 'link', 'add', 'dev', 'test-vtitun', 'type', 'vti', 'remote', '10.3.3.3', 'local', '10.4.4.4'])
self.link_exists('test-vtitun')
subprocess.check_output(['ip', 'link', 'del', 'test-vtitun'])
def test_add_geneve_tunnel(self):
subprocess.check_output(['ip', 'link', 'add', 'dev', 'test-geneve-tun', 'type', 'geneve', 'remote', '10.3.3.3', 'vni', '1234'])
self.link_exists('test-geneve-tun')
subprocess.check_output(['ip', 'link', 'del', 'test-geneve-tun'])
def test_add_ipvlan(self):
subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy'])
self.link_exists('dummy-test')
subprocess.check_output(['ip', 'link', 'add', 'link', 'dummy-test', 'name', 'test-ipvlan', 'type', 'ipvlan'])
self.link_exists('test-ipvlan')
subprocess.check_output(['ip', 'link', 'del', 'test-ipvlan'])
subprocess.check_output(['ip', 'link', 'add', 'link', 'dummy-test', 'name', 'test-ipvlan', 'type', 'ipvlan','mode', 'l2', 'bridge'])
self.link_exists('test-ipvlan')
subprocess.check_output(['ip', 'link', 'del', 'test-ipvlan'])
subprocess.check_output(['ip', 'link', 'add', 'link', 'dummy-test', 'name', 'test-ipvlan', 'type', 'ipvlan','mode', 'l2', 'private'])
self.link_exists('test-ipvlan')
subprocess.check_output(['ip', 'link', 'del', 'test-ipvlan'])
subprocess.check_output(['ip', 'link', 'add', 'link', 'dummy-test', 'name', 'test-ipvlan', 'type', 'ipvlan','mode', 'l2', 'vepa'])
self.link_exists('test-ipvlan')
subprocess.check_output(['ip', 'link', 'del', 'test-ipvlan'])
subprocess.check_output(['ip', 'link', 'del', 'dummy-test'])
def test_add_vxlan(self):
subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy'])
self.link_exists('dummy-test')
subprocess.check_output(['ip', 'link', 'add', 'vxlan-test', 'type', 'vxlan', 'id', '42', 'group', '239.1.1.1', 'dev', 'dummy-test' ,'dstport', '4789'])
self.link_exists('vxlan-test')
subprocess.check_output(['ip', 'link', 'del', 'vxlan-test'])
subprocess.check_output(['ip', 'link', 'del', 'dummy-test'])
def test_add_vrf(self):
subprocess.check_output(['ip', 'link', 'add', 'vrf-test', 'type', 'vrf', 'table', '10'])
self.link_exists('vrf-test')
subprocess.check_output(['ip', 'link', 'del', 'vrf-test'])
def test_add_macsec(self):
subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy'])
self.link_exists('dummy-test')
subprocess.check_output(['ip', 'link', 'add', 'link', 'dummy-test', 'test-macsec', 'type', 'macsec'])
self.link_exists('test-macsec')
subprocess.check_output(['ip', 'macsec', 'add', 'test-macsec', 'tx', 'sa', '0', 'pn', '1', 'on', 'key', '02', '09876543210987654321098765432109'])
subprocess.check_output(['ip', 'macsec', 'add', 'test-macsec', 'rx', 'address', '56:68:a5:c2:4c:14', 'port', '1'])
subprocess.check_output(['ip', 'macsec', 'add', 'test-macsec', 'rx', 'address', '56:68:a5:c2:4c:14', 'port', '1', 'sa', '0', 'pn', '1', 'on', 'key', '01', '12345678901234567890123456789012'])
subprocess.check_output(['ip', 'link', 'del', 'test-macsec'])
subprocess.check_output(['ip', 'link', 'del', 'dummy-test'])
if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,
verbosity=2))