From: Michael Kerrin Date: Mon, 9 Sep 2013 08:12:27 +0000 (+0000) Subject: Add default_availability_zone configuration option to cinder X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=4fd5f9d68312776d10cc2ef775a76c0f3ece60de;p=openstack-build%2Fcinder-build.git Add default_availability_zone configuration option to cinder This option is used to specify the default AZ for the whole service. So when creating a new volume this value is used to specify the AZ of a volume. Previously we were overloading the use of the storage_availability_zone option which is also used to specify what AZ a service belongs to. We still fail back on the storage_availability_zone when creating a new volume if the default_availability_zone is not set. Fixes bug: 1221260 Change-Id: Iec381f50c9aeb4a0abbcaa1d7b0107de09a73544 --- diff --git a/cinder/common/config.py b/cinder/common/config.py index b042b5001..912705fcb 100644 --- a/cinder/common/config.py +++ b/cinder/common/config.py @@ -161,6 +161,12 @@ global_opts = [ cfg.StrOpt('storage_availability_zone', default='nova', help='availability zone of this node'), + cfg.StrOpt('default_availability_zone', + default=None, + help='default availability zone to use when creating a new volume. ' + 'If this is not set then we use the value from the ' + 'storage_availability_zone option as the default ' + 'availability_zone for new volumes.'), cfg.ListOpt('memcached_servers', default=None, help='Memcached servers or None for in process cache.'), diff --git a/cinder/tests/test_volume.py b/cinder/tests/test_volume.py index f9b505ebf..126b3d5be 100644 --- a/cinder/tests/test_volume.py +++ b/cinder/tests/test_volume.py @@ -231,6 +231,34 @@ class VolumeTestCase(BaseVolumeTestCase): None, test_meta) + def test_create_volume_uses_default_availability_zone(self): + """Test setting availability_zone correctly during volume create.""" + volume_api = cinder.volume.api.API() + + def fake_list_availability_zones(): + return ({'name': 'az1', 'available': True}, + {'name': 'az2', 'available': True}, + {'name': 'default-az', 'available': True}) + + self.stubs.Set(volume_api, + 'list_availability_zones', + fake_list_availability_zones) + + # Test backwards compatibility, default_availability_zone not set + CONF.set_override('storage_availability_zone', 'az2') + volume = volume_api.create(self.context, + 1, + 'name', + 'description') + self.assertEqual(volume['availability_zone'], 'az2') + + CONF.set_override('default_availability_zone', 'default-az') + volume = volume_api.create(self.context, + 1, + 'name', + 'description') + self.assertEqual(volume['availability_zone'], 'default-az') + def test_create_volume_with_volume_type(self): """Test volume creation with default volume type.""" def fake_reserve(context, expire=None, project_id=None, **deltas): diff --git a/cinder/volume/flows/create_volume/__init__.py b/cinder/volume/flows/create_volume/__init__.py index 447e8e104..765244622 100644 --- a/cinder/volume/flows/create_volume/__init__.py +++ b/cinder/volume/flows/create_volume/__init__.py @@ -360,7 +360,11 @@ class ExtractVolumeRequestTask(base.CinderTask): pass if availability_zone is None: - availability_zone = CONF.storage_availability_zone + if CONF.default_availability_zone: + availability_zone = CONF.default_availability_zone + else: + # For backwards compatibility use the storge_availability_zone + availability_zone = CONF.storage_availability_zone if not self.az_check_functor(availability_zone): msg = _("Availability zone '%s' is invalid") % (availability_zone) LOG.warn(msg) diff --git a/etc/cinder/cinder.conf.sample b/etc/cinder/cinder.conf.sample index 4fd56312a..07c7faed6 100644 --- a/etc/cinder/cinder.conf.sample +++ b/etc/cinder/cinder.conf.sample @@ -394,6 +394,12 @@ # availability zone of this node (string value) #storage_availability_zone=nova +# default availability zone to use when creating a new volume. +# If this is not set then we use the value from the +# storage_availability_zone option as the default +# availability_zone for new volumes. (string value) +#default_availability_zone= + # Memcached servers or None for in process cache. (list value) #memcached_servers= @@ -1758,4 +1764,4 @@ #volume_dd_blocksize=1M -# Total option count: 377 +# Total option count: 378