Comment 4 for bug 1828543

Revision history for this message
Lajos Katona (lajos-katona) wrote :

I think I got to the depths of this issue. From this point I will refer to code and behavior on current master.

keystoneauth1 translates the http errors to exceptions (https://opendev.org/openstack/keystoneauth/src/branch/master/keystoneauth1/exceptions/http.py#L386).
The method from_response, expects that in case of json reply the html body is a json dict and has error key, and under that has a details key, like this (python code example):
body= {'error': {'message': 'Foooooo', 'details': 'Baaaaar'}}

Placement on the contrary sends something like this:
body={'errors': [{'status': 404, 'title': 'Not Found', 'detail': 'The resource could not be found.\n\n No resource provider with uuid ...... ', 'request_id': ''}]}

So keystone expects a key error, but placement sends errors, and under error placement excepts dict keys like details, and message, but placement sends a list of dicts and the dicts have keys like detail and title.

1) The quick and dirty solution can be that get_inventory (and other methods for placement client in neutron/neutron-lib which expects something useful in the exception details) to use the exception's response, like this:

except ks_exc.NotFound as e:
    if 'Fooo' in e.response.text:
        do_something_with_it()

2) Another future proof way should be to discuss the question with keystone and placement folks to
a) make placement send http errors the way keystone expects them.
b) make keystoneauth handle the perhaps more general http exceptions placement started to use.