]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Start metadata agent without trying to connect db
authorgong yong sheng <gong.yongsheng@99cloud.net>
Thu, 26 Feb 2015 08:09:54 +0000 (16:09 +0800)
committerArmando Migliaccio <armamig@gmail.com>
Thu, 12 Mar 2015 23:01:54 +0000 (23:01 +0000)
We set conf.database.connection into empty in agent,
and tell wsgi does not to connect db in this case.

Change-Id: Icb83157ef6f1157068f3d4238b946fdbb890083f
Closes-bug: #1425844

neutron/agent/metadata_agent.py
neutron/tests/unit/test_metadata_agent.py
neutron/tests/unit/test_wsgi.py
neutron/wsgi.py

index a6cec3a28ee106fef8a389491620318aacf792f5..36935bc37260b679fe1ec5512e99f94683987f96 100644 (file)
@@ -36,5 +36,7 @@ def main():
     config.init(sys.argv[1:])
     config.setup_logging()
     utils.log_opt_values(LOG)
+    # metadata agent need not connect DB
+    cfg.CONF.set_override("connection", "", "database")
     proxy = agent.UnixDomainMetadataProxy(cfg.CONF)
     proxy.run()
index b85ce2d6054718282f189fce6f02cd8f3d14c010..296e445276201f4880ced8b91fc514bf559ab461 100644 (file)
@@ -634,6 +634,8 @@ class TestUnixDomainMetadataProxy(base.BaseTestCase):
                             mock.call(cfg.CONF),
                             mock.call().run()]
                         )
+                        cfg.CONF.set_override.assert_called_once_with(
+                            "connection", "", "database")
 
     def test_init_state_reporting(self):
         with mock.patch('os.makedirs'):
index 38b407071d0f2b91d0b7998b46dc2897c8f2581e..7b55d014bc9ea100a670e1cd50c51372bb066ffe 100644 (file)
@@ -49,6 +49,23 @@ def open_no_proxy(*args, **kwargs):
     return opener.open(*args, **kwargs)
 
 
+class TestWorkerService(base.BaseTestCase):
+    """WorkerService tests."""
+
+    @mock.patch('neutron.db.api')
+    def test_start_withoutdb_call(self, apimock):
+        _service = mock.Mock()
+        _service.pool = mock.Mock()
+        _service.pool.spawn = mock.Mock()
+        _service.pool.spawn.return_value = None
+
+        _app = mock.Mock()
+        cfg.CONF.set_override("connection", "", "database")
+        workerservice = wsgi.WorkerService(_service, _app)
+        workerservice.start()
+        self.assertFalse(apimock.get_engine.called)
+
+
 class TestWSGIServer(base.BaseTestCase):
     """WSGI server tests."""
 
index d99cdaafc41c2669cd706ed9c57a7652a4251990..fed3b2881268b134b26fa6319cace6ea54bc7f27 100644 (file)
@@ -98,9 +98,10 @@ class WorkerService(object):
 
     def start(self):
         # We may have just forked from parent process.  A quick disposal of the
-        # existing sql connections avoids producting 500 errors later when they
+        # existing sql connections avoids producing 500 errors later when they
         # are discovered to be broken.
-        api.get_engine().pool.dispose()
+        if CONF.database.connection:
+            api.get_engine().pool.dispose()
         self._server = self._service.pool.spawn(self._service._run,
                                                 self._application,
                                                 self._service._socket)