From 3d19fe843f9cc698c857ba35237ef44db60c96a8 Mon Sep 17 00:00:00 2001 From: Tetsuro Nakamura Date: Wed, 17 Jul 2019 01:42:55 +0000 Subject: [PATCH] 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 --- .../reservation/reservation_client.py | 34 ++++++++++++++----- requirements.txt | 1 + 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/blazar_tempest_plugin/services/reservation/reservation_client.py b/blazar_tempest_plugin/services/reservation/reservation_client.py index 32c355c..ba89129 100644 --- a/blazar_tempest_plugin/services/reservation/reservation_client.py +++ b/blazar_tempest_plugin/services/reservation/reservation_client.py @@ -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) diff --git a/requirements.txt b/requirements.txt index ae74d89..72b1b33 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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