Sophie

Sophie

distrib > Fedora > 18 > i386 > by-pkgid > 0305113317f9e80328b139dce3f45533 > files > 5

python-quantumclient-2.1-1.fc18.src.rpm

From 7146e402f185a6a341934abd7db7cd56019b3a44 Mon Sep 17 00:00:00 2001
From: gongysh <gongysh@cn.ibm.com>
Date: Fri, 9 Nov 2012 19:36:30 +0800
Subject: [PATCH] Fix curl command for PUT and DELETE.

Bug #1076968

We print request curl command before HTTP request,
and response information after HTTP request.

Change-Id: I19840e8bd606a30389cd029c0add066c945fcdf6
---
 quantumclient/client.py       |  5 ++---
 quantumclient/common/utils.py | 40 ++++++++++++++++++++++------------------
 2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/quantumclient/client.py b/quantumclient/client.py
index 18bb3de..39e770e 100644
--- a/quantumclient/client.py
+++ b/quantumclient/client.py
@@ -123,10 +123,9 @@ class HTTPClient(httplib2.Http):
 
         if 'body' in kwargs:
             kargs['body'] = kwargs['body']
-
+        utils.http_log_req(_logger, args, kargs)
         resp, body = self.request(*args, **kargs)
-
-        utils.http_log(_logger, args, kargs, resp, body)
+        utils.http_log_resp(_logger, resp, body)
         status_code = self.get_status_code(resp)
         if status_code == 401:
             raise exceptions.Unauthorized(message=body)
diff --git a/quantumclient/common/utils.py b/quantumclient/common/utils.py
index bed02e0..45c64a9 100644
--- a/quantumclient/common/utils.py
+++ b/quantumclient/common/utils.py
@@ -148,23 +148,27 @@ def str2dict(strdict):
         return _info
 
 
-def http_log(_logger, args, kwargs, resp, body):
-        if not _logger.isEnabledFor(logging.DEBUG):
-            return
-
-        string_parts = ['curl -i']
-        for element in args:
-            if element in ('GET', 'POST'):
-                string_parts.append(' -X %s' % element)
-            else:
-                string_parts.append(' %s' % element)
+def http_log_req(_logger, args, kwargs):
+    if not _logger.isEnabledFor(logging.DEBUG):
+        return
+
+    string_parts = ['curl -i']
+    for element in args:
+        if element in ('GET', 'POST', 'DELETE', 'PUT'):
+            string_parts.append(' -X %s' % element)
+        else:
+            string_parts.append(' %s' % element)
+
+    for element in kwargs['headers']:
+        header = ' -H "%s: %s"' % (element, kwargs['headers'][element])
+        string_parts.append(header)
+
+    if 'body' in kwargs and kwargs['body']:
+        string_parts.append(" -d '%s'" % (kwargs['body']))
+    _logger.debug("\nREQ: %s\n" % "".join(string_parts))
 
-        for element in kwargs['headers']:
-            header = ' -H "%s: %s"' % (element, kwargs['headers'][element])
-            string_parts.append(header)
 
-        _logger.debug("REQ: %s\n" % "".join(string_parts))
-        if 'body' in kwargs and kwargs['body']:
-            _logger.debug("REQ BODY: %s\n" % (kwargs['body']))
-        _logger.debug("RESP:%s\n", resp)
-        _logger.debug("RESP BODY:%s\n", body)
+def http_log_resp(_logger, resp, body):
+    if not _logger.isEnabledFor(logging.DEBUG):
+        return
+    _logger.debug("RESP:%s %s\n", resp, body)