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
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',
LOG = logging.getLogger('cinder.all')
utils.monkey_patch()
+
+ gmr.TextGuruMeditation.setup_autorun(version)
+
+ rpc.init(CONF)
+
launcher = service.process_launcher()
# cinder-api
try:
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()
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')
@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
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')
@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
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)
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')
@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
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)