iproute/tests/ip-token-sanity-test/ip-token-tests.py

60 lines
1.6 KiB
Python
Raw Normal View History

CI: Add ip token to test Sample Run ``` ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Setup :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: iproute-4.16.0-1.fc28.x86_64 :: [ 16:55:06 ] :: [ PASS ] :: Checking for the presence of iproute rpm :: [ 16:55:06 ] :: [ LOG ] :: Package versions: :: [ 16:55:06 ] :: [ LOG ] :: iproute-4.16.0-1.fc28.x86_64 :: [ 16:55:06 ] :: [ BEGIN ] :: Running 'cp ip-token-tests.py /usr/bin' :: [ 16:55:06 ] :: [ PASS ] :: Command 'cp ip-token-tests.py /usr/bin' (Expected 0, got 0) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 0s :: Assertions: 2 good, 0 bad :: RESULT: PASS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 16:55:07 ] :: [ LOG ] :: ip token tests :: [ 16:55:07 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/ip-token-tests.py' test_add_token (__main__.IPTokenTests) ... token ::1a:2b:3c:4d dev veth-test ok ---------------------------------------------------------------------- Ran 1 test in 0.029s OK :: [ 16:55:07 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-token-tests.py' (Expected 0, got 0) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 1s :: Assertions: 1 good, 0 bad :: RESULT: PASS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Cleanup :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ```
2018-07-24 11:26:27 +00:00
#!/usr/bin/env python3
# SPDX-License-Identifier: LGPL-2.1+
# ~~~
# runtest.sh of /CoreOS/iproute/Sanity/ip-token-sanity-test
# Description: Test basic ip token 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_veth(self):
subprocess.check_output(['ip', 'link', 'add', 'veth-test', 'type', 'veth', 'peer', 'name', 'test-peer'])
def del_veth(self):
subprocess.check_output(['ip', 'link', 'del', 'veth-test'])
class IPTokenTests(unittest.TestCase, IPLinkUtilities):
def setUp(self):
self.add_veth()
self.link_exists('veth-test')
def tearDown(self):
self.del_veth()
def test_add_token(self):
r = subprocess.call("ip token set ::1a:2b:3c:4d/64 dev veth-test", shell=True)
self.assertEqual(r, 0)
output=subprocess.check_output(['ip', 'token', 'get', 'dev', 'veth-test']).rstrip().decode('utf-8')
print(output)
self.assertRegex(output, "token ::1a:2b:3c:4d dev veth-test")
r = subprocess.call("ip token del ::1a:2b:3c:4d/64 dev veth-test", shell=True)
self.assertEqual(r, 0)
if __name__ == '__main__':
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,
verbosity=2))