Raise ConfigFilesNotFoundError if CONF.api_paste_config not found

Otherwise it shows an incomprehensible message
"'NoneType' object has no attribute 'startswith'."

Change-Id: I5d87c4ceac69b26730d63727a2ec3701ccc9cecb
Closes-bug: 1236182
This commit is contained in:
Arata Notsu 2013-10-07 15:51:18 +09:00
parent d11b225b32
commit b00dc64565
2 changed files with 16 additions and 4 deletions

View File

@ -132,12 +132,15 @@ def load_paste_app(app_name):
"""Builds and returns a WSGI app from a paste config file. """Builds and returns a WSGI app from a paste config file.
:param app_name: Name of the application to load :param app_name: Name of the application to load
:raises RuntimeError when config file cannot be located or application :raises ConfigFilesNotFoundError when config file cannot be located
cannot be loaded from config file :raises RuntimeError when application cannot be loaded from config file
""" """
config_path = os.path.abspath(cfg.CONF.find_file( config_path = cfg.CONF.find_file(cfg.CONF.api_paste_config)
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) LOG.info(_("Config paste file: %s"), config_path)
try: try:

View File

@ -15,6 +15,7 @@
import os import os
import mock
from oslo.config import cfg from oslo.config import cfg
from neutron.common import config # noqa from neutron.common import config # noqa
@ -44,3 +45,11 @@ class ConfigurationTest(base.BaseTestCase):
self.assertEqual(86400, cfg.CONF.dhcp_lease_duration) self.assertEqual(86400, cfg.CONF.dhcp_lease_duration)
self.assertFalse(cfg.CONF.allow_overlapping_ips) self.assertFalse(cfg.CONF.allow_overlapping_ips)
self.assertEqual('neutron', cfg.CONF.control_exchange) 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)