summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2017-10-18 19:10:59 +0000
committerGerrit Code Review <review@openstack.org>2017-10-18 19:10:59 +0000
commiteab9a3ed7baa23326c7adf0df8d2555bca829243 (patch)
tree115443d919ba106e34b36480cf6bc255c87073e8
parent2ed3b34a789feda83c453a17e865f105400170fc (diff)
parent45fd7b4a949e6cd8482b3025b96251c5832ddf23 (diff)
downloados-client-config-eab9a3ed7baa23326c7adf0df8d2555bca829243.tar.gz
Merge "Treat clouds.yaml with one cloud like envvars"
-rw-r--r--os_client_config/config.py11
-rw-r--r--os_client_config/tests/test_config.py19
-rw-r--r--releasenotes/notes/default-cloud-7ee0bcb9e5dd24b9.yaml7
3 files changed, 37 insertions, 0 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index aac41a4..87b8d65 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -263,6 +263,17 @@ class OpenStackConfig(object):
if not self.default_cloud:
self.default_cloud = self.envvar_key
+ if not self.default_cloud and self.cloud_config['clouds']:
+ if len(self.cloud_config['clouds'].keys()) == 1:
+ # If there is only one cloud just use it. This matches envvars
+ # behavior and allows for much less typing.
+ # TODO(mordred) allow someone to mark a cloud as "default" in
+ # clouds.yaml.
+ # The next/iter thing is for python3 compat where dict.keys
+ # returns an iterator but in python2 it's a list.
+ self.default_cloud = next(iter(
+ self.cloud_config['clouds'].keys()))
+
# Finally, fall through and make a cloud that starts with defaults
# because we need somewhere to put arguments, and there are neither
# config files or env vars
diff --git a/os_client_config/tests/test_config.py b/os_client_config/tests/test_config.py
index 09a11d2..4f2bf96 100644
--- a/os_client_config/tests/test_config.py
+++ b/os_client_config/tests/test_config.py
@@ -55,6 +55,25 @@ class TestConfig(base.TestCase):
self.assertIsInstance(cloud, cloud_config.CloudConfig)
self.assertEqual(cloud.name, '')
+ def test_get_one_cloud_default_cloud_from_file(self):
+ single_conf = base._write_yaml({
+ 'clouds': {
+ 'single': {
+ 'auth': {
+ 'auth_url': 'http://example.com/v2',
+ 'username': 'testuser',
+ 'password': 'testpass',
+ 'project_name': 'testproject',
+ },
+ 'region_name': 'test-region',
+ }
+ }
+ })
+ c = config.OpenStackConfig(config_files=[single_conf],
+ vendor_files=[self.vendor_yaml])
+ cc = c.get_one_cloud()
+ self.assertEqual(cc.name, 'single')
+
def test_get_one_cloud_auth_defaults(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml])
cc = c.get_one_cloud(cloud='_test-cloud_', auth={'username': 'user'})
diff --git a/releasenotes/notes/default-cloud-7ee0bcb9e5dd24b9.yaml b/releasenotes/notes/default-cloud-7ee0bcb9e5dd24b9.yaml
new file mode 100644
index 0000000..49aba3c
--- /dev/null
+++ b/releasenotes/notes/default-cloud-7ee0bcb9e5dd24b9.yaml
@@ -0,0 +1,7 @@
+---
+issues:
+ - If there was only one cloud defined in clouds.yaml
+ os-client-config was requiring the cloud parameter
+ be passed. This is inconsistent with how the envvars
+ cloud works which WILL work without setting the cloud
+ parameter if it's the only cloud.