From 7ee9aeadb413c52c458425cba8cde527b5c95cd7 Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Sun, 24 Jun 2018 18:11:31 +0530 Subject: [PATCH] CI: Add ip address sanity tests Snip: ``` iproute-4.15.0-1.fc28.x86_64 :: [ 18:10:39 ] :: [ PASS ] :: Checking for the presence of iproute rpm :: [ 18:10:39 ] :: [ PASS ] :: Checking for the presence of iproute rpm :: [ 18:10:39 ] :: [ LOG ] :: Package versions: :: [ 18:10:39 ] :: [ LOG ] :: Package versions: :: [ 18:10:39 ] :: [ LOG ] :: iproute-4.15.0-1.fc28.x86_64 :: [ 18:10:39 ] :: [ LOG ] :: iproute-4.15.0-1.fc28.x86_64 :: [ 18:10:39 ] :: [ BEGIN ] :: Running 'cp ip-address-tests.py /usr/bin' :: [ 18:10:39 ] :: [ PASS ] :: Command 'cp ip-address-tests.py /usr/bin' (Expected 0, got 0) :: [ 18:10:39 ] :: [ PASS ] :: Command 'cp ip-address-tests.py /usr/bin' (Expected 0, got 0) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 0s :: Duration: 0s :: Assertions: 2 good, 0 bad :: Assertions: 2 good, 0 bad :: RESULT: PASS :: RESULT: PASS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Test :: Test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 18:10:39 ] :: [ LOG ] :: ip address tests :: [ 18:10:39 ] :: [ LOG ] :: ip address tests :: [ 18:10:39 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/ip-address-tests.py' test_add_address (__main__.IPAddressTests) ... ok test_add_address_lifetime (__main__.IPAddressTests) ... ok test_add_address_scope (__main__.IPAddressTests) ... ok test_add_broadcast_address_label (__main__.IPAddressTests) ... ok test_add_ipv6_address (__main__.IPAddressTests) ... ok test_del_address (__main__.IPAddressTests) ... ok ---------------------------------------------------------------------- Ran 6 tests in 0.136s OK :: [ 18:10:39 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-address-tests.py' (Expected 0, got 0) :: [ 18:10:39 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-address-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 :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 18:10:40 ] :: [ BEGIN ] :: Running 'rm /usr/bin/ip-address-tests.py' :: [ 18:10:40 ] :: [ PASS ] :: Command 'rm /usr/bin/ip-address-tests.py' (Expected 0, got 0) :: [ 18:10:40 ] :: [ PASS ] :: Command 'rm /usr/bin/ip-address-tests.py' (Expected 0, got 0) :: [ 18:10:40 ] :: [ LOG ] :: ip address tests done :: [ 18:10:40 ] :: [ LOG ] :: ip address tests done :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 0s :: Duration: 0s :: Assertions: 1 good, 0 bad :: Assertions: 1 good, 0 bad :: RESULT: PASS :: RESULT: PASS ``` --- tests/ip-address-sanity-test/Makefile | 47 ++++++++ tests/ip-address-sanity-test/PURPOSE | 3 + .../ip-address-tests.py | 109 ++++++++++++++++++ tests/ip-address-sanity-test/runtest.sh | 34 ++++++ tests/tests.yml | 1 + 5 files changed, 194 insertions(+) create mode 100644 tests/ip-address-sanity-test/Makefile create mode 100644 tests/ip-address-sanity-test/PURPOSE create mode 100755 tests/ip-address-sanity-test/ip-address-tests.py create mode 100755 tests/ip-address-sanity-test/runtest.sh diff --git a/tests/ip-address-sanity-test/Makefile b/tests/ip-address-sanity-test/Makefile new file mode 100644 index 0000000..d43d21d --- /dev/null +++ b/tests/ip-address-sanity-test/Makefile @@ -0,0 +1,47 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-address-sanity-test +# Description: Test basic ip address funcionality +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +#~~~ + +export TEST=/CoreOS/iproute/Sanity/ip-address-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 address 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-address-sanity-test/PURPOSE b/tests/ip-address-sanity-test/PURPOSE new file mode 100644 index 0000000..bcd1d83 --- /dev/null +++ b/tests/ip-address-sanity-test/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/iproute/Sanity/ip-address-sanity-test +Description: Test basic ip address funcionality +Author: Susant Sahani diff --git a/tests/ip-address-sanity-test/ip-address-tests.py b/tests/ip-address-sanity-test/ip-address-tests.py new file mode 100755 index 0000000..4b43b32 --- /dev/null +++ b/tests/ip-address-sanity-test/ip-address-tests.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-address-sanity-test +# Description: Test basic ip address 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') + + def del_dummy(self): + subprocess.check_output(['ip', 'link', 'del', 'dummy-test']) + +class IPAddressTests(unittest.TestCase, IPLinkUtilities): + + def setUp(self): + self.add_dummy() + + def tearDown(self): + self.del_dummy() + + def test_add_address(self): + + r = subprocess.call("ip address add 192.168.1.200/24 dev dummy-test", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'address', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8') + self.assertRegex(output, "192.168.1.200") + + def test_add_broadcast_address_label(self): + + r = subprocess.call("ip addr add 192.168.1.50/24 brd + dev dummy-test label dummy-test-Home", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'address', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8') + self.assertRegex(output, "192.168.1.50") + self.assertRegex(output, "192.168.1.255") + self.assertRegex(output, "dummy-test-Home") + + def test_del_address(self): + + r = subprocess.call("ip address add 192.168.1.200/24 dev dummy-test", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'address', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8') + self.assertRegex(output, "192.168.1.200") + + r = subprocess.call("ip address del 192.168.1.200/24 dev dummy-test", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'address', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8') + self.assertNotRegex(output, "192.168.1.200") + + def test_add_address_scope(self): + + r = subprocess.call("ip address add 192.168.1.200/24 dev dummy-test scope host", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'address', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8') + self.assertRegex(output, "192.168.1.200") + self.assertRegex(output, "host") + + def test_add_address_lifetime(self): + + r = subprocess.call("ip address add 192.168.1.200/24 dev dummy-test valid_lft 1000 preferred_lft 500", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'address', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8') + self.assertRegex(output, "192.168.1.200") + self.assertRegex(output, "1000sec") + self.assertRegex(output, "500sec") + + def test_add_ipv6_address(self): + + r = subprocess.call("ip -6 addr add 2001:0db8:0:f101::1/64 dev dummy-test", shell=True) + self.assertEqual(r, 0) + + output=subprocess.check_output(['ip', 'address', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8') + self.assertRegex(output, "2001:db8:0:f101::1") + + +if __name__ == '__main__': + unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, + verbosity=2)) diff --git a/tests/ip-address-sanity-test/runtest.sh b/tests/ip-address-sanity-test/runtest.sh new file mode 100755 index 0000000..d95de6d --- /dev/null +++ b/tests/ip-address-sanity-test/runtest.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-address-sanity-test +# Description: Test basic ip address 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-address-tests.py /usr/bin" + rlPhaseEnd + + rlPhaseStartTest + rlLog "ip address tests" + rlRun "/usr/bin/python3 /usr/bin/ip-address-tests.py" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm /usr/bin/ip-address-tests.py" + rlLog "ip address tests done" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + +rlGetTestState diff --git a/tests/tests.yml b/tests/tests.yml index 0e30c1e..d2cc96e 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -11,6 +11,7 @@ - ip-rule-sanity-test - bridge-utility - ip-link-sanity-test + - ip-address-sanity-test required_packages: - iproute - bridge-utils