From 96dc29350d3a728bd395a441d04861bab7775775 Mon Sep 17 00:00:00 2001 From: Paul Michali Date: Wed, 8 Apr 2015 12:16:39 +0000 Subject: [PATCH] FWaaS: Reorganize unit 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 FWaaS 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). Note: In the future the Neutron check_unit_test_structure.sh should be made configurable, and duplicate files removed from *aaS repos. Change-Id: I4cf1093eac88f62bbe1303233bfd37058db3821a Closes-Bug: #1441501 --- neutron_fwaas/tests/base.py | 2 +- ...est_db_firewall.py => test_firewall_db.py} | 0 .../test_firewall.py} | 4 +- .../{ => agents}/test_firewall_service.py | 0 .../firewall/agents/varmour/__init__.py | 0 .../drivers/linux/test_iptables_fwaas.py | 2 +- .../firewall/drivers/mcafee/__init__.py | 0 .../firewall/drivers/varmour/__init__.py | 0 ...e_fwaas_plugin.py => test_fwaas_plugin.py} | 3 +- .../plugins/cisco/test_cisco_fwaas_plugin.py | 10 ++-- .../services/firewall/test_fwaas_plugin.py | 9 ++-- tools/check_bash.sh | 2 +- tools/check_unit_test_structure.sh | 52 +++++++++++++++++++ tox.ini | 3 +- 14 files changed, 71 insertions(+), 16 deletions(-) rename neutron_fwaas/tests/unit/db/firewall/{test_db_firewall.py => test_firewall_db.py} (100%) rename neutron_fwaas/tests/unit/{test_extension_firewall.py => extensions/test_firewall.py} (99%) rename neutron_fwaas/tests/unit/services/firewall/{ => agents}/test_firewall_service.py (100%) mode change 100755 => 100644 neutron_fwaas/tests/unit/services/firewall/agents/varmour/__init__.py mode change 100755 => 100644 neutron_fwaas/tests/unit/services/firewall/drivers/mcafee/__init__.py mode change 100755 => 100644 neutron_fwaas/tests/unit/services/firewall/drivers/varmour/__init__.py rename neutron_fwaas/tests/unit/services/firewall/freescale/{test_freescale_fwaas_plugin.py => test_fwaas_plugin.py} (99%) create mode 100755 tools/check_unit_test_structure.sh diff --git a/neutron_fwaas/tests/base.py b/neutron_fwaas/tests/base.py index 273ca88b2..8932d192b 100644 --- a/neutron_fwaas/tests/base.py +++ b/neutron_fwaas/tests/base.py @@ -15,7 +15,7 @@ # from neutron.tests import base as n_base -from neutron.tests.unit import test_db_plugin +from neutron.tests.unit.db import test_db_base_plugin_v2 as test_db_plugin class BaseTestCase(n_base.BaseTestCase): diff --git a/neutron_fwaas/tests/unit/db/firewall/test_db_firewall.py b/neutron_fwaas/tests/unit/db/firewall/test_firewall_db.py similarity index 100% rename from neutron_fwaas/tests/unit/db/firewall/test_db_firewall.py rename to neutron_fwaas/tests/unit/db/firewall/test_firewall_db.py diff --git a/neutron_fwaas/tests/unit/test_extension_firewall.py b/neutron_fwaas/tests/unit/extensions/test_firewall.py similarity index 99% rename from neutron_fwaas/tests/unit/test_extension_firewall.py rename to neutron_fwaas/tests/unit/extensions/test_firewall.py index f42902cc7..782782794 100644 --- a/neutron_fwaas/tests/unit/test_extension_firewall.py +++ b/neutron_fwaas/tests/unit/extensions/test_firewall.py @@ -19,8 +19,8 @@ import mock from neutron.openstack.common import uuidutils from neutron.plugins.common import constants from neutron.tests import base -from neutron.tests.unit import test_api_v2 -from neutron.tests.unit import test_api_v2_extension +from neutron.tests.unit.api.v2 import test_base as test_api_v2 +from neutron.tests.unit.extensions import base as test_api_v2_extension from webob import exc import webtest diff --git a/neutron_fwaas/tests/unit/services/firewall/test_firewall_service.py b/neutron_fwaas/tests/unit/services/firewall/agents/test_firewall_service.py similarity index 100% rename from neutron_fwaas/tests/unit/services/firewall/test_firewall_service.py rename to neutron_fwaas/tests/unit/services/firewall/agents/test_firewall_service.py diff --git a/neutron_fwaas/tests/unit/services/firewall/agents/varmour/__init__.py b/neutron_fwaas/tests/unit/services/firewall/agents/varmour/__init__.py old mode 100755 new mode 100644 diff --git a/neutron_fwaas/tests/unit/services/firewall/drivers/linux/test_iptables_fwaas.py b/neutron_fwaas/tests/unit/services/firewall/drivers/linux/test_iptables_fwaas.py index 56735ce05..f44c39622 100644 --- a/neutron_fwaas/tests/unit/services/firewall/drivers/linux/test_iptables_fwaas.py +++ b/neutron_fwaas/tests/unit/services/firewall/drivers/linux/test_iptables_fwaas.py @@ -18,7 +18,7 @@ from oslo_config import cfg from neutron.agent.common import config as a_cfg from neutron.tests import base -from neutron.tests.unit import test_api_v2 +from neutron.tests.unit.api.v2 import test_base as test_api_v2 import neutron_fwaas.services.firewall.drivers.linux.iptables_fwaas as fwaas diff --git a/neutron_fwaas/tests/unit/services/firewall/drivers/mcafee/__init__.py b/neutron_fwaas/tests/unit/services/firewall/drivers/mcafee/__init__.py old mode 100755 new mode 100644 diff --git a/neutron_fwaas/tests/unit/services/firewall/drivers/varmour/__init__.py b/neutron_fwaas/tests/unit/services/firewall/drivers/varmour/__init__.py old mode 100755 new mode 100644 diff --git a/neutron_fwaas/tests/unit/services/firewall/freescale/test_freescale_fwaas_plugin.py b/neutron_fwaas/tests/unit/services/firewall/freescale/test_fwaas_plugin.py similarity index 99% rename from neutron_fwaas/tests/unit/services/firewall/freescale/test_freescale_fwaas_plugin.py rename to neutron_fwaas/tests/unit/services/firewall/freescale/test_fwaas_plugin.py index b270c621a..a0aeeecb0 100644 --- a/neutron_fwaas/tests/unit/services/firewall/freescale/test_freescale_fwaas_plugin.py +++ b/neutron_fwaas/tests/unit/services/firewall/freescale/test_fwaas_plugin.py @@ -21,7 +21,8 @@ from neutron import manager from webob import exc from neutron.plugins.common import constants as const -from neutron_fwaas.tests.unit.db.firewall import test_db_firewall +from neutron_fwaas.tests.unit.db.firewall import ( + test_firewall_db as test_db_firewall) """Unit testing for Freescale FWaaS Plugin.""" diff --git a/neutron_fwaas/tests/unit/services/firewall/plugins/cisco/test_cisco_fwaas_plugin.py b/neutron_fwaas/tests/unit/services/firewall/plugins/cisco/test_cisco_fwaas_plugin.py index dd5f5daed..cc346b2cc 100644 --- a/neutron_fwaas/tests/unit/services/firewall/plugins/cisco/test_cisco_fwaas_plugin.py +++ b/neutron_fwaas/tests/unit/services/firewall/plugins/cisco/test_cisco_fwaas_plugin.py @@ -20,20 +20,22 @@ from neutron.api.v2 import attributes as attr from neutron import context from neutron import manager from neutron.plugins.common import constants as const -from neutron.tests.unit import test_l3_plugin +from neutron.tests.unit.extensions import test_l3 as test_l3_plugin import neutron_fwaas from neutron_fwaas.db.cisco import cisco_fwaas_db as csrfw_db from neutron_fwaas.extensions.cisco import csr_firewall_insertion from neutron_fwaas.extensions import firewall from neutron_fwaas.services.firewall.plugins.cisco import cisco_fwaas_plugin -from neutron_fwaas.tests.unit.db.firewall import test_db_firewall +from neutron_fwaas.tests.unit.db.firewall import ( + test_firewall_db as test_db_firewall) from oslo_config import cfg # We need the test_l3_plugin to ensure we have a valid port_id corresponding # to a router interface. -CORE_PLUGIN_KLASS = 'neutron.tests.unit.test_l3_plugin.TestNoL3NatPlugin' -L3_PLUGIN_KLASS = 'neutron.tests.unit.test_l3_plugin.TestL3NatServicePlugin' +CORE_PLUGIN_KLASS = 'neutron.tests.unit.extensions.test_l3.TestNoL3NatPlugin' +L3_PLUGIN_KLASS = ( + 'neutron.tests.unit.extensions.test_l3.TestL3NatServicePlugin') # the plugin under test CSR_FW_PLUGIN_KLASS = ( "neutron_fwaas.services.firewall.plugins.cisco.cisco_fwaas_plugin." diff --git a/neutron_fwaas/tests/unit/services/firewall/test_fwaas_plugin.py b/neutron_fwaas/tests/unit/services/firewall/test_fwaas_plugin.py index 9dba36499..0e9ab17f3 100644 --- a/neutron_fwaas/tests/unit/services/firewall/test_fwaas_plugin.py +++ b/neutron_fwaas/tests/unit/services/firewall/test_fwaas_plugin.py @@ -22,7 +22,7 @@ from neutron.api.v2 import attributes as attr from neutron import context from neutron import manager from neutron.plugins.common import constants as const -from neutron.tests.unit import test_l3_plugin +from neutron.tests.unit.extensions import test_l3 as test_l3_plugin from oslo_config import cfg from webob import exc @@ -31,7 +31,8 @@ from neutron_fwaas.extensions import firewall from neutron_fwaas.extensions import firewallrouterinsertion from neutron_fwaas.services.firewall import fwaas_plugin from neutron_fwaas.tests import base -from neutron_fwaas.tests.unit.db.firewall import test_db_firewall +from neutron_fwaas.tests.unit.db.firewall import ( + test_firewall_db as test_db_firewall) extensions_path = neutron_fwaas.extensions.__path__[0] @@ -66,9 +67,9 @@ class TestFirewallRouterInsertionBase( plugin = None # the plugin without L3 support if not plugin: - plugin = 'neutron.tests.unit.test_l3_plugin.TestNoL3NatPlugin' + plugin = 'neutron.tests.unit.extensions.test_l3.TestNoL3NatPlugin' # the L3 service plugin - l3_plugin = ('neutron.tests.unit.test_l3_plugin.' + l3_plugin = ('neutron.tests.unit.extensions.test_l3.' 'TestL3NatServicePlugin') cfg.CONF.set_override('api_extensions_path', extensions_path) diff --git a/tools/check_bash.sh b/tools/check_bash.sh index e9d178eeb..e90c8ca6c 100644 --- a/tools/check_bash.sh +++ b/tools/check_bash.sh @@ -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 diff --git a/tools/check_unit_test_structure.sh b/tools/check_unit_test_structure.sh new file mode 100755 index 000000000..10af9dd4a --- /dev/null +++ b/tools/check_unit_test_structure.sh @@ -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_fwaas/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_fwaas/$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 diff --git a/tox.ini b/tox.ini index ad1e980e5..71827c671 100644 --- a/tox.ini +++ b/tox.ini @@ -47,8 +47,7 @@ downloadcache = ~/cache/pip commands = sh ./tools/check_bash.sh flake8 - #neutron-db-manage check_migration - #sh -c "find neutron-fwaas -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]