From e3e7ca1187b3ccfaf85a8c3107902fdb6303c8ce Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Jul 30 2018 09:52:04 +0000 Subject: CI: Add l2tp to test Sample run ``` :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Test :: Test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 15:21:16 ] :: [ LOG ] :: ip l2tp tests :: [ 15:21:16 ] :: [ LOG ] :: ip l2tp tests :: [ 15:21:16 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/ip-l2tp-tests.py' test_add_l2tp_add_tunnel (__main__.IPL2tpTests) ... Tunnel 3000, encap UDP From 192.168.11.12 to 192.168.11.13 Peer tunnel 4000 UDP source / dest ports: 5000/6000 UDP checksum: disabled ok test_add_l2tp_add_tunnel_session (__main__.IPL2tpTests) ... Tunnel 3000, encap UDP From 192.168.11.12 to 192.168.11.13 Peer tunnel 4000 UDP source / dest ports: 5000/6000 UDP checksum: disabled Session 1000 in tunnel 3000 Peer session 2000, tunnel 4000 interface name: l2tpeth0 offset 0, peer offset 0 ok test_setup_l2tp (__main__.IPL2tpTests) ... Tunnel 3000, encap UDP From 192.168.11.12 to 192.168.11.13 Peer tunnel 4000 UDP source / dest ports: 5000/6000 UDP checksum: disabled Session 1000 in tunnel 3000 Peer session 2000, tunnel 4000 interface name: l2tpeth0 offset 0, peer offset 0 Tunnel 4000, encap UDP From 192.168.11.13 to 192.168.11.12 Peer tunnel 3000 UDP source / dest ports: 6000/5000 UDP checksum: disabled Tunnel 3000, encap UDP From 192.168.11.12 to 192.168.11.13 Peer tunnel 4000 UDP source / dest ports: 5000/6000 UDP checksum: disabled Session 2000 in tunnel 4000 Peer session 1000, tunnel 3000 interface name: l2tpeth1 offset 0, peer offset 0 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: enp0s31f6: mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000 link/ether 8c:16:45:6c:83:b9 brd ff:ff:ff:ff:ff:ff 3: wlp4s0: mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000 link/ether 7c:76:35:ea:89:90 brd ff:ff:ff:ff:ff:ff 4: tun0: mtu 1360 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 100 link/none 92: 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 93: 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 94: 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 100: ip6tnl0@NONE: mtu 1452 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/tunnel6 :: brd :: 101: ip6gre0@NONE: mtu 1448 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/gre6 :: brd :: 104: 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 117: 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 126: 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 168: test-peer@veth-test: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 96:03:08:d2:65:40 brd ff:ff:ff:ff:ff:ff 169: veth-test@test-peer: mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether c2:8c:3b:9f:ea:32 brd ff:ff:ff:ff:ff:ff 170: l2tpeth0: mtu 1488 qdisc fq_codel state UNKNOWN mode DEFAULT group default qlen 1000 link/ether 76:41:ec:b9:d2:75 brd ff:ff:ff:ff:ff:ff 171: l2tpeth1: mtu 65481 qdisc noop state DOWN mode DEFAULT group default qlen 1000 link/ether 8e:7f:ab:21:a2:ea brd ff:ff:ff:ff:ff:ff PING 10.42.1.2 (10.42.1.2) 56(84) bytes of data. 64 bytes from 10.42.1.2: icmp_seq=1 ttl=64 time=0.013 ms 64 bytes from 10.42.1.2: icmp_seq=2 ttl=64 time=0.043 ms 64 bytes from 10.42.1.2: icmp_seq=3 ttl=64 time=0.066 ms 64 bytes from 10.42.1.2: icmp_seq=4 ttl=64 time=0.045 ms 64 bytes from 10.42.1.2: icmp_seq=5 ttl=64 time=0.041 ms --- 10.42.1.2 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4126ms rtt min/avg/max/mdev = 0.013/0.041/0.066/0.018 ms ok ---------------------------------------------------------------------- Ran 3 tests in 4.322s OK :: [ 15:21:21 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-l2tp-tests.py' (Expected 0, got 0) :: [ 15:21:21 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-l2tp-tests.py' (Expected 0, got 0) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 5s :: Duration: 5s :: Assertions: 1 good, 0 bad :: Assertions: 1 good, 0 bad :: RESULT: PASS :: RESULT: PASS ``` --- diff --git a/tests/ip-l2tp-sanity-test/Makefile b/tests/ip-l2tp-sanity-test/Makefile new file mode 100644 index 0000000..7040c7c --- /dev/null +++ b/tests/ip-l2tp-sanity-test/Makefile @@ -0,0 +1,47 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-l2tp-sanity-test +# Description: Test basic ip l2tp funcionality +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +#~~~ + +export TEST=/CoreOS/iproute/Sanity/ip-l2tp-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 l2tp 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-l2tp-sanity-test/PURPOSE b/tests/ip-l2tp-sanity-test/PURPOSE new file mode 100644 index 0000000..4224b1d --- /dev/null +++ b/tests/ip-l2tp-sanity-test/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/iproute/Sanity/ip-l2tp-sanity-test +Description: Test basic ip l2tp funcionality +Author: Susant Sahani diff --git a/tests/ip-l2tp-sanity-test/ip-l2tp-tests.py b/tests/ip-l2tp-sanity-test/ip-l2tp-tests.py new file mode 100755 index 0000000..1f20a14 --- /dev/null +++ b/tests/ip-l2tp-sanity-test/ip-l2tp-tests.py @@ -0,0 +1,149 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-l2tp-sanity-test +# Description: Test basic ip l2tp 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 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_address(self, address, interface): + subprocess.check_output(['ip', 'address', 'add', address, 'dev', interface]) + +class IPL2tpTests(unittest.TestCase, IPLinkUtilities): + + def setUp(self): + self.add_veth() + self.link_exists('veth-test') + + self.add_address('192.168.11.12/24', 'veth-test') + self.add_address('192.168.11.13/24', 'test-peer') + + def tearDown(self): + self.del_veth() + + def test_add_l2tp_add_tunnel(self): + + r = subprocess.call("ip l2tp add tunnel tunnel_id 3000 peer_tunnel_id 4000 encap udp local 192.168.11.12 remote 192.168.11.13 udp_sport 5000 udp_dport 6000", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '3000']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "From 192.168.11.12 to 192.168.11.13") + self.assertRegex(output, "Peer tunnel 4000") + self.assertRegex(output, "UDP source / dest ports: 5000/6000") + + r = subprocess.call("ip l2tp del tunnel tunnel_id 3000", shell=True) + self.assertEqual(r, 0) + + def test_add_l2tp_add_tunnel_session(self): + + r = subprocess.call("ip l2tp add tunnel tunnel_id 3000 peer_tunnel_id 4000 encap udp local 192.168.11.12 remote 192.168.11.13 udp_sport 5000 udp_dport 6000", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '3000']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "From 192.168.11.12 to 192.168.11.13") + self.assertRegex(output, "Peer tunnel 4000") + self.assertRegex(output, "UDP source / dest ports: 5000/6000") + + r = subprocess.call(" ip l2tp add session tunnel_id 3000 session_id 1000 peer_session_id 2000", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tunnel_id', '3000', 'session_id' ,'1000']).rstrip().decode('utf-8') + print(output) + + r = subprocess.call("ip l2tp del session tunnel_id 3000 session_id 1000", shell=True) + self.assertEqual(r, 0) + + r = subprocess.call("ip l2tp del tunnel tunnel_id 3000", shell=True) + self.assertEqual(r, 0) + + def test_setup_l2tp(self): + + r = subprocess.call("ip l2tp add tunnel tunnel_id 3000 peer_tunnel_id 4000 encap udp local 192.168.11.12 remote 192.168.11.13 udp_sport 5000 udp_dport 6000", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '3000']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "From 192.168.11.12 to 192.168.11.13") + self.assertRegex(output, "Peer tunnel 4000") + self.assertRegex(output, "UDP source / dest ports: 5000/6000") + + r = subprocess.call(" ip l2tp add session tunnel_id 3000 session_id 1000 peer_session_id 2000", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tunnel_id', '3000', 'session_id' ,'1000']).rstrip().decode('utf-8') + print(output) + + r = subprocess.call("ip l2tp add tunnel tunnel_id 4000 peer_tunnel_id 3000 encap udp local 192.168.11.13 remote 192.168.11.12 udp_sport 6000 udp_dport 5000", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'l2tp', 'show', 'tunnel', 'tunnel_id', '3000']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "From 192.168.11.13 to 192.168.11.12") + self.assertRegex(output, "Peer tunnel 4000") + self.assertRegex(output, "UDP source / dest ports: 6000/5000") + + r = subprocess.call("ip l2tp add session tunnel_id 4000 session_id 2000 peer_session_id 1000", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'l2tp', 'show', 'session', 'tunnel_id', '4000', 'session_id' ,'2000']).rstrip().decode('utf-8') + print(output) + + r = subprocess.call("ip link set l2tpeth0 up mtu 1488", shell=True) + self.assertEqual(r, 0) + r = subprocess.call("ip link set l2tpeth0 up mtu 1488", shell=True) + self.assertEqual(r, 0) + + r = subprocess.call("ip addr add 10.42.1.1 peer 10.42.1.2 dev l2tpeth0", shell=True) + self.assertEqual(r, 0) + r = subprocess.call("ip addr add 10.42.1.2 peer 10.42.1.1 dev l2tpeth1", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'link', 'show']).rstrip().decode('utf-8') + print(output) + + output=subprocess.check_output(['ping', '10.42.1.2','-c', '5']).rstrip().decode('utf-8') + print(output) + + r = subprocess.call("ip l2tp del session tunnel_id 3000 session_id 1000", shell=True) + self.assertEqual(r, 0) + r = subprocess.call("ip l2tp del session tunnel_id 4000 session_id 2000", shell=True) + self.assertEqual(r, 0) + + r = subprocess.call("ip l2tp del tunnel tunnel_id 3000", shell=True) + self.assertEqual(r, 0) + r = subprocess.call("ip l2tp del tunnel tunnel_id 4000", shell=True) + self.assertEqual(r, 0) + + +if __name__ == '__main__': + unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, + verbosity=2)) diff --git a/tests/ip-l2tp-sanity-test/runtest.sh b/tests/ip-l2tp-sanity-test/runtest.sh new file mode 100755 index 0000000..75b0589 --- /dev/null +++ b/tests/ip-l2tp-sanity-test/runtest.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-l2tp-sanity-test +# Description: Test basic ip l2tp 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-l2tp-tests.py /usr/bin" + rlPhaseEnd + + rlPhaseStartTest + rlLog "ip l2tp tests" + rlRun "/usr/bin/python3 /usr/bin/ip-l2tp-tests.py" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm /usr/bin/ip-l2tp-tests.py" + rlLog "ip l2tp tests done" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + +rlGetTestState diff --git a/tests/tests.yml b/tests/tests.yml index 8e03214..ff6adf8 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -17,6 +17,7 @@ - ip-token-sanity-test - ip-tuntap-sanity-test - ip-tunnel-sanity-test + - ip-l2tp-sanity-test required_packages: - iproute - bridge-utils