VPNaaS: Reorganize test tree

Similar to what is happening in Neutron, this commit renames and moves unit
test files so that they match the directory structure of the code tree.
Since the VPN repo's test files have imports from Neutron, there are import
changes as well, to the imports to match the Neutron test file organization.

A check script is added to monitor the test file naming and locations (to
ensure consistency).

Change-Id: I875285230127ed660137d271f7e98d82eb57ffab
Partial-Bug: #1440834
This commit is contained in:
Paul Michali 2015-04-07 11:57:50 +00:00
parent f1a50db9d9
commit bc2a1d7754
9 changed files with 63 additions and 12 deletions

View File

@ -15,8 +15,8 @@
#
from neutron.tests import base as n_base
from neutron.tests.unit import test_api_v2_extension
from neutron.tests.unit import test_db_plugin
from neutron.tests.unit.db import test_db_base_plugin_v2 as test_db_plugin
from neutron.tests.unit.extensions import base as test_api_v2_extension
class BaseTestCase(n_base.BaseTestCase):

View File

@ -30,8 +30,8 @@ from neutron import manager
from neutron.openstack.common import uuidutils
from neutron.plugins.common import constants
from neutron.scheduler import l3_agent_scheduler
from neutron.tests.unit import test_db_plugin
from neutron.tests.unit import test_l3_plugin
from neutron.tests.unit.db import test_db_base_plugin_v2 as test_db_plugin
from neutron.tests.unit.extensions import test_l3 as test_l3_plugin
from oslo_config import cfg
import webob.exc
@ -433,7 +433,7 @@ class VPNPluginDbTestCase(VPNTestMixin,
service_plugins = {'vpnaas_plugin': vpnaas_plugin}
plugin_str = ('neutron_vpnaas.tests.unit.db.vpn.'
'test_db_vpnaas.TestVpnCorePlugin')
'test_vpn_db.TestVpnCorePlugin')
super(VPNPluginDbTestCase, self).setUp(
plugin_str,

View File

@ -17,7 +17,7 @@ import copy
import mock
from neutron.openstack.common import uuidutils
from neutron.plugins.common import constants
from neutron.tests.unit import test_api_v2
from neutron.tests.unit.api.v2 import test_base as test_api_v2
from webob import exc
from neutron_vpnaas.extensions import vpnaas

View File

@ -19,12 +19,12 @@ from neutron.common import constants
from neutron import context
from neutron import manager
from neutron.plugins.common import constants as p_constants
from neutron.tests.unit.openvswitch import test_agent_scheduler
from neutron.tests.unit import test_agent_ext_plugin
from neutron.tests.unit.extensions import test_agent as test_agent_ext_plugin
from neutron.tests.unit.plugins.openvswitch import test_agent_scheduler
from neutron_vpnaas.db.vpn import vpn_validator
from neutron_vpnaas.services.vpn.service_drivers import ipsec as ipsec_driver
from neutron_vpnaas.tests.unit.db.vpn import test_db_vpnaas
from neutron_vpnaas.tests.unit.db.vpn import test_vpn_db as test_db_vpnaas
FAKE_HOST = test_agent_ext_plugin.L3_HOSTA
VPN_DRIVER_CLASS = 'neutron_vpnaas.services.vpn.plugin.VPNDriverPlugin'

View File

@ -22,7 +22,7 @@
# Ignore comments, but include shebangs
OBSERVED=$(grep -E '^([^#]|#!).*bash' tox.ini tools/* | wc -l)
EXPECTED=5
EXPECTED=6
if [ ${EXPECTED} -ne ${OBSERVED} ]; then
echo Unexpected number of bash usages are detected.
echo Please read the comment in $0

View File

@ -0,0 +1,52 @@
#!/usr/bin/env bash
# This script identifies the unit test modules that do not correspond
# directly with a module in the code tree. See TESTING.rst for the
# intended structure.
neutron_path=$(cd "$(dirname "$0")/.." && pwd)
base_test_path=neutron_vpnaas/tests/unit
test_path=$neutron_path/$base_test_path
test_files=$(find ${test_path} -iname 'test_*.py')
ignore_regexes=(
"^plugins.*$"
)
error_count=0
ignore_count=0
total_count=0
for test_file in ${test_files[@]}; do
relative_path=${test_file#$test_path/}
expected_path=$(dirname $neutron_path/neutron_vpnaas/$relative_path)
test_filename=$(basename "$test_file")
expected_filename=${test_filename#test_}
# Module filename (e.g. foo/bar.py -> foo/test_bar.py)
filename=$expected_path/$expected_filename
# Package dir (e.g. foo/ -> test_foo.py)
package_dir=${filename%.py}
if [ ! -f "$filename" ] && [ ! -d "$package_dir" ]; then
for ignore_regex in ${ignore_regexes[@]}; do
if [[ "$relative_path" =~ $ignore_regex ]]; then
((ignore_count++))
continue 2
fi
done
echo "Unexpected test file: $base_test_path/$relative_path"
((error_count++))
fi
((total_count++))
done
if [ "$ignore_count" -ne 0 ]; then
echo "$ignore_count unmatched test modules were ignored"
fi
if [ "$error_count" -eq 0 ]; then
echo 'Success! All test modules match targets in the code tree.'
exit 0
else
echo "Failure! $error_count of $total_count test modules do not match targets in the code tree."
exit 1
fi

View File

@ -60,8 +60,7 @@ commands =
sh ./tools/check_bash.sh
flake8
pylint --rcfile=.pylintrc --output-format=colorized {posargs:neutron_vpnaas}
#neutron-db-manage check_migration
#sh -c "find neutron-vpnaas -type f -regex '.*\.pot?' -print0|xargs -0 -n 1 msgfmt --check-format -o /dev/null"
{toxinidir}/tools/check_unit_test_structure.sh
whitelist_externals = sh
[testenv:i18n]