Merge "Add WSGI application entry point for tacker-api"
This commit is contained in:
commit
a1d73c9892
8 files changed
+182
-2
No files matched your search
+37
-1
@@ -57,6 +57,10 @@ TACKER_CONF_DIR=/etc/tacker
|
||||
TACKER_CONF=$TACKER_CONF_DIR/tacker.conf
|
||||
TACKER_DATA_DIR=${TACKER_DATA_DIR:=$DATA_DIR/tacker}
|
||||
|
||||
# Run the Tacker API under uWSGI.
|
||||
TACKER_USE_UWSGI=${TACKER_USE_UWSGI:-True}
|
||||
TACKER_UWSGI_CONF=$TACKER_CONF_DIR/tacker-api-uwsgi.ini
|
||||
|
||||
|
||||
# Default name for Tacker database
|
||||
TACKER_DB_NAME=${TACKER_DB_NAME:-tacker}
|
||||
@@ -163,6 +167,33 @@ function init_tacker {
|
||||
# install_tacker() - Collect source and prepare
|
||||
function install_tacker {
|
||||
setup_develop $TACKER_DIR
|
||||
if [[ "$TACKER_USE_UWSGI" == "True" ]]; then
|
||||
pip_install uwsgi
|
||||
fi
|
||||
}
|
||||
|
||||
# _write_tacker_uwsgi_conf() - Write a uWSGI configuration for the
|
||||
# Tacker API.
|
||||
function _write_tacker_uwsgi_conf {
|
||||
sudo rm -f $TACKER_UWSGI_CONF
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi http-socket $TACKER_HOST:$TACKER_PORT
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi module "tacker.api.wsgi.api:application"
|
||||
if [[ "$TACKER_BIN_DIR" != "/usr/bin" && "$TACKER_BIN_DIR" != "/usr/local/bin" ]]; then
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi virtualenv $(dirname $TACKER_BIN_DIR)
|
||||
fi
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi processes ${API_WORKERS:-2}
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi enable-threads true
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi threads 4
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi master true
|
||||
# Load the application in each worker instead of the master so
|
||||
# that oslo.messaging and logging are initialized per process.
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi lazy-apps true
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi die-on-term true
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi exit-on-reload false
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi buffer-size 65535
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi thunder-lock true
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi worker-reload-mercy ${WORKER_TIMEOUT:-90}
|
||||
iniset -sudo $TACKER_UWSGI_CONF uwsgi add-header "Connection: close"
|
||||
}
|
||||
|
||||
function start_tacker {
|
||||
@@ -173,7 +204,12 @@ function start_tacker {
|
||||
# Start the Tacker service
|
||||
sudo cp $TACKER_DIR/etc/systemd/system/tacker.service $SYSTEMD_DIR/devstack@tacker.service
|
||||
iniset -sudo $SYSTEMD_DIR/devstack@tacker.service "Service" "User" $STACK_USER
|
||||
iniset -sudo $SYSTEMD_DIR/devstack@tacker.service "Service" "ExecStart" "$TACKER_BIN_DIR/tacker-server $cfg_file_options"
|
||||
if [[ "$TACKER_USE_UWSGI" == "True" ]]; then
|
||||
_write_tacker_uwsgi_conf
|
||||
iniset -sudo $SYSTEMD_DIR/devstack@tacker.service "Service" "ExecStart" "$TACKER_BIN_DIR/uwsgi --procname-prefix tacker-api --ini $TACKER_UWSGI_CONF"
|
||||
else
|
||||
iniset -sudo $SYSTEMD_DIR/devstack@tacker.service "Service" "ExecStart" "$TACKER_BIN_DIR/tacker-server $cfg_file_options"
|
||||
fi
|
||||
sudo systemctl enable devstack@tacker.service
|
||||
sudo systemctl restart devstack@tacker.service
|
||||
# Start the Tacker conductor service
|
||||
|
||||
@@ -52,6 +52,10 @@ apidoc_excluded_paths = [
|
||||
# TODO(ueha): Excluding 'db/types.py' will be removed after the issue of
|
||||
# TypeDecorator is fixed.
|
||||
'db/types.py',
|
||||
# The WSGI application is initialized at module import time, so it
|
||||
# cannot be imported by autodoc.
|
||||
'api/wsgi/*',
|
||||
'api/wsgi',
|
||||
'hacking']
|
||||
apidoc_separate_modules = True
|
||||
|
||||
|
||||
@@ -40,6 +40,8 @@ console_scripts =
|
||||
tacker-server = tacker.cmd.eventlet.tacker_server:main
|
||||
tacker-conductor = tacker.cmd.conductor:main
|
||||
tacker-status = tacker.cmd.status:main
|
||||
wsgi_scripts =
|
||||
tacker-api-wsgi = tacker.api.wsgi_app:init_application
|
||||
tacker.service_plugins =
|
||||
dummy = tacker.tests.unit.dummy_plugin:DummyServicePlugin
|
||||
vnfm = tacker.vnfm.plugin:VNFMPlugin
|
||||
|
||||
@@ -757,7 +757,10 @@ class VnfPkgmController(wsgi.Controller):
|
||||
else:
|
||||
chunk_size = artifact_size
|
||||
|
||||
request.response.headers['Content-Length'] = chunk_size
|
||||
# NOTE: The header value must be a string (PEP 3333). The
|
||||
# eventlet wsgi server tolerates an integer but uWSGI drops
|
||||
# such a header.
|
||||
request.response.headers['Content-Length'] = str(chunk_size)
|
||||
return request.response
|
||||
else:
|
||||
msg = _("Not Found Artifact File.")
|
||||
|
||||
Whitespace-only changes.
@@ -0,0 +1,28 @@
|
||||
# Copyright (C) 2026 Nippon Telegraph and Telephone 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.
|
||||
|
||||
"""WSGI application for the Tacker API.
|
||||
|
||||
Use this module with a WSGI server such as uWSGI, e.g.:
|
||||
|
||||
uwsgi --module tacker.api.wsgi.api:application ...
|
||||
|
||||
The application is initialized at import time, so this module must not
|
||||
be imported except by a WSGI server.
|
||||
"""
|
||||
|
||||
from tacker.api import wsgi_app
|
||||
|
||||
application = wsgi_app.init_application()
|
||||
@@ -0,0 +1,54 @@
|
||||
# Copyright (C) 2026 Nippon Telegraph and Telephone 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.
|
||||
|
||||
"""WSGI application entry point for the Tacker API.
|
||||
|
||||
This module provides the WSGI application used to run the Tacker API
|
||||
under a WSGI server such as uWSGI or mod_wsgi, without the
|
||||
eventlet based standalone server. Use ``tacker.api.wsgi.api`` as the
|
||||
WSGI module, or the ``tacker-api-wsgi`` script generated from the
|
||||
``wsgi_scripts`` entry point for non-editable installations.
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
from tacker.common import config
|
||||
from tacker import objects
|
||||
from tacker.sol_refactored import objects as sol_objects
|
||||
|
||||
|
||||
CONFIG_FILES = ['api-paste.ini', 'tacker.conf']
|
||||
|
||||
|
||||
def _get_config_files(env=None):
|
||||
if env is None:
|
||||
env = os.environ
|
||||
dirname = env.get('OS_TACKER_CONFIG_DIR', '/etc/tacker').strip()
|
||||
return [os.path.join(dirname, config_file)
|
||||
for config_file in CONFIG_FILES
|
||||
if os.path.exists(os.path.join(dirname, config_file))]
|
||||
|
||||
|
||||
def init_application():
|
||||
conf_files = _get_config_files()
|
||||
config.init([], default_config_files=conf_files)
|
||||
config.setup_logging(cfg.CONF)
|
||||
|
||||
objects.register_all()
|
||||
sol_objects.register_all()
|
||||
|
||||
return config.load_paste_app('tacker')
|
||||
@@ -0,0 +1,53 @@
|
||||
# Copyright (C) 2026 Nippon Telegraph and Telephone 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 os
|
||||
import tempfile
|
||||
from unittest import mock
|
||||
|
||||
from tacker.api import wsgi_app
|
||||
from tacker.tests import base
|
||||
|
||||
|
||||
class TestWsgiApp(base.BaseTestCase):
|
||||
|
||||
def test_get_config_files_default_dir_missing(self):
|
||||
env = {'OS_TACKER_CONFIG_DIR': '/nonexistent-tacker-conf-dir'}
|
||||
self.assertEqual([], wsgi_app._get_config_files(env))
|
||||
|
||||
def test_get_config_files_from_env(self):
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
for name in wsgi_app.CONFIG_FILES:
|
||||
with open(os.path.join(tmpdir, name), 'w') as f:
|
||||
f.write('')
|
||||
env = {'OS_TACKER_CONFIG_DIR': tmpdir}
|
||||
self.assertEqual(
|
||||
[os.path.join(tmpdir, name)
|
||||
for name in wsgi_app.CONFIG_FILES],
|
||||
wsgi_app._get_config_files(env))
|
||||
|
||||
@mock.patch.object(wsgi_app.config, 'load_paste_app')
|
||||
@mock.patch.object(wsgi_app.sol_objects, 'register_all')
|
||||
@mock.patch.object(wsgi_app.objects, 'register_all')
|
||||
@mock.patch.object(wsgi_app.config, 'setup_logging')
|
||||
@mock.patch.object(wsgi_app.config, 'init')
|
||||
def test_init_application(self, mock_init, mock_logging,
|
||||
mock_register, mock_sol_register,
|
||||
mock_load_paste_app):
|
||||
wsgi_app.init_application()
|
||||
mock_init.assert_called_once()
|
||||
mock_register.assert_called_once_with()
|
||||
mock_sol_register.assert_called_once_with()
|
||||
mock_load_paste_app.assert_called_once_with('tacker')
|
||||
Reference in new issue
Block a user