summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-02-15 08:37:27 +0000
committerGerrit Code Review <review@openstack.org>2017-02-15 08:37:27 +0000
commit085058bfb20429e669c0e92b599a96d269032f1f (patch)
treece45def3dc9a8596857f744c8967e4dc8f419f2d
parent82b464bcd4e9f6b90bffb67a64b37970642592d5 (diff)
parentb462a3b8cd0ccbf374dd140315ec1c431a8546be (diff)
Merge "Support magnum-api multiple process workers"
-rw-r--r--magnum/cmd/api.py8
-rw-r--r--magnum/conf/api.py5
-rw-r--r--magnum/tests/unit/cmd/test_api.py25
3 files changed, 35 insertions, 3 deletions
diff --git a/magnum/cmd/api.py b/magnum/cmd/api.py
index 394f67a..eaad02f 100644
--- a/magnum/cmd/api.py
+++ b/magnum/cmd/api.py
@@ -17,6 +17,7 @@
17import os 17import os
18import sys 18import sys
19 19
20from oslo_concurrency import processutils
20from oslo_log import log as logging 21from oslo_log import log as logging
21from oslo_reports import guru_meditation_report as gmr 22from oslo_reports import guru_meditation_report as gmr
22from werkzeug import serving 23from werkzeug import serving
@@ -79,5 +80,10 @@ def main():
79 LOG.info(_LI('Serving on %(proto)s://%(host)s:%(port)s'), 80 LOG.info(_LI('Serving on %(proto)s://%(host)s:%(port)s'),
80 dict(proto="https" if use_ssl else "http", host=host, port=port)) 81 dict(proto="https" if use_ssl else "http", host=host, port=port))
81 82
82 serving.run_simple(host, port, app, 83 workers = CONF.api.workers
84 if not workers:
85 workers = processutils.get_worker_count()
86 LOG.info(_LI('Server will handle each request in a new process up to'
87 ' %s concurrent processes'), workers)
88 serving.run_simple(host, port, app, processes=workers,
83 ssl_context=_get_ssl_configs(use_ssl)) 89 ssl_context=_get_ssl_configs(use_ssl))
diff --git a/magnum/conf/api.py b/magnum/conf/api.py
index 11756c9..0df0da8 100644
--- a/magnum/conf/api.py
+++ b/magnum/conf/api.py
@@ -39,7 +39,10 @@ api_service_opts = [
39 "effect. "), 39 "effect. "),
40 cfg.BoolOpt('enabled_ssl', 40 cfg.BoolOpt('enabled_ssl',
41 default=False, 41 default=False,
42 help='Enable SSL Magnum API service') 42 help='Enable SSL Magnum API service'),
43 cfg.IntOpt('workers',
44 help='The maximum number of magnum-api processes to '
45 'fork and run. Default to number of CPUs on the host.')
43] 46]
44 47
45 48
diff --git a/magnum/tests/unit/cmd/test_api.py b/magnum/tests/unit/cmd/test_api.py
index e6ce096..ea55ead 100644
--- a/magnum/tests/unit/cmd/test_api.py
+++ b/magnum/tests/unit/cmd/test_api.py
@@ -14,6 +14,8 @@
14 14
15import mock 15import mock
16 16
17from oslo_concurrency import processutils
18
17from magnum.cmd import api 19from magnum.cmd import api
18from magnum.tests import base 20from magnum.tests import base
19 21
@@ -32,9 +34,28 @@ class TestMagnumAPI(base.TestCase):
32 app = mock_app.load_app.return_value 34 app = mock_app.load_app.return_value
33 mock_prep.assert_called_once_with(mock.ANY) 35 mock_prep.assert_called_once_with(mock.ANY)
34 mock_app.load_app.assert_called_once_with() 36 mock_app.load_app.assert_called_once_with()
37 workers = processutils.get_worker_count()
38 mock_run.assert_called_once_with(base.CONF.api.host,
39 base.CONF.api.port,
40 app, processes=workers,
41 ssl_context=None)
42
43 @mock.patch('werkzeug.serving.run_simple')
44 @mock.patch.object(api, 'api_app')
45 @mock.patch('magnum.common.service.prepare_service')
46 def test_api_http_config_workers(self, mock_prep, mock_app,
47 mock_run, mock_base):
48 fake_workers = 8
49 self.config(workers=fake_workers, group='api')
50 api.main()
51
52 app = mock_app.load_app.return_value
53 mock_prep.assert_called_once_with(mock.ANY)
54 mock_app.load_app.assert_called_once_with()
35 mock_run.assert_called_once_with(base.CONF.api.host, 55 mock_run.assert_called_once_with(base.CONF.api.host,
36 base.CONF.api.port, 56 base.CONF.api.port,
37 app, ssl_context=None) 57 app, processes=fake_workers,
58 ssl_context=None)
38 59
39 @mock.patch('os.path.exists') 60 @mock.patch('os.path.exists')
40 @mock.patch('werkzeug.serving.run_simple') 61 @mock.patch('werkzeug.serving.run_simple')
@@ -91,6 +112,8 @@ class TestMagnumAPI(base.TestCase):
91 mock_app.load_app.assert_called_once_with() 112 mock_app.load_app.assert_called_once_with()
92 mock_exist.assert_has_calls([mock.call('tmp_crt'), 113 mock_exist.assert_has_calls([mock.call('tmp_crt'),
93 mock.call('tmp_key')]) 114 mock.call('tmp_key')])
115 workers = processutils.get_worker_count()
94 mock_run.assert_called_once_with(base.CONF.api.host, 116 mock_run.assert_called_once_with(base.CONF.api.host,
95 base.CONF.api.port, app, 117 base.CONF.api.port, app,
118 processes=workers,
96 ssl_context=('tmp_crt', 'tmp_key')) 119 ssl_context=('tmp_crt', 'tmp_key'))