Fix volume retype with AZ

This patch fixes volume type retyping when multiple
availability zones are in place.  This ensures that the
request_spec to the scheduler has the availability zone
in the right place for the AvailabilityZoneFilter to be
able to see it and use it for filtering.

Change-Id: I3f6cca6eb87ac4727b06b167b5aa12da07ba8fb5
Closes-Bug: #1883928
This commit is contained in:
Hemna 2020-06-17 20:14:41 -04:00 committed by Walter A. Boring IV (hemna)
parent 0ca496fc48
commit 8a7c5e32f0
3 changed files with 52 additions and 0 deletions

View File

@ -47,6 +47,10 @@ class VolumeRetypeTestCase(base.BaseVolumeTestCase):
"fake_vol_type",
{},
description="fake_type")
volume_types.create(self.context,
"fake_vol_type2",
{},
description="fake_type2")
volume_types.create(self.context,
"multiattach-type",
{'multiattach': "<is> True"},
@ -58,6 +62,9 @@ class VolumeRetypeTestCase(base.BaseVolumeTestCase):
self.default_vol_type = objects.VolumeType.get_by_name_or_id(
self.context,
'fake_vol_type')
self.fake_vol_type2 = objects.VolumeType.get_by_name_or_id(
self.context,
'fake_vol_type2')
self.multiattach_type = objects.VolumeType.get_by_name_or_id(
self.context,
'multiattach-type')
@ -70,9 +77,47 @@ class VolumeRetypeTestCase(base.BaseVolumeTestCase):
return self.multiattach_type
elif identifier == 'multiattach-type2':
return self.multiattach_type2
elif identifier == 'fake_vol_type2':
return self.fake_vol_type2
else:
return self.default_vol_type
@mock.patch('cinder.scheduler.rpcapi.SchedulerAPI.retype')
@mock.patch('cinder.context.RequestContext.authorize')
@mock.patch.object(volume_types, 'get_by_name_or_id')
def test_retype_has_az(self, _mock_get_types, mock_authorize, mock_rpc):
"""Verify retype has az in request spec."""
_mock_get_types.side_effect = self.fake_get_vtype
vol = tests_utils.create_volume(
self.context,
volume_type_id=self.default_vol_type.id,
status='available',
availability_zone='nova')
self.volume_api.retype(self.user_context,
vol,
'fake_vol_type2')
mock_authorize.assert_called_once_with(
vol_action_policies.RETYPE_POLICY, target_obj=mock.ANY)
fake_spec = {
'volume_properties': mock.ANY,
'volume_id': mock.ANY,
'volume_type': mock.ANY,
'migration_policy': mock.ANY,
'quota_reservations': mock.ANY,
'old_reservations': mock.ANY,
'availability_zones': ['nova'],
}
mock_rpc.assert_called_once_with(
self.user_context, mock.ANY,
request_spec=fake_spec,
filter_properties=mock.ANY
)
@mock.patch('cinder.context.RequestContext.authorize')
def test_non_multi_to_multi_retype(self, mock_authorize):
"""Test going from non-multiattach type to multiattach"""

View File

@ -1747,6 +1747,8 @@ class API(base.Base):
new_type)
if type_azs is not None:
request_spec['availability_zones'] = type_azs
else:
request_spec['availability_zones'] = [volume.availability_zone]
self.scheduler_rpcapi.retype(context, volume,
request_spec=request_spec,

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Fixed a problem with volume retype not honoring the existing volume's
Availability Zone if one isn't specified.