From 5c4250bd81dde5d5ef160c70d034c5abd4f45528 Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Tue, 24 Jul 2018 17:14:59 +0530 Subject: [PATCH] CI: Add tuntap to test Sample run ``` :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 17:14:21 ] :: [ LOG ] :: ip tuntap tests :: [ 17:14:21 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/ip-tuntap-tests.py' test_add_tap (__main__.IPTuntapTests) ... fopen /sys/class/net/ip6gre0/tun_flags: No such file or directory fopen /sys/class/net/wlan0/tun_flags: No such file or directory ok ok test_add_tun_user_group (__main__.IPTuntapTests) ... fopen /sys/class/net/ip6gre0/tun_flags: No such file or directory ok ---------------------------------------------------------------------- Ran 3 tests in 0.049s OK :: [ 17:14:21 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-tuntap-tests.py' (Expected 0, got 0) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 0s :: Assertions: 1 good, 0 bad :: RESULT: PASS ``` --- tests/ip-tuntap-sanity-test/Makefile | 47 ++++++++++++++ tests/ip-tuntap-sanity-test/PURPOSE | 3 + .../ip-tuntap-sanity-test/ip-tuntap-tests.py | 65 +++++++++++++++++++ tests/ip-tuntap-sanity-test/runtest.sh | 34 ++++++++++ tests/tests.yml | 1 + 5 files changed, 150 insertions(+) create mode 100644 tests/ip-tuntap-sanity-test/Makefile create mode 100644 tests/ip-tuntap-sanity-test/PURPOSE create mode 100755 tests/ip-tuntap-sanity-test/ip-tuntap-tests.py create mode 100755 tests/ip-tuntap-sanity-test/runtest.sh diff --git a/tests/ip-tuntap-sanity-test/Makefile b/tests/ip-tuntap-sanity-test/Makefile new file mode 100644 index 0000000..5f35f52 --- /dev/null +++ b/tests/ip-tuntap-sanity-test/Makefile @@ -0,0 +1,47 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-tuntap-sanity-test +# Description: Test basic ip tuntap funcionality +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +#~~~ + +export TEST=/CoreOS/iproute/Sanity/ip-tuntap-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 tuntap 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-tuntap-sanity-test/PURPOSE b/tests/ip-tuntap-sanity-test/PURPOSE new file mode 100644 index 0000000..7c6223a --- /dev/null +++ b/tests/ip-tuntap-sanity-test/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/iproute/Sanity/ip-tuntap-sanity-test +Description: Test basic ip tuntap funcionality +Author: Susant Sahani diff --git a/tests/ip-tuntap-sanity-test/ip-tuntap-tests.py b/tests/ip-tuntap-sanity-test/ip-tuntap-tests.py new file mode 100755 index 0000000..9f59a9f --- /dev/null +++ b/tests/ip-tuntap-sanity-test/ip-tuntap-tests.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-tuntap-sanity-test +# Description: Test basic ip tuntap 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))) + +class IPTuntapTests(unittest.TestCase, IPLinkUtilities): + + def test_add_tap(self): + + subprocess.check_output(['ip', 'tuntap', 'add', 'name', 'tap-test', 'mode', 'tap']) + self.link_exists('tap-test') + + output=subprocess.check_output(['ip', 'tuntap', 'show', 'dev', 'tap-test']).rstrip().decode('utf-8') + self.assertRegex(output, "tap-test: tap") + + subprocess.check_output(['ip', 'link', 'del', 'tap-test']) + + def test_add_tun(self): + + subprocess.check_output(['ip', 'tuntap', 'add', 'name', 'tun-test', 'mode', 'tun']) + self.link_exists('tun-test') + + output=subprocess.check_output(['ip', 'tuntap', 'show', 'dev', 'tun-test']).rstrip().decode('utf-8') + self.assertRegex(output, "tun-test: tun") + + subprocess.check_output(['ip', 'link', 'del', 'tun-test']) + + def test_add_tun_user_group(self): + + subprocess.check_output(['ip', 'tuntap', 'add', 'name', 'tun-test', 'mode', 'tun', 'user', 'root', 'group', 'root']) + self.link_exists('tun-test') + + output=subprocess.check_output(['ip', 'tuntap', 'show', 'dev', 'tun-test']).rstrip().decode('utf-8') + self.assertRegex(output, "tun-test: tun") + self.assertRegex(output, "user 0 group 0") + + subprocess.check_output(['ip', 'link', 'del', 'tun-test']) + +if __name__ == '__main__': + unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, + verbosity=2)) diff --git a/tests/ip-tuntap-sanity-test/runtest.sh b/tests/ip-tuntap-sanity-test/runtest.sh new file mode 100755 index 0000000..00bfe05 --- /dev/null +++ b/tests/ip-tuntap-sanity-test/runtest.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-tuntap-sanity-test +# Description: Test basic ip tuntap 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-tuntap-tests.py /usr/bin" + rlPhaseEnd + + rlPhaseStartTest + rlLog "ip tuntap tests" + rlRun "/usr/bin/python3 /usr/bin/ip-tuntap-tests.py" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm /usr/bin/ip-tuntap-tests.py" + rlLog "ip tuntap tests done" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + +rlGetTestState diff --git a/tests/tests.yml b/tests/tests.yml index a18191f..8c27973 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -15,6 +15,7 @@ - ip-address-label-sanity-test - ip-fou-sanity-test - ip-token-sanity-test + - ip-tuntap-sanity-test required_packages: - iproute - bridge-utils