summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-07-11 12:30:01 +0000
committerGerrit Code Review <review@openstack.org>2015-07-11 12:30:01 +0000
commit27dff22c6bd59d42b7a747fe388cd26ad1a57ada (patch)
tree8af7db418875c17443ace9ee3169a981fe13bb9a
parent33144d7c294438f2fce3b9c6c85a546f6eb2679d (diff)
parent6523cf62fa369fe1909a951ac7bce465aa222c06 (diff)
downloados-client-config-27dff22c6bd59d42b7a747fe388cd26ad1a57ada.tar.gz
Merge "Specify the config file with environment variable"
-rw-r--r--README.rst4
-rw-r--r--os_client_config/config.py4
-rw-r--r--os_client_config/tests/test_environ.py9
3 files changed, 17 insertions, 0 deletions
diff --git a/README.rst b/README.rst
index 5ce9399..4cae735 100644
--- a/README.rst
+++ b/README.rst
@@ -43,6 +43,10 @@ locations:
The first file found wins.
+You can also set the environment variable `OS_CLIENT_CONFIG_FILE` to an
+absolute path of a file to look for and that location will be inserted at the
+front of the file search list.
+
The keys are all of the keys you'd expect from `OS_*` - except lower case
and without the OS prefix. So, region name is set with `region_name`.
diff --git a/os_client_config/config.py b/os_client_config/config.py
index 93d7aa0..203772e 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -106,6 +106,10 @@ class OpenStackConfig(object):
self._config_files = config_files or CONFIG_FILES
self._vendor_files = vendor_files or VENDOR_FILES
+ config_file_override = os.environ.pop('OS_CLIENT_CONFIG_FILE', None)
+ if config_file_override:
+ self._config_files.insert(0, config_file_override)
+
self.defaults = defaults.get_defaults()
if override_defaults:
self.defaults.update(override_defaults)
diff --git a/os_client_config/tests/test_environ.py b/os_client_config/tests/test_environ.py
index ff44afc..7f284c5 100644
--- a/os_client_config/tests/test_environ.py
+++ b/os_client_config/tests/test_environ.py
@@ -84,3 +84,12 @@ class TestEnviron(base.TestCase):
self._assert_cloud_details(cc)
cc = c.get_one_cloud('_test_cloud_no_vendor')
self._assert_cloud_details(cc)
+
+ def test_config_file_override(self):
+ self.useFixture(
+ fixtures.EnvironmentVariable(
+ 'OS_CLIENT_CONFIG_FILE', self.cloud_yaml))
+ c = config.OpenStackConfig(config_files=[],
+ vendor_files=[self.vendor_yaml])
+ cc = c.get_one_cloud('_test-cloud_')
+ self._assert_cloud_details(cc)