simplify rest_client logging

this takes the rest client req/resp down to a single short info
line per call. This eliminates the issue where the multiline output
is interleaved between many testr process, thus confusing. It
should be a pretty concise view of the rest calls being made from
tempest.

It removes parameters that were previously used for debug. We'll
incrementally add these back if this was too much removal.

Change-Id: I342483e2a3c1396537df1fab825ebef8a7e75101
diff --git a/tempest/common/rest_client.py b/tempest/common/rest_client.py
index 88dbe58..7d90d69 100644
--- a/tempest/common/rest_client.py
+++ b/tempest/common/rest_client.py
@@ -15,7 +15,6 @@
 #    under the License.
 
 import collections
-import hashlib
 import json
 from lxml import etree
 import re
@@ -224,44 +223,20 @@
         versions = map(lambda x: x['id'], body)
         return resp, versions
 
-    def _log_request(self, method, req_url, headers, body):
-        self.LOG.info('Request: ' + method + ' ' + req_url)
-        if headers:
-            print_headers = headers
-            if 'X-Auth-Token' in headers and headers['X-Auth-Token']:
-                token = headers['X-Auth-Token']
-                if len(token) > 64 and TOKEN_CHARS_RE.match(token):
-                    print_headers = headers.copy()
-                    print_headers['X-Auth-Token'] = "<Token omitted>"
-            self.LOG.debug('Request Headers: ' + str(print_headers))
-        if body:
-            str_body = str(body)
-            length = len(str_body)
-            self.LOG.debug('Request Body: ' + str_body[:2048])
-            if length >= 2048:
-                self.LOG.debug("Large body (%d) md5 summary: %s", length,
-                               hashlib.md5(str_body).hexdigest())
+    def _get_request_id(self, resp):
+        for i in ('x-openstack-request-id', 'x-compute-request-id'):
+            if i in resp:
+                return resp[i]
+        return ""
 
-    def _log_response(self, resp, resp_body):
-        status = resp['status']
-        self.LOG.info("Response Status: " + status)
-        headers = resp.copy()
-        del headers['status']
-        if headers.get('x-compute-request-id'):
-            self.LOG.info("Nova/Cinder request id: %s" %
-                          headers.pop('x-compute-request-id'))
-        elif headers.get('x-openstack-request-id'):
-            self.LOG.info("OpenStack request id %s" %
-                          headers.pop('x-openstack-request-id'))
-        if len(headers):
-            self.LOG.debug('Response Headers: ' + str(headers))
-        if resp_body:
-            str_body = str(resp_body)
-            length = len(str_body)
-            self.LOG.debug('Response Body: ' + str_body[:2048])
-            if length >= 2048:
-                self.LOG.debug("Large body (%d) md5 summary: %s", length,
-                               hashlib.md5(str_body).hexdigest())
+    def _log_request(self, method, req_url, resp):
+        extra = dict(request_id=self._get_request_id(resp))
+        self.LOG.info(
+            'Request: %s %s %s' % (
+                resp['status'],
+                method,
+                req_url),
+            extra=extra)
 
     def _parse_resp(self, body):
         if self._get_type() is "json":
@@ -340,11 +315,11 @@
         # Authenticate the request with the auth provider
         req_url, req_headers, req_body = self.auth_provider.auth_request(
             method, url, headers, body, self.filters)
-        self._log_request(method, req_url, req_headers, req_body)
+
         # Do the actual request
         resp, resp_body = self.http_obj.request(
             req_url, method, headers=req_headers, body=req_body)
-        self._log_response(resp, resp_body)
+        self._log_request(method, req_url, resp)
         # Verify HTTP response codes
         self.response_checker(method, url, req_headers, req_body, resp,
                               resp_body)
diff --git a/tempest/services/identity/json/identity_client.py b/tempest/services/identity/json/identity_client.py
index 99b4036..58451fb 100644
--- a/tempest/services/identity/json/identity_client.py
+++ b/tempest/services/identity/json/identity_client.py
@@ -276,10 +276,9 @@
             # Because XML response is not easily
             # converted to the corresponding JSON one
             headers = self.get_headers(accept_type="json")
