Glance client not properly catching HTTP 300 Multiple Choice

Bug #850685 reported by Nicolas d
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance
Fix Released
Medium
Jay Pipes
Diablo
Fix Released
Undecided
Unassigned

Bug Description

Hi,

I was testing Glance auth using keystone. After some help finding the good param, I got this error :

> glance -d -v index
/usr/local/bin/glance:4: UserWarning: Module paste was already imported from None, but /usr/lib/python2.6/dist-packages is being added to sys.path
  import pkg_resources
Traceback (most recent call last):
  File "/usr/local/bin/glance", line 5, in <module>
    pkg_resources.run_script('glance==2012.1', 'glance')
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 467, in run_script
    self.require(requires)[0].run_script(script_name, ns)
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 1200, in run_script
    execfile(script_filename, namespace, namespace)
  File "/usr/local/lib/python2.6/dist-packages/glance-2012.1-py2.6.egg/EGG-INFO/scripts/glance", line 1204, in <module>
    result = command(options, args)
  File "/usr/local/lib/python2.6/dist-packages/glance-2012.1-py2.6.egg/EGG-INFO/scripts/glance", line 60, in wrapper
    ret = func(*args, **kwargs)
  File "/usr/local/lib/python2.6/dist-packages/glance-2012.1-py2.6.egg/EGG-INFO/scripts/glance", line 495, in images_index
    print_header=True)
  File "/usr/local/lib/python2.6/dist-packages/glance-2012.1-py2.6.egg/EGG-INFO/scripts/glance", line 441, in _images_index
    images = client.get_images(**parameters)
  File "/usr/local/lib/python2.6/dist-packages/glance-2012.1-py2.6.egg/glance/client.py", line 53, in get_images
    res = self.do_request("GET", "/images", params=params)
  File "/usr/local/lib/python2.6/dist-packages/glance-2012.1-py2.6.egg/glance/common/client.py", line 140, in do_request
    method, action, body=body, headers=headers, params=params)
  File "/usr/local/lib/python2.6/dist-packages/glance-2012.1-py2.6.egg/glance/common/client.py", line 234, in _do_request
    raise Exception("Unknown error occurred! %s" % res.read())
Exception: Unknown error occurred! {"versions": [{"status": "CURRENT", "id": "v1.1", "links": [{"href": "http://192.168.23.5:9292/v1/", "rel": "self"}]}, {"status": "SUPPORTED", "id": "v1.0", "links": [{"href": "http://192.168.23.5:9292/v1/", "rel": "self"}]}]}

Here the sampledata.py, I used for keystone : http://paste.openstack.org/show/2433/
And the vars fill with :
OS_AUTH_USER=admin
OS_AUTH_KEY=secrete
OS_AUTH_TENANT=test
OS_AUTH_URL=http://192.168.23.5:5000/v2.0
OS_AUTH_STRATEGY=keystone

Jay Pipes (jaypipes) who help me think that it's due to a bug in Glance client. I open this bug so we can track it.

Revision history for this message
Jay Pipes (jaypipes) wrote :

In glance/common/client.py, in the client's _do_request() method, need to catch a 300 error as well.

Changed in glance:
status: New → Triaged
importance: Undecided → Medium
milestone: none → essex-1
Revision history for this message
Nicolas d (nicolas2b) wrote :

Hi,

I'm looking for advices : I would like to fix this (it totally blocks me).
I see in client.py that, if the status code is OK, it return the response, otherwise it raise an exception.
Because HTTP 300 indicate multiple possible url, I think we must get those urls, find the current one and do an new request to this url. Am I correct ?
Should I do some kind of recursive call (called _do_request() with the new url) or put the request code in the if block ?

Thanks

--- Nicolas

Revision history for this message
Dolph Mathews (dolph) wrote :

Use older an older keystone pull (say, August 1st or so), as I'm not aware that any other projects are caught up with keystone's most recent changes.

