Use sqlite db on file for unit tests

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
This commit is contained in:
Salvatore Orlando 2012-09-21 17:06:47 -07:00
parent f0c6fc290e
commit 652477b765
13 changed files with 19 additions and 80 deletions

View File

@ -33,6 +33,7 @@ from quantum import quantum_plugin_base_v2
LOG = logging.getLogger(__name__)
TEST_DB = "quantum.test.db"
AGENT_OWNER_PREFIX = 'network:'
@ -71,8 +72,7 @@ class QuantumDbPluginV2(quantum_plugin_base_v2.QuantumPluginBaseV2):
# 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):

View File

@ -19,3 +19,6 @@ api_paste_config = api-paste.ini.test
# The messaging module to use, defaults to kombu.
rpc_backend = quantum.openstack.common.rpc.impl_fake
[DATABASE]
sql_connection = 'sqlite:///quantum.test.db'

View File

@ -42,7 +42,7 @@ class CiscoNetworkPluginV2TestCase(test_db_plugin.QuantumDbPluginV2TestCase):
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,

View File

@ -43,8 +43,3 @@ class TestLinuxBridgePortsV2(test_plugin.TestPortsV2,
class TestLinuxBridgeNetworksV2(test_plugin.TestNetworksV2,
LinuxBridgePluginV2TestCase):
pass
class TestLinuxBridgeSubnetsV2(test_plugin.TestSubnetsV2,
LinuxBridgePluginV2TestCase):
pass

View File

@ -39,7 +39,3 @@ class TestNecPortsV2(test_plugin.TestPortsV2, NecPluginV2TestCase):
class TestNecNetworksV2(test_plugin.TestNetworksV2, NecPluginV2TestCase):
pass
class TestNecSubnetsV2(test_plugin.TestSubnetsV2, NecPluginV2TestCase):
pass

View File

@ -1,49 +0,0 @@
# 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

View File

@ -1,8 +1,5 @@
[DEFAULT]
[DATABASE]
sql_connection = sqlite://
[CLUSTER:fake]
default_tz_uuid = fake_tz_uuid
nova_zone_id = whatever

View File

@ -232,3 +232,8 @@ class FakeClient:
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()

View File

@ -33,19 +33,20 @@ class NiciraPluginV2TestCase(test_plugin.QuantumDbPluginV2TestCase):
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()
@ -66,7 +67,3 @@ class TestNiciraPortsV2(test_plugin.TestPortsV2, NiciraPluginV2TestCase):
class TestNiciraNetworksV2(test_plugin.TestNetworksV2,
NiciraPluginV2TestCase):
pass
class TestNiciraSubnetsV2(test_plugin.TestSubnetsV2, NiciraPluginV2TestCase):
pass

View File

@ -43,8 +43,3 @@ class TestOpenvswitchPortsV2(test_plugin.TestPortsV2,
class TestOpenvswitchNetworksV2(test_plugin.TestNetworksV2,
OpenvswitchPluginV2TestCase):
pass
class TestOpenvswitchSubnetsV2(test_plugin.TestSubnetsV2,
OpenvswitchPluginV2TestCase):
pass

View File

@ -15,6 +15,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import unittest2
from quantum.db import api as db
@ -27,7 +28,7 @@ from quantum.plugins.ryu import ofp_service_type
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})

View File

@ -56,7 +56,3 @@ class TestRyuPortsV2(test_plugin.TestPortsV2, RyuPluginV2TestCase):
class TestRyuNetworksV2(test_plugin.TestNetworksV2, RyuPluginV2TestCase):
pass
class TestRyuSubnetsV2(test_plugin.TestSubnetsV2, RyuPluginV2TestCase):
pass

View File

@ -119,6 +119,9 @@ class QuantumDbPluginV2TestCase(unittest2.TestCase):
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):