Fixes LP Bug#899383 - Cleanup config file search
Cleans up a bunch of configuration-related errors
when trying to run tempest out of the box with a
simple call to:
$> nosetests storm
* Raises a sensible error if the config file cannot be found
* Makes it possible to set the config file directory and
config file name via environment variables
* Removes unnecessary calls to create storm.config.StormConfig()
and share a configuration object by passing the openstack.Manager's
config object with the various rest client objects
* Updates the README to show how to make a config file and run
the tests in tempest
Change-Id: I60e33595b88df596cc9585bcaf18d37ae77d6f2b
diff --git a/storm/config.py b/storm/config.py
index 454f684..42b9894 100644
--- a/storm/config.py
+++ b/storm/config.py
@@ -1,4 +1,8 @@
import ConfigParser
+import logging
+import os
+
+LOG = logging.getLogger(__name__)
class NovaConfig(object):
@@ -119,15 +123,24 @@
class StormConfig(object):
"""Provides OpenStack configuration information."""
- _path = "etc/storm.conf"
+ def __init__(self, conf_dir, conf_file):
+ """
+ Initialize a configuration from a conf directory and conf file.
- def __init__(self, path=None):
- """Initialize a configuration from a path."""
- self._conf = self.load_config(self._path)
+ :param conf_dir: Directory to look for config files
+ :param conf_file: Name of config file to use
+ """
+ path = os.path.join(conf_dir, conf_file)
+
+ if not os.path.exists(path):
+ msg = "Config file %(path)s not found" % locals()
+ raise RuntimeError(msg)
+
+ self._conf = self.load_config(path)
self.nova = NovaConfig(self._conf)
self.env = EnvironmentConfig(self._conf)
- def load_config(self, path=None):
+ def load_config(self, path):
"""Read configuration from given path and return a config object."""
config = ConfigParser.SafeConfigParser()
config.read(path)