[billy-olsen,r=] Specify os_region_name based on the region.

This ensures that the region is configured within the cinder.conf file.

Partially-Closes-Bug: LP#1468306
This commit is contained in:
billy.olsen@canonical.com 2016-02-16 11:46:22 -07:00
parent 6d237b7d80
commit 441ebdc635
6 changed files with 34 additions and 1 deletions

View File

@ -154,3 +154,18 @@ class CinderSubordinateConfigContext(SubordinateConfigContext):
"backends configured.", level=WARNING)
return ctxt
class RegionContext(OSContextGenerator):
"""Provides context data regarding the region the service is in.
This context provides the region that is configured by the admin via the
region option in the config settings for the charm. If no region config
is available, then this will provide an empty context.
"""
def __call__(self):
region = config('region')
if region:
return {'region': region}
else:
return {}

View File

@ -203,7 +203,8 @@ CONFIG_FILES = OrderedDict([
service='cinder',
service_user='cinder'),
context.BindHostContext(),
context.WorkerConfigContext()],
context.WorkerConfigContext(),
cinder_contexts.RegionContext()],
'services': ['cinder-api', 'cinder-volume', 'cinder-backup',
'cinder-scheduler', 'haproxy']
}),

View File

@ -57,6 +57,10 @@ glance_api_servers = {{ glance_api_servers }}
glance_api_version = {{ glance_api_version }}
{% endif -%}
{% if region -%}
os_region_name = {{ region }}
{% endif -%}
{% if user_config_flags -%}
{% for key, value in user_config_flags.iteritems() -%}
{{ key }} = {{ value }}

View File

@ -48,6 +48,10 @@ glance_api_servers = {{ glance_api_servers }}
glance_api_version = {{ glance_api_version }}
{% endif -%}
{% if region -%}
os_region_name = {{ region }}
{% endif -%}
{% if user_config_flags -%}
{% for key, value in user_config_flags.iteritems() -%}
{{ key }} = {{ value }}

View File

@ -45,6 +45,10 @@ glance_api_servers = {{ glance_api_servers }}
glance_api_version = {{ glance_api_version }}
{% endif -%}
{% if region -%}
os_region_name = {{ region }}
{% endif -%}
{% if user_config_flags -%}
{% for key, value in user_config_flags.iteritems() -%}
{{ key }} = {{ value }}

View File

@ -341,3 +341,8 @@ class TestCinderContext(CharmTestCase):
u'cinder.volume.drivers.OtherDriver']]}}
self.assertEquals(ctxt, exp)
def test_region_context(self):
self.config.return_value = 'two'
ctxt = contexts.RegionContext()()
self.assertEqual('two', ctxt['region'])