diff --git a/aodh/api/__init__.py b/aodh/api/__init__.py index f2a76d59c..712d657cc 100644 --- a/aodh/api/__init__.py +++ b/aodh/api/__init__.py @@ -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', diff --git a/aodh/api/app.py b/aodh/api/app.py index b7c090014..8588e32de 100644 --- a/aodh/api/app.py +++ b/aodh/api/app.py @@ -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()) diff --git a/aodh/tests/functional/api/test_app.py b/aodh/tests/functional/api/test_app.py deleted file mode 100644 index 04ce0b776..000000000 --- a/aodh/tests/functional/api/test_app.py +++ /dev/null @@ -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) diff --git a/releasenotes/notes/load-api-paste-ini-from-config-dirs-69480861a9633df4.yaml b/releasenotes/notes/load-api-paste-ini-from-config-dirs-69480861a9633df4.yaml new file mode 100644 index 000000000..f64223f02 --- /dev/null +++ b/releasenotes/notes/load-api-paste-ini-from-config-dirs-69480861a9633df4.yaml @@ -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