diff --git a/quantum/tests/unit/cisco/__init__.py b/quantum/tests/unit/cisco/__init__.py new file mode 100644 index 000000000..cbf4a4506 --- /dev/null +++ b/quantum/tests/unit/cisco/__init__.py @@ -0,0 +1,16 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright 2012 OpenStack LLC. +# 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. diff --git a/quantum/plugins/cisco/tests/unit/v2/test_network_plugin.py b/quantum/tests/unit/cisco/test_network_plugin.py similarity index 86% rename from quantum/plugins/cisco/tests/unit/v2/test_network_plugin.py rename to quantum/tests/unit/cisco/test_network_plugin.py index ccfd8e8b8..87137ab80 100644 --- a/quantum/plugins/cisco/tests/unit/v2/test_network_plugin.py +++ b/quantum/tests/unit/cisco/test_network_plugin.py @@ -16,7 +16,6 @@ import inspect import logging import mock -import os from quantum.api.v2.router import APIRouter from quantum.common import config @@ -35,35 +34,17 @@ from quantum.wsgi import JSONDeserializer LOG = logging.getLogger(__name__) -def curdir(*p): - return os.path.join(os.path.dirname(__file__), *p) +class CiscoNetworkPluginV2TestCase(test_db_plugin.QuantumDbPluginV2TestCase): - -class NetworkPluginV2TestCase(test_db_plugin.QuantumDbPluginV2TestCase): + _plugin_name = 'quantum.plugins.cisco.network_plugin.PluginV2' def setUp(self): + super(CiscoNetworkPluginV2TestCase, self).setUp() db._ENGINE = None db._MAKER = None QuantumManager._instance = None - self._tenant_id = 'test-tenant' - - json_deserializer = JSONDeserializer() - self._deserializers = { - 'application/json': json_deserializer, - } - - plugin = 'quantum.plugins.cisco.network_plugin.PluginV2' - # Create the default configurations - args = ['--config-file', curdir('quantumv2.conf.cisco.test')] - # If test_config specifies some config-file, use it, as well - for config_file in test_config.get('config_files', []): - args.extend(['--config-file', config_file]) - config.parse(args=args) # Update the plugin - cfg.CONF.set_override('core_plugin', plugin) - cfg.CONF.set_override('base_mac', "12:34:56:78:90:ab") - cfg.CONF.max_dns_nameservers = 2 - cfg.CONF.max_subnet_host_routes = 2 + cfg.CONF.set_override('core_plugin', self._plugin_name) def new_init(): db.configure_db({'sql_connection': 'sqlite://', @@ -81,9 +62,6 @@ class NetworkPluginV2TestCase(test_db_plugin.QuantumDbPluginV2TestCase): self._skip_native_bulk = not _is_native_bulk_supported() - ext_mgr = test_config.get('extension_manager', None) - if ext_mgr: - self.ext_api = test_extensions.setup_extensions_middleware(ext_mgr) LOG.debug("%s.%s.%s done" % (__name__, self.__class__.__name__, inspect.stack()[0][3])) @@ -105,13 +83,19 @@ class NetworkPluginV2TestCase(test_db_plugin.QuantumDbPluginV2TestCase): return plugin_ref -class TestV2HTTPResponse(NetworkPluginV2TestCase, - test_db_plugin.TestV2HTTPResponse): +class TestCiscoBasicGet(CiscoNetworkPluginV2TestCase, + test_db_plugin.TestBasicGet): + pass + + +class TestCiscoV2HTTPResponse(CiscoNetworkPluginV2TestCase, + test_db_plugin.TestV2HTTPResponse): pass -class TestPortsV2(NetworkPluginV2TestCase, test_db_plugin.TestPortsV2): +class TestCiscoPortsV2(CiscoNetworkPluginV2TestCase, + test_db_plugin.TestPortsV2): def test_create_ports_bulk_emulated_plugin_failure(self): real_has_attr = hasattr @@ -163,7 +147,8 @@ class TestPortsV2(NetworkPluginV2TestCase, test_db_plugin.TestPortsV2): self._validate_behavior_on_bulk_failure(res, 'ports') -class TestNetworksV2(NetworkPluginV2TestCase, test_db_plugin.TestNetworksV2): +class TestCiscoNetworksV2(CiscoNetworkPluginV2TestCase, + test_db_plugin.TestNetworksV2): def test_create_networks_bulk_emulated_plugin_failure(self): real_has_attr = hasattr @@ -207,7 +192,8 @@ class TestNetworksV2(NetworkPluginV2TestCase, test_db_plugin.TestNetworksV2): self._validate_behavior_on_bulk_failure(res, 'networks') -class TestSubnetsV2(NetworkPluginV2TestCase, test_db_plugin.TestSubnetsV2): +class TestCiscoSubnetsV2(CiscoNetworkPluginV2TestCase, + test_db_plugin.TestSubnetsV2): def test_create_subnets_bulk_emulated_plugin_failure(self): real_has_attr = hasattr diff --git a/quantum/plugins/cisco/tests/unit/v2/test_nexus_plugin.py b/quantum/tests/unit/cisco/test_nexus_plugin.py similarity index 78% rename from quantum/plugins/cisco/tests/unit/v2/test_nexus_plugin.py rename to quantum/tests/unit/cisco/test_nexus_plugin.py index 4ef51c8c0..94ae5db59 100644 --- a/quantum/plugins/cisco/tests/unit/v2/test_nexus_plugin.py +++ b/quantum/tests/unit/cisco/test_nexus_plugin.py @@ -14,10 +14,12 @@ # limitations under the License. import logging +import mock import unittest from quantum.common import exceptions as exc from quantum.db import api as db +from quantum.openstack.common import importutils from quantum.plugins.cisco.common import cisco_constants as const from quantum.plugins.cisco.common import cisco_credentials_v2 as creds from quantum.plugins.cisco.db import network_db_v2 as cdb @@ -28,7 +30,16 @@ from quantum.plugins.cisco.nexus import cisco_nexus_plugin_v2 LOG = logging.getLogger(__name__) -class TestNexusPlugin(unittest.TestCase): +NEXUS_IP_ADDRESS = '1.1.1.1' +NEXUS_USERNAME = 'username' +NEXUS_PASSWORD = 'password' +NEXUS_PORTS = ['1/10'] +NEXUS_SSH_PORT = '22' +NEXUS_DRIVER = ('quantum.plugins.cisco.tests.unit.v2.nexus.' + 'fake_nexus_driver.CiscoNEXUSFakeDriver') + + +class TestCiscoNexusPlugin(unittest.TestCase): def setUp(self): """ @@ -43,9 +54,24 @@ class TestNexusPlugin(unittest.TestCase): self.second_net_id = 000005 self.second_vlan_name = "q-" + str(self.second_net_id) + "vlan" self.second_vlan_id = 265 - cdb.initialize() - creds.Store.initialize() - self._cisco_nexus_plugin = cisco_nexus_plugin_v2.NexusPlugin() + + def new_cdb_init(): + db.configure_db({'sql_connection': 'sqlite://', + 'base': network_models_v2.model_base.BASEV2}) + + def new_nexus_init(self): + self._client = importutils.import_object(NEXUS_DRIVER) + self._nexus_ip = NEXUS_IP_ADDRESS + self._nexus_username = NEXUS_USERNAME + self._nexus_password = NEXUS_PASSWORD + self._nexus_ports = NEXUS_PORTS + self._nexus_ssh_port = NEXUS_SSH_PORT + + with mock.patch.object(cdb, 'initialize', new=new_cdb_init): + cdb.initialize() + with mock.patch.object(cisco_nexus_plugin_v2.NexusPlugin, + '__init__', new=new_nexus_init): + self._cisco_nexus_plugin = cisco_nexus_plugin_v2.NexusPlugin() def test_create_delete_network(self): """ diff --git a/tools/test-requires b/tools/test-requires index 83091e59a..e8fb99be4 100644 --- a/tools/test-requires +++ b/tools/test-requires @@ -10,3 +10,7 @@ pep8 sphinx>=1.1.2 unittest2 webtest==1.3.3 +# Packages for the Cisco Plugin +############################### +configobj +###############################