From 441ebdc6357deef297a4983aaff33a8516cbc3a4 Mon Sep 17 00:00:00 2001 From: "billy.olsen@canonical.com" <> Date: Tue, 16 Feb 2016 11:46:22 -0700 Subject: [PATCH] [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 --- hooks/cinder_contexts.py | 15 +++++++++++++++ hooks/cinder_utils.py | 3 ++- templates/cinder.conf | 4 ++++ templates/icehouse/cinder.conf | 4 ++++ templates/kilo/cinder.conf | 4 ++++ unit_tests/test_cinder_contexts.py | 5 +++++ 6 files changed, 34 insertions(+), 1 deletion(-) diff --git a/hooks/cinder_contexts.py b/hooks/cinder_contexts.py index 0a9678c8..8dea1af1 100644 --- a/hooks/cinder_contexts.py +++ b/hooks/cinder_contexts.py @@ -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 {} diff --git a/hooks/cinder_utils.py b/hooks/cinder_utils.py index 6498014b..72d59dee 100644 --- a/hooks/cinder_utils.py +++ b/hooks/cinder_utils.py @@ -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'] }), diff --git a/templates/cinder.conf b/templates/cinder.conf index efc6c5b8..263ff4a3 100644 --- a/templates/cinder.conf +++ b/templates/cinder.conf @@ -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 }} diff --git a/templates/icehouse/cinder.conf b/templates/icehouse/cinder.conf index b38f9b11..dde86e32 100644 --- a/templates/icehouse/cinder.conf +++ b/templates/icehouse/cinder.conf @@ -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 }} diff --git a/templates/kilo/cinder.conf b/templates/kilo/cinder.conf index 8844b3a8..f864daa6 100644 --- a/templates/kilo/cinder.conf +++ b/templates/kilo/cinder.conf @@ -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 }} diff --git a/unit_tests/test_cinder_contexts.py b/unit_tests/test_cinder_contexts.py index 018e1b45..f8bec6e8 100644 --- a/unit_tests/test_cinder_contexts.py +++ b/unit_tests/test_cinder_contexts.py @@ -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'])