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
This commit is contained in:
Paul Michali 2014-12-15 18:06:10 -05:00
parent baed505c2e
commit c69c9904c9
10 changed files with 64 additions and 42 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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 +

View File

@ -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'

View File

@ -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'

View File

@ -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'

View File

@ -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

View File

@ -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()

View File

@ -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'

View File

@ -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',