let the list images fails fast if the glance API is not responding

Bug #1560093 reported by Andrea Rosa
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Glance Client
Confirmed
Wishlist
Unassigned

Bug Description

The list method of the images.py file (for both v1 and v2) version returns a generators over a list of images.
In case the client can't talk correctly with the glance API we have an exception but this exception is actually raised only once the generator is consumed.
The reason for this is that inside the nested paginate method the client trigger the API call to get the list of images [1] and as that method is a generator the excpetion is not caught immediately.
That leads to some ugly behaviour by the callers of the client method, for example in nova we have to "force" a consume of the generator to catch any potential excpetions [2].
I think the client should fails fast if it gets an error from the API, to do that it should be enough to separate the fetching of the images from the generator.

What do you think?

[1] https://github.com/openstack/python-glanceclient/blob/14b9ba29811d63aa6b61e877376cc538c32aeadc/glanceclient/v2/images.py#L108

[2] https://github.com/openstack/nova/blob/f03bbbab68408e0b3a311256962211b4f5d2cd1e/nova/image/glance.py#L251-L254

Revision history for this message
Cyril Roelandt (cyril-roelandt) wrote :

Failing early makes sense to me. You seem to know the code well, so do you know where the exception you are talking about is raised? I think it would also make sense to check the value of "resp" at https://github.com/openstack/python-glanceclient/blob/14b9ba29811d63aa6b61e877376cc538c32aeadc/glanceclient/v2/images.py#L108 .

Revision history for this message
Andrea Rosa (andrea-rosa-m) wrote :

I am not very familiar with glanceclient code but my understanding is that the line you pointed out could raise some exception as response back from the API server.
I agree with you that check the response code is a good thing to do.
Hope this helps

Revision history for this message
Cao ShuFeng (caosf-fnst) wrote :

If you really want to implement this, I suggest that we add a "retrieve_all=False" param to the list() function.
So that we can keep backward compatibility.
Maybe like this[1].

[1]: https://github.com/openstack/python-neutronclient/blob/master/neutronclient/v2_0/client.py#L353

Revision history for this message
Cyril Roelandt (cyril-roelandt) wrote :

Failing early makes sense to me. You seem to know the code well, so do you know where the exception you are talking about is raised? I think it would also make sense to check the value of "resp" at https://github.com/openstack/python-glanceclient/blob/14b9ba29811d63aa6b61e877376cc538c32aeadc/glanceclient/v2/images.py#L108 .

Revision history for this message
Cyril Roelandt (cyril-roelandt) wrote :

Oops, sorry for the repost :)

Revision history for this message
Andrea Rosa (andrea-rosa-m) wrote :

@caosf-fnst I am not going to work on this bug, in my opinion this is a low priority one and it could be classified as a wishlist, what do you think?

Ian Cordasco (icordasc)
Changed in python-glanceclient:
importance: Undecided → Wishlist
status: New → Confirmed
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.