]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Update volume-type's quota when extending volume
authorHaomai Wang <haomai@unitedstack.com>
Mon, 29 Sep 2014 05:36:54 +0000 (13:36 +0800)
committerMike Perez <thingee@gmail.com>
Wed, 22 Oct 2014 13:17:51 +0000 (09:17 -0400)
Now cinder only update total "gigabytes" quota but not update special
volume-type's "gigabytes" quota.

Fix bug #1375120

Change-Id: Ibb0b91afc81ba8c864f3c56fbe8a31972edd9bfc
Signed-off-by: Haomai Wang <haomai@unitedstack.com>
cinder/tests/test_volume.py
cinder/volume/api.py

index b8acbf356907a4eea15cd9378bd734d383ca5771..fc4d21c5093bd3ed44e8089f2fd345f16919bd1f 100644 (file)
@@ -2557,6 +2557,35 @@ class VolumeTestCase(BaseVolumeTestCase):
         # clean up
         self.volume.delete_volume(self.context, volume['id'])
 
+    def test_extend_volume_with_volume_type(self):
+        elevated = context.get_admin_context()
+        project_id = self.context.project_id
+        db.volume_type_create(elevated, {'name': 'type', 'extra_specs': {}})
+        vol_type = db.volume_type_get_by_name(elevated, 'type')
+
+        volume_api = cinder.volume.api.API()
+        volume = volume_api.create(self.context, 100, 'name', 'description',
+                                   volume_type=vol_type)
+        try:
+            usage = db.quota_usage_get(elevated, project_id, 'gigabytes_type')
+            volumes_in_use = usage.in_use
+        except exception.QuotaUsageNotFound:
+            volumes_in_use = 0
+        self.assertEqual(volumes_in_use, 100)
+        volume['status'] = 'available'
+        volume['host'] = 'fakehost'
+        volume['volume_type_id'] = vol_type.get('id')
+
+        volume_api.extend(self.context, volume, 200)
+
+        try:
+            usage = db.quota_usage_get(elevated, project_id, 'gigabytes_type')
+            volumes_reserved = usage.reserved
+        except exception.QuotaUsageNotFound:
+            volumes_reserved = 0
+
+        self.assertEqual(volumes_reserved, 100)
+
     def test_create_volume_from_unelevated_context(self):
         """Test context does't change after volume creation failure."""
         def fake_create_volume(*args, **kwargs):
index ba9a9096a2c854a8fbd5029923858612b616c360..57c79a36710430307a9a3e464dc4684127079906 100644 (file)
@@ -993,7 +993,10 @@ class API(base.Base):
             raise exception.InvalidInput(reason=msg)
 
         try:
-            reservations = QUOTAS.reserve(context, gigabytes=+size_increase)
+            reserve_opts = {'gigabytes': size_increase}
+            QUOTAS.add_volume_type_opts(context, reserve_opts,
+                                        volume.get('volume_type_id'))
+            reservations = QUOTAS.reserve(context, **reserve_opts)
         except exception.OverQuota as exc:
             usages = exc.kwargs['usages']
             quotas = exc.kwargs['quotas']