naccyde / rpms / iproute

Forked from rpms/iproute 9 months ago
Clone

Blame tests/ip-fou-sanity-test/ip-fou-tests.py

Petr Šabata d9a596
#!/usr/bin/env python3
Petr Šabata d9a596
# SPDX-License-Identifier: LGPL-2.1+
Petr Šabata d9a596
# ~~~
Petr Šabata d9a596
#   runtest.sh of /CoreOS/iproute/Sanity/ip-fou-sanity-test
Petr Šabata d9a596
#   Description: Test basic ip fou funcionality
Petr Šabata d9a596
#
Petr Šabata d9a596
#   Author: Susant Sahani <susant@redhat.com>
Petr Šabata d9a596
#   Copyright (c) 2018 Red Hat, Inc.
Petr Šabata d9a596
# ~~~
Petr Šabata d9a596
Petr Šabata d9a596
import errno
Petr Šabata d9a596
import os
Petr Šabata d9a596
import sys
Petr Šabata d9a596
import time
Petr Šabata d9a596
import unittest
Petr Šabata d9a596
import subprocess
Petr Šabata d9a596
import signal
Petr Šabata d9a596
import shutil
Petr Šabata d9a596
Petr Šabata d9a596
def setUpModule():
Petr Šabata d9a596
Petr Šabata d9a596
    if shutil.which('ip') is None:
Petr Šabata d9a596
        raise OSError(errno.ENOENT, 'ip not found')
Petr Šabata d9a596
Petr Šabata d9a596
class IPFOUTests(unittest.TestCase):
Petr Šabata d9a596
Petr Šabata d9a596
    def test_configure_fou_receive_port_gre(self):
Petr Šabata d9a596
        ''' Configure a FOU receive port for GRE bound to 7777'''
Petr Šabata d9a596
Petr Šabata d9a596
        subprocess.call(" ip fou add port 7777 ipproto 47", shell=True)
Petr Šabata d9a596
        output=subprocess.check_output(['ip', 'fou', 'show']).rstrip().decode('utf-8')
Petr Šabata d9a596
        print(output)
Petr Šabata d9a596
        self.assertRegex(output, "port 7777 ipproto 47")
Petr Šabata d9a596
Petr Šabata d9a596
        subprocess.call("ip fou del port 7777", shell=True)
Petr Šabata d9a596
Petr Šabata d9a596
    def test_configure_fou_receive_port_ipip(self):
Petr Šabata d9a596
        ''' Configure a FOU receive port for IPIP bound to 8888'''
Petr Šabata d9a596
Petr Šabata d9a596
        subprocess.call("ip fou add port 8888 ipproto 4", shell=True)
Petr Šabata d9a596
        output=subprocess.check_output(['ip', 'fou', 'show']).rstrip().decode('utf-8')
Petr Šabata d9a596
        print(output)
Petr Šabata d9a596
        self.assertRegex(output, "port 8888 ipproto 4")
Petr Šabata d9a596
Petr Šabata d9a596
        subprocess.call("ip fou del port 8888", shell=True)
Petr Šabata d9a596
Petr Šabata d9a596
    def test_configure_fou_receive_port_gue(self):
Petr Šabata d9a596
        ''' Configure a GUE receive port bound to 9999 '''
Petr Šabata d9a596
Petr Šabata d9a596
        subprocess.call("ip fou add port 9999 gue", shell=True)
Petr Šabata d9a596
        output=subprocess.check_output(['ip', 'fou', 'show']).rstrip().decode('utf-8')
Petr Šabata d9a596
        print(output)
Petr Šabata d9a596
        self.assertRegex(output, "port 9999 gue")
Petr Šabata d9a596
Petr Šabata d9a596
        subprocess.call("ip fou del port 9999", shell=True)
Petr Šabata d9a596
Petr Šabata d9a596
    def test_configure_fou_with_ipip(self):
Petr Šabata d9a596
        ''' IP over UDP tunnel '''
Petr Šabata d9a596
Petr Šabata d9a596
        subprocess.call("ip fou add port 9000 ipproto 4", shell=True)
Petr Šabata d9a596
        output=subprocess.check_output(['ip', 'fou', 'show']).rstrip().decode('utf-8')
Petr Šabata d9a596
        print(output)
Petr Šabata d9a596
        self.assertRegex(output, "port 9000 ipproto 4")
Petr Šabata d9a596
Petr Šabata d9a596
        subprocess.call("ip link add name tunudp type ipip remote 192.168.2.2 local 192.168.2.1 ttl 225 encap fou encap-sport auto encap-dport 9000", shell=True)
Petr Šabata d9a596
        output=subprocess.check_output(['ip', '-d', 'link', 'show', 'tunudp']).rstrip().decode('utf-8')
Petr Šabata d9a596
        self.assertRegex(output, "encap fou")
Petr Šabata d9a596
Petr Šabata d9a596
        subprocess.call("ip link del tunudp", shell=True)
Petr Šabata d9a596
        subprocess.call("ip fou del port 9000", shell=True)
Petr Šabata d9a596
Petr Šabata d9a596
if __name__ == '__main__':
Petr Šabata d9a596
    unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout,
Petr Šabata d9a596
                                                     verbosity=2))