Merge "Treat clouds.yaml with one cloud like envvars"
This commit is contained in:
commit
eab9a3ed7b
@ -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
|
||||
|
@ -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'})
|
||||
|
7
releasenotes/notes/default-cloud-7ee0bcb9e5dd24b9.yaml
Normal file
7
releasenotes/notes/default-cloud-7ee0bcb9e5dd24b9.yaml
Normal file
@ -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.
|
Loading…
Reference in New Issue
Block a user