]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix cinder-all binary
authorIvan Kolodyazhny <e0ne@e0ne.info>
Tue, 15 Sep 2015 22:01:37 +0000 (01:01 +0300)
committerKurt Martin <kurt.f.martin@hpe.com>
Wed, 16 Sep 2015 22:40:41 +0000 (22:40 +0000)
1. Add rpc.init for cinder-api service
2. Add multi-backend support for cinder-volume service

Closes-Bug: #1496154
Change-Id: I91626bd74fc224302e131c5235030a02431a04c1

cinder/cmd/all.py
cinder/tests/unit/test_cmd.py

index 945ee0c7b4a9942486ca9e2cd60ad5d76e880309..ceee9c9c8b6868dff623587d8dfa9b16581a882f 100644 (file)
@@ -32,14 +32,18 @@ import sys
 
 from oslo_config import cfg
 from oslo_log import log as logging
+from oslo_reports import guru_meditation_report as gmr
 
 from cinder import i18n
 i18n.enable_lazy()
 
 # Need to register global_opts
+from cinder.cmd import volume as volume_cmd
 from cinder.common import config   # noqa
+from cinder.db import api as session
 from cinder.i18n import _LE
 from cinder import objects
+from cinder import rpc
 from cinder import service
 from cinder import utils
 from cinder import version
@@ -48,6 +52,7 @@ from cinder import version
 CONF = cfg.CONF
 
 
+# TODO(e0ne): get a rid of code duplication in cinder.cmd module in Mitaka
 def main():
     objects.register_all()
     CONF(sys.argv[1:], project='cinder',
@@ -56,6 +61,11 @@ def main():
     LOG = logging.getLogger('cinder.all')
 
     utils.monkey_patch()
+
+    gmr.TextGuruMeditation.setup_autorun(version)
+
+    rpc.init(CONF)
+
     launcher = service.process_launcher()
     # cinder-api
     try:
@@ -64,9 +74,32 @@ def main():
     except (Exception, SystemExit):
         LOG.exception(_LE('Failed to load osapi_volume'))
 
-    for binary in ['cinder-volume', 'cinder-scheduler', 'cinder-backup']:
+    for binary in ['cinder-scheduler', 'cinder-backup']:
         try:
             launcher.launch_service(service.Service.create(binary=binary))
         except (Exception, SystemExit):
             LOG.exception(_LE('Failed to load %s'), binary)
+
+    # cinder-volume
+    try:
+        if CONF.enabled_backends:
+            for backend in CONF.enabled_backends:
+                CONF.register_opt(volume_cmd.host_opt, group=backend)
+                backend_host = getattr(CONF, backend).backend_host
+                host = "%s@%s" % (backend_host or CONF.host, backend)
+                server = service.Service.create(host=host,
+                                                service_name=backend,
+                                                binary='cinder-volume')
+                # Dispose of the whole DB connection pool here before
+                # starting another process.  Otherwise we run into cases
+                # where child processes share DB connections which results
+                # in errors.
+                session.dispose_engine()
+                launcher.launch_service(server)
+        else:
+            server = service.Service.create(binary='cinder-volume')
+            launcher.launch_service(server)
+    except (Exception, SystemExit):
+        LOG.exception(_LE('Failed to load conder-volume'))
+
     launcher.wait()
index 6abf79c3cba9e605a7346494c490dbdf0e0b98e4..8f0d4460226245ab3ea3f1241a960c121c0f1719 100644 (file)
@@ -117,6 +117,7 @@ class TestCinderAllCmd(test.TestCase):
     def tearDown(self):
         super(TestCinderAllCmd, self).tearDown()
 
+    @mock.patch('cinder.rpc.init')
     @mock.patch('cinder.service.Service.create')
     @mock.patch('cinder.service.WSGIService')
     @mock.patch('cinder.service.process_launcher')
@@ -124,7 +125,7 @@ class TestCinderAllCmd(test.TestCase):
     @mock.patch('oslo_log.log.getLogger')
     @mock.patch('oslo_log.log.setup')
     def test_main(self, log_setup, get_logger, monkey_patch, process_launcher,
-                  wsgi_service, service_create):
+                  wsgi_service, service_create, rpc_init):
         launcher = process_launcher.return_value
         server = wsgi_service.return_value
         server.workers = mock.sentinel.worker_count
