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: <LOOPBACK> 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: <NOARP> 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: <BROADCAST,MULTICAST> 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: <BROADCAST,MULTICAST> 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: <BROADCAST,MULTICAST> 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: <NOARP> mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/tunnel6 :: brd :: 6: ip6gre0@NONE: <NOARP> mtu 1448 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/gre6 :: brd :: 7: tunl0@NONE: <NOARP> 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: <NOARP> 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: <NOARP> 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: <BROADCAST,NOARP> 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: <LOOPBACK> 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: <NOARP> 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: <BROADCAST,MULTICAST> 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: <BROADCAST,MULTICAST> 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: <NOARP> mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/tunnel6 :: brd :: 6: ip6gre0@NONE: <NOARP> mtu 1448 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/gre6 :: brd :: 7: tunl0@NONE: <NOARP> 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: <NOARP> 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: <NOARP> 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: <BROADCAST,MULTICAST> 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: <LOOPBACK,UP,LOWER_UP> 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: <NOARP> mtu 1476 qdisc noop state DOWN group default qlen 1000 link/gre 0.0.0.0 brd 0.0.0.0 3: gretap0@NONE: <BROADCAST,MULTICAST> 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: <BROADCAST,MULTICAST> 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: <NOARP> mtu 1452 qdisc noop state DOWN group default qlen 1000 link/tunnel6 :: brd :: 6: ip6gre0@NONE: <NOARP> mtu 1448 qdisc noop state DOWN group default qlen 1000 link/gre6 :: brd :: 7: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN group default qlen 1000 link/ipip 0.0.0.0 brd 0.0.0.0 8: sit0@NONE: <NOARP> 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: <NOARP> 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: <BROADCAST,MULTICAST,UP,LOWER_UP> 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 ```
This commit is contained in:
parent
e3e7ca1187
commit
0b5c720c9c
47
tests/ip-netns-sanity-test/Makefile
Normal file
47
tests/ip-netns-sanity-test/Makefile
Normal file
@ -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 <susant@redhat.com>
|
||||||
|
# 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 <susant@redhat.com>" > $(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)
|
3
tests/ip-netns-sanity-test/PURPOSE
Normal file
3
tests/ip-netns-sanity-test/PURPOSE
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
PURPOSE of /CoreOS/iproute/Sanity/ip-netns-sanity-test
|
||||||
|
Description: Test basic ip netns funcionality
|
||||||
|
Author: Susant Sahani <susant@redhat.com>
|
118
tests/ip-netns-sanity-test/ip-netns-tests.py
Executable file
118
tests/ip-netns-sanity-test/ip-netns-tests.py
Executable file
@ -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 <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 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: <LOOPBACK,UP,LOWER_UP>")
|
||||||
|
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))
|
34
tests/ip-netns-sanity-test/runtest.sh
Executable file
34
tests/ip-netns-sanity-test/runtest.sh
Executable file
@ -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 <susant@redhat.com>
|
||||||
|
# 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
|
@ -18,6 +18,7 @@
|
|||||||
- ip-tuntap-sanity-test
|
- ip-tuntap-sanity-test
|
||||||
- ip-tunnel-sanity-test
|
- ip-tunnel-sanity-test
|
||||||
- ip-l2tp-sanity-test
|
- ip-l2tp-sanity-test
|
||||||
|
- ip-netns-sanity-test
|
||||||
required_packages:
|
required_packages:
|
||||||
- iproute
|
- iproute
|
||||||
- bridge-utils
|
- bridge-utils
|
||||||
|
Loading…
Reference in New Issue
Block a user