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 <zhaochao1984@gmail.com>
This commit is contained in:
Zhao Chao 2018-03-02 17:03:44 +08:00
parent f71719a0f3
commit d597bb4714
8 changed files with 12 additions and 7 deletions

View File

@ -1,4 +1,4 @@
HTTP/1.1 200 OK HTTP/1.1 204 No Content
Content-Type: application/json Content-Type: application/json
Content-Length: 0 Content-Length: 0
Date: Mon, 18 Mar 2013 19:09:17 GMT Date: Mon, 18 Mar 2013 19:09:17 GMT

View File

@ -92,7 +92,7 @@ Disable root user
Disables the root user. Disables the root user.
Normal response codes: 202 Normal response codes: 204
Error response codes: badRequest(400), unauthorized(401), forbidden(403), Error response codes: badRequest(400), unauthorized(401), forbidden(403),
itemNotFound(404), badMethod(405), overLimit(413), unprocessableEntity(422), itemNotFound(404), badMethod(405), overLimit(413), unprocessableEntity(422),

View File

@ -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.

View File

@ -120,7 +120,7 @@ class DefaultRootController(BaseDatastoreRootController):
if not is_root_enabled: if not is_root_enabled:
raise exception.RootHistoryNotFound() raise exception.RootHistoryNotFound()
models.Root.delete(context, instance_id) models.Root.delete(context, instance_id)
return wsgi.Result(None, 200) return wsgi.Result(None, 204)
class ClusterRootController(DefaultRootController): class ClusterRootController(DefaultRootController):

View File

@ -184,5 +184,5 @@ class TestRoot(object):
reh = self.dbaas_admin.management.root_enabled_history reh = self.dbaas_admin.management.root_enabled_history
self.root_enabled_timestamp = reh(instance_info.id).enabled self.root_enabled_timestamp = reh(instance_info.id).enabled
self.dbaas.root.delete(instance_info.id) 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) self._verify_root_timestamp(instance_info.id)

View File

@ -124,7 +124,7 @@ class TestRootOnCreate(object):
is still enabled. is still enabled.
""" """
self.dbaas.root.delete(self.instance_id) 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 enabled = self.enabled(self.instance_id).rootEnabled
assert_equal(200, self.dbaas.last_http_code) assert_equal(200, self.dbaas.last_http_code)

View File

@ -508,7 +508,7 @@ class Root(Example):
self.snippet( self.snippet(
"disable_root_user", "disable_root_user",
"/instances/%s/root" % json_instance.id, "/instances/%s/root" % json_instance.id,
"DELETE", 200, "OK", "DELETE", 204, "No Content",
lambda client: client.root.delete(json_instance.id)) lambda client: client.root.delete(json_instance.id))
# restore root for subsequent tests # restore root for subsequent tests

View File

@ -120,7 +120,7 @@ class RootActionsRunner(TestRunner):
raise SkipTest("No valid root password defined in %s." raise SkipTest("No valid root password defined in %s."
% self.test_helper.get_class_name()) % 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.restored_root_creds2 = list(self.current_root_creds)
self.assert_root_disable(self.instance_info.id, expected_http_code) self.assert_root_disable(self.instance_info.id, expected_http_code)