summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Shrewsbury <shrewsbury.dave@gmail.com>2015-07-14 10:54:21 -0400
committerDavid Shrewsbury <shrewsbury.dave@gmail.com>2015-07-14 10:54:21 -0400
commitb74df460a821d522d78ee76ba699bc4265efa2bc (patch)
tree752246f8d8bbad1209a6529af1547a4eee5625d8
parent27dff22c6bd59d42b7a747fe388cd26ad1a57ada (diff)
downloados-client-config-b74df460a821d522d78ee76ba699bc4265efa2bc.tar.gz
Fix set_default() when used before config init
Using set_default() before initializing OpenStackConfig would cause an error since the _defaults dict would still be None and not an actual dict. This corrects that by calling get_defaults() to make sure it is initialized properly, and also adds a warning to note that the method is now deprecated. Change-Id: I81803c680b614f9bee47c6f69a4efffa638dcebc
-rw-r--r--os_client_config/config.py5
-rw-r--r--os_client_config/tests/test_config.py19
2 files changed, 23 insertions, 1 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index 203772e..89503e7 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -64,6 +64,11 @@ BOOL_KEYS = ('insecure', 'cache')
# Remove this sometime in June 2015 once OSC is comfortably
# changed-over and global-defaults is updated.
def set_default(key, value):
+ warnings.warn(
+ "Use of set_default() is deprecated. Defaults should be set with the "
+ "`override_defaults` parameter of OpenStackConfig."
+ )
+ defaults.get_defaults() # make sure the dict is initialized
defaults._defaults[key] = value
diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py
index dde7d83..1444ed5 100644
--- a/os_client_config/tests/test_config.py
+++ b/os_client_config/tests/test_config.py
@@ -252,9 +252,26 @@ class TestConfigArgparse(base.TestCase):
class TestConfigDefault(base.TestCase):
+ def setUp(self):
+ super(TestConfigDefault, self).setUp()
+
+ # Reset defaults after each test so that other tests are
+ # not affected by any changes.
+ self.addCleanup(self._reset_defaults)
+
+ def _reset_defaults(self):
+ defaults._defaults = None
+
def test_set_no_default(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
cc = c.get_one_cloud(cloud='_test-cloud_', argparse=None)
self._assert_cloud_details(cc)
- self.assertEqual(cc.auth_type, 'password')
+ self.assertEqual('password', cc.auth_type)
+
+ def test_set_default_before_init(self):
+ config.set_default('auth_type', 'token')
+ c = config.OpenStackConfig(config_files=[self.cloud_yaml],
+ vendor_files=[self.vendor_yaml])
+ cc = c.get_one_cloud(cloud='_test-cloud_', argparse=None)
+ self.assertEqual('token', cc.auth_type)