bug
1054387
So far unit tests were executed using an in-memory database.
Memory was not being freed thus causing oom frequently due to
the increased number of unit tests.
Since sqlite in memory db do not work very well anyway with nose,
we are moving to file-based databases; slower, but safer.
Also, this patch removes a bunch of unit tests which do not add
anything to code coverage or number or test cases exercised.
Change-Id: Ib853727a5268643fbe8a99f6ebd0fc10aca6a43a
LOG = logging.getLogger(__name__)
+TEST_DB = "quantum.test.db"
AGENT_OWNER_PREFIX = 'network:'
# must override __init__ and setup the database
# and not call into this class's __init__.
# This connection is setup as memory for the tests.
- sql_connection = 'sqlite:///:memory:'
- db.configure_db({'sql_connection': sql_connection,
+ db.configure_db({'sql_connection': "sqlite:///%s" % TEST_DB,
'base': models_v2.model_base.BASEV2})
def _get_tenant_id_for_create(self, context, resource):
# The messaging module to use, defaults to kombu.
rpc_backend = quantum.openstack.common.rpc.impl_fake
+
+[DATABASE]
+sql_connection = 'sqlite:///quantum.test.db'
\ No newline at end of file
def setUp(self):
def new_init():
- db.configure_db({'sql_connection': 'sqlite://',
+ db.configure_db({'sql_connection': 'sqlite:///quantum.test.db',
'base': network_models_v2.model_base.BASEV2})
with mock.patch.object(network_db_v2,
class TestLinuxBridgeNetworksV2(test_plugin.TestNetworksV2,
LinuxBridgePluginV2TestCase):
pass
-
-
-class TestLinuxBridgeSubnetsV2(test_plugin.TestSubnetsV2,
- LinuxBridgePluginV2TestCase):
- pass
class TestNecNetworksV2(test_plugin.TestNetworksV2, NecPluginV2TestCase):
pass
-
-
-class TestNecSubnetsV2(test_plugin.TestSubnetsV2, NecPluginV2TestCase):
- pass
+++ /dev/null
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
-#
-# Copyright 2012 NEC Corporation. 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.
-# @author: Ryota MIBU
-
-from quantum.plugins.nec.common import config
-from quantum.tests.unit import test_db_plugin
-
-
-class NECPluginTestBase(object):
-
- def setUp(self):
- # Make sure at each test a new instance of the plugin is returned
- test_db_plugin.QuantumManager._instance = None
-
- self._tenant_id = 'test-tenant'
-
- json_deserializer = test_db_plugin.JSONDeserializer()
- self._deserializers = {
- 'application/json': json_deserializer,
- }
-
- plugin = 'quantum.plugins.nec.nec_plugin.NECPluginV2'
- config.CONF.set_override('core_plugin', plugin)
- driver = "quantum.tests.unit.nec.stub_ofc_driver.StubOFCDriver"
- config.CONF.set_override('driver', driver, 'OFC')
- config.CONF.set_override('rpc_backend',
- 'quantum.openstack.common.rpc.impl_fake')
- self.api = test_db_plugin.APIRouter()
- self._skip_native_bulk = False
- super(NECPluginTestBase, self).setUp(plugin)
-
-
-# TODO(r-mibu): write UT for packet_filters.
-class TestPacketFiltersV2(NECPluginTestBase,
- test_db_plugin.QuantumDbPluginV2TestCase):
- pass
[DEFAULT]
-[DATABASE]
-sql_connection = sqlite://
-
[CLUSTER:fake]
default_tz_uuid = fake_tz_uuid
nova_zone_id = whatever
method = args[0]
handler = getattr(self, "handle_%s" % method.lower())
return handler(*args[1:])
+
+ def reset_all(self):
+ self._fake_lswitch_dict.clear()
+ self._fake_lport_dict.clear()
+ self._fake_lportstatus_dict.clear()
test_lib.test_config['config_files'] = [os.path.join(etc_path,
'nvp.ini.test')]
# mock nvp api client
- fc = fake_nvpapiclient.FakeClient(etc_path)
+ self.fc = fake_nvpapiclient.FakeClient(etc_path)
self.mock_nvpapi = mock.patch('%s.NvpApiClient.NVPApiHelper'
% NICIRA_PKG_PATH, autospec=True)
instance = self.mock_nvpapi.start()
instance.return_value.login.return_value = "the_cookie"
def _fake_request(*args, **kwargs):
- return fc.fake_request(*args, **kwargs)
+ return self.fc.fake_request(*args, **kwargs)
instance.return_value.request.side_effect = _fake_request
super(NiciraPluginV2TestCase, self).setUp(self._plugin_name)
def tearDown(self):
+ self.fc.reset_all()
super(NiciraPluginV2TestCase, self).tearDown()
self.mock_nvpapi.stop()
class TestNiciraNetworksV2(test_plugin.TestNetworksV2,
NiciraPluginV2TestCase):
pass
-
-
-class TestNiciraSubnetsV2(test_plugin.TestSubnetsV2, NiciraPluginV2TestCase):
- pass
class TestOpenvswitchNetworksV2(test_plugin.TestNetworksV2,
OpenvswitchPluginV2TestCase):
pass
-
-
-class TestOpenvswitchSubnetsV2(test_plugin.TestSubnetsV2,
- OpenvswitchPluginV2TestCase):
- pass
# License for the specific language governing permissions and limitations
# under the License.
+import os
import unittest2
from quantum.db import api as db
class RyuDBTest(unittest2.TestCase):
def setUp(self):
- options = {"sql_connection": cfg.CONF.DATABASE.sql_connection}
+ options = {"sql_connection": 'sqlite:///quantum.test.db'}
options.update({'base': models_v2.model_base.BASEV2})
reconnect_interval = cfg.CONF.DATABASE.reconnect_interval
options.update({"reconnect_interval": reconnect_interval})
class TestRyuNetworksV2(test_plugin.TestNetworksV2, RyuPluginV2TestCase):
pass
-
-
-class TestRyuSubnetsV2(test_plugin.TestSubnetsV2, RyuPluginV2TestCase):
- pass
cfg.CONF.reset()
# Restore the original attribute map
attributes.RESOURCE_ATTRIBUTE_MAP = self._attribute_map_bk
+ # Remove test database
+ if os.path.exists(db_base_plugin_v2.TEST_DB):
+ os.remove('quantum.test.db')
def _req(self, method, resource, data=None, fmt='json',
id=None, params=None, action=None):