From 73cd43c0ee2e7d65c401ebf53fcfe71f9013161c Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Tue, 24 Jul 2018 17:41:29 +0530 Subject: [PATCH] CI: Add ip tunnel to test Sample run ``` :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 17:39:52 ] :: [ LOG ] :: ip tunnel tests :: [ 17:39:52 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/ip-tunnel-tests.py' test_add_gre (__main__.IPTunnelTests) ... sit0: ipv6/ip remote any local any ttl 64 nopmtudisc 6rd-prefix 2002::/16 ip_vti0: ip/ip remote any local any ttl inherit nopmtudisc key 0 gre0: gre/ip remote any local any ttl inherit nopmtudisc tunl0: any/ip remote any local any ttl inherit nopmtudisc gretun-test: gre/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64 ok test_add_ipip (__main__.IPTunnelTests) ... sit0: ipv6/ip remote any local any ttl 64 nopmtudisc 6rd-prefix 2002::/16 ip_vti0: ip/ip remote any local any ttl inherit nopmtudisc key 0 gre0: gre/ip remote any local any ttl inherit nopmtudisc tunl0: any/ip remote any local any ttl inherit nopmtudisc ipiptun-test: ip/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64 ok test_add_isatap (__main__.IPTunnelTests) ... sit0: ipv6/ip remote any local any ttl 64 nopmtudisc 6rd-prefix 2002::/16 ip_vti0: ip/ip remote any local any ttl inherit nopmtudisc key 0 gre0: gre/ip remote any local any ttl inherit nopmtudisc tunl0: any/ip remote any local any ttl inherit nopmtudisc isatap-test: ipv6/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64 6rd-prefix 2002::/16 ok test_add_sit (__main__.IPTunnelTests) ... sit0: ipv6/ip remote any local any ttl 64 nopmtudisc 6rd-prefix 2002::/16 ip_vti0: ip/ip remote any local any ttl inherit nopmtudisc key 0 gre0: gre/ip remote any local any ttl inherit nopmtudisc tunl0: any/ip remote any local any ttl inherit nopmtudisc sittun-test: ipv6/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64 6rd-prefix 2002::/16 ok test_add_vti (__main__.IPTunnelTests) ... sit0: ipv6/ip remote any local any ttl 64 nopmtudisc 6rd-prefix 2002::/16 ip_vti0: ip/ip remote any local any ttl inherit nopmtudisc key 0 gre0: gre/ip remote any local any ttl inherit nopmtudisc tunl0: any/ip remote any local any ttl inherit nopmtudisc vti-test: ipv6/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64 6rd-prefix 2002::/16 ok ---------------------------------------------------------------------- Ran 5 tests in 0.197s OK ``` --- tests/ip-tunnel-sanity-test/Makefile | 47 ++++++++ tests/ip-tunnel-sanity-test/PURPOSE | 3 + .../ip-tunnel-sanity-test/ip-tunnel-tests.py | 104 ++++++++++++++++++ tests/ip-tunnel-sanity-test/runtest.sh | 34 ++++++ tests/tests.yml | 1 + 5 files changed, 189 insertions(+) create mode 100644 tests/ip-tunnel-sanity-test/Makefile create mode 100644 tests/ip-tunnel-sanity-test/PURPOSE create mode 100755 tests/ip-tunnel-sanity-test/ip-tunnel-tests.py create mode 100755 tests/ip-tunnel-sanity-test/runtest.sh diff --git a/tests/ip-tunnel-sanity-test/Makefile b/tests/ip-tunnel-sanity-test/Makefile new file mode 100644 index 0000000..cffa119 --- /dev/null +++ b/tests/ip-tunnel-sanity-test/Makefile @@ -0,0 +1,47 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-tunnel-sanity-test +# Description: Test basic ip tunnel funcionality +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +#~~~ + +export TEST=/CoreOS/iproute/Sanity/ip-tunnel-sanity-test +export TESTVERSION=1.0 + +BUILT_FILES= + +FILES=$(METADATA) runtest.sh Makefile PURPOSE + +.PHONY: all install download clean + +run: $(FILES) build + ./runtest.sh + +build: $(BUILT_FILES) + test -x runtest.sh || chmod a+x runtest.sh + +clean: + rm -f *~ $(BUILT_FILES) + + +include /usr/share/rhts/lib/rhts-make.include + +$(METADATA): Makefile + @echo "Owner: Susant Sahani " > $(METADATA) + @echo "Name: $(TEST)" >> $(METADATA) + @echo "TestVersion: $(TESTVERSION)" >> $(METADATA) + @echo "Path: $(TEST_DIR)" >> $(METADATA) + @echo "Description: Test basic ip tunnel funcionality" >> $(METADATA) + @echo "Type: Sanity" >> $(METADATA) + @echo "TestTime: 15m" >> $(METADATA) + @echo "RunFor: iproute" >> $(METADATA) + @echo "Requires: iproute" >> $(METADATA) + @echo "Priority: Normal" >> $(METADATA) + @echo "License: GPLv2" >> $(METADATA) + @echo "Confidential: no" >> $(METADATA) + @echo "Destructive: no" >> $(METADATA) + + rhts-lint $(METADATA) diff --git a/tests/ip-tunnel-sanity-test/PURPOSE b/tests/ip-tunnel-sanity-test/PURPOSE new file mode 100644 index 0000000..0b8f618 --- /dev/null +++ b/tests/ip-tunnel-sanity-test/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/iproute/Sanity/ip-tunnel-sanity-test +Description: Test basic ip tunnel funcionality +Author: Susant Sahani diff --git a/tests/ip-tunnel-sanity-test/ip-tunnel-tests.py b/tests/ip-tunnel-sanity-test/ip-tunnel-tests.py new file mode 100755 index 0000000..58b7641 --- /dev/null +++ b/tests/ip-tunnel-sanity-test/ip-tunnel-tests.py @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-tunnel-sanity-test +# Description: Test basic ip tunnel funcionality +# +# Author: Susant Sahani +# 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 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']) + + def link_exists(self, link): + self.assertTrue(os.path.exists(os.path.join('/sys/class/net', link))) + +class IPTunnelTests(unittest.TestCase, IPLinkUtilities): + + def setUp(self): + self.add_dummy() + self.link_exists('dummy-test') + + def tearDown(self): + self.del_dummy() + + def test_add_ipip(self): + + subprocess.check_output(['ip', 'tunnel', 'add', 'ipiptun-test', 'mode', 'ipip', 'local', '10.3.3.3', 'remote', '10.4.4.4', 'ttl', '64', 'dev', 'dummy-test']) + self.link_exists('ipiptun-test') + + output=subprocess.check_output(['ip', 'tunnel']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "ipiptun-test: ip/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64") + + subprocess.check_output(['ip', 'link', 'del', 'ipiptun-test']) + + def test_add_gre(self): + + subprocess.check_output(['ip', 'tunnel', 'add', 'gretun-test', 'mode', 'gre', 'local', '10.3.3.3', 'remote', '10.4.4.4', 'ttl', '64', 'dev', 'dummy-test']) + self.link_exists('gretun-test') + + output=subprocess.check_output(['ip', 'tunnel']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "gretun-test: gre/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64") + + subprocess.check_output(['ip', 'link', 'del', 'gretun-test']) + + def test_add_sit(self): + + subprocess.check_output(['ip', 'tunnel', 'add', 'sittun-test', 'mode', 'sit', 'local', '10.3.3.3', 'remote', '10.4.4.4', 'ttl', '64', 'dev', 'dummy-test']) + self.link_exists('sittun-test') + + output=subprocess.check_output(['ip', 'tunnel']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "sittun-test: ipv6/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64") + + subprocess.check_output(['ip', 'link', 'del', 'sittun-test']) + + def test_add_isatap(self): + + subprocess.check_output(['ip', 'tunnel', 'add', 'isatap-test', 'mode', 'sit', 'local', '10.3.3.3', 'remote', '10.4.4.4', 'ttl', '64', 'dev', 'dummy-test']) + self.link_exists('isatap-test') + + output=subprocess.check_output(['ip', 'tunnel']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "isatap-test: ipv6/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64") + + subprocess.check_output(['ip', 'link', 'del', 'isatap-test']) + + def test_add_vti(self): + + subprocess.check_output(['ip', 'tunnel', 'add', 'vti-test', 'mode', 'sit', 'local', '10.3.3.3', 'remote', '10.4.4.4', 'ttl', '64', 'dev', 'dummy-test']) + self.link_exists('vti-test') + + output=subprocess.check_output(['ip', 'tunnel']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "vti-test: ipv6/ip remote 10.4.4.4 local 10.3.3.3 dev dummy-test ttl 64") + + subprocess.check_output(['ip', 'link', 'del', 'vti-test']) + + +if __name__ == '__main__': + unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, + verbosity=2)) diff --git a/tests/ip-tunnel-sanity-test/runtest.sh b/tests/ip-tunnel-sanity-test/runtest.sh new file mode 100755 index 0000000..58a154d --- /dev/null +++ b/tests/ip-tunnel-sanity-test/runtest.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-tunnel-sanity-test +# Description: Test basic ip tunnel funcionality +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +#~~~ + +# Include Beaker environment +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +PACKAGE="iproute" + +rlJournalStart + rlPhaseStartSetup + rlAssertRpm $PACKAGE + rlRun "cp ip-tunnel-tests.py /usr/bin" + rlPhaseEnd + + rlPhaseStartTest + rlLog "ip tunnel tests" + rlRun "/usr/bin/python3 /usr/bin/ip-tunnel-tests.py" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm /usr/bin/ip-tunnel-tests.py" + rlLog "ip tunnel tests done" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + +rlGetTestState diff --git a/tests/tests.yml b/tests/tests.yml index 8c27973..8e03214 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -16,6 +16,7 @@ - ip-fou-sanity-test - ip-token-sanity-test - ip-tuntap-sanity-test + - ip-tunnel-sanity-test required_packages: - iproute - bridge-utils