-        self._log_request(method, url, headers, body)
         resp, resp_body = self.http_obj.request(url, method,
                                                 headers=headers, body=body)
-        self._log_response(resp, resp_body)
+        self._log_request(method, url, resp)
 
         if resp.status in [401, 403]:
             resp_body = json.loads(resp_body)
diff --git a/tempest/services/identity/v3/json/identity_client.py b/tempest/services/identity/v3/json/identity_client.py
index 65f3355..113cb9a 100644
--- a/tempest/services/identity/v3/json/identity_client.py
+++ b/tempest/services/identity/v3/json/identity_client.py
@@ -503,10 +503,9 @@
             # Because XML response is not easily
             # converted to the corresponding JSON one
             headers = self.get_headers(accept_type="json")
-        self._log_request(method, url, headers, body)
         resp, resp_body = self.http_obj.request(url, method,
                                                 headers=headers, body=body)
-        self._log_response(resp, resp_body)
+        self._log_request(method, url, resp)
 
         if resp.status in [401, 403]:
             resp_body = json.loads(resp_body)
diff --git a/tempest/services/identity/v3/xml/identity_client.py b/tempest/services/identity/v3/xml/identity_client.py
index 6ff6d56..492e639 100644
--- a/tempest/services/identity/v3/xml/identity_client.py
+++ b/tempest/services/identity/v3/xml/identity_client.py
@@ -491,10 +491,9 @@
             # Because XML response is not easily
             # converted to the corresponding JSON one
             headers = self.get_headers(accept_type="json")
-        self._log_request(method, url, headers, body)
         resp, resp_body = self.http_obj.request(url, method,
                                                 headers=headers, body=body)
-        self._log_response(resp, resp_body)
+        self._log_request(method, url, resp)
 
         if resp.status in [401, 403]:
             resp_body = json.loads(resp_body)
diff --git a/tempest/services/object_storage/account_client.py b/tempest/services/object_storage/account_client.py
index 7c3fa85..6e7910e 100644
--- a/tempest/services/object_storage/account_client.py
+++ b/tempest/services/object_storage/account_client.py
@@ -173,12 +173,11 @@
             method=method, url=url, headers=headers, body=body,
             filters=self.filters
         )
-        self._log_request(method, req_url, headers, body)
         # use original body
         resp, resp_body = self.http_obj.request(req_url, method,
                                                 headers=req_headers,
                                                 body=req_body)
-        self._log_response(resp, resp_body)
+        self._log_request(method, req_url, resp)
 
         if resp.status == 401 or resp.status == 403:
             raise exceptions.Unauthorized()
diff --git a/tempest/services/object_storage/object_client.py b/tempest/services/object_storage/object_client.py
index 77d29a5..49f7f49 100644
--- a/tempest/services/object_storage/object_client.py
+++ b/tempest/services/object_storage/object_client.py
@@ -160,11 +160,10 @@
             filters=self.filters
         )
         # Use original method
-        self._log_request(method, req_url, headers, body)
         resp, resp_body = self.http_obj.request(req_url, method,
                                                 headers=req_headers,
                                                 body=req_body)
-        self._log_response(resp, resp_body)
+        self._log_request(method, req_url, resp)
         if resp.status == 401 or resp.status == 403:
             raise exceptions.Unauthorized()
 
diff --git a/tempest/tests/test_rest_client.py b/tempest/tests/test_rest_client.py
index da9ab72..0677aa0 100644
--- a/tempest/tests/test_rest_client.py
+++ b/tempest/tests/test_rest_client.py
@@ -43,7 +43,7 @@
         self.useFixture(mockpatch.PatchObject(self.rest_client, '_get_region',
                                               side_effect=self._get_region()))
         self.useFixture(mockpatch.PatchObject(self.rest_client,
-                                              '_log_response'))
+                                              '_log_request'))
 
 
 class TestRestClientHTTPMethods(BaseRestClientTestClass):