summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2011-12-10 14:01:17 -0800
committerVishvananda Ishaya <vishvananda@gmail.com>2011-12-10 14:01:17 -0800
commitce2d62f95cd9b62858c9b4ef37b418881ceaef07 (patch)
tree98a6f9f15eb729e2e3248fb05a8dcf09637e24d3
parent0c6c7700299e225aee2c86fbe725c8e146b9f0d4 (diff)
downloadnova-ce2d62f95cd9b62858c9b4ef37b418881ceaef07.tar.gz
nova-ce2d62f95cd9b62858c9b4ef37b418881ceaef07.tar.xz
nova-ce2d62f95cd9b62858c9b4ef37b418881ceaef07.zip
Moves find config to utils because it is useful
This is to prepare for a future patch will will use find config to load other config files. Change-Id: Ic9bd9027baf518734c3f51f516651b80d1e752f2
-rw-r--r--nova/exception.py4
-rw-r--r--nova/tests/test_wsgi.py2
-rw-r--r--nova/utils.py23
-rw-r--r--nova/wsgi.py24
4 files changed, 27 insertions, 26 deletions
diff --git a/nova/exception.py b/nova/exception.py
index 565e55387..9d9ce16f5 100644
--- a/nova/exception.py
+++ b/nova/exception.py
@@ -810,8 +810,8 @@ class MalformedRequestBody(NovaException):
message = _("Malformed message body: %(reason)s")
-class PasteConfigNotFound(NotFound):
- message = _("Could not find paste config at %(path)s")
+class ConfigNotFound(NotFound):
+ message = _("Could not find config at %(path)s")
class PasteAppNotFound(NotFound):
diff --git a/nova/tests/test_wsgi.py b/nova/tests/test_wsgi.py
index b71e8d418..26af63789 100644
--- a/nova/tests/test_wsgi.py
+++ b/nova/tests/test_wsgi.py
@@ -37,7 +37,7 @@ class TestLoaderNothingExists(unittest.TestCase):
def test_config_not_found(self):
self.assertRaises(
- nova.exception.PasteConfigNotFound,
+ nova.exception.ConfigNotFound,
nova.wsgi.Loader,
)
diff --git a/nova/utils.py b/nova/utils.py
index e79d57622..adf45debd 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -77,6 +77,29 @@ def import_object(import_str):
return cls()
+def find_config(config_path):
+ """Find a configuration file using the given hint.
+
+ :param config_path: Full or relative path to the config.
+ :returns: Full path of the config, if it exists.
+ :raises: `nova.exception.ConfigNotFound`
+
+ """
+ possible_locations = [
+ config_path,
+ os.path.join(FLAGS.state_path, "etc", "nova", config_path),
+ os.path.join(FLAGS.state_path, "etc", config_path),
+ os.path.join(FLAGS.state_path, config_path),
+ "/etc/nova/%s" % config_path,
+ ]
+
+ for path in possible_locations:
+ if os.path.exists(path):
+ return os.path.abspath(path)
+
+ raise exception.ConfigNotFound(path=os.path.abspath(config_path))
+
+
def vpn_ping(address, port, timeout=0.05, session_id=None):
"""Sends a vpn negotiation packet and returns the server session.
diff --git a/nova/wsgi.py b/nova/wsgi.py
index 09b45be5a..5ca0edd45 100644
--- a/nova/wsgi.py
+++ b/nova/wsgi.py
@@ -375,29 +375,7 @@ class Loader(object):
"""
config_path = config_path or FLAGS.api_paste_config
- self.config_path = self._find_config(config_path)
-
- def _find_config(self, config_path):
- """Find the paste configuration file using the given hint.
-
- :param config_path: Full or relative path to the paste config.
- :returns: Full path of the paste config, if it exists.
- :raises: `nova.exception.PasteConfigNotFound`
-
- """
- possible_locations = [
- config_path,
- os.path.join(FLAGS.state_path, "etc", "nova", config_path),
- os.path.join(FLAGS.state_path, "etc", config_path),
- os.path.join(FLAGS.state_path, config_path),
- "/etc/nova/%s" % config_path,
- ]
-
- for path in possible_locations:
- if os.path.exists(path):
- return os.path.abspath(path)
-
- raise exception.PasteConfigNotFound(path=os.path.abspath(config_path))
+ self.config_path = utils.find_config(config_path)
def load_app(self, name):
"""Return the paste URLMap wrapped WSGI application.