diff --git a/config.yaml b/config.yaml index fa4d89c5..16fcd31a 100644 --- a/config.yaml +++ b/config.yaml @@ -639,3 +639,20 @@ options: default notification format unversioned until this is implemented. . Possible Values are both, versioned, unversioned. + cross-az-attach: # LP: 1856776 + type: boolean + default: True # OpenStack default value + description: | + Allow attach between instance and volume in different availability zones. + . + If False, volumes attached to an instance must be in the same + availability zone in Cinder as the instance availability zone in Nova. + This also means care should be taken when booting an instance from a + volume where source is not "volume" because Nova will attempt to create + a volume using the same availability zone as what is assigned to the + instance. + . + If that AZ is not in Cinder, the volume create request will fail and the + instance will fail the build request. + . + By default there is no availability zone restriction on volume attach. \ No newline at end of file diff --git a/hooks/nova_cc_context.py b/hooks/nova_cc_context.py index 84040c90..54b08cc9 100644 --- a/hooks/nova_cc_context.py +++ b/hooks/nova_cc_context.py @@ -283,6 +283,13 @@ def canonical_url(): return '%s://%s' % (scheme, ch_network_ip.format_ipv6_addr(addr) or addr) +class CinderConfigContext(ch_context.OSContextGenerator): + def __call__(self): + return { + 'cross_az_attach': hookenv.config('cross-az-attach') + } + + class NeutronCCContext(ch_context.NeutronContext): interfaces = ['quantum-network-service', 'neutron-network-service'] diff --git a/hooks/nova_cc_utils.py b/hooks/nova_cc_utils.py index 85033ca9..fd1cc982 100644 --- a/hooks/nova_cc_utils.py +++ b/hooks/nova_cc_utils.py @@ -178,6 +178,7 @@ def get_base_resource_map(): nova_cc_context.VolumeServiceContext(), ch_context.ZeroMQContext(), ch_context.NotificationDriverContext(), + nova_cc_context.CinderConfigContext(), nova_cc_context.NovaIPv6Context(), nova_cc_context.NeutronCCContext(), nova_cc_context.NovaConfigContext(), diff --git a/templates/parts/section-cinder b/templates/parts/section-cinder index dabc3f1e..57a0c6f2 100644 --- a/templates/parts/section-cinder +++ b/templates/parts/section-cinder @@ -6,4 +6,5 @@ catalog_info = {{ volume_catalog_info }} {% if region -%} os_region_name = {{ region }} {% endif %} +cross_az_attach = {{ cross_az_attach }} {% endif -%} diff --git a/unit_tests/test_nova_cc_contexts.py b/unit_tests/test_nova_cc_contexts.py index 2bed2310..3fb7caca 100644 --- a/unit_tests/test_nova_cc_contexts.py +++ b/unit_tests/test_nova_cc_contexts.py @@ -523,6 +523,15 @@ class NovaComputeContextTests(CharmTestCase): ctxt = context.NeutronAPIContext()() self.assertEqual(ctxt, expected) + def test_CinderContext(self): + self.test_config.update({'cross-az-attach': False, }) + ctxt = context.CinderConfigContext()() + self.assertEqual({'cross_az_attach': False}, ctxt) + + self.test_config.update({'cross-az-attach': True, }) + ctxt = context.CinderConfigContext()() + self.assertEqual({'cross_az_attach': True}, ctxt) + @mock.patch('charmhelpers.contrib.openstack.context.' 'NovaVendorMetadataContext.__call__') def test_vendordata_static_and_dynamic(self, parent):