gnocchixyz / python-gnocchiclient

Python client from Gnocchi
http://gnocchi.xyz/gnocchiclient
Apache License 2.0
13 stars 28 forks source link

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

Open pshchelo opened 1 year ago

pshchelo commented 1 year ago

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.

https://github.com/Pylons/webob/issues/403 https://github.com/pecan/pecan/pull/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 - https://github.com/gnocchixyz/python-gnocchiclient/blob/e2075f0f2e26c8fc12f6ee0c8e3ad506c232136e/gnocchiclient/v1/base.py#L21

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').

tobias-urdin commented 1 year ago

This should be solved in gnocchi API server with https://github.com/gnocchixyz/gnocchi/pull/1090 when CI started testing Pecan >= 1.4 I think

pshchelo commented 1 year ago

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

tobias-urdin commented 1 year ago

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.