keystoneclient should only attempt to decode JSON in msg body if the response was a success

Bug #1007661 reported by Joseph Heck
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Identity (keystone)
Fix Released
Low
Joseph Heck

Bug Description

Since errors could be non-JSON encoded strings, the body in the JSON client should only attempt to be decoded on a 2xx success mode.

error from dashboard logging:

Recoverable error: n/a (HTTP 400)
Creating a new keystoneclient connection to http://proxy:5000/v2.0.
REQ: curl -i http://proxy:5000/v2.0/tenants -X GET -H "User-Agent: python-keystoneclient" -H "X-Auth-Token: 8f45e1bca50d420fbc544380109f1fde"
RESP: {'status': '400', 'content-length': 36, 'content-type': 'text/plain'}
RESP BODY: Unable to find the server at haproxy
Could not decode JSON from body: Unable to find the server at haproxy
Request returned failure status.
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/keystoneclient/client.py", line 121, in request
body = json.loads(body)
File "/usr/lib/python2.7/json/_init_.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 384, in raw_decode
raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded
Could not retrieve tenant list.
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/horizon/users.py", line 155, in authorized_tenants
authd = api.tenant_list_for_token(self._request, token)
File "/usr/lib/python2.7/dist-packages/horizon/api/keystone.py", line 165, in tenant_list_for_token
return c.tenants.list()
File "/usr/lib/python2.7/dist-packages/keystoneclient/v2_0/tenants.py", line 90, in list
return self._list("/tenants%s" % query, "tenants")
File "/usr/lib/python2.7/dist-packages/keystoneclient/base.py", line 65, in _list
resp, body = self.api.get(url)
File "/usr/lib/python2.7/dist-packages/keystoneclient/client.py", line 166, in get
return self._cs_request(url, 'GET', **kwargs)
File "/usr/lib/python2.7/dist-packages/keystoneclient/client.py", line 150, in _cs_request
**kwargs)
File "/usr/lib/python2.7/dist-packages/keystoneclient/client.py", line 130, in request
raise exceptions.from_response(resp, body)
BadRequest: Unable to communicate with identity service: Unable to find the server at haproxy. (HTTP 400)
novaclient connection created using token "08e95a0d6bb4453392aed4016567602c" and url "http://haproxy:8774/v2/a7e78652440641009d1065c163de6d87"
REQ: curl -i http://haproxy:8774/v2/a7e78652440641009d1065c163de6d87/servers/detail?project_id=a7e78652440641009d1065c163de6d87 -X GET -H "X-Auth-Project-Id: a7e78652440641009d1065c163de6d87" -H "User-Agent: python-novaclient" -H "Accept: application/json" -H "X-Auth-Token: 08e95a0d6bb4453392aed4016567602c"

Joseph Heck (heckj)
Changed in keystone:
status: New → Triaged
importance: Undecided → Low
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to python-keystoneclient (master)

Fix proposed to branch: master
Review: https://review.openstack.org/8155

Changed in keystone:
assignee: nobody → Joseph Heck (heckj)
status: Triaged → In Progress
Revision history for this message
Joseph Heck (heckj) wrote :

Switching to invalid per Dolph's example of how changing the flow reduces the value of information directly logged to the client:

$ git checkout master
Already on 'master'

$ keystone --token=ADMIN --endpoint=http://localhost:35357/v2.0/tokens user-list
Could not find token: users (HTTP 404)

$ git fetch ssh://<email address hidden>:29418/openstack/python-keystoneclient refs/changes/55/8155/1 && git checkout FETCH_HEAD
From ssh://review.openstack.org:29418/openstack/python-keystoneclient
 * branch refs/changes/55/8155/1 -> FETCH_HEAD
Note: checking out 'FETCH_HEAD'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at bc0196e... decoding json only on 2xx success response bug 1007661

$ keystone --token=ADMIN --endpoint=http://localhost:35357/v2.0/tokens user-list
Unable to communicate with identity service: {"error": {"message": "Could not find token: users", "code": 404, "title": "Not Found"}}. (HTTP 404)

Changed in keystone:
status: In Progress → Invalid
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to python-keystoneclient (master)

Reviewed: https://review.openstack.org/8155
Committed: http://github.com/openstack/python-keystoneclient/commit/f75310c623ebebec3e23335e6dab07fabbddd423
Submitter: Jenkins
Branch: master

commit f75310c623ebebec3e23335e6dab07fabbddd423
Author: Joe Heck <email address hidden>
Date: Fri Jun 1 17:03:35 2012 -0700

    decoding json only on 2xx success response
    bug 1007661

    Change-Id: I9090c78bb9a19ae46d865fca80af0b3bf4257dc6

Changed in keystone:
status: Invalid → Fix Committed
Thierry Carrez (ttx)
Changed in keystone:
milestone: none → folsom-2
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in keystone:
milestone: folsom-2 → 2012.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.