From 90c1f7753860f6c2f1a52d983003e1fbf872fe3c Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Jul 31 2018 12:52:25 +0000 Subject: CI: Add ip route to test Sample run ''' :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Test :: Test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 18:23:29 ] :: [ LOG ] :: ip route tests :: [ 18:23:29 ] :: [ LOG ] :: ip route tests :: [ 18:23:29 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/ip-route-tests.py' test_add_blackhole (__main__.IPRouteTests) ... default via 192.168.225.1 dev wlp4s0 proto dhcp metric 600 10.0.0.0/8 via 10.67.116.1 dev tun0 proto static metric 50 10.67.116.0/22 dev tun0 proto kernel scope link src 10.67.117.15 metric 50 blackhole 192.168.1.0/24 192.168.225.0/24 dev wlp4s0 proto kernel scope link src 192.168.225.101 metric 600 192.168.225.1 dev wlp4s0 proto static scope link metric 600 209.132.188.220 via 192.168.225.1 dev wlp4s0 proto static metric 600 192.168.225.1 dev wlp4s0 proto static scope link metric 600 209.132.188.220 via 192.168.225.1 dev wlp4s0 proto static metric 600 ok test_add_prohibit (__main__.IPRouteTests) ... default via 192.168.225.1 dev wlp4s0 proto dhcp metric 600 10.0.0.0/8 via 10.67.116.1 dev tun0 proto static metric 50 10.67.116.0/22 dev tun0 proto kernel scope link src 10.67.117.15 metric 50 prohibit 192.168.1.0/24 192.168.225.0/24 dev wlp4s0 proto kernel scope link src 192.168.225.101 metric 600 192.168.225.1 dev wlp4s0 proto static scope link metric 600 209.132.188.220 via 192.168.225.1 dev wlp4s0 proto static metric 600 ok test_add_route (__main__.IPRouteTests) ... default via 192.168.225.1 dev wlp4s0 proto dhcp metric 600 10.0.0.0/8 via 10.67.116.1 dev tun0 proto static metric 50 10.67.116.0/22 dev tun0 proto kernel scope link src 10.67.117.15 metric 50 192.168.1.0/24 dev dummy-test scope link 192.168.225.0/24 dev wlp4s0 proto kernel scope link src 192.168.225.101 metric 600 192.168.225.1 dev wlp4s0 proto static scope link metric 600 209.132.188.220 via 192.168.225.1 dev wlp4s0 proto static metric 600 ok test_add_route_table (__main__.IPRouteTests) ... 192.168.1.0/24 dev dummy-test scope link ok test_add_throw (__main__.IPRouteTests) ... default via 192.168.225.1 dev wlp4s0 proto dhcp metric 600 10.0.0.0/8 via 10.67.116.1 dev tun0 proto static metric 50 10.67.116.0/22 dev tun0 proto kernel scope link src 10.67.117.15 metric 50 throw 192.168.1.0/24 192.168.225.0/24 dev wlp4s0 proto kernel scope link src 192.168.225.101 metric 600 192.168.225.1 dev wlp4s0 proto static scope link metric 600 209.132.188.220 via 192.168.225.1 dev wlp4s0 proto static metric 600 ok test_add_unreachable (__main__.IPRouteTests) ... default via 192.168.225.1 dev wlp4s0 proto dhcp metric 600 10.0.0.0/8 via 10.67.116.1 dev tun0 proto static metric 50 10.67.116.0/22 dev tun0 proto kernel scope link src 10.67.117.15 metric 50 unreachable 192.168.1.0/24 192.168.225.0/24 dev wlp4s0 proto kernel scope link src 192.168.225.101 metric 600 192.168.225.1 dev wlp4s0 proto static scope link metric 600 209.132.188.220 via 192.168.225.1 dev wlp4s0 proto static metric 600 ok ---------------------------------------------------------------------- Ran 6 tests in 0.155s OK :: [ 18:23:29 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-route-tests.py' (Expected 0, got 0) :: [ 18:23:29 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-route-tests.py' (Expected 0, got 0) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 1s :: Duration: 1s :: Assertions: 1 good, 0 bad :: Assertions: 1 good, 0 bad :: RESULT: PASS :: RESULT: PASS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Cleanup :: Cleanup :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ''' --- diff --git a/tests/ip-route-sanity-test/Makefile b/tests/ip-route-sanity-test/Makefile new file mode 100644 index 0000000..0b21130 --- /dev/null +++ b/tests/ip-route-sanity-test/Makefile @@ -0,0 +1,47 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-route-sanity-test +# Description: Test basic ip route funcionality +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +#~~~ + +export TEST=/CoreOS/iproute/Sanity/ip-route-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 route 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-route-sanity-test/PURPOSE b/tests/ip-route-sanity-test/PURPOSE new file mode 100644 index 0000000..792d9ba --- /dev/null +++ b/tests/ip-route-sanity-test/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/iproute/Sanity/ip-route-sanity-test +Description: Test basic ip route funcionality +Author: Susant Sahani diff --git a/tests/ip-route-sanity-test/ip-route-tests.py b/tests/ip-route-sanity-test/ip-route-tests.py new file mode 100755 index 0000000..2845cae --- /dev/null +++ b/tests/ip-route-sanity-test/ip-route-tests.py @@ -0,0 +1,110 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-route-sanity-test +# Description: Test basic ip route 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_dummy(self): + """ Setup """ + subprocess.check_output(['ip', 'link', 'add', 'dummy-test', 'type', 'dummy']) + self.link_exists('dummy-test') + subprocess.check_output(['ip', 'link', 'set', 'dev', 'dummy-test', 'up']) + + def del_dummy(self): + subprocess.check_output(['ip', 'link', 'del', 'dummy-test']) + +class IPRouteTests(unittest.TestCase, IPLinkUtilities): + + def setUp(self): + self.add_dummy() + + def tearDown(self): + self.del_dummy() + + def test_add_route(self): + + subprocess.check_output(['ip', 'route', 'add', '192.168.1.0/24', 'dev', 'dummy-test']) + + output=subprocess.check_output(['ip', 'route', 'show']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "192.168.1.0/24 dev dummy-test scope link") + + subprocess.check_output(['ip', 'route', 'delete', '192.168.1.0/24', 'dev', 'dummy-test']) + + def test_add_route_table(self): + + subprocess.check_output(['ip', 'route', 'add', 'table', '555', '192.168.1.0/24', 'dev', 'dummy-test']) + + output=subprocess.check_output(['ip', 'route', 'show', 'table', '555']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "192.168.1.0/24 dev dummy-test scope link") + + subprocess.check_output(['ip', 'route', 'delete', '192.168.1.0/24', 'dev', 'dummy-test', 'table', '555']) + + def test_add_blackhole(self): + + subprocess.check_output(['ip', 'route', 'add', 'blackhole', '192.168.1.0/24']) + + output=subprocess.check_output(['ip', 'route', 'show']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "blackhole 192.168.1.0/24") + + subprocess.check_output(['ip', 'route', 'delete', '192.168.1.0/24']) + + def test_add_unreachable(self): + + subprocess.check_output(['ip', 'route', 'add', 'unreachable', '192.168.1.0/24']) + + output=subprocess.check_output(['ip', 'route', 'show']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "unreachable 192.168.1.0/24") + + subprocess.check_output(['ip', 'route', 'delete', '192.168.1.0/24']) + + def test_add_prohibit(self): + + subprocess.check_output(['ip', 'route', 'add', 'prohibit', '192.168.1.0/24']) + + output=subprocess.check_output(['ip', 'route', 'show']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "prohibit 192.168.1.0/24") + + subprocess.check_output(['ip', 'route', 'delete', '192.168.1.0/24']) + + def test_add_throw(self): + + subprocess.check_output(['ip', 'route', 'add', 'throw', '192.168.1.0/24']) + + output=subprocess.check_output(['ip', 'route', 'show']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "throw 192.168.1.0/24") + + subprocess.check_output(['ip', 'route', 'delete', '192.168.1.0/24']) + + +if __name__ == '__main__': + unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, + verbosity=2)) diff --git a/tests/ip-route-sanity-test/runtest.sh b/tests/ip-route-sanity-test/runtest.sh new file mode 100755 index 0000000..13340fc --- /dev/null +++ b/tests/ip-route-sanity-test/runtest.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-route-sanity-test +# Description: Test basic ip route 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-route-tests.py /usr/bin" + rlPhaseEnd + + rlPhaseStartTest + rlLog "ip route tests" + rlRun "/usr/bin/python3 /usr/bin/ip-route-tests.py" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm /usr/bin/ip-route-tests.py" + rlLog "ip route tests done" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + +rlGetTestState diff --git a/tests/tests.yml b/tests/tests.yml index 9b58bad..d1e3112 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -19,6 +19,7 @@ - ip-tunnel-sanity-test - ip-l2tp-sanity-test - ip-netns-sanity-test + - ip-route-sanity-test required_packages: - iproute - bridge-utils