From 205c94f761ac23a1aed5aa0a02b7e3177b85f37f Mon Sep 17 00:00:00 2001 From: Hidekazu Nakamura Date: Mon, 18 Jan 2016 11:22:21 +0900 Subject: [PATCH] Add multiple engine workers Implement murano-engine workers for scalability. Depends-On: I1de509b061bd5d3fe0cd5e27673c54a13209a56a Change-Id: I3cbc9dff9cc0e476a897af3f1931ff2a61eb72cc Implements: blueprint multiple-engine-workers --- devstack/plugin.sh | 5 ++ murano/cmd/engine.py | 9 ++- murano/common/config.py | 2 + murano/tests/unit/cmd/__init__.py | 0 murano/tests/unit/cmd/test_engine_workers.py | 56 +++++++++++++++++++ ...tiple-engine-workers-7fec79572a6a9d01.yaml | 6 ++ 6 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 murano/tests/unit/cmd/__init__.py create mode 100644 murano/tests/unit/cmd/test_engine_workers.py create mode 100644 releasenotes/notes/multiple-engine-workers-7fec79572a6a9d01.yaml diff --git a/devstack/plugin.sh b/devstack/plugin.sh index 492f0ac9f..8b942e5e8 100755 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -158,6 +158,11 @@ function configure_murano { # Configure Murano API URL iniset $MURANO_CONF_FILE murano url "http://127.0.0.1:8082" + + # Configure the number of engine workers + if [[ -n "$MURANO_ENGINE_WORKERS" ]]; then + iniset $MURANO_CONF_FILE engine workers $MURANO_ENGINE_WORKERS + fi } # install_murano_apps() - Install Murano apps from repository murano-apps, if required diff --git a/murano/cmd/engine.py b/murano/cmd/engine.py index 5861e11ea..1c3f2a0fa 100644 --- a/murano/cmd/engine.py +++ b/murano/cmd/engine.py @@ -28,6 +28,7 @@ else: import sys +from oslo_concurrency import processutils from oslo_log import log as logging from oslo_service import service @@ -49,9 +50,11 @@ def main(): config.parse_args() logging.setup(CONF, 'murano') - launcher = service.ServiceLauncher(CONF) - launcher.launch_service(engine.EngineService()) - + workers = CONF.engine.workers + if not workers: + workers = processutils.get_worker_count() + launcher = service.launch(CONF, + engine.EngineService(), workers=workers) launcher.wait() except RuntimeError as e: sys.stderr.write("ERROR: %s\n" % e) diff --git a/murano/common/config.py b/murano/common/config.py index 2b71c07df..387c78f5a 100644 --- a/murano/common/config.py +++ b/murano/common/config.py @@ -205,6 +205,8 @@ engine_opts = [ cfg.IntOpt('agent_timeout', default=3600, help=_('Time for waiting for a response from murano agent ' 'during the deployment')), + cfg.IntOpt('workers', + help=_('Number of workers')) ] # TODO(sjmc7): move into engine opts? diff --git a/murano/tests/unit/cmd/__init__.py b/murano/tests/unit/cmd/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/murano/tests/unit/cmd/test_engine_workers.py b/murano/tests/unit/cmd/test_engine_workers.py new file mode 100644 index 000000000..3fb788971 --- /dev/null +++ b/murano/tests/unit/cmd/test_engine_workers.py @@ -0,0 +1,56 @@ +# Copyright (c) 2016 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. + +import mock + +from oslo_concurrency import processutils +from oslo_config import cfg +from oslo_log import log as logging + +from murano.cmd import engine +from murano.common import config +from murano.tests.unit import base + +CONF = cfg.CONF + + +class TestEngineWorkers(base.MuranoTestCase): + + def setUp(self): + super(TestEngineWorkers, self).setUp() + + @mock.patch.object(config, 'parse_args') + @mock.patch.object(logging, 'setup') + @mock.patch('oslo_service.service.launch') + def test_workers_default(self, launch, setup, parse_args): + engine.main() + launch.assert_called_once_with(mock.ANY, mock.ANY, + workers=processutils.get_worker_count()) + + @mock.patch.object(config, 'parse_args') + @mock.patch.object(logging, 'setup') + @mock.patch('oslo_service.service.launch') + def test_workers_good_setting(self, launch, setup, parse_args): + self.override_config("workers", 8, "engine") + engine.main() + launch.assert_called_once_with(mock.ANY, mock.ANY, workers=8) + + @mock.patch.object(config, 'parse_args') + @mock.patch.object(logging, 'setup') + @mock.patch('oslo_service.service.launch') + def test_workers_zero_setting(self, launch, setup, parse_args): + self.override_config("workers", 0, "engine") + engine.main() + launch.assert_called_once_with(mock.ANY, mock.ANY, + workers=processutils.get_worker_count()) diff --git a/releasenotes/notes/multiple-engine-workers-7fec79572a6a9d01.yaml b/releasenotes/notes/multiple-engine-workers-7fec79572a6a9d01.yaml new file mode 100644 index 000000000..4d391e9bb --- /dev/null +++ b/releasenotes/notes/multiple-engine-workers-7fec79572a6a9d01.yaml @@ -0,0 +1,6 @@ +--- +features: + - Add multiple engine workers +issues: + - Enabling multiple workers might break workflows under BSD and Windows systems +