From 0b5c720c9c3f171b73928a70267c3ecd154ef743 Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Tue, 31 Jul 2018 15:36:29 +0530 Subject: [PATCH] CI: Add netns to test Sample run: ``` :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Test :: Test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 15:37:14 ] :: [ LOG ] :: ip netns tests :: [ 15:37:14 ] :: [ LOG ] :: ip netns tests :: [ 15:37:14 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/ip-netns-tests.py' test_add_dummy_interface_to_ns (__main__.IPNsTests) ... 1: lo: mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: gre0@NONE: mtu 1476 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/gre 0.0.0.0 brd 0.0.0.0 3: gretap0@NONE: mtu 1462 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff 4: erspan0@NONE: mtu 1446 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff 4: erspan0@NONE: mtu 1446 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff 5: ip6tnl0@NONE: mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/tunnel6 :: brd :: 6: ip6gre0@NONE: mtu 1448 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/gre6 :: brd :: 7: tunl0@NONE: mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 8: sit0@NONE: mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/sit 0.0.0.0 brd 0.0.0.0 9: ip_vti0@NONE: mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 143: dummy-test: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 6e:d1:ba:73:59:c5 brd ff:ff:ff:ff:ff:ff ok test_add_ns (__main__.IPNsTests) ... ok test_add_veth_interface_to_ns (__main__.IPNsTests) ... 1: lo: mtu 65536 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: gre0@NONE: mtu 1476 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/gre 0.0.0.0 brd 0.0.0.0 3: gretap0@NONE: mtu 1462 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff 4: erspan0@NONE: mtu 1446 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff 5: ip6tnl0@NONE: mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/tunnel6 :: brd :: 6: ip6gre0@NONE: mtu 1448 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/gre6 :: brd :: 7: tunl0@NONE: mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 8: sit0@NONE: mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/sit 0.0.0.0 brd 0.0.0.0 9: ip_vti0@NONE: mtu 1480 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 144: test-peer@if145: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 62:ce:d1:9f:bc:de brd ff:ff:ff:ff:ff:ff link-netnsid 0 1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: gre0@NONE: mtu 1476 qdisc noop state DOWN group default qlen 1000 link/gre 0.0.0.0 brd 0.0.0.0 3: gretap0@NONE: mtu 1462 qdisc noop state DOWN group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff 4: erspan0@NONE: mtu 1446 qdisc noop state DOWN group default qlen 1000 link/ether 00:00:00:00:00:00 brd ff:ff:ff:ff:ff:ff 5: ip6tnl0@NONE: mtu 1452 qdisc noop state DOWN group default qlen 1000 link/tunnel6 :: brd :: 6: ip6gre0@NONE: mtu 1448 qdisc noop state DOWN group default qlen 1000 link/gre6 :: brd :: 7: tunl0@NONE: mtu 1480 qdisc noop state DOWN group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 8: sit0@NONE: mtu 1480 qdisc noop state DOWN group default qlen 1000 link/sit 0.0.0.0 brd 0.0.0.0 9: ip_vti0@NONE: mtu 1480 qdisc noop state DOWN group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 144: test-peer@if145: mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether 62:ce:d1:9f:bc:de brd ff:ff:ff:ff:ff:ff link-netnsid 0 inet 10.200.1.2/24 scope global test-peer valid_lft forever preferred_lft forever inet6 fe80::60ce:d1ff:fe9f:bcde/64 scope link tentative valid_lft forever preferred_lft forever PING 10.200.1.1 (10.200.1.1) 56(84) bytes of data. 64 bytes from 10.200.1.1: icmp_seq=1 ttl=64 time=0.063 ms 64 bytes from 10.200.1.1: icmp_seq=2 ttl=64 time=0.042 ms 64 bytes from 10.200.1.1: icmp_seq=3 ttl=64 time=0.054 ms 64 bytes from 10.200.1.1: icmp_seq=4 ttl=64 time=0.059 ms 64 bytes from 10.200.1.1: icmp_seq=5 ttl=64 time=0.064 ms --- 10.200.1.1 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4073ms rtt min/avg/max/mdev = 0.042/0.056/0.064/0.010 ms ok ---------------------------------------------------------------------- Ran 3 tests in 4.431s Ran 3 tests in 4.431s OK :: [ 15:37:18 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-netns-tests.py' (Expected 0, got 0) :: [ 15:37:18 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-netns-tests.py' (Expected 0, got 0) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 4s :: Duration: 4s :: Assertions: 1 good, 0 bad :: Assertions: 1 good, 0 bad :: RESULT: PASS :: RESULT: PASS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Cleanup :: Cleanup ``` --- tests/ip-netns-sanity-test/Makefile | 47 ++++++++ tests/ip-netns-sanity-test/PURPOSE | 3 + tests/ip-netns-sanity-test/ip-netns-tests.py | 118 +++++++++++++++++++ tests/ip-netns-sanity-test/runtest.sh | 34 ++++++ tests/tests.yml | 1 + 5 files changed, 203 insertions(+) create mode 100644 tests/ip-netns-sanity-test/Makefile create mode 100644 tests/ip-netns-sanity-test/PURPOSE create mode 100755 tests/ip-netns-sanity-test/ip-netns-tests.py create mode 100755 tests/ip-netns-sanity-test/runtest.sh diff --git a/tests/ip-netns-sanity-test/Makefile b/tests/ip-netns-sanity-test/Makefile new file mode 100644 index 0000000..f4cfc49 --- /dev/null +++ b/tests/ip-netns-sanity-test/Makefile @@ -0,0 +1,47 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-netns-sanity-test +# Description: Test basic ip netns funcionality +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +#~~~ + +export TEST=/CoreOS/iproute/Sanity/ip-ns-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 netns 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-netns-sanity-test/PURPOSE b/tests/ip-netns-sanity-test/PURPOSE new file mode 100644 index 0000000..169a84d --- /dev/null +++ b/tests/ip-netns-sanity-test/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/iproute/Sanity/ip-netns-sanity-test +Description: Test basic ip netns funcionality +Author: Susant Sahani diff --git a/tests/ip-netns-sanity-test/ip-netns-tests.py b/tests/ip-netns-sanity-test/ip-netns-tests.py new file mode 100755 index 0000000..78bcb8a --- /dev/null +++ b/tests/ip-netns-sanity-test/ip-netns-tests.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-netns-sanity-test +# Description: Test basic ip netns 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 GenericUtilities(): + + def path_exists(self, path): + self.assertTrue(os.path.exists(os.path.join('/var/run/netns', path))) + + 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']) + + def add_dummy(self): + subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy']) + + def del_dummy(self): + subprocess.check_output(['ip', 'link', 'del', 'dummy-test']) + +class IPNsTests(unittest.TestCase, GenericUtilities): + + def test_add_ns(self): + + subprocess.check_output(['ip', 'netns', 'add', 'net-ns-test']) + self.path_exists('net-ns-test') + + output=subprocess.check_output(['ip', 'netns', 'list']).rstrip().decode('utf-8') + self.assertRegex(output, "net-ns-test") + + self.addCleanup(subprocess.call, ['ip', 'netns', 'del', 'net-ns-test']) + + def test_add_dummy_interface_to_ns(self): + + self.add_dummy() + self.link_exists('dummy-test') + + subprocess.check_output(['ip', 'netns', 'add', 'net-ns-test']) + self.path_exists('net-ns-test') + + output=subprocess.check_output(['ip', 'netns', 'list']).rstrip().decode('utf-8') + self.assertRegex(output, "net-ns-test") + + subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'netns', 'net-ns-test']) + + output=subprocess.check_output(['ip', 'netns', 'exec', 'net-ns-test', 'ip', 'link', 'show']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "dummy-test") + + self.addCleanup(subprocess.call, ['ip', 'netns', 'del', 'net-ns-test']) + self.addCleanup(subprocess.call, ['ip', 'netns', 'exec', 'net-ns-test', 'ip', 'link', 'del', 'dummy-test']) + + def test_add_veth_interface_to_ns(self): + + self.add_veth() + self.link_exists('veth-test') + + subprocess.check_output(['ip', 'netns', 'add', 'net-ns-test']) + self.path_exists('net-ns-test') + + output=subprocess.check_output(['ip', 'netns', 'list']).rstrip().decode('utf-8') + self.assertRegex(output, "net-ns-test") + + subprocess.check_output(['ip', 'link', 'set', 'dev', 'test-peer', 'netns', 'net-ns-test']) + + output=subprocess.check_output(['ip', 'netns', 'exec', 'net-ns-test', 'ip', 'link', 'show']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "test-peer") + + # Setup IP address of veth-test. + subprocess.check_output(['ip', 'addr', 'add', '10.200.1.1/24', 'dev', 'veth-test']) + subprocess.check_output(['ip', 'link', 'set', 'veth-test', 'up']) + + # Setup IP address of v-peer1. + subprocess.check_output(['ip', 'netns', 'exec', 'net-ns-test', 'ip', 'addr', 'add',' 10.200.1.2/24', 'dev', 'test-peer']) + subprocess.check_output(['ip', 'netns', 'exec', 'net-ns-test', 'ip', 'link', 'set', 'test-peer', 'up']) + subprocess.check_output(['ip', 'netns', 'exec', 'net-ns-test', 'ip', 'link', 'set', 'lo', 'up']) + + output=subprocess.check_output(['ip', 'netns', 'exec', 'net-ns-test', 'ip', 'addr', 'show']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "test-peer") + self.assertRegex(output, "lo: ") + self.assertRegex(output, "inet 10.200.1.2/24") + + output=subprocess.check_output(['ip', 'netns', 'exec', 'net-ns-test', 'ping', '10.200.1.1', '-c', '5']).rstrip().decode('utf-8') + print(output) + + self.addCleanup(subprocess.call, ['ip', 'netns', 'del', 'net-ns-test']) + self.addCleanup(subprocess.call, ['ip', 'netns', 'exec', 'net-ns-test', 'ip', 'link', 'del', 'test-peer']) + + +if __name__ == '__main__': + unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, + verbosity=2)) diff --git a/tests/ip-netns-sanity-test/runtest.sh b/tests/ip-netns-sanity-test/runtest.sh new file mode 100755 index 0000000..c0276fd --- /dev/null +++ b/tests/ip-netns-sanity-test/runtest.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# SPDX-Licenetnse-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-netns-sanity-test +# Description: Test basic ip netns 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-netns-tests.py /usr/bin" + rlPhaseEnd + + rlPhaseStartTest + rlLog "ip netns tests" + rlRun "/usr/bin/python3 /usr/bin/ip-netns-tests.py" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm /usr/bin/ip-netns-tests.py" + rlLog "ip netns tests done" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + +rlGetTestState diff --git a/tests/tests.yml b/tests/tests.yml index ff6adf8..9b58bad 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -18,6 +18,7 @@ - ip-tuntap-sanity-test - ip-tunnel-sanity-test - ip-l2tp-sanity-test + - ip-netns-sanity-test required_packages: - iproute - bridge-utils