From 3fa9f34cd245c82b1d0d163492eee52c45eba282 Mon Sep 17 00:00:00 2001 From: Brad Cowie Date: Thu, 23 Aug 2018 15:48:06 +1200 Subject: [PATCH 1/5] Add unit test for testing packaging. --- test-requirements.txt | 1 + tests/unit/packaging/test_packaging.py | 67 ++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100755 tests/unit/packaging/test_packaging.py diff --git a/test-requirements.txt b/test-requirements.txt index 1dde006e5c..c75d60be0b 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,6 +1,7 @@ bitstring codecov concurrencytest +deb_pkg_tools eventlet==0.22.1 # pyup: ignore exabgp influxdb diff --git a/tests/unit/packaging/test_packaging.py b/tests/unit/packaging/test_packaging.py new file mode 100755 index 0000000000..23b04f4292 --- /dev/null +++ b/tests/unit/packaging/test_packaging.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python + +"""Test FAUCET packaging""" + +# Copyright (C) 2015 Brad Cowie, Christopher Lorier and Joe Stringer. +# Copyright (C) 2015 Research and Innovation Advanced Network New Zealand Ltd. +# Copyright (C) 2015--2018 The Contributors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import os +import unittest +import pip.req + +from deb_pkg_tools.control import deb822_from_string, parse_control_fields + +class CheckRequirementsTestCase(unittest.TestCase): # pytype: disable=module-attr + """Test packaging requirements.""" + + def test_requirements_match(self): + """Test all requirements are listed as apt package dependencies.""" + + SRC_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../../../') + control_file = os.path.join(SRC_DIR, 'debian/control') + requirements_file = os.path.join(SRC_DIR, 'requirements.txt') + + real_name = { + 'msgpack-python': 'python3-msgpack', + 'pyyaml': 'python3-yaml' + } + + with open(control_file) as handle: + control = handle.read() + + faucet_dpkg = str() + for line in control.split("\n"): + if line.startswith("Package: python3-faucet"): + faucet_dpkg += line + elif len(faucet_dpkg) > 0: + if not line: + break + faucet_dpkg += "{}\n".format(line) + + faucet_dpkg = parse_control_fields(deb822_from_string(faucet_dpkg)) + faucet_dpkg_deps = [x.name for x in faucet_dpkg['Depends']] + + for item in pip.req.parse_requirements(requirements_file, + session="unittest"): + if isinstance(item, pip.req.InstallRequirement): + if item.name in real_name: + self.assertIn(real_name[item.name], faucet_dpkg_deps) + else: + self.assertIn("python3-{}".format(item.name), faucet_dpkg_deps) + + +if __name__ == "__main__": + unittest.main() # pytype: disable=module-attr From 99b7cef0b4465a7e238cc66139a6bd3d809811a7 Mon Sep 17 00:00:00 2001 From: Brad Cowie Date: Thu, 23 Aug 2018 15:50:28 +1200 Subject: [PATCH 2/5] Fix case. --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index d2ee7af17f..76938a9c14 100644 --- a/debian/control +++ b/debian/control @@ -69,7 +69,7 @@ Description: This is a component the Faucet OpenFlow controller (Python 3) . This package installs the library for Python 3. -package: faucet-all-in-one +Package: faucet-all-in-one Architecture: all Depends: faucet (>= 1.7.0), gauge (>= 1.7.0), From 359f172e804ec435fc40518ded59b31ac56e7ede Mon Sep 17 00:00:00 2001 From: Brad Cowie Date: Thu, 23 Aug 2018 16:02:19 +1200 Subject: [PATCH 3/5] ipaddress only required for python2 which we don't support. --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 1adb2ad569..c0c53d5e18 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,6 @@ chewie==0.0.2 datadiff eventlet==0.22.1 # pyup: ignore influxdb -ipaddress msgpack msgpack-python networkx From 34f6dc67fd1c38a517c8014b98b8b2f5c49e6fcd Mon Sep 17 00:00:00 2001 From: Brad Cowie Date: Thu, 23 Aug 2018 16:02:43 +1200 Subject: [PATCH 4/5] Add missing dependencies. --- debian/control | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian/control b/debian/control index 76938a9c14..8930ed823d 100644 --- a/debian/control +++ b/debian/control @@ -26,9 +26,11 @@ Depends: python3-oslo.config (>= 1:3.9~), python3-pbr (>= 1.9), python3-prometheus-client (>= 0.0.18), python3-yaml (>= 3.1.1), + python3-eventlet, python3-ryu (>= 4.22), python3-beka (>= 0.3.3), python3-chewie (>= 0.0.2), + python3-pytricia (>= 1.0.0), python3:any (>= 3.4~), Suggests: python-faucet-doc, faucet, gauge, oslo.config, Description: source code for faucet and gauge (Python3) From e82e64deeeaf555c902650c2f30c7aff6a9e8402 Mon Sep 17 00:00:00 2001 From: Brad Cowie Date: Thu, 23 Aug 2018 19:35:39 +1200 Subject: [PATCH 5/5] Set locale to keep python read() happy. --- docker/runtests.sh | 2 +- travis/run-integration-tests.sh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100755 travis/run-integration-tests.sh diff --git a/docker/runtests.sh b/docker/runtests.sh index f2a64b755f..8b7e397780 100755 --- a/docker/runtests.sh +++ b/docker/runtests.sh @@ -57,7 +57,7 @@ locale-gen en_US.UTF-8 || exit 1 if [ "$UNITTESTS" == 1 ] ; then echo "========== Running faucet unit tests ==========" cd /faucet-src/tests - ./run_unit_tests.sh || exit 1 + LANG=en_US.UTF-8 LANGUAGE=en_US.en LC_ALL=en_US.UTF-8 ./run_unit_tests.sh || exit 1 fi if [ "$DEPCHECK" == 1 ] ; then diff --git a/travis/run-integration-tests.sh b/travis/run-integration-tests.sh new file mode 100755 index 0000000000..fe9d61fdd7 --- /dev/null +++ b/travis/run-integration-tests.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +if [ "${MATRIX_SHARD}" = "sanity" ] ; then + FAUCET_TESTS="-u FaucetSanityTest" + ./tests/run_unit_tests.sh || exit 1 + codecov || true +else + ALLTESTFILES="tests/integration/mininet_tests.py clib/clib_mininet_tests.py" + ALLTESTS=`grep -E -o "^class (Faucet[a-zA-Z0-9]+Test)" ${ALLTESTFILES}|cut -f2 -d" "|sort` + declare -A sharded + + function shard { + work=$1 + workers=$2 + i=0 + for shard in $work ; do + i=$(expr $i % $workers) + sharded[$i]="${sharded[$i]} $shard" + i=$(expr $i + 1) + done + } + + shard "$ALLTESTS" ${MATRIX_SHARDS} + FAUCET_TESTS="-i ${sharded[${MATRIX_SHARD}]}" +fi + +echo Shard $MATRIX_SHARD: $FAUCETTESTS +sudo docker run --privileged --sysctl net.ipv6.conf.all.disable_ipv6=0 \ + -v $HOME/.cache/pip:/var/tmp/pip-cache \ + -e FAUCET_TESTS="${FAUCET_TESTS}" \ + -t ${FAUCET_TEST_IMG} || exit 1 +exit 0