Skip to content

Commit

Permalink
Add default_availability_zone configuration option to cinder
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Michael Kerrin committed Sep 12, 2013
1 parent 6a84a0b commit 4fd5f9d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
6 changes: 6 additions & 0 deletions cinder/common/config.py
Expand Up @@ -161,6 +161,12 @@ def _get_my_ip():
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.'),
Expand Down
28 changes: 28 additions & 0 deletions cinder/tests/test_volume.py
Expand Up @@ -231,6 +231,34 @@ def test_create_volume_with_invalid_metadata(self):
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):
Expand Down
6 changes: 5 additions & 1 deletion cinder/volume/flows/create_volume/__init__.py
Expand Up @@ -360,7 +360,11 @@ def _extract_availability_zone(self, availability_zone, snapshot,
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)
Expand Down
8 changes: 7 additions & 1 deletion etc/cinder/cinder.conf.sample
Expand Up @@ -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=<None>

# Memcached servers or None for in process cache. (list value)
#memcached_servers=<None>

Expand Down Expand Up @@ -1758,4 +1764,4 @@
#volume_dd_blocksize=1M


# Total option count: 377
# Total option count: 378

0 comments on commit 4fd5f9d

Please sign in to comment.