Merge "Add support for configuring region lists with yaml"

This commit is contained in:
Jenkins 2015-07-11 12:19:51 +00:00 committed by Gerrit Code Review
commit 33144d7c29
8 changed files with 73 additions and 14 deletions

View File

@ -105,7 +105,10 @@ An example config file is probably helpful:
username: openstackci
password: XXXXXXXX
project_id: 610275
region_name: DFW,ORD,IAD
regions:
- DFW
- ORD
- IAD
You may note a few things. First, since `auth_url` settings are silly
and embarrasingly ugly, known cloud vendor profile information is included and
@ -116,7 +119,7 @@ knows that so that you don't have to. In case the cloud vendor profile is not
available, you can provide one called `clouds-public.yaml`, following the same
location rules previously mentioned for the config files.
Also, `region_name` can be a list of regions. When you call `get_all_clouds`,
`regions` can be a list of regions. When you call `get_all_clouds`,
you'll get a cloud config object for each cloud/region combo.
As seen with `dns_service_type`, any setting that makes sense to be per-service,

View File

@ -199,14 +199,24 @@ class OpenStackConfig(object):
return self._cache_arguments
def _get_regions(self, cloud):
try:
return self.cloud_config['clouds'][cloud]['region_name']
except KeyError:
# No region configured
return ''
if cloud not in self.cloud_config['clouds']:
return ['']
config = self._normalize_keys(self.cloud_config['clouds'][cloud])
if 'regions' in config:
return config['regions']
elif 'region_name' in config:
regions = config['region_name'].split(',')
if len(regions) > 1:
warnings.warn(
"Comma separated lists in region_name are deprecated."
" Please use a yaml list in the regions"
" parameter in {0} instead.".format(self.config_filename))
return regions
else:
return ['']
def _get_region(self, cloud=None):
return self._get_regions(cloud).split(',')[0]
return self._get_regions(cloud)[0]
def get_cloud_names(self):
return self.cloud_config['clouds'].keys()
@ -301,7 +311,7 @@ class OpenStackConfig(object):
clouds = []
for cloud in self.get_cloud_names():
for region in self._get_regions(cloud).split(','):
for region in self._get_regions(cloud):
clouds.append(self.get_one_cloud(cloud, region_name=region))
return clouds

View File

@ -67,6 +67,17 @@ USER_CONF = {
},
'region_name': 'test-region',
},
'_test_cloud_regions': {
'auth': {
'username': 'testuser',
'password': 'testpass',
'project-id': 'testproject',
},
'regions': [
'region1',
'region2',
],
},
'_test_cloud_hyphenated': {
'auth': {
'username': 'testuser',

View File

@ -32,7 +32,11 @@ class TestConfig(base.TestCase):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
clouds = c.get_all_clouds()
user_clouds = [cloud for cloud in base.USER_CONF['clouds'].keys()]
# We add one by hand because the regions cloud is going to exist
# twice since it has two regions in it
user_clouds = [
cloud for cloud in base.USER_CONF['clouds'].keys()
] + ['_test_cloud_regions']
configured_clouds = [cloud.name for cloud in clouds]
self.assertItemsEqual(user_clouds, configured_clouds)
@ -132,6 +136,7 @@ class TestConfig(base.TestCase):
'_test-cloud_',
'_test_cloud_hyphenated',
'_test_cloud_no_vendor',
'_test_cloud_regions',
],
sorted(c.get_cloud_names()))
c = config.OpenStackConfig(config_files=[self.no_yaml],
@ -216,6 +221,25 @@ class TestConfigArgparse(base.TestCase):
self.assertEqual(cc.region_name, 'test-region')
self.assertIsNone(cc.snack_type)
def test_get_one_cloud_no_argparse_regions(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
cc = c.get_one_cloud(cloud='_test_cloud_regions', argparse=None)
self._assert_cloud_details(cc)
self.assertEqual(cc.region_name, 'region1')
self.assertIsNone(cc.snack_type)
def test_get_one_cloud_no_argparse_region2(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])
cc = c.get_one_cloud(
cloud='_test_cloud_regions', region_name='region2', argparse=None)
self._assert_cloud_details(cc)
self.assertEqual(cc.region_name, 'region2')
self.assertIsNone(cc.snack_type)
def test_fix_env_args(self):
c = config.OpenStackConfig(config_files=[self.cloud_yaml],
vendor_files=[self.vendor_yaml])

View File

@ -2,5 +2,7 @@ name: hp
profile:
auth:
auth_url: https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0
region_name: region-a.geo-1,region-b.geo-1
regions:
- region-a.geo-1
- region-b.geo-1
dns_service_type: hpext:dns

View File

@ -2,7 +2,12 @@ name: rackspace
profile:
auth:
auth_url: https://identity.api.rackspacecloud.com/v2.0/
region_name: DFW,ORD,IAD,SYD,HKG
regions:
- DFW
- HKG
- IAD
- ORD
- SYD
database_service_type: rax:database
compute_service_name: cloudServersOpenStack
image_api_version: '2'

View File

@ -2,7 +2,9 @@ name: runabove
profile:
auth:
auth_url: https://auth.runabove.io/v2.0
region_name: SBG-1,BHS-1
regions:
- BHS-1
- SBG-1
image_api_version: '2'
image_format: qcow2
floating_ip_source: None

View File

@ -2,7 +2,9 @@ name: unitedstack
profile:
auth:
auth_url: https://identity.api.ustack.com/v3
region_name: bj1,gd1
regions:
- bj1
- gd1
identity_api_version: '3'
image_api_version: '2'
image_format: raw