Merge "Roll back reservations quota in RPC if necessary"

This commit is contained in:
Jenkins 2016-02-19 00:24:49 +00:00 committed by Gerrit Code Review
commit 409be4c652
2 changed files with 13 additions and 3 deletions

View File

@ -465,7 +465,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'
@ -480,9 +481,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'
@ -500,10 +503,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'
@ -521,6 +526,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')

View 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):
@ -267,6 +269,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