[placement] Add sending global request ID in delete

Add the 'X-Openstack-Request-Id' header
in the request of DELETE.
When deleteing a resource provider, the header is added.

Subsequent patches will add the header in the other cases.

Change-Id: Id78b849fe0f874d7a8e13c72f63b10724faf1aa7
Partial-Bug: #1734625
This commit is contained in:
Takashi NATSUME 2017-12-04 21:57:23 +09:00
parent 3bc4cb022f
commit c647865bf6
3 changed files with 28 additions and 5 deletions

View File

@ -305,8 +305,11 @@ class SchedulerReportClient(object):
kwargs['json'] = data
return self._client.put(url, raise_exc=False, **kwargs)
def delete(self, url, version=None):
return self._client.delete(url, raise_exc=False, microversion=version)
def delete(self, url, version=None, global_request_id=None):
headers = ({request_id.INBOUND_HEADER: global_request_id}
if global_request_id else {})
return self._client.delete(url, raise_exc=False, microversion=version,
headers=headers)
@safe_connect
def get_allocation_candidates(self, resources):
@ -1421,7 +1424,7 @@ class SchedulerReportClient(object):
for instance in instances:
self.delete_allocation_for_instance(instance.uuid)
url = "/resource_providers/%s" % rp_uuid
resp = self.delete(url)
resp = self.delete(url, global_request_id=context.global_id)
if resp:
LOG.info("Deleted resource provider %s", rp_uuid)
# clean the caches

View File

@ -188,3 +188,21 @@ class SchedulerReportClientTests(test.TestCase):
self.assertRaises(exception.InvalidResourceClass,
self.client.set_inventory_for_provider,
self.compute_uuid, self.compute_name, inv_data)
@mock.patch('keystoneauth1.session.Session.get_endpoint',
return_value='http://localhost:80/placement')
def test_global_request_id(self, mock_endpoint):
global_request_id = 'req-%s' % uuids.global_request_id
def assert_app(environ, start_response):
# Assert the 'X-Openstack-Request-Id' header in the request.
self.assertIn('HTTP_X_OPENSTACK_REQUEST_ID', environ)
self.assertEqual(global_request_id,
environ['HTTP_X_OPENSTACK_REQUEST_ID'])
start_response('204 OK', [])
return []
with interceptor.RequestsInterceptor(
app=lambda: assert_app, url=self.url):
self.client.delete('/resource_providers/%s' % self.compute_uuid,
global_request_id=global_request_id)

View File

@ -3112,7 +3112,8 @@ class TestAllocations(SchedulerReportClientTestCase):
self.client.delete_resource_provider(self.context, cn, cascade=True)
self.assertEqual(2, mock_del_alloc.call_count)
exp_url = "/resource_providers/%s" % uuids.cn
mock_delete.assert_called_once_with(exp_url)
mock_delete.assert_called_once_with(
exp_url, global_request_id=self.context.global_id)
self.assertFalse(self.client._provider_tree.exists(uuids.cn))
@mock.patch("nova.scheduler.client.report.SchedulerReportClient."
@ -3135,7 +3136,8 @@ class TestAllocations(SchedulerReportClientTestCase):
self.client.delete_resource_provider(self.context, cn)
mock_del_alloc.assert_not_called()
exp_url = "/resource_providers/%s" % uuids.cn
mock_delete.assert_called_once_with(exp_url)
mock_delete.assert_called_once_with(
exp_url, global_request_id=self.context.global_id)
self.assertNotIn(uuids.cn, self.client._provider_aggregate_map)
@mock.patch("nova.scheduler.client.report.SchedulerReportClient."