gnocchixyz / python-gnocchiclient

Python client from Gnocchi

Home Page:http://gnocchi.xyz/gnocchiclient

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Most delete commands do not work when Gnocchi runs under Pecan >= 1.4

pshchelo opened this issue · comments

Not sure if that is a bug to file for Gnocchi itself (may be for docs only), but seemingly mostly the client is what is at fault here.

Pecan 1.4 (via WebOb 1.8) became more strict re "Accept" header handling.

Pylons/webob#403
pecan/pecan#119

Most delete handlers in Gnocchi API are exposed by pecan.expose() (like https://github.com/gnocchixyz/gnocchi/blob/5b5bb1ca744ca86a00f1ecf07271dc532ed4fab7/gnocchi/rest/api.py#L297 ) as they do not expect any body in the request or response.
On the other hand, Gnocchiclient always adds "Accept: application/json" to the headers of requests it makes -

"Accept": "application/json",

Thus, with new, more strict Pecan, most delete requests fail with HTTP 406 Not Acceptable as gnocchi api strictly can not return JSON here. This goes for every delete except for resource batch delete that is designed to return something and thus exposed with pecan.expose('json').

This should be solved in gnocchi API server with gnocchixyz/gnocchi#1090 when CI started testing Pecan >= 1.4 I think

Need to check what is returned now in these APIs in gnocci, because it might have changed from nothing/no content to literal null - decorating with expose('json') in pecan forces it to always return a valid json. Empty string / no body is not a valid JSON. Python returning nothing == returning None, so pecan encodes in as null which is a valid JSON to return.
And now we have a mismatch of HTTP 204 No Content that should have no body in response and yet some response body present.
Thus this change in gnocchi changed the return value of an API. May be OK for python client code, but probably not for every consumer of API.

I took a look at various OpenStack projects that are built on Pecan, and every one of them jumps thru some hoops to ensure the expose('json') decorated DELETE methods do in fact return no body with HTTP 204

I really hope the status code for DELETE responses was not changed, since that would violate the API, we test against that. However, I don't think the testing validates that the response body is empty.