diff --git a/cinder/tests/unit/test_volume.py b/cinder/tests/unit/test_volume.py index 69bffbd0c60..d12cf9c6261 100644 --- a/cinder/tests/unit/test_volume.py +++ b/cinder/tests/unit/test_volume.py @@ -3856,8 +3856,9 @@ class VolumeTestCase(BaseVolumeTestCase): 'fake2': {'key3': 'value3', 'key4': 'value4'}} self.assertEqual(expect_results, results) + @mock.patch.object(QUOTAS, 'limit_check') @mock.patch.object(QUOTAS, 'reserve') - def test_extend_volume(self, reserve): + def test_extend_volume(self, reserve, limit_check): """Test volume can be extended at API level.""" # create a volume and assign to host volume = tests_utils.create_volume(self.context, size=2, @@ -3908,6 +3909,12 @@ class VolumeTestCase(BaseVolumeTestCase): volume_api.extend, self.context, volume, 3) + limit_check.side_effect = exception.OverQuota( + overs=['per_volume_gigabytes'], quotas={'per_volume_gigabytes': 2}) + self.assertRaises(exception.VolumeSizeExceedsLimit, + volume_api.extend, self.context, + volume, 3) + # clean up self.volume.delete_volume(self.context, volume['id']) diff --git a/cinder/volume/api.py b/cinder/volume/api.py index 76306eceb2d..0eab864b5c0 100644 --- a/cinder/volume/api.py +++ b/cinder/volume/api.py @@ -1215,6 +1215,15 @@ class API(base.Base): 'size': volume.size}) raise exception.InvalidInput(reason=msg) + try: + values = {'per_volume_gigabytes': new_size} + QUOTAS.limit_check(context, project_id=context.project_id, + **values) + except exception.OverQuota as e: + quotas = e.kwargs['quotas'] + raise exception.VolumeSizeExceedsLimit( + size=new_size, limit=quotas['per_volume_gigabytes']) + try: reserve_opts = {'gigabytes': size_increase} QUOTAS.add_volume_type_opts(context, reserve_opts,