]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Use sqlite db on file for unit tests
authorSalvatore Orlando <salv.orlando@gmail.com>
Sat, 22 Sep 2012 00:06:47 +0000 (17:06 -0700)
committerSalvatore Orlando <salv.orlando@gmail.com>
Sun, 23 Sep 2012 12:51:50 +0000 (05:51 -0700)
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

13 files changed:
quantum/db/db_base_plugin_v2.py
quantum/tests/etc/quantum.conf.test
quantum/tests/unit/cisco/test_network_plugin.py
quantum/tests/unit/linuxbridge/test_linuxbridge_plugin.py
quantum/tests/unit/nec/test_nec_plugin.py
quantum/tests/unit/nec/test_nec_plugin_v2.py [deleted file]
quantum/tests/unit/nicira/etc/nvp.ini.test
quantum/tests/unit/nicira/fake_nvpapiclient.py
quantum/tests/unit/nicira/test_nicira_plugin.py
quantum/tests/unit/openvswitch/test_openvswitch_plugin.py
quantum/tests/unit/ryu/test_ryu_db.py
quantum/tests/unit/ryu/test_ryu_plugin.py
quantum/tests/unit/test_db_plugin.py

index 5940487652cfb4c935f80d1445911b600edc948b..9cc2b4f78d5c95914da78170fb6f3c695d93be1b 100644 (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):
index 961af504208a496fdf3e0063feaf6a02a97b2acf..2bf73d06c8ce565a48893c6b7e539c20ee367dfa 100644 (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'
\ No newline at end of file
index 00f7448fb4924e5e3deae382d67fad8ae96c0455..d4cfa5dd2d425bfb7f314998550918ad888e73c8 100644 (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,
index 03d3546be5744d997ee480017c0f926613baa65e..3a2c0b7c2d89d1a7b543b50ced8b6ccf2dae3f6f 100644 (file)
@@ -43,8 +43,3 @@ class TestLinuxBridgePortsV2(test_plugin.TestPortsV2,
 class TestLinuxBridgeNetworksV2(test_plugin.TestNetworksV2,
                                 LinuxBridgePluginV2TestCase):
     pass
-
-
-class TestLinuxBridgeSubnetsV2(test_plugin.TestSubnetsV2,
-                               LinuxBridgePluginV2TestCase):
-    pass
index ec7e1972528ff42766200b8f8417db1181175cec..1d1aebdf51246fe3fb1735c027bcb2f856e93b81 100644 (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
diff --git a/quantum/tests/unit/nec/test_nec_plugin_v2.py b/quantum/tests/unit/nec/test_nec_plugin_v2.py
deleted file mode 100644 (file)
index 0f5c086..0000000
+++ /dev/null
@@ -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
index 8167078751ac6238731666c8ae41017bedc34724..d7452d5975f68e0b61c6f3d9d84c0a59475b17b4 100644 (file)
@@ -1,8 +1,5 @@
 [DEFAULT]
 
-[DATABASE]
-sql_connection = sqlite://
-
 [CLUSTER:fake]
 default_tz_uuid = fake_tz_uuid
 nova_zone_id = whatever
index 9b79254989b518f67b79a98379fdbd4f6772c649..5338ca69315589c2dedc697ae7c229dafe155fa6 100644 (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()
index dce59856622487b66b3eb496fa6736ed7304b86f..c6e11881b2aafbeadff4d37296f52bf71368f083 100644 (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
index df65a209fc96216d3b0a4773ddf8dc3f27f7fd62..6727d9221035456215678032294ddfa6ffaf673d 100644 (file)
@@ -43,8 +43,3 @@ class TestOpenvswitchPortsV2(test_plugin.TestPortsV2,
 class TestOpenvswitchNetworksV2(test_plugin.TestNetworksV2,
                                 OpenvswitchPluginV2TestCase):
     pass
-
-
-class TestOpenvswitchSubnetsV2(test_plugin.TestSubnetsV2,
-                               OpenvswitchPluginV2TestCase):
-    pass
index c12849c042449e2c975d0473d77e85a2d8cec67c..f7b4e9347813bf625edcb03902a518e2fe12bb0b 100644 (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})
index f5e2c233a2a0fe6f9ed819ce1e7281799260ecda..fb508aa34a6162378609a5c7abb2f16ebf1d4caa 100644 (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
index 4fb3897ceb3b74fd155b0288460bd9d2657b9137..e4655e2772e92c5e4b34341ca95141fb74da1292 100644 (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):