]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Admin extends tenant's volume but change admin's quota
authorwuyuting <wytdahu@gmail.com>
Fri, 13 Feb 2015 02:16:24 +0000 (10:16 +0800)
committerwuyuting <wytdahu@gmail.com>
Wed, 29 Apr 2015 02:04:30 +0000 (10:04 +0800)
When admin extends a tenant's volume, the tenant's
quota-usage doesn't change. However, admin's quota-usage
has changed. The right practice is: extend whose volume,
whose quota-usage should be changed.

Change-Id: Ia1bed7f212cbee715e29698ebbfe3c67486a55f5
Closes-Bug: #1421492

cinder/tests/unit/test_volume.py
cinder/volume/api.py
cinder/volume/manager.py

index 06639a8d95793fd2fb84a9e38650e2c6f0ec7df1..ffe2663f1d3afdea443b84283d15e5a7f385989d 100644 (file)
@@ -3412,6 +3412,8 @@ class VolumeTestCase(BaseVolumeTestCase):
         volume_api.extend(self.context, volume, 3)
         volume = db.volume_get(context.get_admin_context(), volume['id'])
         self.assertEqual('extending', volume['status'])
+        reserve.assert_called_once_with(self.context, gigabytes=1,
+                                        project_id=volume['project_id'])
 
         # Test the quota exceeded
         volume['status'] = 'available'
@@ -3477,13 +3479,19 @@ class VolumeTestCase(BaseVolumeTestCase):
         # Test driver success
         with mock.patch.object(self.volume.driver,
                                'extend_volume') as extend_volume:
-            extend_volume.return_value = fake_extend
-            volume['status'] = 'extending'
-            self.volume.extend_volume(self.context, volume['id'], '4',
-                                      fake_reservations)
-            volume = db.volume_get(context.get_admin_context(), volume['id'])
-            self.assertEqual(4, volume['size'])
-            self.assertEqual('available', volume['status'])
+            with mock.patch.object(QUOTAS, 'commit') as quotas_commit:
+                extend_volume.return_value = fake_extend
+                volume['status'] = 'extending'
+                self.volume.extend_volume(self.context, volume['id'], '4',
+                                          fake_reservations)
+                volume = db.volume_get(context.get_admin_context(),
+                                       volume['id'])
+                self.assertEqual(4, volume['size'])
+                self.assertEqual('available', volume['status'])
+                quotas_commit.assert_called_with(
+                    self.context,
+                    ['RESERVATION'],
+                    project_id=volume['project_id'])
 
         # clean up
         self.volume.delete_volume(self.context, volume['id'])
index 8a2af8f5f48645552e28e49e3bff07f3501ee1ba..d4bde31fc1a3afe1d4c27fd4b6c5cf0d422ddd40 100644 (file)
@@ -1165,7 +1165,9 @@ class API(base.Base):
             reserve_opts = {'gigabytes': size_increase}
             QUOTAS.add_volume_type_opts(context, reserve_opts,
                                         volume.get('volume_type_id'))
-            reservations = QUOTAS.reserve(context, **reserve_opts)
+            reservations = QUOTAS.reserve(context,
+                                          project_id=volume['project_id'],
+                                          **reserve_opts)
         except exception.OverQuota as exc:
             usages = exc.kwargs['usages']
             quotas = exc.kwargs['quotas']
index ef18fcc45081da6c95055cb3394892cb3f2ab080..3881c6c20e2ced30a0e435b37835ac1ffda808c7 100644 (file)
@@ -1566,6 +1566,7 @@ class VolumeManager(manager.SchedulerDependentManager):
                                       {'status': 'error_extending'})
 
         volume = self.db.volume_get(context, volume_id)
+        project_id = volume['project_id']
         size_increase = (int(new_size)) - volume['size']
         self._notify_about_volume_usage(context, volume, "resize.start")
         try:
@@ -1580,10 +1581,10 @@ class VolumeManager(manager.SchedulerDependentManager):
                                                   "to extend volume") %
                                                 volume_id)
             finally:
-                QUOTAS.rollback(context, reservations)
+                QUOTAS.rollback(context, reservations, project_id=project_id)
                 return
 
-        QUOTAS.commit(context, reservations)
+        QUOTAS.commit(context, reservations, project_id=project_id)
         volume = self.db.volume_update(context,
                                        volume['id'],
                                        {'size': int(new_size),