diff --git a/neutron/common/config.py b/neutron/common/config.py index 4f0eb47bf0..fc7058a10d 100644 --- a/neutron/common/config.py +++ b/neutron/common/config.py @@ -132,12 +132,15 @@ def load_paste_app(app_name): """Builds and returns a WSGI app from a paste config file. :param app_name: Name of the application to load - :raises RuntimeError when config file cannot be located or application - cannot be loaded from config file + :raises ConfigFilesNotFoundError when config file cannot be located + :raises RuntimeError when application cannot be loaded from config file """ - config_path = os.path.abspath(cfg.CONF.find_file( - cfg.CONF.api_paste_config)) + config_path = cfg.CONF.find_file(cfg.CONF.api_paste_config) + if not config_path: + raise cfg.ConfigFilesNotFoundError( + config_files=[cfg.CONF.api_paste_config]) + config_path = os.path.abspath(config_path) LOG.info(_("Config paste file: %s"), config_path) try: diff --git a/neutron/tests/unit/test_config.py b/neutron/tests/unit/test_config.py index cb773ed64d..1b1e9929a8 100644 --- a/neutron/tests/unit/test_config.py +++ b/neutron/tests/unit/test_config.py @@ -15,6 +15,7 @@ import os +import mock from oslo.config import cfg from neutron.common import config # noqa @@ -44,3 +45,11 @@ class ConfigurationTest(base.BaseTestCase): self.assertEqual(86400, cfg.CONF.dhcp_lease_duration) self.assertFalse(cfg.CONF.allow_overlapping_ips) self.assertEqual('neutron', cfg.CONF.control_exchange) + + def test_load_paste_app_not_found(self): + self.config(api_paste_config='no_such_file.conf') + with mock.patch.object(cfg.CONF, 'find_file', return_value=None) as ff: + e = self.assertRaises(cfg.ConfigFilesNotFoundError, + config.load_paste_app, 'app') + ff.assert_called_once_with('no_such_file.conf') + self.assertEqual(['no_such_file.conf'], e.config_files)