Use global request id for scenario tests

This patch adds a global request id to each header for blazar requests
used in the scenario tests. Now the global request ids are in the debug
logs, which helps you to track each request over multiple OpenStack
services improving the debuggability for test failures.

Depends-On: https://review.opendev.org/#/c/670995/
Change-Id: Idd7095fa0c7af4b29a5a84b035fe1e882b995fa0
This commit is contained in:
Tetsuro Nakamura 2019-07-17 01:42:55 +00:00
parent de514b2236
commit 3d19fe843f
2 changed files with 26 additions and 9 deletions

View File

@ -14,6 +14,7 @@
# under the License.
from oslo_serialization import jsonutils as json
from oslo_utils import uuidutils as uuids
from tempest.lib.common import rest_client
@ -31,8 +32,16 @@ class ResourceReservationV1Client(rest_client.RestClient):
body = json.loads(body)
return rest_client.ResponseBody(resp, body)
def _get_headers(self):
headers = {
'Content-Type': 'application/json',
'Accept': 'application/json',
'X-Openstack-Request-Id': 'req-' + str(uuids.generate_uuid())
}
return headers
def list_lease(self):
resp, body = self.get(self.lease)
resp, body = self.get(self.lease, headers=self._get_headers())
return self._response_helper(resp, body)
def get_lease(self, lease):
@ -41,36 +50,43 @@ class ResourceReservationV1Client(rest_client.RestClient):
def create_lease(self, body):
body = json.dump_as_bytes(body)
resp, body = self.post(self.lease, body=body)
resp, body = self.post(
self.lease, body=body, headers=self._get_headers())
return self._response_helper(resp, body)
def update_lease(self, lease, body):
body = json.dump_as_bytes(body)
resp, body = self.put(self.lease_path % lease, body=body)
resp, body = self.put(
self.lease_path % lease, body=body, headers=self._get_headers())
return self._response_helper(resp, body)
def delete_lease(self, lease):
resp, body = self.delete(self.lease_path % lease)
resp, body = self.delete(
self.lease_path % lease, headers=self._get_headers())
return self._response_helper(resp, body)
def list_host(self):
resp, body = self.get(self.host)
resp, body = self.get(self.host, headers=self._get_headers())
return self._response_helper(resp, body)
def get_host(self, host):
resp, body = self.get(self.host_path % host)
resp, body = self.get(
self.host_path % host, headers=self._get_headers())
return self._response_helper(resp, body)
def create_host(self, body):
body = json.dump_as_bytes(body)
resp, body = self.post(self.host, body=body)
resp, body = self.post(
self.host, body=body, headers=self._get_headers())
return self._response_helper(resp, body)
def update_host(self, host, body):
body = json.dump_as_bytes(body)
resp, body = self.put(self.host_path % host, body=body)
resp, body = self.put(
self.host_path % host, body=body, headers=self._get_headers())
return self._response_helper(resp, body)
def delete_host(self, host):
resp, body = self.delete(self.host_path % host)
resp, body = self.delete(
self.host_path % host, headers=self._get_headers())
return self._response_helper(resp, body)

View File

@ -7,5 +7,6 @@ six>=1.10.0 # MIT
oslo.config>=5.2.0 # Apache-2.0
oslo.log>=3.36.0 # Apache-2.0
oslo.serialization!=2.19.1,>=2.18.0 # Apache-2.0
oslo.utils>=3.37.0 # Apache-2.0
tempest>=17.1.0 # Apache-2.0
gabbi>=1.42.1 # Apache-2.0