Load api-paste.ini from configuration directories first
The api-paste.ini file defines WSGI definition of API. This file is regarded as one configuration file and sometimes users need to modify the file, for example to enable an additional middleware. However currently aodh-api by default expects the file is located in the aodh source directory and users should set the [api] paste_config parameter in addition to copy and modify the file. This change makes the aodh-api process search the api-paste.ini file from configuration directories automatically, so that users can more easily customize the file by putting the modified file in /etc/aodh (or any other config directories). If the paste_config parameter is defined as a full path then aodh-api directly loads the file from the specified path. If the file is not found then the default file in the aodh source directory is used. Change-Id: I4a6194fbf6a5317a523d75e3fb6bd2fd055f5100
This commit is contained in:
parent
6bbf61a67b
commit
8ac7c65cff
@ -12,16 +12,12 @@
|
||||
# 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
|
||||
|
||||
from oslo_config import cfg
|
||||
|
||||
# Register options for the service
|
||||
OPTS = [
|
||||
cfg.StrOpt('paste_config',
|
||||
default=os.path.abspath(
|
||||
os.path.join(
|
||||
os.path.dirname(__file__), "api-paste.ini")),
|
||||
default='api-paste.ini',
|
||||
help="Configuration file for WSGI definition of API."),
|
||||
cfg.StrOpt(
|
||||
'auth_mode',
|
||||
|
@ -17,7 +17,6 @@
|
||||
import os
|
||||
import uuid
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_log import log
|
||||
from paste import deploy
|
||||
import pecan
|
||||
@ -62,7 +61,10 @@ def load_app(conf):
|
||||
cfg_path = conf.find_file(cfg_path)
|
||||
|
||||
if cfg_path is None or not os.path.exists(cfg_path):
|
||||
raise cfg.ConfigFilesNotFoundError([conf.api.paste_config])
|
||||
LOG.debug("No api-paste configuration file found! Using default.")
|
||||
cfg_path = os.path.abspath(
|
||||
os.path.join(
|
||||
os.path.dirname(__file__), "api-paste.ini"))
|
||||
|
||||
config = dict(conf=conf)
|
||||
configkey = str(uuid.uuid4())
|
||||
|
@ -1,38 +0,0 @@
|
||||
# Copyright 2014 IBM Corp. All Rights Reserved.
|
||||
# Copyright 2015 Red Hat, Inc.
|
||||
#
|
||||
# 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.
|
||||
|
||||
from unittest import mock
|
||||
|
||||
from oslo_config import cfg
|
||||
from oslo_config import fixture as fixture_config
|
||||
|
||||
from aodh.api import app
|
||||
from aodh import service
|
||||
from aodh.tests import base
|
||||
|
||||
|
||||
class TestApp(base.BaseTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestApp, self).setUp()
|
||||
conf = service.prepare_service(argv=[], config_files=[])
|
||||
self.CONF = self.useFixture(fixture_config.Config(conf)).conf
|
||||
|
||||
def test_api_paste_file_not_exist(self):
|
||||
self.CONF.set_override('paste_config', 'non-existent-file', "api")
|
||||
with mock.patch.object(self.CONF, 'find_file') as ff:
|
||||
ff.return_value = None
|
||||
self.assertRaises(cfg.ConfigFilesNotFoundError,
|
||||
app.load_app, self.CONF)
|
@ -0,0 +1,8 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Now the ``aodh-api`` service look for the paste config file (a.k.a.
|
||||
``api-paste.ini`` from configruation directories like ``/etc/aodh``.
|
||||
If the file is not found in the configuration directories, it uses
|
||||
the default file. To use only a specific file, use a full file path for
|
||||
the ``[api] paste_confing`` parameter
|
Loading…
Reference in New Issue
Block a user