Execute unit tests for Cisco plugin with Quantum tests

Bug #1041917

On account of the new requirement to run plugin-specific tests also
along with the Quantum tests, changes are being made to
incorporate the Cisco plugin unit tests into the Quantum unit test
suite. Earlier unit tests have been moved and modified.

Change-Id: I099bcaf0b2ca2f7ed7d25176dfaa75966b90dd71
This commit is contained in:
Sumit Naiksatam 2012-08-26 11:02:31 -07:00
parent dee4e232af
commit 0b4cecf682
4 changed files with 67 additions and 35 deletions

View File

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

View File

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

View File

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

View File

@ -10,3 +10,7 @@ pep8
sphinx>=1.1.2
unittest2
webtest==1.3.3
# Packages for the Cisco Plugin
###############################
configobj
###############################