diff --git a/devstack/plugin.sh b/devstack/plugin.sh index b8dbe737..f11b6242 100644 --- a/devstack/plugin.sh +++ b/devstack/plugin.sh @@ -158,7 +158,7 @@ function configure_masakari { fi if [ "$MASAKARI_USE_MOD_WSGI" == "True" ]; then - write_uwsgi_config "$MASAKARI_UWSGI_CONF" "$MASAKARI_UWSGI" "/instance-ha" + write_uwsgi_config "$MASAKARI_UWSGI_CONF" "$MASAKARI_UWSGI" "/instance-ha" "" "masakari-api" fi } diff --git a/devstack/settings b/devstack/settings index d8057cfd..b537e03c 100644 --- a/devstack/settings +++ b/devstack/settings @@ -45,7 +45,7 @@ MASAKARI_MANAGE=$MASAKARI_BIN_DIR/masakari-manage MASAKARI_SERVICE_PORT=${MASAKARI_SERVICE_PORT:-15868} MASAKARI_SERVICE_PORT_INT=${MASAKARI_SERVICE_PORT_INT:-25868} -MASAKARI_UWSGI=$MASAKARI_BIN_DIR/masakari-wsgi +MASAKARI_UWSGI=masakari.wsgi.api:application MASAKARI_UWSGI_CONF=$MASAKARI_CONF_DIR/masakari-api-uwsgi.ini enable_service masakari masakari-api masakari-engine diff --git a/masakari/api/auth.py b/masakari/api/auth.py index 1511c57f..b5021083 100644 --- a/masakari/api/auth.py +++ b/masakari/api/auth.py @@ -13,7 +13,6 @@ # under the License. """ Common Auth Middleware. - """ from oslo_log import log as logging @@ -22,10 +21,10 @@ from oslo_serialization import jsonutils import webob.dec import webob.exc +from masakari.api import wsgi import masakari.conf from masakari import context from masakari.i18n import _ -from masakari import wsgi CONF = masakari.conf.CONF diff --git a/masakari/api/openstack/__init__.py b/masakari/api/openstack/__init__.py index 1dd4dec6..a5aafbb2 100644 --- a/masakari/api/openstack/__init__.py +++ b/masakari/api/openstack/__init__.py @@ -23,10 +23,10 @@ import webob.dec import webob.exc from masakari.api.openstack import wsgi +from masakari.api import wsgi as base_wsgi import masakari.conf from masakari.i18n import translate from masakari import utils -from masakari import wsgi as base_wsgi LOG = logging.getLogger(__name__) @@ -153,7 +153,7 @@ class APIRouterV1(base_wsgi.Router): def factory(cls, global_config, **local_config): """Simple paste factory - :class:`masakari.wsgi.Router` doesn't have one. + :class:`masakari.api.wsgi.Router` doesn't have one. """ return cls() diff --git a/masakari/api/openstack/common.py b/masakari/api/openstack/common.py index 1927160a..7efb639c 100644 --- a/masakari/api/openstack/common.py +++ b/masakari/api/openstack/common.py @@ -228,7 +228,7 @@ def get_sort_params(input_params, default_key='created_at', The input parameters are not modified. :param input_params: webob.multidict of request parameters (from - masakari.wsgi.Request.params) + masakari.api.wsgi.Request.params) :param default_key: default sort key value, added to the list if no 'sort_key' parameters are supplied :param default_dir: default sort dir value, added to the list if no diff --git a/masakari/api/openstack/wsgi.py b/masakari/api/openstack/wsgi.py index 3b21609b..c05ed43b 100644 --- a/masakari/api/openstack/wsgi.py +++ b/masakari/api/openstack/wsgi.py @@ -25,10 +25,10 @@ import webob from masakari.api import api_version_request as api_version from masakari.api import versioned_method +from masakari.api import wsgi from masakari import exception from masakari import i18n from masakari.i18n import _ -from masakari import wsgi LOG = logging.getLogger(__name__) diff --git a/masakari/wsgi.py b/masakari/api/wsgi.py similarity index 100% rename from masakari/wsgi.py rename to masakari/api/wsgi.py diff --git a/masakari/service.py b/masakari/service.py index dcfe0bf7..97d0b825 100644 --- a/masakari/service.py +++ b/masakari/service.py @@ -25,6 +25,7 @@ import oslo_messaging as messaging from oslo_service import service from oslo_utils import importutils +from masakari.api import wsgi import masakari.conf from masakari import context from masakari import coordination as masakari_coordination @@ -34,7 +35,6 @@ from masakari.objects import base as objects_base from masakari import rpc from masakari import utils from masakari import version -from masakari import wsgi LOG = logging.getLogger(__name__) diff --git a/masakari/tests/unit/api/openstack/fakes.py b/masakari/tests/unit/api/openstack/fakes.py index 58c4c602..f03d153e 100644 --- a/masakari/tests/unit/api/openstack/fakes.py +++ b/masakari/tests/unit/api/openstack/fakes.py @@ -24,9 +24,9 @@ from masakari.api.openstack import ha from masakari.api.openstack.ha import versions from masakari.api.openstack import wsgi as os_wsgi from masakari.api import urlmap +from masakari.api import wsgi from masakari import context from masakari.tests import uuidsentinel -from masakari import wsgi @webob.dec.wsgify diff --git a/masakari/tests/unit/test_wsgi.py b/masakari/tests/unit/api/test_wsgi.py similarity index 86% rename from masakari/tests/unit/test_wsgi.py rename to masakari/tests/unit/api/test_wsgi.py index c2527cd2..4b462c85 100644 --- a/masakari/tests/unit/test_wsgi.py +++ b/masakari/tests/unit/api/test_wsgi.py @@ -14,7 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. -"""Unit tests for `masakari.wsgi`.""" +"""Unit tests for `masakari.api.wsgi`.""" import os.path import socket @@ -27,10 +27,10 @@ from oslo_config import cfg import requests import testtools +from masakari.api import wsgi import masakari.exception from masakari import test from masakari.tests.unit import utils -import masakari.wsgi SSL_CERT_DIR = os.path.normpath(os.path.join( os.path.dirname(os.path.abspath(__file__)), @@ -49,7 +49,7 @@ class TestLoaderNothingExists(test.NoDBTestCase): self.flags(api_paste_config='api-paste.ini', group='wsgi') self.assertRaises( masakari.exception.ConfigNotFound, - masakari.wsgi.Loader, + wsgi.Loader, ) def test_asbpath_config_not_found(self): @@ -57,7 +57,7 @@ class TestLoaderNothingExists(test.NoDBTestCase): group='wsgi') self.assertRaises( masakari.exception.ConfigNotFound, - masakari.wsgi.Loader, + wsgi.Loader, ) @@ -76,7 +76,7 @@ document_root = /tmp self.config.write(self._paste_config.lstrip()) self.config.seek(0) self.config.flush() - self.loader = masakari.wsgi.Loader(self.config.name) + self.loader = wsgi.Loader(self.config.name) def test_config_found(self): self.assertEqual(self.config.name, self.loader.config_path) @@ -101,18 +101,18 @@ class TestWSGIServer(test.NoDBTestCase): """WSGI server tests.""" def test_no_app(self): - server = masakari.wsgi.Server("test_app", None) + server = wsgi.Server("test_app", None) self.assertEqual("test_app", server.name) def test_custom_max_header_line(self): self.flags(max_header_line=4096, group='wsgi') # Default is 16384 - masakari.wsgi.Server("test_custom_max_header_line", None) + wsgi.Server("test_custom_max_header_line", None) self.assertEqual(CONF.wsgi.max_header_line, eventlet.wsgi.MAX_HEADER_LINE) def test_start_random_port(self): - server = masakari.wsgi.Server("test_random_port", None, - host="127.0.0.1", port=0) + server = wsgi.Server("test_random_port", None, host="127.0.0.1", + port=0) server.start() self.assertNotEqual(0, server.port) server.stop() @@ -120,8 +120,7 @@ class TestWSGIServer(test.NoDBTestCase): @testtools.skipIf(not utils.is_ipv6_supported(), "no ipv6 support") def test_start_random_port_with_ipv6(self): - server = masakari.wsgi.Server("test_random_port", None, - host="::1", port=0) + server = wsgi.Server("test_random_port", None, host="::1", port=0) server.start() self.assertEqual("::1", server.host) self.assertNotEqual(0, server.port) @@ -134,8 +133,8 @@ class TestWSGIServer(test.NoDBTestCase): def test_socket_options_for_simple_server(self): # test normal socket options has set properly self.flags(tcp_keepidle=500, group='wsgi') - server = masakari.wsgi.Server("test_socket_options", None, - host="127.0.0.1", port=0) + server = wsgi.Server( + "test_socket_options", None, host="127.0.0.1", port=0) server.start() sock = server._socket self.assertEqual(1, sock.getsockopt(socket.SOL_SOCKET, @@ -151,7 +150,7 @@ class TestWSGIServer(test.NoDBTestCase): def test_server_pool_waitall(self): # test pools waitall method gets called while stopping server - server = masakari.wsgi.Server("test_server", None, + server = wsgi.Server("test_server", None, host="127.0.0.1") server.start() with mock.patch.object(server._pool, @@ -161,7 +160,7 @@ class TestWSGIServer(test.NoDBTestCase): mock_waitall.assert_called_once_with() def test_uri_length_limit(self): - server = masakari.wsgi.Server("test_uri_length_limit", None, + server = wsgi.Server("test_uri_length_limit", None, host="127.0.0.1", max_url_len=16384) server.start() @@ -180,7 +179,7 @@ class TestWSGIServer(test.NoDBTestCase): server.wait() def test_reset_pool_size_to_default(self): - server = masakari.wsgi.Server("test_resize", None, + server = wsgi.Server("test_resize", None, host="127.0.0.1", max_url_len=16384) server.start() @@ -200,8 +199,7 @@ class TestWSGIServer(test.NoDBTestCase): # configured 'client_socket_timeout' value. with mock.patch.object(eventlet, 'spawn') as mock_spawn: - server = masakari.wsgi.Server("test_app", None, - host="127.0.0.1", port=0) + server = wsgi.Server("test_app", None, host="127.0.0.1", port=0) server.start() _, kwargs = mock_spawn.call_args self.assertEqual(CONF.wsgi.client_socket_timeout, @@ -215,8 +213,7 @@ class TestWSGIServer(test.NoDBTestCase): # configured 'keep_alive' value. with mock.patch.object(eventlet, 'spawn') as mock_spawn: - server = masakari.wsgi.Server("test_app", None, - host="127.0.0.1", port=0) + server = wsgi.Server("test_app", None, host="127.0.0.1", port=0) server.start() _, kwargs = mock_spawn.call_args self.assertEqual(CONF.wsgi.keep_alive, diff --git a/masakari/tests/unit/test_service.py b/masakari/tests/unit/test_service.py index e4c685bb..80581f99 100644 --- a/masakari/tests/unit/test_service.py +++ b/masakari/tests/unit/test_service.py @@ -116,7 +116,7 @@ class TestWSGIService(test.NoDBTestCase): def setUp(self): super(TestWSGIService, self).setUp() - self.stub_out('masakari.wsgi.Loader.load_app', mock.MagicMock()) + self.stub_out('masakari.api.wsgi.Loader.load_app', mock.MagicMock()) def test_workers_set_default(self): test_service = service.WSGIService("masakari_api") diff --git a/masakari/wsgi/__init__.py b/masakari/wsgi/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/masakari/wsgi/api.py b/masakari/wsgi/api.py new file mode 100644 index 00000000..5f9f8c3c --- /dev/null +++ b/masakari/wsgi/api.py @@ -0,0 +1,24 @@ +# 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. + +"""WSGI application entry-point for Masakari API.""" + +import threading + +from masakari.cmd import api + + +application = None +lock = threading.Lock() +with lock: + if application is None: + application = api.initialize_application() diff --git a/releasenotes/notes/add-masakari-wsgi-module-a5f5a649a2ec460c.yaml b/releasenotes/notes/add-masakari-wsgi-module-a5f5a649a2ec460c.yaml new file mode 100644 index 00000000..10e42062 --- /dev/null +++ b/releasenotes/notes/add-masakari-wsgi-module-a5f5a649a2ec460c.yaml @@ -0,0 +1,22 @@ +--- +features: + - | + A new module, ``masakari.wsgi``, has been added as a place to gather WSGI + ``application`` objects. This is intended to ease deployment by providing + a consistent location for these objects. For example, if using uWSGI then + instead of: + + .. code-block:: ini + + [uwsgi] + wsgi-file = /bin/masakari-wsgi + + You can now use: + + .. code-block:: ini + + [uwsgi] + module = masakari.wsgi.api:application + + This also simplifies deployment with other WSGI servers that expect module + paths such as gunicorn.