From 8a7c5e32f05503a2ffcb1375570ff167f8c2e027 Mon Sep 17 00:00:00 2001 From: Hemna Date: Wed, 17 Jun 2020 20:14:41 -0400 Subject: [PATCH] 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 --- .../tests/unit/volume/test_volume_retype.py | 45 +++++++++++++++++++ cinder/volume/api.py | 2 + .../fix-retype-with-az-e048123d982f213d.yaml | 5 +++ 3 files changed, 52 insertions(+) create mode 100644 releasenotes/notes/fix-retype-with-az-e048123d982f213d.yaml diff --git a/cinder/tests/unit/volume/test_volume_retype.py b/cinder/tests/unit/volume/test_volume_retype.py index 05503a7d7d4..01882e09264 100644 --- a/cinder/tests/unit/volume/test_volume_retype.py +++ b/cinder/tests/unit/volume/test_volume_retype.py @@ -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': " 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""" diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 9c20fadfd63..093017d0a15 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -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, diff --git a/releasenotes/notes/fix-retype-with-az-e048123d982f213d.yaml b/releasenotes/notes/fix-retype-with-az-e048123d982f213d.yaml new file mode 100644 index 00000000000..1d297999c97 --- /dev/null +++ b/releasenotes/notes/fix-retype-with-az-e048123d982f213d.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fixed a problem with volume retype not honoring the existing volume's + Availability Zone if one isn't specified.