From 01444842da54e91a02f9819e4c5fe24df185044d Mon Sep 17 00:00:00 2001 From: ZhiQiang Fan Date: Thu, 12 Jun 2014 16:10:55 +0800 Subject: [PATCH] Improve api_paste_config file searching Currently, if the file defined by api_paste_config is not found under working directory, it will use etc/ceilometer/api_paste.ini instead, this is because at that time, devstack doesn't support the new config file. After patch I57165d588da35f13b2d22629b48dc087502598a7 is merged, this workaround is no longer needed, and we should use advanced find_file() provided by oslo.config to search config file. Meanwhile, if the file is found under working directory, we should use absolute/relative path instead of bare base name, otherwise, the deploy.loadapp will not work. Change-Id: I9bcb7b69a0159d548401de1c36f773a1965722b6 Closes-Bug: #1329126 --- ceilometer/api/app.py | 26 +++++++++----------------- ceilometer/tests/api/test_app.py | 7 +++++++ 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/ceilometer/api/app.py b/ceilometer/api/app.py index f354ae123..9067eaf15 100644 --- a/ceilometer/api/app.py +++ b/ceilometer/api/app.py @@ -129,23 +129,15 @@ def get_handler_cls(): def load_app(): # Build the WSGI app - cfg_file = cfg.CONF.api_paste_config - LOG.info("WSGI config requested: %s" % cfg_file) - if not os.path.exists(cfg_file): - # this code is to work around chicken-egg dependency between - # ceilometer gate jobs use of devstack and this change. - # The gate job uses devstack to run tempest. - # devstack does not copy api_paste.ini into /etc/ceilometer because it - # is introduced in this change. Once this is merged, we will change - # devstack to copy api_paste.ini and once that is merged will remove - # this code. - root = os.path.abspath(os.path.join(os.path.dirname(__file__), - '..', '..', 'etc', 'ceilometer' - ) - ) - cfg_file = os.path.join(root, cfg_file) - if not os.path.exists(cfg_file): - raise Exception('api_paste_config file not found') + cfg_file = None + cfg_path = cfg.CONF.api_paste_config + if not os.path.isabs(cfg_path): + cfg_file = CONF.find_file(cfg_path) + elif os.path.exists(cfg_path): + cfg_file = cfg_path + + if not cfg_file: + raise cfg.ConfigFilesNotFoundError([cfg.CONF.api_paste_config]) LOG.info("Full WSGI config used: %s" % cfg_file) return deploy.loadapp("config:" + cfg_file) diff --git a/ceilometer/tests/api/test_app.py b/ceilometer/tests/api/test_app.py index b7d9b5eb1..9fb2a1867 100644 --- a/ceilometer/tests/api/test_app.py +++ b/ceilometer/tests/api/test_app.py @@ -17,6 +17,7 @@ import socket +import mock from oslo.config import cfg from ceilometer.api import app @@ -42,3 +43,9 @@ class TestApp(base.BaseTestCase): self.CONF.set_override('host', 'ddddd', group='api') server_cls = app.get_server_cls(cfg.CONF.api.host) self.assertEqual(server_cls.address_family, socket.AF_INET) + + def test_api_paste_file_not_exist(self): + self.CONF.set_override('api_paste_config', 'non-existent-file') + with mock.patch.object(self.CONF, 'find_file') as ff: + ff.return_value = None + self.assertRaises(cfg.ConfigFilesNotFoundError, app.load_app)