Bump placement API version

We can now pass request ids and consumer generation ids, which
can detect race conditions that affect allocation updates.

Change-Id: Idccf7aeeecc619871b27e16c68f0706c1514c63b
This commit is contained in:
Lucian Petrut 2018-10-30 18:03:59 +02:00
parent 635963186a
commit 99949548dc
2 changed files with 13 additions and 9 deletions

View File

@ -21,7 +21,7 @@ from oslo_log import log as logging
LOG = logging.getLogger(__name__)
SYMMETRIC_GET_PUT_ALLOCATIONS = "1.12" # Queens
CONSUMER_GENERATION_VERSION = "1.28" # Rocky
class PlacementUtils(object):
@ -47,7 +47,7 @@ class PlacementUtils(object):
new_rp_uuid, merge_existing=True):
allocs = self._get_allocs_for_consumer(
context, consumer_uuid,
version=SYMMETRIC_GET_PUT_ALLOCATIONS)
version=CONSUMER_GENERATION_VERSION)
allocations = allocs['allocations']
if old_rp_uuid == new_rp_uuid:
@ -78,12 +78,13 @@ class PlacementUtils(object):
del allocations[old_rp_uuid]
self._put_allocs(context, consumer_uuid, allocs,
version=SYMMETRIC_GET_PUT_ALLOCATIONS)
version=CONSUMER_GENERATION_VERSION)
def _put_allocs(self, context, consumer_uuid, allocations, version=None):
url = '/allocations/%s' % consumer_uuid
r = self.reportclient.put(url, allocations,
version=version)
version=version,
global_request_id=context.global_id)
if r.status_code != 204:
errors = r.json().get('errors') or []
# NOTE(jaypipes): Yes, it sucks doing string comparison like this
@ -101,7 +102,8 @@ class PlacementUtils(object):
def _get_allocs_for_consumer(self, context, consumer, version=None):
resp = self.reportclient.get('/allocations/%s' % consumer,
version=version)
version=version,
global_request_id=context.global_id)
if not resp:
# TODO(efried): Use code/title/detail to make a better exception
raise exception.ConsumerAllocationRetrievalFailed(

View File

@ -83,7 +83,7 @@ class PlacementUtilsTestCase(test_base.HyperVBaseTestCase):
mock_get_allocs.assert_called_once_with(
self.context, mock.sentinel.consumer,
version=placement.SYMMETRIC_GET_PUT_ALLOCATIONS)
version=placement.CONSUMER_GENERATION_VERSION)
mock_put.assert_not_called()
@ddt.data(True, False)
@ -111,7 +111,7 @@ class PlacementUtilsTestCase(test_base.HyperVBaseTestCase):
mock_put.assert_called_once_with(
self.context, mock.sentinel.consumer,
{'allocations': exp_allocs},
version=placement.SYMMETRIC_GET_PUT_ALLOCATIONS)
version=placement.CONSUMER_GENERATION_VERSION)
@ddt.data({}, # no errors
{'status_code': 409,
@ -136,7 +136,8 @@ class PlacementUtilsTestCase(test_base.HyperVBaseTestCase):
self.client.put.assert_called_once_with(
'/allocations/%s' % mock.sentinel.consumer,
mock.sentinel.allocs,
version=mock.sentinel.version)
version=mock.sentinel.version,
global_request_id=self.context.global_id)
def test_get_allocs(self):
ret_val = self.placement._get_allocs_for_consumer(
@ -146,7 +147,8 @@ class PlacementUtilsTestCase(test_base.HyperVBaseTestCase):
self.client.get.assert_called_once_with(
'/allocations/%s' % mock.sentinel.consumer,
version=mock.sentinel.version)
version=mock.sentinel.version,
global_request_id=self.context.global_id)
def test_get_allocs_missing(self):
self.client.get.return_value = fake_requests.FakeResponse(500)