"""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:
import os
+import mock
from oslo.config import cfg
from neutron.common import config # noqa
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)