5c4250bd81
Sample run ``` :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 17:14:21 ] :: [ LOG ] :: ip tuntap tests :: [ 17:14:21 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/ip-tuntap-tests.py' test_add_tap (__main__.IPTuntapTests) ... fopen /sys/class/net/ip6gre0/tun_flags: No such file or directory fopen /sys/class/net/wlan0/tun_flags: No such file or directory ok ok test_add_tun_user_group (__main__.IPTuntapTests) ... fopen /sys/class/net/ip6gre0/tun_flags: No such file or directory ok ---------------------------------------------------------------------- Ran 3 tests in 0.049s OK :: [ 17:14:21 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-tuntap-tests.py' (Expected 0, got 0) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 0s :: Assertions: 1 good, 0 bad :: RESULT: PASS ```
66 lines
2.1 KiB
Python
Executable File
66 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: LGPL-2.1+
|
|
# ~~~
|
|
# runtest.sh of /CoreOS/iproute/Sanity/ip-tuntap-sanity-test
|
|
# Description: Test basic ip tuntap 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)))
|
|
|
|
class IPTuntapTests(unittest.TestCase, IPLinkUtilities):
|
|
|
|
def test_add_tap(self):
|
|
|
|
subprocess.check_output(['ip', 'tuntap', 'add', 'name', 'tap-test', 'mode', 'tap'])
|
|
self.link_exists('tap-test')
|
|
|
|
output=subprocess.check_output(['ip', 'tuntap', 'show', 'dev', 'tap-test']).rstrip().decode('utf-8')
|
|
self.assertRegex(output, "tap-test: tap")
|
|
|
|
subprocess.check_output(['ip', 'link', 'del', 'tap-test'])
|
|
|
|
def test_add_tun(self):
|
|
|
|
subprocess.check_output(['ip', 'tuntap', 'add', 'name', 'tun-test', 'mode', 'tun'])
|
|
self.link_exists('tun-test')
|
|
|
|
output=subprocess.check_output(['ip', 'tuntap', 'show', 'dev', 'tun-test']).rstrip().decode('utf-8')
|
|
self.assertRegex(output, "tun-test: tun")
|
|
|
|
subprocess.check_output(['ip', 'link', 'del', 'tun-test'])
|
|
|
|
def test_add_tun_user_group(self):
|
|
|
|
subprocess.check_output(['ip', 'tuntap', 'add', 'name', 'tun-test', 'mode', 'tun', 'user', 'root', 'group', 'root'])
|
|
self.link_exists('tun-test')
|
|
|
|
output=subprocess.check_output(['ip', 'tuntap', 'show', 'dev', 'tun-test']).rstrip().decode('utf-8')
|
|
self.assertRegex(output, "tun-test: tun")
|
|
self.assertRegex(output, "user 0 group 0")
|
|
|
|
subprocess.check_output(['ip', 'link', 'del', 'tun-test'])
|
|
|
|
if __name__ == '__main__':
|
|
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,
|
|
verbosity=2))
|