Merge "splitting http req and resp logging also some pep8 cleanup in shell.py"

This commit is contained in:
Jenkins
2012-08-23 20:08:28 +00:00
committed by Gerrit Code Review
2 changed files with 18 additions and 11 deletions

View File

@@ -61,6 +61,13 @@ class HTTPClient(httplib2.Http):
self.force_exception_to_status_code = True self.force_exception_to_status_code = True
self.disable_ssl_certificate_validation = insecure self.disable_ssl_certificate_validation = insecure
# logging setup
self.debug_log = os.environ.get('KEYSTONECLIENT_DEBUG', False)
if self.debug_log:
ch = logging.StreamHandler()
_logger.setLevel(logging.DEBUG)
_logger.addHandler(ch)
def authenticate(self): def authenticate(self):
""" Authenticate against the keystone API. """ Authenticate against the keystone API.
@@ -77,12 +84,8 @@ class HTTPClient(httplib2.Http):
""" """
raise NotImplementedError raise NotImplementedError
def http_log(self, args, kwargs, resp, body): def http_log_req(self, args, kwargs):
if os.environ.get('KEYSTONECLIENT_DEBUG', False): if not self.debug_log:
ch = logging.StreamHandler()
_logger.setLevel(logging.DEBUG)
_logger.addHandler(ch)
elif not _logger.isEnabledFor(logging.DEBUG):
return return
string_parts = ['curl -i'] string_parts = ['curl -i']
@@ -99,6 +102,9 @@ class HTTPClient(httplib2.Http):
_logger.debug("REQ: %s\n" % "".join(string_parts)) _logger.debug("REQ: %s\n" % "".join(string_parts))
if 'body' in kwargs: if 'body' in kwargs:
_logger.debug("REQ BODY: %s\n" % (kwargs['body'])) _logger.debug("REQ BODY: %s\n" % (kwargs['body']))
def http_log_resp(self, resp, body):
if self.debug_log:
_logger.debug("RESP: %s\nRESP BODY: %s\n", resp, body) _logger.debug("RESP: %s\nRESP BODY: %s\n", resp, body)
def request(self, url, method, **kwargs): def request(self, url, method, **kwargs):
@@ -115,11 +121,11 @@ class HTTPClient(httplib2.Http):
request_kwargs['headers']['Content-Type'] = 'application/json' request_kwargs['headers']['Content-Type'] = 'application/json'
request_kwargs['body'] = json.dumps(kwargs['body']) request_kwargs['body'] = json.dumps(kwargs['body'])
self.http_log_req((url, method,), request_kwargs)
resp, body = super(HTTPClient, self).request(url, resp, body = super(HTTPClient, self).request(url,
method, method,
**request_kwargs) **request_kwargs)
self.http_log_resp(resp, body)
self.http_log((url, method,), request_kwargs, resp, body)
if body: if body:
try: try:

View File

@@ -204,7 +204,8 @@ class OpenStackIdentityShell(object):
return parser return parser
def _add_bash_completion_subparser(self, subparsers): def _add_bash_completion_subparser(self, subparsers):
subparser = subparsers.add_parser('bash_completion', subparser = subparsers.add_parser(
'bash_completion',
add_help=False, add_help=False,
formatter_class=OpenStackHelpFormatter formatter_class=OpenStackHelpFormatter
) )