]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add default_availability_zone configuration option to cinder
authorMichael Kerrin <michael.kerrin@hp.com>
Mon, 9 Sep 2013 08:12:27 +0000 (08:12 +0000)
committerMichael Kerrin <michael.kerrin@hp.com>
Thu, 12 Sep 2013 09:07:29 +0000 (09:07 +0000)
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

cinder/common/config.py
cinder/tests/test_volume.py
cinder/volume/flows/create_volume/__init__.py
etc/cinder/cinder.conf.sample

index b042b50019f0053e5ff1d0dd0b4269918342463e..912705fcb9d4dc69ea4417eb9c84cf057c2e70fc 100644 (file)
@@ -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.'),
index f9b505ebf34318594376fe032ff2044627159be9..126b3d5be7284ccbaff98a8f4803272cc22a47ca 100644 (file)
@@ -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):
index 447e8e104433abf64d1858180307380242aa184b..765244622dfde6ca7c421cf734928754a78cd979 100644 (file)
@@ -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)
index 4fd56312af7d90d957ec315cb03651893cd6de3f..07c7faed63a59e04eaa3ceb4122cfae6a71da7c4 100644 (file)
 # 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=<None>
+
 # Memcached servers or None for in process cache. (list value)
 #memcached_servers=<None>
 
 #volume_dd_blocksize=1M
 
 
-# Total option count: 377
+# Total option count: 378