Fix log_curl_request API version duplication

log_curl_request duplicates API version when logging request (e.g.
http://192.168.122.222:6385/v1/v1/nodes/detail). Trailing API version
should be removed from the ironic endpoint when constructing logged
string.

Closes-bug: #1395740
Change-Id: Ia3fc29ed0ccaf2fbe9fea041098dcf079d711e8f
This commit is contained in:
Vladyslav Drok 2014-11-24 16:27:06 +02:00
parent b4be05f7b5
commit f467415ba9

@ -36,10 +36,16 @@ CHUNKSIZE = 1024 * 64 # 64kB
API_VERSION = '/v1'
def _trim_endpoint_api_version(url):
"""Trim API version and trailing slash from endpoint."""
return url.rstrip('/').rstrip(API_VERSION)
class HTTPClient(object):
def __init__(self, endpoint, **kwargs):
self.endpoint = endpoint
self.endpoint_trimmed = _trim_endpoint_api_version(endpoint)
self.auth_token = kwargs.get('token')
self.auth_ref = kwargs.get('auth_ref')
self.connection_params = self.get_connection_params(endpoint, **kwargs)
@ -48,9 +54,7 @@ class HTTPClient(object):
def get_connection_params(endpoint, **kwargs):
parts = urlparse.urlparse(endpoint)
# trim API version and trailing slash from endpoint
path = parts.path
path = path.rstrip('/').rstrip(API_VERSION)
path = _trim_endpoint_api_version(parts.path)
_args = (parts.hostname, parts.port, path)
_kwargs = {'timeout': (float(kwargs.get('timeout'))
@ -101,7 +105,7 @@ class HTTPClient(object):
if 'body' in kwargs:
curl.append('-d \'%s\'' % kwargs['body'])
curl.append('%s%s' % (self.endpoint, url))
curl.append(urlparse.urljoin(self.endpoint_trimmed, url))
LOG.debug(' '.join(curl))
@staticmethod