]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Raise ConfigFilesNotFoundError if CONF.api_paste_config not found
authorArata Notsu <notsu@virtualtech.jp>
Mon, 7 Oct 2013 06:51:18 +0000 (15:51 +0900)
committerArata Notsu <notsu@virtualtech.jp>
Tue, 8 Oct 2013 08:39:34 +0000 (17:39 +0900)
Otherwise it shows an incomprehensible message
"'NoneType' object has no attribute 'startswith'."

Change-Id: I5d87c4ceac69b26730d63727a2ec3701ccc9cecb
Closes-bug: 1236182

neutron/common/config.py
neutron/tests/unit/test_config.py

index 4f0eb47bf0b8d1b53cadb9ee219a555313c90d60..fc7058a10d7e658bef7595f63f5638b9966e1a4c 100644 (file)
@@ -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:
index cb773ed64dcef0c660f5d1ae69d9e3fc9c73bde7..1b1e9929a849fb12564e249c29f832d09dbd86d0 100644 (file)
@@ -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)