@@ -137,19 +138,21 @@ class TestCinderAllCmd(test.TestCase):
         log_setup.assert_called_once_with(CONF, "cinder")
         get_logger.assert_called_once_with('cinder.all')
         monkey_patch.assert_called_once_with()
+        rpc_init.assert_called_once_with(CONF)
         process_launcher.assert_called_once_with()
         wsgi_service.assert_called_once_with('osapi_volume')
         launcher.launch_service.assert_any_call(server, workers=server.workers)
 
-        service_create.assert_has_calls([mock.call(binary='cinder-volume'),
-                                         mock.call(binary='cinder-scheduler'),
-                                         mock.call(binary='cinder-backup')])
+        service_create.assert_has_calls([mock.call(binary='cinder-scheduler'),
+                                         mock.call(binary='cinder-backup'),
+                                         mock.call(binary='cinder-volume')])
         self.assertEqual(3, service_create.call_count)
         launcher.launch_service.assert_has_calls([mock.call(service)] * 3)
         self.assertEqual(4, launcher.launch_service.call_count)
 
         launcher.wait.assert_called_once_with()
 
+    @mock.patch('cinder.rpc.init')
     @mock.patch('cinder.service.Service.create')
     @mock.patch('cinder.service.WSGIService')
     @mock.patch('cinder.service.process_launcher')
@@ -158,7 +161,8 @@ class TestCinderAllCmd(test.TestCase):
     @mock.patch('oslo_log.log.setup')
     def test_main_load_osapi_volume_exception(self, log_setup, get_logger,
                                               monkey_patch, process_launcher,
-                                              wsgi_service, service_create):
+                                              wsgi_service, service_create,
+                                              rpc_init):
         launcher = process_launcher.return_value
         server = wsgi_service.return_value
         server.workers = mock.sentinel.worker_count
@@ -176,6 +180,7 @@ class TestCinderAllCmd(test.TestCase):
             monkey_patch.assert_called_once_with()
             process_launcher.assert_called_once_with()
             wsgi_service.assert_called_once_with('osapi_volume')
+            rpc_init.assert_called_with(CONF)
             launcher.launch_service.assert_any_call(server,
                                                     workers=server.workers)
             self.assertTrue(mock_log.exception.called)
@@ -188,6 +193,7 @@ class TestCinderAllCmd(test.TestCase):
             wsgi_service.reset_mock()
             mock_log.reset_mock()
 
+    @mock.patch('cinder.rpc.init')
     @mock.patch('cinder.service.Service.create')
     @mock.patch('cinder.service.WSGIService')
     @mock.patch('cinder.service.process_launcher')
@@ -196,7 +202,8 @@ class TestCinderAllCmd(test.TestCase):
     @mock.patch('oslo_log.log.setup')
     def test_main_load_binary_exception(self, log_setup, get_logger,
                                         monkey_patch, process_launcher,
-                                        wsgi_service, service_create):
+                                        wsgi_service, service_create,
+                                        rpc_init):
         launcher = process_launcher.return_value
         server = wsgi_service.return_value
         server.workers = mock.sentinel.worker_count
@@ -223,6 +230,7 @@ class TestCinderAllCmd(test.TestCase):
         for binary in ['cinder-volume', 'cinder-scheduler', 'cinder-backup']:
             service_create.assert_any_call(binary=binary)
             launcher.launch_service.assert_called_with(service)
+        rpc_init.assert_called_once_with(CONF)
         self.assertTrue(mock_log.exception.called)