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
This commit is contained in:
Nate Potter
2016-01-04 23:10:19 +00:00
committed by Michał Dulko
parent eb8be7655d
commit 3ef58dd656
2 changed files with 13 additions and 3 deletions

View 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')

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):
@@ -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