From 471fd8dd85b7db8799bb7913ac087bb1d554d66b Mon Sep 17 00:00:00 2001 From: "zhiguo.li" Date: Tue, 22 Aug 2017 10:07:05 +0800 Subject: [PATCH] Optimize the way to serach file 'glance-api-paste.ini' With the original method _get_deployment_config_file() in config.py, if the option config_file is specified in glance-api.conf, and run command 'glance-api' under a directory, the the method load_paste_app() will throw an IOError, but the IOError dose not been catched. The same error will happen with'glance-registery'. The reason for this IOError is the code "os.path.abspath(path)" in _get_deployment_config_file() will return a value '{cur_dir}/glance-api-paste.ini', but the 'glance-api-paste.ini' does not exist under {cur_dir}.Such as running the command under /opt, but the 'glance-api-paste.ini' dose not exist under /opt. This pacth modifies one line of code in method _get_paste_config_path() for solving the IOError. At the same time, it provides one test case. Change-Id: I970c1acb073700b15e153dd08c9ec14d20f0e83d Closes-Bug: 1712226 --- glance/common/config.py | 2 +- glance/tests/unit/common/test_config.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/glance/common/config.py b/glance/common/config.py index 5e4eb3cefd..5d32ec074a 100644 --- a/glance/common/config.py +++ b/glance/common/config.py @@ -766,7 +766,7 @@ def _get_deployment_config_file(): path = CONF.paste_deploy.config_file if not path: path = _get_paste_config_path() - if not path: + if not path or not (os.path.isfile(os.path.abspath(path))): msg = _("Unable to locate paste config file for %s.") % CONF.prog raise RuntimeError(msg) return os.path.abspath(path) diff --git a/glance/tests/unit/common/test_config.py b/glance/tests/unit/common/test_config.py index 0888b0507f..d91c55f0a7 100644 --- a/glance/tests/unit/common/test_config.py +++ b/glance/tests/unit/common/test_config.py @@ -95,6 +95,13 @@ class TestPasteApp(test_utils.BaseTestCase): self._do_test_load_paste_app(expected_middleware, paste_config_file=paste_config_file) + def test_load_paste_app_with_paste_config_file_but_not_exist(self): + paste_config_file = os.path.abspath("glance-registry-paste.ini") + expected_middleware = oslo_middleware.Healthcheck + self.assertRaises(RuntimeError, self._do_test_load_paste_app, + expected_middleware, + paste_config_file=paste_config_file) + def test_get_path_non_exist(self): self.assertRaises(RuntimeError, config._get_deployment_config_file)