iproute/tests/ip-address-label-sanity-test/ip-address-label-tests.py
Susant Sahani fd68e09fe1 CI: Add ip addrlabel to test
Sample Run

```
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

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

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 17:56:55 ] :: [   LOG    ] :: ip address label tests
:: [ 17:56:55 ] :: [   LOG    ] :: ip address label tests
:: [ 17:56:55 ] :: [  BEGIN   ] :: Running '/usr/bin/python3 /usr/bin/ip-address-label-tests.py'
test_add_address_label (__main__.IPAddressLabelTests) ... prefix ::1/128 label 0
prefix ::/96 label 3
prefix ::ffff:0.0.0.0/96 label 4
prefix 2001:6f8:12d8:2::/64 dev if14 label 200
prefix 2001:6f8:900:8cbc::/64 dev if14 label 300
prefix 2001:4dd0:ff00:834::/64 dev if14 label 200
prefix 2a01:238:423d:8800::/64 dev if14 label 300
prefix 2001:4dd0:ff00:834::/64 dev if14 label 200
prefix 2a01:238:423d:8800::/64 dev if14 label 300
prefix 2a01:238:423d:8800::/64 label 300
prefix 2001:4dd0:ff00:834::/64 label 200
prefix 2001:6f8:900:8cbc::/64 label 300
prefix 2001:6f8:12d8:2::/64 label 200
prefix 2001::/32 label 6
prefix 2001:10::/28 label 7
prefix 3ffe::/16 label 12
prefix 2002::/16 label 2
prefix fec0::/10 label 11
prefix fc00::/7 label 5
prefix ::/0 label 1
ok
test_add_address_label_dev (__main__.IPAddressLabelTests) ... prefix ::1/128 label 0
prefix ::/96 label 3
prefix ::ffff:0.0.0.0/96 label 4
prefix 2001:6f8:12d8:2::/64 dev if14 label 200
prefix 2001:6f8:900:8cbc::/64 dev if14 label 300
prefix 2001:4dd0:ff00:834::/64 dev if14 label 200
prefix 2a01:238:423d:8800::/64 dev if14 label 300
prefix 2001:6f8:12d8:2::/64 dev dummy-test label 200
prefix 2001:6f8:900:8cbc::/64 dev dummy-test label 300
prefix 2001:4dd0:ff00:834::/64 dev dummy-test label 200
prefix 2a01:238:423d:8800::/64 dev dummy-test label 300
prefix 2001::/32 label 6
prefix 2001:10::/28 label 7
prefix 3ffe::/16 label 12
prefix 2002::/16 label 2
prefix fec0::/10 label 11
prefix fc00::/7 label 5
prefix ::/0 label 1
ok

----------------------------------------------------------------------
Ran 2 tests in 0.077s

OK
```
2018-07-23 21:12:47 +05:30

90 lines
3.8 KiB
Python
Executable File

#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1+
# ~~~
# runtest.sh of /CoreOS/iproute/Sanity/ip-address-label-sanity-test
# Description: Test basic ip addrlabel 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 link_exists(self, link):
self.assertTrue(os.path.exists(os.path.join('/sys/class/net', link)))
def add_dummy(self):
subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy'])
self.link_exists('dummy-test')
def del_dummy(self):
subprocess.check_output(['ip', 'link', 'del', 'dummy-test'])
class IPAddressLabelTests(unittest.TestCase, IPLinkUtilities):
def setUp(self):
self.add_dummy()
self.link_exists('dummy-test')
def tearDown(self):
self.del_dummy()
def test_add_address_label(self):
subprocess.call("ip addrlabel add prefix 2001:6f8:12d8:2::/64 label 200", shell=True)
subprocess.call("ip addrlabel add prefix 2001:6f8:900:8cbc::/64 label 300", shell=True)
subprocess.call("ip addrlabel add prefix 2001:4dd0:ff00:834::/64 label 200", shell=True)
subprocess.call("ip addrlabel add prefix 2a01:238:423d:8800::/64 label 300", shell=True)
output=subprocess.check_output(['ip', 'addrlabel']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "prefix 2001:6f8:12d8:2::/64 label 200")
self.assertRegex(output, "prefix 2001:6f8:900:8cbc::/64 label 300")
self.assertRegex(output, "prefix 2001:4dd0:ff00:834::/64 label 200")
self.assertRegex(output, "prefix 2a01:238:423d:8800::/64 label 300")
subprocess.call("ip addrlabel del prefix 2001:6f8:12d8:2::/64 label 200", shell=True)
subprocess.call("ip addrlabel del prefix 2001:6f8:900:8cbc::/64 label 300", shell=True)
subprocess.call("ip addrlabel del prefix 2001:4dd0:ff00:834::/64 label 200", shell=True)
subprocess.call("ip addrlabel del prefix 2a01:238:423d:8800::/64 label 300", shell=True)
def test_add_address_label_dev(self):
subprocess.call("ip addrlabel add prefix 2001:6f8:12d8:2::/64 label 200 dev dummy-test", shell=True)
subprocess.call("ip addrlabel add prefix 2001:6f8:900:8cbc::/64 label 300 dev dummy-test", shell=True)
subprocess.call("ip addrlabel add prefix 2001:4dd0:ff00:834::/64 label 200 dev dummy-test", shell=True)
subprocess.call("ip addrlabel add prefix 2a01:238:423d:8800::/64 label 300 dev dummy-test", shell=True)
output=subprocess.check_output(['ip', 'addrlabel']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "prefix 2001:6f8:12d8:2::/64 dev dummy-test label 200")
self.assertRegex(output, "prefix 2001:6f8:900:8cbc::/64 dev dummy-test label 300")
self.assertRegex(output, "prefix 2001:4dd0:ff00:834::/64 dev dummy-test label 200")
self.assertRegex(output, "prefix 2a01:238:423d:8800::/64 dev dummy-test label 300")
subprocess.call("ip addrlabel del prefix 2001:6f8:12d8:2::/64 label 200 dev dummy-test", shell=True)
subprocess.call("ip addrlabel del prefix 2001:6f8:900:8cbc::/64 label 300 dev dummy-test", shell=True)
subprocess.call("ip addrlabel del prefix 2001:4dd0:ff00:834::/64 label 200 dev dummy-test", shell=True)
subprocess.call("ip addrlabel del prefix 2a01:238:423d:8800::/64 label 300 dev dummy-test", shell=True)
if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,
verbosity=2))