From 529dc665a06bb6f28a38830d974dd2302db3bda8 Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Fri, 13 Jan 2017 09:46:00 -0600 Subject: [PATCH] Satisfy API Reference documentation deleting tags The API Reference documentation for Glance v2 documents the response status code for the metadefs delete-tags call as 204, but instead that call returns a 200 status code. This patch fixes the disparity and adds the ability to start testing our response serializer. This patch changes the response code instead of the documentation because 204 (No Content) is the correct response for this call and because all the other metadefs DELETE calls return 204. So to preserve consistency and to honor the published contract, this patch changes the code, not the documentation. This patch was discussed with the API-WG (on 2 Feb 2017) and the TC (on 14 Feb 2017), and they both endorse this approach. See the meeting logs for details. Closes-bug: #1656183 Depends-On: I84626976ca729f65b0ee0ea6afe5c9a6a408eecc Change-Id: I4b6dc1714aeca409a85bfa1f9b729147da704df8 --- glance/api/v2/metadef_namespaces.py | 3 +++ glance/tests/unit/v2/test_metadef_resources.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/glance/api/v2/metadef_namespaces.py b/glance/api/v2/metadef_namespaces.py index 9afab9dc0d..3bd44907c5 100644 --- a/glance/api/v2/metadef_namespaces.py +++ b/glance/api/v2/metadef_namespaces.py @@ -549,6 +549,9 @@ class ResponseSerializer(wsgi.JSONResponseSerializer): def delete_properties(self, response, result): response.status_int = http.NO_CONTENT + def delete_tags(self, response, result): + response.status_int = http.NO_CONTENT + def __render(self, json_data, response, response_status=None): body = jsonutils.dumps(json_data, ensure_ascii=False) response.unicode_body = six.text_type(body) diff --git a/glance/tests/unit/v2/test_metadef_resources.py b/glance/tests/unit/v2/test_metadef_resources.py index 8a5f3f2f52..2f120b648e 100644 --- a/glance/tests/unit/v2/test_metadef_resources.py +++ b/glance/tests/unit/v2/test_metadef_resources.py @@ -2064,3 +2064,16 @@ class TestMetadefsControllers(base.IsolatedUnitTest): self.tag_controller.update, request, tag, NAMESPACE4, TAG1) self.assertNotificationsLog([]) + + +class TestMetadefNamespaceResponseSerializers(base.IsolatedUnitTest): + + def setUp(self): + super(TestMetadefNamespaceResponseSerializers, self).setUp() + self.serializer = namespaces.ResponseSerializer(schema={}) + self.response = mock.Mock() + self.result = mock.Mock() + + def test_delete_tags(self): + self.serializer.delete_tags(self.response, self.result) + self.assertEqual(204, self.response.status_int)