From d597bb4714e666c924e8a48ad30ebad71a3b45ed Mon Sep 17 00:00:00 2001 From: Zhao Chao Date: Fri, 2 Mar 2018 17:03:44 +0800 Subject: [PATCH] Return 204 instead of 200 for root-disable API As no content will be returned to the client if a root-disable request succeeds, a HTTP 204 (Not Content) response is more appropriate. Redis root-disable scenario test fails because it's return HTTP 204, but all API related tests are expecting a HTTP 200. Although changing Redis root-disable API is a much simpler way to resolve the problem, migrating from HTTP 200 to HTTP 204 should be a better solution. Related tests and documents are also updated accordingly. APIImpact Change-Id: If732a578009fd35436e810fb7ceceefd1ada3778 Signed-off-by: Zhao Chao --- .../samples/db-disable-root-user-response-json-http.txt | 2 +- api-ref/source/user-management.inc | 2 +- ...eturn-http-204-for-disable-root-api-a818fc41fd6e75eb.yaml | 5 +++++ trove/extensions/common/service.py | 2 +- trove/tests/api/root.py | 2 +- trove/tests/api/root_on_create.py | 2 +- trove/tests/examples/snippets.py | 2 +- trove/tests/scenario/runners/root_actions_runners.py | 2 +- 8 files changed, 12 insertions(+), 7 deletions(-) create mode 100644 releasenotes/notes/return-http-204-for-disable-root-api-a818fc41fd6e75eb.yaml diff --git a/api-ref/source/samples/db-disable-root-user-response-json-http.txt b/api-ref/source/samples/db-disable-root-user-response-json-http.txt index 031611acd7..17632f6ae4 100644 --- a/api-ref/source/samples/db-disable-root-user-response-json-http.txt +++ b/api-ref/source/samples/db-disable-root-user-response-json-http.txt @@ -1,4 +1,4 @@ -HTTP/1.1 200 OK +HTTP/1.1 204 No Content Content-Type: application/json Content-Length: 0 Date: Mon, 18 Mar 2013 19:09:17 GMT diff --git a/api-ref/source/user-management.inc b/api-ref/source/user-management.inc index 595c442ec8..d17be907d2 100644 --- a/api-ref/source/user-management.inc +++ b/api-ref/source/user-management.inc @@ -92,7 +92,7 @@ Disable root user Disables the root user. -Normal response codes: 202 +Normal response codes: 204 Error response codes: badRequest(400), unauthorized(401), forbidden(403), itemNotFound(404), badMethod(405), overLimit(413), unprocessableEntity(422), diff --git a/releasenotes/notes/return-http-204-for-disable-root-api-a818fc41fd6e75eb.yaml b/releasenotes/notes/return-http-204-for-disable-root-api-a818fc41fd6e75eb.yaml new file mode 100644 index 0000000000..ee404465fa --- /dev/null +++ b/releasenotes/notes/return-http-204-for-disable-root-api-a818fc41fd6e75eb.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Peviously root disable API returns a HTTP 200 response without any content, + a HTTP 204 reponse which is more appropriate will be returned now. diff --git a/trove/extensions/common/service.py b/trove/extensions/common/service.py index 75a659411f..5b8bf16191 100644 --- a/trove/extensions/common/service.py +++ b/trove/extensions/common/service.py @@ -120,7 +120,7 @@ class DefaultRootController(BaseDatastoreRootController): if not is_root_enabled: raise exception.RootHistoryNotFound() models.Root.delete(context, instance_id) - return wsgi.Result(None, 200) + return wsgi.Result(None, 204) class ClusterRootController(DefaultRootController): diff --git a/trove/tests/api/root.py b/trove/tests/api/root.py index f18a29e36b..72b17bf01e 100644 --- a/trove/tests/api/root.py +++ b/trove/tests/api/root.py @@ -184,5 +184,5 @@ class TestRoot(object): reh = self.dbaas_admin.management.root_enabled_history self.root_enabled_timestamp = reh(instance_info.id).enabled self.dbaas.root.delete(instance_info.id) - assert_equal(200, self.dbaas.last_http_code) + assert_equal(204, self.dbaas.last_http_code) self._verify_root_timestamp(instance_info.id) diff --git a/trove/tests/api/root_on_create.py b/trove/tests/api/root_on_create.py index 13266e6e02..37f05b9478 100644 --- a/trove/tests/api/root_on_create.py +++ b/trove/tests/api/root_on_create.py @@ -124,7 +124,7 @@ class TestRootOnCreate(object): is still enabled. """ self.dbaas.root.delete(self.instance_id) - assert_equal(200, self.dbaas.last_http_code) + assert_equal(204, self.dbaas.last_http_code) enabled = self.enabled(self.instance_id).rootEnabled assert_equal(200, self.dbaas.last_http_code) diff --git a/trove/tests/examples/snippets.py b/trove/tests/examples/snippets.py index 06c7601eee..6194fd3f8a 100644 --- a/trove/tests/examples/snippets.py +++ b/trove/tests/examples/snippets.py @@ -508,7 +508,7 @@ class Root(Example): self.snippet( "disable_root_user", "/instances/%s/root" % json_instance.id, - "DELETE", 200, "OK", + "DELETE", 204, "No Content", lambda client: client.root.delete(json_instance.id)) # restore root for subsequent tests diff --git a/trove/tests/scenario/runners/root_actions_runners.py b/trove/tests/scenario/runners/root_actions_runners.py index c95793e9a6..2ecec2f699 100644 --- a/trove/tests/scenario/runners/root_actions_runners.py +++ b/trove/tests/scenario/runners/root_actions_runners.py @@ -120,7 +120,7 @@ class RootActionsRunner(TestRunner): raise SkipTest("No valid root password defined in %s." % self.test_helper.get_class_name()) - def run_disable_root(self, expected_http_code=200): + def run_disable_root(self, expected_http_code=204): self.restored_root_creds2 = list(self.current_root_creds) self.assert_root_disable(self.instance_info.id, expected_http_code)