]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Roll back reservations quota in RPC if necessary
authorNate Potter <nathaniel.potter@intel.com>
Mon, 4 Jan 2016 23:10:19 +0000 (23:10 +0000)
committerMichał Dulko <michal.dulko@intel.com>
Tue, 16 Feb 2016 13:21:33 +0000 (14:21 +0100)
Currently the latest version of the volume rpcapi passes along
old_reservations in retype whereas older versions do not. In the
case where old_reservations aren't passed, they will be checked again
in c-vol. This patch rolls back the quotas that were checked for
old_reservations if the client can't send the latest version in
the RPCAPI so that they aren't reserved twice.

This is an amendment to this recently merged patch:
Iba24edd8ad824837028353b52c90742df55c9173

Closes-Bug: 1546089
Related-bug: 1508249
Change-Id: I54b39f367b8552ed5e932c71265432e7cf72c073

cinder/tests/unit/test_volume_rpcapi.py
cinder/volume/rpcapi.py

index e03a49f0e7b57b2ad4321ab40d1e367013cab5d6..315a7c2c8e75e69ff8d5eb8600c5e58454ca5f9e 100644 (file)
@@ -453,7 +453,8 @@ class VolumeRpcAPITestCase(test.TestCase):
 
     @mock.patch('oslo_messaging.RPCClient.can_send_version',
                 return_value=True)
-    def test_retype(self, can_send_version):
+    @mock.patch('cinder.quota.DbQuotaDriver.rollback')
+    def test_retype(self, rollback, can_send_version):
         class FakeHost(object):
             def __init__(self):
                 self.host = 'host'
@@ -468,9 +469,11 @@ class VolumeRpcAPITestCase(test.TestCase):
                               reservations=self.fake_reservations,
                               old_reservations=self.fake_reservations,
                               version='1.37')
+        rollback.assert_not_called()
         can_send_version.assert_called_once_with('1.37')
 
-    def test_retype_version_134(self):
+    @mock.patch('cinder.quota.DbQuotaDriver.rollback')
+    def test_retype_version_134(self, rollback):
         class FakeHost(object):
             def __init__(self):
                 self.host = 'host'
@@ -488,10 +491,12 @@ class VolumeRpcAPITestCase(test.TestCase):
                                   reservations=self.fake_reservations,
                                   old_reservations=self.fake_reservations,
                                   version='1.34')
+        self.assertTrue(rollback.called)
         can_send_version.assert_any_call('1.37')
         can_send_version.assert_any_call('1.34')
 
-    def test_retype_version_112(self):
+    @mock.patch('cinder.quota.DbQuotaDriver.rollback')
+    def test_retype_version_112(self, rollback):
         class FakeHost(object):
             def __init__(self):
                 self.host = 'host'
@@ -509,6 +514,7 @@ class VolumeRpcAPITestCase(test.TestCase):
                                   reservations=self.fake_reservations,
                                   old_reservations=self.fake_reservations,
                                   version='1.12')
+            self.assertTrue(rollback.called)
             can_send_version.assert_any_call('1.37')
             can_send_version.assert_any_call('1.34')
 
index c0e8e9cce5e80a497366e1771669c3128ef10f11..363fb69b14ed0d77e14fc98e5746637057d05feb 100644 (file)
@@ -19,11 +19,13 @@ Client side of the volume RPC API.
 from oslo_config import cfg
 from oslo_serialization import jsonutils
 
+from cinder import quota
 from cinder import rpc
 from cinder.volume import utils
 
 
 CONF = cfg.CONF
+QUOTAS = quota.QUOTAS
 
 
 class VolumeAPI(rpc.RPCAPI):
@@ -265,6 +267,8 @@ class VolumeAPI(rpc.RPCAPI):
             version = '1.37'
             msg_args.update(volume=volume, old_reservations=old_reservations)
         else:
+            if old_reservations is not None:
+                QUOTAS.rollback(ctxt, old_reservations)
             if self.client.can_send_version('1.34'):
                 version = '1.34'
                 msg_args['volume'] = volume