From 64f399e8cd3044e3a4ac806c5ccbaaf50c060e77 Mon Sep 17 00:00:00 2001 From: Dima Kuznetsov Date: Tue, 18 Apr 2017 16:42:24 +0300 Subject: [PATCH] Fix tests --- .testr.conf | 4 +++ requirements.txt | 25 +++++++++++++++++ test-requirements.txt | 14 +++++++++ tools/tox_install.sh | 53 +++++++++++++++++++++++++++++++++++ tox.ini | 51 +++++++++++++++++++++++++++++++++ wan_qos/db/wan_qos_db.py | 2 +- wan_qos/tests/unit/test_db.py | 2 +- 7 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 .testr.conf create mode 100644 requirements.txt create mode 100644 test-requirements.txt create mode 100755 tools/tox_install.sh create mode 100644 tox.ini diff --git a/.testr.conf b/.testr.conf new file mode 100644 index 0000000..e50fdd0 --- /dev/null +++ b/.testr.conf @@ -0,0 +1,4 @@ +[DEFAULT] +test_command=OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_LOG_CAPTURE=1 ${PYTHON:-python} -m subunit.run discover -t ./ ${OS_TEST_PATH:-./wan_qos/tests/unit} $LISTOPT $IDOPTION | cat +test_id_option=--load-list $IDFILE +test_list_option=--list diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..816c58e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,25 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. + +pbr>=2.0.0 # Apache-2.0 +Babel>=2.3.4 # BSD +kazoo>=2.2 # Apache-2.0 +ovs>=2.7.0 # Apache-2.0 +pyzmq>=14.3.1 # LGPL+BSD +ryu>=4.9 # Apache-2.0 +SQLAlchemy!=1.1.5,!=1.1.6,!=1.1.7,!=1.1.8,>=1.0.10 # MIT +alembic>=0.8.10 # MIT +neutron-lib>=1.3.0 # Apache-2.0 +oslo.config>=3.22.0 # Apache-2.0 +oslo.db>=4.19.0 # Apache-2.0 +oslo.i18n>=2.1.0 # Apache-2.0 +oslo.log>=3.22.0 # Apache-2.0 +oslo.reports>=0.6.0 # Apache-2.0 +oslo.serialization>=1.10.0 # Apache-2.0 +crc16>=0.1.1 # LGPLv3+ +netaddr!=0.7.16,>=0.7.13 # BSD +six>=1.9.0 # MIT +httplib2>=0.7.5 # MIT +WebOb>=1.7.1 # MIT + diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000..87b17be --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1,14 @@ +# The order of packages is significant, because pip processes them in the order +# of appearance. Changing the order has an impact on the overall integration +# process, which may cause wedges in the gate later. + +hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 + +mock>=2.0 # BSD +python-subunit>=0.0.18 # Apache-2.0/BSD +os-testr>=0.8.0 # Apache-2.0 +oslotest>=1.10.0 # Apache-2.0 +testrepository>=0.0.18 # Apache-2.0/BSD +testresources>=0.2.4 # Apache-2.0/BSD +testscenarios>=0.4 # Apache-2.0/BSD +testtools>=1.4.0 # MIT diff --git a/tools/tox_install.sh b/tools/tox_install.sh new file mode 100755 index 0000000..ba12396 --- /dev/null +++ b/tools/tox_install.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +# Many of neutron's repos suffer from the problem of depending on neutron, +# but it not existing on pypi. + +# This wrapper for tox's package installer will use the existing package +# if it exists, else use zuul-cloner if that program exists, else grab it +# from neutron master via a hard-coded URL. That last case should only +# happen with devs running unit tests locally. + +# From the tox.ini config page: +# install_command=ARGV +# default: +# pip install {opts} {packages} + +ZUUL_CLONER=/usr/zuul-env/bin/zuul-cloner +neutron_installed=$(echo "import neutron" | python 2>/dev/null ; echo $?) +BRANCH_NAME=master + +set -ex + +cwd=$(/bin/pwd) + +CONSTRAINTS_FILE=$1 +shift + +install_cmd="pip install" +if [ $CONSTRAINTS_FILE != "unconstrained" ]; then + install_cmd="$install_cmd -c$CONSTRAINTS_FILE" +fi + +if [ $neutron_installed -eq 0 ]; then + echo "ALREADY INSTALLED" > /tmp/tox_install.txt + echo "Neutron already installed; using existing package" +elif [ -x "$ZUUL_CLONER" ]; then + echo "ZUUL CLONER" > /tmp/tox_install.txt + cd /tmp + export ZUUL_BRANCH=${ZUUL_BRANCH-$BRANCH} + $ZUUL_CLONER --cache-dir \ + /opt/git \ + --branch $BRANCH_NAME \ + git://git.openstack.org \ + openstack/neutron + cd openstack/neutron + $install_cmd -e . + cd "$cwd" +else + echo "PIP HARDCODE" > /tmp/tox_install.txt + $install_cmd -U -egit+https://git.openstack.org/openstack/neutron@$BRANCH_NAME#egg=neutron +fi + +$install_cmd -U $* +exit $? diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..797f0eb --- /dev/null +++ b/tox.ini @@ -0,0 +1,51 @@ +[tox] +minversion = 1.6 +envlist = pep8,py27,py35 +skipsdist = True + +[testenv] +# Note the hash seed is set to 0 until neutron can be tested with a +# random hash seed successfully. +setenv = VIRTUAL_ENV={envdir} + PYTHONHASHSEED=0 + PYTHONWARNINGS=default::DeprecationWarning +usedevelop = True +install_command = {toxinidir}/tools/tox_install.sh {env:UPPER_CONSTRAINTS_FILE:https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt} {opts} {packages} +deps = -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt +whitelist_externals = sh +commands = + ostestr '{posargs}' +# sh tools/pretty_tox.sh '{posargs}' + +[testenv:pep8] +commands = + flake8 + neutron-db-manage --subproject dragonflow check_migration + +[testenv:venv] +commands = {posargs} + +[flake8] +# E126 continuation line over-indented for hanging indent +# H404 multi line docstring should start with a summary +# H405 multi line docstring summary not separated with an empty line +# N530 Direct neutron imports not allowed +# N531 log message does not translate +ignore = E126,H404,H405,N530,N531 +# H904: Delay string interpolations at logging calls +# H203: Use assertIs(Not)None to check for None +enable-extensions=H904,H203 +show-source = true +exclude = ./.*,dist,doc,build,tools + +[testenv:pylint] +deps = + {[testenv]deps} + pylint +commands = + pylint --rcfile=.pylintrc --output-format=colorized {posargs:neutron} + +[hacking] +#import_exceptions = wan_qos._i18n +local-check-factory = neutron_lib.hacking.checks.factory diff --git a/wan_qos/db/wan_qos_db.py b/wan_qos/db/wan_qos_db.py index cd054ba..65a5038 100644 --- a/wan_qos/db/wan_qos_db.py +++ b/wan_qos/db/wan_qos_db.py @@ -15,8 +15,8 @@ import threading -from neutron import context as ctx from neutron_lib import exceptions +from neutron_lib import context as ctx from oslo_log import log as logging from oslo_utils import timeutils from oslo_utils import uuidutils diff --git a/wan_qos/tests/unit/test_db.py b/wan_qos/tests/unit/test_db.py index 4845fdb..e85aa7e 100644 --- a/wan_qos/tests/unit/test_db.py +++ b/wan_qos/tests/unit/test_db.py @@ -1,5 +1,5 @@ -from neutron import context as ctx from neutron.tests.unit import testlib_api +from neutron_lib import context as ctx from wan_qos.db import wan_qos_db from wan_qos.services import plugin