Fix cinder-all binary
1. Add rpc.init for cinder-api service 2. Add multi-backend support for cinder-volume service Closes-Bug: #1496154 Change-Id: I91626bd74fc224302e131c5235030a02431a04c1
This commit is contained in:
parent
bd9719508d
commit
93d26e4009
@ -32,14 +32,18 @@ import sys
|
|||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log as logging
|
from oslo_log import log as logging
|
||||||
|
from oslo_reports import guru_meditation_report as gmr
|
||||||
|
|
||||||
from cinder import i18n
|
from cinder import i18n
|
||||||
i18n.enable_lazy()
|
i18n.enable_lazy()
|
||||||
|
|
||||||
# Need to register global_opts
|
# Need to register global_opts
|
||||||
|
from cinder.cmd import volume as volume_cmd
|
||||||
from cinder.common import config # noqa
|
from cinder.common import config # noqa
|
||||||
|
from cinder.db import api as session
|
||||||
from cinder.i18n import _LE
|
from cinder.i18n import _LE
|
||||||
from cinder import objects
|
from cinder import objects
|
||||||
|
from cinder import rpc
|
||||||
from cinder import service
|
from cinder import service
|
||||||
from cinder import utils
|
from cinder import utils
|
||||||
from cinder import version
|
from cinder import version
|
||||||
@ -48,6 +52,7 @@ from cinder import version
|
|||||||
CONF = cfg.CONF
|
CONF = cfg.CONF
|
||||||
|
|
||||||
|
|
||||||
|
# TODO(e0ne): get a rid of code duplication in cinder.cmd module in Mitaka
|
||||||
def main():
|
def main():
|
||||||
objects.register_all()
|
objects.register_all()
|
||||||
CONF(sys.argv[1:], project='cinder',
|
CONF(sys.argv[1:], project='cinder',
|
||||||
@ -56,6 +61,11 @@ def main():
|
|||||||
LOG = logging.getLogger('cinder.all')
|
LOG = logging.getLogger('cinder.all')
|
||||||
|
|
||||||
utils.monkey_patch()
|
utils.monkey_patch()
|
||||||
|
|
||||||
|
gmr.TextGuruMeditation.setup_autorun(version)
|
||||||
|
|
||||||
|
rpc.init(CONF)
|
||||||
|
|
||||||
launcher = service.process_launcher()
|
launcher = service.process_launcher()
|
||||||
# cinder-api
|
# cinder-api
|
||||||
try:
|
try:
|
||||||
@ -64,9 +74,32 @@ def main():
|
|||||||
except (Exception, SystemExit):
|
except (Exception, SystemExit):
|
||||||
LOG.exception(_LE('Failed to load osapi_volume'))
|
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:
|
try:
|
||||||
launcher.launch_service(service.Service.create(binary=binary))
|
launcher.launch_service(service.Service.create(binary=binary))
|
||||||
except (Exception, SystemExit):
|
except (Exception, SystemExit):
|
||||||
LOG.exception(_LE('Failed to load %s'), binary)
|
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()
|
launcher.wait()
|
||||||
|
@ -117,6 +117,7 @@ class TestCinderAllCmd(test.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super(TestCinderAllCmd, self).tearDown()
|
super(TestCinderAllCmd, self).tearDown()
|
||||||
|
|
||||||
|
@mock.patch('cinder.rpc.init')
|
||||||
@mock.patch('cinder.service.Service.create')
|
@mock.patch('cinder.service.Service.create')
|
||||||
@mock.patch('cinder.service.WSGIService')
|
@mock.patch('cinder.service.WSGIService')
|
||||||
@mock.patch('cinder.service.process_launcher')
|
@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.getLogger')
|
||||||
@mock.patch('oslo_log.log.setup')
|
@mock.patch('oslo_log.log.setup')
|
||||||
def test_main(self, log_setup, get_logger, monkey_patch, process_launcher,
|
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
|
launcher = process_launcher.return_value
|
||||||
server = wsgi_service.return_value
|
server = wsgi_service.return_value
|
||||||
server.workers = mock.sentinel.worker_count
|
server.workers = mock.sentinel.worker_count
|
||||||
@ -137,19 +138,21 @@ class TestCinderAllCmd(test.TestCase):
|
|||||||
log_setup.assert_called_once_with(CONF, "cinder")
|
log_setup.assert_called_once_with(CONF, "cinder")
|
||||||
get_logger.assert_called_once_with('cinder.all')
|
get_logger.assert_called_once_with('cinder.all')
|
||||||
monkey_patch.assert_called_once_with()
|
monkey_patch.assert_called_once_with()
|
||||||
|
rpc_init.assert_called_once_with(CONF)
|
||||||
process_launcher.assert_called_once_with()
|
process_launcher.assert_called_once_with()
|
||||||
wsgi_service.assert_called_once_with('osapi_volume')
|
wsgi_service.assert_called_once_with('osapi_volume')
|
||||||
launcher.launch_service.assert_any_call(server, workers=server.workers)
|
launcher.launch_service.assert_any_call(server, workers=server.workers)
|
||||||
|
|
||||||
service_create.assert_has_calls([mock.call(binary='cinder-volume'),
|
service_create.assert_has_calls([mock.call(binary='cinder-scheduler'),
|
||||||
mock.call(binary='cinder-scheduler'),
|
mock.call(binary='cinder-backup'),
|
||||||
mock.call(binary='cinder-backup')])
|
mock.call(binary='cinder-volume')])
|
||||||
self.assertEqual(3, service_create.call_count)
|
self.assertEqual(3, service_create.call_count)
|
||||||
launcher.launch_service.assert_has_calls([mock.call(service)] * 3)
|
launcher.launch_service.assert_has_calls([mock.call(service)] * 3)
|
||||||
self.assertEqual(4, launcher.launch_service.call_count)
|
self.assertEqual(4, launcher.launch_service.call_count)
|
||||||
|
|
||||||
launcher.wait.assert_called_once_with()
|
launcher.wait.assert_called_once_with()
|
||||||
|
|
||||||
|
@mock.patch('cinder.rpc.init')
|
||||||
@mock.patch('cinder.service.Service.create')
|
@mock.patch('cinder.service.Service.create')
|
||||||
@mock.patch('cinder.service.WSGIService')
|
@mock.patch('cinder.service.WSGIService')
|
||||||
@mock.patch('cinder.service.process_launcher')
|
@mock.patch('cinder.service.process_launcher')
|
||||||
@ -158,7 +161,8 @@ class TestCinderAllCmd(test.TestCase):
|
|||||||
@mock.patch('oslo_log.log.setup')
|
@mock.patch('oslo_log.log.setup')
|
||||||
def test_main_load_osapi_volume_exception(self, log_setup, get_logger,
|
def test_main_load_osapi_volume_exception(self, log_setup, get_logger,
|
||||||
monkey_patch, process_launcher,
|
monkey_patch, process_launcher,
|
||||||
wsgi_service, service_create):
|
wsgi_service, service_create,
|
||||||
|
rpc_init):
|
||||||
launcher = process_launcher.return_value
|
launcher = process_launcher.return_value
|
||||||
server = wsgi_service.return_value
|
server = wsgi_service.return_value
|
||||||
server.workers = mock.sentinel.worker_count
|
server.workers = mock.sentinel.worker_count
|
||||||
@ -176,6 +180,7 @@ class TestCinderAllCmd(test.TestCase):
|
|||||||
monkey_patch.assert_called_once_with()
|
monkey_patch.assert_called_once_with()
|
||||||
process_launcher.assert_called_once_with()
|
process_launcher.assert_called_once_with()
|
||||||
wsgi_service.assert_called_once_with('osapi_volume')
|
wsgi_service.assert_called_once_with('osapi_volume')
|
||||||
|
rpc_init.assert_called_with(CONF)
|
||||||
launcher.launch_service.assert_any_call(server,
|
launcher.launch_service.assert_any_call(server,
|
||||||
workers=server.workers)
|
workers=server.workers)
|
||||||
self.assertTrue(mock_log.exception.called)
|
self.assertTrue(mock_log.exception.called)
|
||||||
@ -188,6 +193,7 @@ class TestCinderAllCmd(test.TestCase):
|
|||||||
wsgi_service.reset_mock()
|
wsgi_service.reset_mock()
|
||||||
mock_log.reset_mock()
|
mock_log.reset_mock()
|
||||||
|
|
||||||
|
@mock.patch('cinder.rpc.init')
|
||||||
@mock.patch('cinder.service.Service.create')
|
@mock.patch('cinder.service.Service.create')
|
||||||
@mock.patch('cinder.service.WSGIService')
|
@mock.patch('cinder.service.WSGIService')
|
||||||
@mock.patch('cinder.service.process_launcher')
|
@mock.patch('cinder.service.process_launcher')
|
||||||
@ -196,7 +202,8 @@ class TestCinderAllCmd(test.TestCase):
|
|||||||
@mock.patch('oslo_log.log.setup')
|
@mock.patch('oslo_log.log.setup')
|
||||||
def test_main_load_binary_exception(self, log_setup, get_logger,
|
def test_main_load_binary_exception(self, log_setup, get_logger,
|
||||||
monkey_patch, process_launcher,
|
monkey_patch, process_launcher,
|
||||||
wsgi_service, service_create):
|
wsgi_service, service_create,
|
||||||
|
rpc_init):
|
||||||
launcher = process_launcher.return_value
|
launcher = process_launcher.return_value
|
||||||
server = wsgi_service.return_value
|
server = wsgi_service.return_value
|
||||||
server.workers = mock.sentinel.worker_count
|
server.workers = mock.sentinel.worker_count
|
||||||
@ -223,6 +230,7 @@ class TestCinderAllCmd(test.TestCase):
|
|||||||
for binary in ['cinder-volume', 'cinder-scheduler', 'cinder-backup']:
|
for binary in ['cinder-volume', 'cinder-scheduler', 'cinder-backup']:
|
||||||
service_create.assert_any_call(binary=binary)
|
service_create.assert_any_call(binary=binary)
|
||||||
launcher.launch_service.assert_called_with(service)
|
launcher.launch_service.assert_called_with(service)
|
||||||
|
rpc_init.assert_called_once_with(CONF)
|
||||||
self.assertTrue(mock_log.exception.called)
|
self.assertTrue(mock_log.exception.called)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user