From 1418f9951af6a7851cef87eeba95017e70d24f1c Mon Sep 17 00:00:00 2001 From: Susant Sahani Date: Thu, 2 Aug 2018 17:24:20 +0530 Subject: [PATCH] CI: Add ip neighbour to test sample run ``` :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Test :: Test :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: [ 17:23:10 ] :: [ LOG ] :: ip neighbor tests :: [ 17:23:10 ] :: [ LOG ] :: ip neighbor tests :: [ 17:23:10 ] :: [ BEGIN ] :: Running '/usr/bin/python3 /usr/bin/ip-neighbor-tests.py' test_add_neighbor (__main__.IPNeighborTests) ... 192.168.100.1 lladdr 00:c0:7b:7d:00:c8 PERMANENT ok test_replace_neighbor (__main__.IPNeighborTests) ... 192.168.99.254 lladdr 00:80:c8:27:69:2d PERMANENT 192.168.99.254 lladdr 00:80:c8:27:69:2d PERMANENT ok ---------------------------------------------------------------------- Ran 2 tests in 0.053s OK :: [ 17:23:10 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-neighbor-tests.py' (Expected 0, got 0) :: [ 17:23:10 ] :: [ PASS ] :: Command '/usr/bin/python3 /usr/bin/ip-neighbor-tests.py' (Expected 0, got 0) :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Duration: 0s :: Duration: 0s :: Assertions: 1 good, 0 bad :: Assertions: 1 good, 0 bad :: RESULT: PASS :: RESULT: PASS :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: :: Cleanup :: Cleanup :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: ``` --- tests/ip-neighbor-sanity-test/Makefile | 47 ++++++++++++ tests/ip-neighbor-sanity-test/PURPOSE | 3 + .../ip-neighbor-tests.py | 74 +++++++++++++++++++ tests/ip-neighbor-sanity-test/runtest.sh | 34 +++++++++ tests/tests.yml | 1 + 5 files changed, 159 insertions(+) create mode 100644 tests/ip-neighbor-sanity-test/Makefile create mode 100644 tests/ip-neighbor-sanity-test/PURPOSE create mode 100755 tests/ip-neighbor-sanity-test/ip-neighbor-tests.py create mode 100755 tests/ip-neighbor-sanity-test/runtest.sh diff --git a/tests/ip-neighbor-sanity-test/Makefile b/tests/ip-neighbor-sanity-test/Makefile new file mode 100644 index 0000000..67178fd --- /dev/null +++ b/tests/ip-neighbor-sanity-test/Makefile @@ -0,0 +1,47 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-neighbor-sanity-test +# Description: Test basic ip neighbor funcionality +# +# Author: Susant Sahani +# Copyright (c) 2018 Red Hat, Inc. +#~~~ + +export TEST=/CoreOS/iproute/Sanity/ip-neighbor-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 neighbor 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-neighbor-sanity-test/PURPOSE b/tests/ip-neighbor-sanity-test/PURPOSE new file mode 100644 index 0000000..cad9d8d --- /dev/null +++ b/tests/ip-neighbor-sanity-test/PURPOSE @@ -0,0 +1,3 @@ +PURPOSE of /CoreOS/iproute/Sanity/ip-neighbor-sanity-test +Description: Test basic ip neighbor funcionality +Author: Susant Sahani diff --git a/tests/ip-neighbor-sanity-test/ip-neighbor-tests.py b/tests/ip-neighbor-sanity-test/ip-neighbor-tests.py new file mode 100755 index 0000000..940bdb0 --- /dev/null +++ b/tests/ip-neighbor-sanity-test/ip-neighbor-tests.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-neighbour-sanity-test +# Description: Test basic ip neighbour 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): + + 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 IPNeighborTests(unittest.TestCase, IPLinkUtilities): + + def setUp(self): + self.add_dummy() + self.link_exists('dummy-test') + + def tearDown(self): + self.del_dummy() + + def test_add_neighbor(self): + + subprocess.call("ip neighbor add 192.168.100.1 lladdr 00:c0:7b:7d:00:c8 dev dummy-test nud permanent", shell=True) + output=subprocess.check_output(['ip', 'neighbour', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "192.168.100.1 lladdr 00:c0:7b:7d:00:c8 PERMANENT") + + subprocess.call("ip neighbor del 192.168.100.1 dev dummy-test", shell=True) + + def test_replace_neighbor(self): + + subprocess.call("ip neighbor add 192.168.99.254 lladdr 00:80:c8:27:69:2d dev dummy-test", shell=True) + output=subprocess.check_output(['ip', 'neighbour', 'show', 'dev', 'dummy-test']).rstrip().decode('utf-8') + print(output) + self.assertRegex(output, "192.168.99.254 lladdr 00:80:c8:27:69:2d PERMANENT") + + subprocess.call("ip neighbor change 192.168.99.254 lladdr 00:80:c8:27:69:2d dev dummy-test", shell=True) + print(output) + self.assertRegex(output, "192.168.99.254 lladdr 00:80:c8:27:69:2d PERMANENT") + + subprocess.call("ip neighbor del 192.168.99.254 dev dummy-test", shell=True) + + +if __name__ == '__main__': + unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, + verbosity=2)) diff --git a/tests/ip-neighbor-sanity-test/runtest.sh b/tests/ip-neighbor-sanity-test/runtest.sh new file mode 100755 index 0000000..dd5aba5 --- /dev/null +++ b/tests/ip-neighbor-sanity-test/runtest.sh @@ -0,0 +1,34 @@ +#!/bin/bash +# SPDX-License-Identifier: LGPL-2.1+ +# ~~~ +# runtest.sh of /CoreOS/iproute/Sanity/ip-neighbor-sanity-test +# Description: Test basic ip neighbor 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-neighbor-tests.py /usr/bin" + rlPhaseEnd + + rlPhaseStartTest + rlLog "ip neighbor tests" + rlRun "/usr/bin/python3 /usr/bin/ip-neighbor-tests.py" + rlPhaseEnd + + rlPhaseStartCleanup + rlRun "rm /usr/bin/ip-neighbor-tests.py" + rlLog "ip neighbor tests done" + rlPhaseEnd +rlJournalPrintText +rlJournalEnd + +rlGetTestState diff --git a/tests/tests.yml b/tests/tests.yml index d1e3112..ae233e0 100644 --- a/tests/tests.yml +++ b/tests/tests.yml @@ -20,6 +20,7 @@ - ip-l2tp-sanity-test - ip-netns-sanity-test - ip-route-sanity-test + - ip-neighbor-sanity-test required_packages: - iproute - bridge-utils