Merge "Repair package-update command"

This commit is contained in:
Jenkins 2016-01-18 10:00:25 +00:00 committed by Gerrit Code Review
commit 89176536a1
2 changed files with 31 additions and 12 deletions

View File

@ -302,35 +302,50 @@ class HTTPClient(object):
return self.client_request("PATCH", url, **kwargs)
class SessionClient(keystone_adapter.LegacyJsonAdapter):
class SessionClient(keystone_adapter.Adapter):
"""Murano specific keystoneclient Adapter.
Murano can't use keystoneclient LegacyJsonAdapter, because murano has the
check for right content-type for "update" operation which is
'application/murano-packages-json-patch'. So, we need to create our own
adapter.
"""
def request(self, url, method, **kwargs):
raise_exc = kwargs.pop('raise_exc', True)
resp, body = super(SessionClient, self).request(url,
method,
raise_exc=False,
**kwargs)
resp = super(SessionClient, self).request(url,
method,
raise_exc=False,
**kwargs)
if raise_exc and resp.status_code >= 400:
LOG.trace("Error communicating with {url}: {exc}"
.format(url=url, exc=exc.from_response(resp)))
raise exc.from_response(resp)
return resp, body
return resp, resp.text
def json_request(self, method, url, **kwargs):
# Legacy adapter expects the payload in 'body', but
# will pass it to the non-legacy adapter in the
# 'json' spot so encoding happens later
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = kwargs.pop('content_type',
'application/json')
if 'data' in kwargs:
if 'body' in kwargs:
raise ValueError("Can't provide both 'data' and "
"'body' to a request")
LOG.warning("Use of 'body' is deprecated; use 'data' instead")
kwargs['body'] = kwargs.pop('data')
kwargs['data'] = jsonutils.dumps(kwargs['data'])
# NOTE(starodubcevna): We need to prove that json field is empty,
# or it will be modified by keystone adapter.
kwargs['json'] = None
# The argument order is different, beware
return self.request(url, method, **kwargs)
resp, body = self.request(url, method, **kwargs)
if body:
try:
body = jsonutils.loads(body)
except ValueError:
pass
return resp, body
def json_patch_request(self, url, method='PATCH', **kwargs):
content_type = 'application/murano-packages-json-patch'

View File

@ -0,0 +1,4 @@
fixes:
- command 'package_update' was broken since murano start support of keystone v3.
The error occured because murano tried to pass custom content type parameter
in the request kwargs, not headers.