Revision history for this message
Brian Waldon (bcwaldon) wrote :

I would check what management url Keystone is returning. It will override the default doc root of '/v1'. Can you show the output of an authentication request to your Keystone server?

It looks like your sample data has a bad glance endpoint (see line 37 in your paste). Using v1.1 will cause a multiple choices response.

Jay: I don't really want to code real 300-handling into glance client. It should only know how to speak one major (possibly minor) version of the api. The only 300 handling I would want to do is to present it as a client-side error (requesting an unsupported version).

Revision history for this message
Nicolas d (nicolas2b) wrote :

Hi,

You can find the output of an auth to my keystone server here : http://paste.openstack.org/show/2470/.

About my sample data, I don't find the problem,. Do you mean the change from an '.com' url to an ip ?
On the current git repo (https://github.com/openstack/keystone/blob/master/keystone/test/sampledata.py#L37), it uses 'v1.1'

Thanks

Revision history for this message
Jay Pipes (jaypipes) wrote : Re: [Bug 850685] Re: Glance client not properly catching HTTP 300 Multiple Choice

On Sun, Sep 18, 2011 at 1:48 PM, Brian Waldon
<email address hidden> wrote:
> Jay: I don't really want to code real 300-handling into glance client.
> It should only know how to speak one major (possibly minor) version of
> the api. The only 300 handling I would want to do is to present it as a
> client-side error (requesting an unsupported version).

That's fine. What it should NOT do is what it currently does and
return a 400 Bad Request :)

-jay

Revision history for this message
Brian Waldon (bcwaldon) wrote :

So in the case that a server and client cannot talk to each other (signified by a 300) we just need to catch it and present it to the user in a helpful way. I would support creating a specific exception in the client to wrap it with.

Jay Pipes (jaypipes)
Changed in glance:
assignee: nobody → Jay Pipes (jaypipes)
status: Triaged → In Progress
Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote : A change has been merged to openstack/glance

Reviewed: https://review.openstack.org/634
Committed: http://github.com/openstack/glance/commit/1bb0600efb444fa4d8a27e876a8c002324746c1e
Submitter: Jenkins
Branch: master

 status fixcommitted
 done

commit 1bb0600efb444fa4d8a27e876a8c002324746c1e
Author: Jay Pipes <email address hidden>
Date: Fri Sep 23 17:28:50 2011 -0400

    Fixes LP Bug #850685

    Handle 300 Multiple Choices gracefully in client

    This patch adds a new exception MultipleChoices that
    is now raised when the client encounters a 300 from the
    server, with a helpful error message indicating the likely
    cause is that the caller has forgotten to include a version
    string in the request URI.

    Change-Id: I3ccc2686bea30a770751fde605c78a3b7c5930b6

Changed in glance:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in glance:
status: Fix Committed → Fix Released
Revision history for this message
Openstack Gerrit (openstack-gerrit) wrote : Fix merged to glance (stable/diablo)

Reviewed: https://review.openstack.org/1771
Committed: http://github.com/openstack/glance/commit/9c7492e3b9e61f8d25a98cff308e484b1e139dcc
Submitter: Jenkins
Branch: stable/diablo

 tag in-stable-diablo
 done

commit 9c7492e3b9e61f8d25a98cff308e484b1e139dcc
Author: Jay Pipes <email address hidden>
Date: Fri Sep 23 17:28:50 2011 -0400

    Fixes LP Bug #850685

    Handle 300 Multiple Choices gracefully in client

    This patch adds a new exception MultipleChoices that
    is now raised when the client encounters a 300 from the
    server, with a helpful error message indicating the likely
    cause is that the caller has forgotten to include a version
    string in the request URI.

    (cherry picked from commit 1bb0600efb444fa4d8a27e876a8c002324746c1e)

    Change-Id: I3ccc2686bea30a770751fde605c78a3b7c5930b6

Thierry Carrez (ttx)
Changed in glance:
milestone: essex-1 → 2012.1
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.