Have python-novaclient support global_request_id
As part of the Boston Summit, support the global_request_id effort by making python-novaclient support passing global_request_id during construction. part of bp:oslo-middleware-request-id oslo spec I65de8261746b25d45e105394f4eeb95b9cb3bd42 Change-Id: Ife29b1856c0c278eab1708c3971fef14b9d77e2e
This commit is contained in:
parent
8f6c216931
commit
d25502cbe2
@ -40,7 +40,7 @@ from novaclient import extension as ext
|
||||
from novaclient.i18n import _
|
||||
from novaclient import utils
|
||||
|
||||
|
||||
REQ_ID_HEADER = 'X-OpenStack-Request-ID'
|
||||
# TODO(jichenjc): when an extension in contrib is moved to core extension,
|
||||
# Add the name into the following list, then after last patch merged,
|
||||
# remove the whole function
|
||||
@ -57,12 +57,16 @@ class SessionClient(adapter.LegacyJsonAdapter):
|
||||
self.timings = kwargs.pop('timings', False)
|
||||
self.api_version = kwargs.pop('api_version', None)
|
||||
self.api_version = self.api_version or api_versions.APIVersion()
|
||||
self.global_request_id = kwargs.pop('global_request_id', None)
|
||||
super(SessionClient, self).__init__(*args, **kwargs)
|
||||
|
||||
def request(self, url, method, **kwargs):
|
||||
kwargs.setdefault('headers', kwargs.get('headers', {}))
|
||||
api_versions.update_headers(kwargs["headers"], self.api_version)
|
||||
|
||||
if self.global_request_id is not None:
|
||||
kwargs['headers'].setdefault(REQ_ID_HEADER, self.global_request_id)
|
||||
|
||||
# NOTE(dbelova): osprofiler_web.get_trace_id_headers does not add any
|
||||
# headers in case if osprofiler is not initialized.
|
||||
if osprofiler_web:
|
||||
|
@ -14,6 +14,7 @@
|
||||
# under the License.
|
||||
|
||||
import copy
|
||||
import uuid
|
||||
|
||||
from keystoneauth1 import session
|
||||
import mock
|
||||
@ -70,6 +71,16 @@ class SessionClientTest(utils.TestCase):
|
||||
cs.reset_timings()
|
||||
self.assertEqual(0, len(cs.get_timings()))
|
||||
|
||||
def test_global_id(self):
|
||||
global_id = "req-%s" % uuid.uuid4()
|
||||
self.requests_mock.get('http://no.where')
|
||||
|
||||
client = novaclient.client.SessionClient(session=session.Session(),
|
||||
global_request_id=global_id)
|
||||
client.request("http://no.where", 'GET')
|
||||
headers = self.requests_mock.last_request.headers
|
||||
self.assertEqual(headers['X-OpenStack-Request-ID'], global_id)
|
||||
|
||||
|
||||
class ClientsUtilsTest(utils.TestCase):
|
||||
|
||||
|
@ -0,0 +1,6 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
A new ``global_request_id`` parameter is accepted on the client
|
||||
constructor, which will then pass ``X-OpenStack-Request-ID`` on
|
||||
all requests made.
|
Loading…
x
Reference in New Issue
Block a user