From: Nate Potter Date: Mon, 4 Jan 2016 23:10:19 +0000 (+0000) Subject: Roll back reservations quota in RPC if necessary X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3ef58dd656d6fdf08457f16a2a39b0fbffd3c2ca;p=openstack-build%2Fcinder-build.git Roll back reservations quota in RPC if necessary 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 --- diff --git a/cinder/tests/unit/test_volume_rpcapi.py b/cinder/tests/unit/test_volume_rpcapi.py index e03a49f0e..315a7c2c8 100644 --- a/cinder/tests/unit/test_volume_rpcapi.py +++ b/cinder/tests/unit/test_volume_rpcapi.py @@ -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') diff --git a/cinder/volume/rpcapi.py b/cinder/volume/rpcapi.py index c0e8e9cce..363fb69b1 100644 --- a/cinder/volume/rpcapi.py +++ b/cinder/volume/rpcapi.py @@ -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