From c69c9904c902fe243929b8d9170ae55b0248c75f Mon Sep 17 00:00:00 2001 From: Paul Michali Date: Mon, 15 Dec 2014 18:06:10 -0500 Subject: [PATCH] VPNaaS: Unit tests using policy.conf Instead of adding override_nvalue() in setUp() for tests that need the policy.json setting for config, created a new base class for VPN tests, which derives from the neutron BaseTestCase and overrides the config for policy_file. Change-Id: Ia504df51510d964c5f5baccb0b921af1de406f21 Partially-Implements: blueprint service-split --- neutron_vpnaas/tests/__init__.py | 26 ---------- neutron_vpnaas/tests/base.py | 52 +++++++++++++++++++ .../tests/unit/db/vpn/test_db_vpnaas.py | 5 +- .../vpn/device_drivers/test_cisco_csr_rest.py | 2 +- .../vpn/device_drivers/test_cisco_ipsec.py | 2 +- .../services/vpn/device_drivers/test_ipsec.py | 2 +- .../vpn/service_drivers/test_cisco_ipsec.py | 2 +- .../vpn/service_drivers/test_ipsec.py | 5 +- .../tests/unit/services/vpn/test_vpn_agent.py | 2 +- .../services/vpn/test_vpnaas_extension.py | 8 +-- 10 files changed, 64 insertions(+), 42 deletions(-) create mode 100644 neutron_vpnaas/tests/base.py diff --git a/neutron_vpnaas/tests/__init__.py b/neutron_vpnaas/tests/__init__.py index e4a83eb93..e69de29bb 100644 --- a/neutron_vpnaas/tests/__init__.py +++ b/neutron_vpnaas/tests/__init__.py @@ -1,26 +0,0 @@ -# Copyright 2012 VMware, Inc. All rights reserved. -# -# 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 neutron -from oslo.config import cfg - - -def override_nvalues(): - neutron_path = os.path.abspath( - os.path.join(os.path.dirname(neutron.__file__), os.pardir)) - neutron_policy = os.path.join(neutron_path, 'etc/policy.json') - cfg.CONF.set_override('policy_file', neutron_policy) diff --git a/neutron_vpnaas/tests/base.py b/neutron_vpnaas/tests/base.py new file mode 100644 index 000000000..0b649ce55 --- /dev/null +++ b/neutron_vpnaas/tests/base.py @@ -0,0 +1,52 @@ +# Copyright 2014 OpenStack Foundation. +# All Rights Reserved. +# +# 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 neutron +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 oslo.config import cfg + + +def override_nvalues(): + neutron_path = os.path.abspath( + os.path.join(os.path.dirname(neutron.__file__), os.pardir)) + neutron_policy = os.path.join(neutron_path, 'etc/policy.json') + cfg.CONF.set_override('policy_file', neutron_policy) + + +class BaseTestCase(n_base.BaseTestCase): + + def setUp(self): + override_nvalues() + super(BaseTestCase, self).setUp() + + +class ExtensionTestCase(test_api_v2_extension.ExtensionTestCase): + + def setUp(self): + override_nvalues() + super(ExtensionTestCase, self).setUp() + + +class NeutronDbPluginV2TestCase(test_db_plugin.NeutronDbPluginV2TestCase): + + def setUp(self, plugin=None, service_plugins=None, ext_mgr=None): + override_nvalues() + super(NeutronDbPluginV2TestCase, self).setUp( + plugin, service_plugins, ext_mgr) diff --git a/neutron_vpnaas/tests/unit/db/vpn/test_db_vpnaas.py b/neutron_vpnaas/tests/unit/db/vpn/test_db_vpnaas.py index a27a6e465..3b48610a4 100644 --- a/neutron_vpnaas/tests/unit/db/vpn/test_db_vpnaas.py +++ b/neutron_vpnaas/tests/unit/db/vpn/test_db_vpnaas.py @@ -35,7 +35,7 @@ from neutron.tests.unit import test_db_plugin from neutron.tests.unit import test_l3_plugin from neutron_vpnaas.db.vpn import vpn_db from neutron_vpnaas.services.vpn import plugin as vpn_plugin -from neutron_vpnaas import tests +from neutron_vpnaas.tests import base DB_CORE_PLUGIN_KLASS = 'neutron.db.db_base_plugin_v2.NeutronDbPluginV2' DB_VPN_PLUGIN_KLASS = "neutron_vpnaas.services.vpn.plugin.VPNPlugin" @@ -411,10 +411,9 @@ class VPNTestMixin(object): class VPNPluginDbTestCase(VPNTestMixin, test_l3_plugin.L3NatTestCaseMixin, - test_db_plugin.NeutronDbPluginV2TestCase): + base.NeutronDbPluginV2TestCase): def setUp(self, core_plugin=None, vpnaas_plugin=DB_VPN_PLUGIN_KLASS, vpnaas_provider=None): - tests.override_nvalues() if not vpnaas_provider: vpnaas_provider = ( constants.VPN + diff --git a/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_cisco_csr_rest.py b/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_cisco_csr_rest.py index 32e4b5aad..df35e825f 100644 --- a/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_cisco_csr_rest.py +++ b/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_cisco_csr_rest.py @@ -20,9 +20,9 @@ import requests from requests import exceptions as r_exc from requests_mock.contrib import fixture as mock_fixture -from neutron.tests import base from neutron_vpnaas.services.vpn.device_drivers import ( cisco_csr_rest_client as csr_client) +from neutron_vpnaas.tests import base dummy_policy_id = 'dummy-ipsec-policy-id-name' diff --git a/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_cisco_ipsec.py b/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_cisco_ipsec.py index e1e1c62c1..5a4ce238b 100644 --- a/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_cisco_ipsec.py +++ b/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_cisco_ipsec.py @@ -21,11 +21,11 @@ import mock from neutron import context from neutron.openstack.common import uuidutils from neutron.plugins.common import constants -from neutron.tests import base from neutron_vpnaas.services.vpn.device_drivers import ( cisco_csr_rest_client as csr_client) from neutron_vpnaas.services.vpn.device_drivers \ import cisco_ipsec as ipsec_driver +from neutron_vpnaas.tests import base _uuid = uuidutils.generate_uuid FAKE_HOST = 'fake_host' diff --git a/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_ipsec.py b/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_ipsec.py index f639a0bd9..21fd9b605 100644 --- a/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_ipsec.py +++ b/neutron_vpnaas/tests/unit/services/vpn/device_drivers/test_ipsec.py @@ -17,8 +17,8 @@ import mock from neutron.openstack.common import uuidutils from neutron.plugins.common import constants -from neutron.tests import base from neutron_vpnaas.services.vpn.device_drivers import ipsec as ipsec_driver +from neutron_vpnaas.tests import base _uuid = uuidutils.generate_uuid FAKE_HOST = 'fake_host' diff --git a/neutron_vpnaas/tests/unit/services/vpn/service_drivers/test_cisco_ipsec.py b/neutron_vpnaas/tests/unit/services/vpn/service_drivers/test_cisco_ipsec.py index 56d304a4e..afb9dc144 100644 --- a/neutron_vpnaas/tests/unit/services/vpn/service_drivers/test_cisco_ipsec.py +++ b/neutron_vpnaas/tests/unit/services/vpn/service_drivers/test_cisco_ipsec.py @@ -21,7 +21,6 @@ from neutron import context as n_ctx from neutron.db import servicetype_db as st_db from neutron.openstack.common import uuidutils from neutron.plugins.common import constants -from neutron.tests import base from neutron.tests.unit import testlib_api from neutron_vpnaas.services.vpn import plugin as vpn_plugin from neutron_vpnaas.services.vpn.service_drivers import cisco_csr_db as csr_db @@ -29,6 +28,7 @@ from neutron_vpnaas.services.vpn.service_drivers \ import cisco_ipsec as ipsec_driver from neutron_vpnaas.services.vpn.service_drivers \ import cisco_validator as validator +from neutron_vpnaas.tests import base _uuid = uuidutils.generate_uuid diff --git a/neutron_vpnaas/tests/unit/services/vpn/service_drivers/test_ipsec.py b/neutron_vpnaas/tests/unit/services/vpn/service_drivers/test_ipsec.py index a84412f1a..7d3efb8ba 100644 --- a/neutron_vpnaas/tests/unit/services/vpn/service_drivers/test_ipsec.py +++ b/neutron_vpnaas/tests/unit/services/vpn/service_drivers/test_ipsec.py @@ -24,11 +24,10 @@ from neutron.db import servicetype_db as st_db from neutron.extensions import vpnaas from neutron.openstack.common import uuidutils from neutron.plugins.common import constants -from neutron.tests import base from neutron_vpnaas.db.vpn import vpn_validator from neutron_vpnaas.services.vpn import plugin as vpn_plugin from neutron_vpnaas.services.vpn.service_drivers import ipsec as ipsec_driver -from neutron_vpnaas import tests +from neutron_vpnaas.tests import base _uuid = uuidutils.generate_uuid @@ -73,7 +72,6 @@ class TestValidatorSelection(base.BaseTestCase): class TestIPsecDriverValidation(base.BaseTestCase): def setUp(self): - tests.override_nvalues() super(TestIPsecDriverValidation, self).setUp() self.l3_plugin = mock.Mock() mock.patch( @@ -220,7 +218,6 @@ class TestIPsecDriverValidation(base.BaseTestCase): class TestIPsecDriver(base.BaseTestCase): def setUp(self): - tests.override_nvalues() super(TestIPsecDriver, self).setUp() mock.patch('neutron.common.rpc.create_connection').start() diff --git a/neutron_vpnaas/tests/unit/services/vpn/test_vpn_agent.py b/neutron_vpnaas/tests/unit/services/vpn/test_vpn_agent.py index 4cbfdc161..4f43624c9 100644 --- a/neutron_vpnaas/tests/unit/services/vpn/test_vpn_agent.py +++ b/neutron_vpnaas/tests/unit/services/vpn/test_vpn_agent.py @@ -23,9 +23,9 @@ from neutron.agent.l3 import router_info from neutron.agent.linux import interface from neutron.common import config as base_config from neutron.openstack.common import uuidutils -from neutron.tests import base from neutron_vpnaas.services.vpn import agent from neutron_vpnaas.services.vpn import device_drivers +from neutron_vpnaas.tests import base _uuid = uuidutils.generate_uuid NOOP_DEVICE_CLASS = 'NoopDeviceDriver' diff --git a/neutron_vpnaas/tests/unit/services/vpn/test_vpnaas_extension.py b/neutron_vpnaas/tests/unit/services/vpn/test_vpnaas_extension.py index 8538fcf3b..7fd96d6a1 100644 --- a/neutron_vpnaas/tests/unit/services/vpn/test_vpnaas_extension.py +++ b/neutron_vpnaas/tests/unit/services/vpn/test_vpnaas_extension.py @@ -22,18 +22,18 @@ from neutron.extensions import vpnaas from neutron.openstack.common import uuidutils from neutron.plugins.common import constants from neutron.tests.unit import test_api_v2 -from neutron.tests.unit import test_api_v2_extension -from neutron_vpnaas import tests + +from neutron_vpnaas.tests import base + _uuid = uuidutils.generate_uuid _get_path = test_api_v2._get_path -class VpnaasExtensionTestCase(test_api_v2_extension.ExtensionTestCase): +class VpnaasExtensionTestCase(base.ExtensionTestCase): fmt = 'json' def setUp(self): - tests.override_nvalues() super(VpnaasExtensionTestCase, self).setUp() plural_mappings = {'ipsecpolicy': 'ipsecpolicies', 'ikepolicy': 'ikepolicies',