Fix POST and PUT status codes and update API Reference
Blazar returned 202 (Accepted) for POST and PUT methods. However, the POST method should return 201 (Created) because Blazar ensures that a new host or a new lease is created before responding. Similarly, the PUT method should return 200 (OK) since Blazar ensures that the resource is updated properly. This patch also fixes the status code documented in the API Reference for DELETE requests, which was wrongly described as 200 (OK) instead of 204 (No Content). The release note is submitted in a separate patch. Change-Id: Ia5afd12552e4c9169ebe35324d5a5b4495359b63
This commit is contained in:

committed by
Hiroaki Kobayashi

parent
84785b7dde
commit
9da871ac59
@@ -59,7 +59,7 @@ Create a host.
|
|||||||
|
|
||||||
**Response codes**
|
**Response codes**
|
||||||
|
|
||||||
Normal response code: 200
|
Normal response code: 201
|
||||||
|
|
||||||
Error response codes: Bad Request(400), Unauthorized(401), Forbidden(403),
|
Error response codes: Bad Request(400), Unauthorized(401), Forbidden(403),
|
||||||
Conflict(409), Internal Server Error(500)
|
Conflict(409), Internal Server Error(500)
|
||||||
@@ -227,7 +227,7 @@ The host must exist.
|
|||||||
|
|
||||||
**Response codes**
|
**Response codes**
|
||||||
|
|
||||||
Normal response code: 200
|
Normal response code: 204
|
||||||
|
|
||||||
Error response codes: Bad Request(400), Unauthorized(401), Forbidden(403),
|
Error response codes: Bad Request(400), Unauthorized(401), Forbidden(403),
|
||||||
Not Found(404), Conflict(409), Internal Server Error(500)
|
Not Found(404), Conflict(409), Internal Server Error(500)
|
||||||
|
@@ -111,7 +111,7 @@ Create a lease.
|
|||||||
|
|
||||||
**Response codes**
|
**Response codes**
|
||||||
|
|
||||||
Normal response code: 200
|
Normal response code: 201
|
||||||
|
|
||||||
Error response codes: Bad Request(400), Unauthorized(401), Forbidden(403),
|
Error response codes: Bad Request(400), Unauthorized(401), Forbidden(403),
|
||||||
Conflict(409), Internal Server Error(500)
|
Conflict(409), Internal Server Error(500)
|
||||||
@@ -500,7 +500,7 @@ The lease must exist.
|
|||||||
|
|
||||||
**Response codes**
|
**Response codes**
|
||||||
|
|
||||||
Normal response codes: 200
|
Normal response codes: 204
|
||||||
|
|
||||||
Error response codes: Bad Request(400), Unauthorized(401), Forbidden(403), Not Found(404),
|
Error response codes: Bad Request(400), Unauthorized(401), Forbidden(403), Not Found(404),
|
||||||
Conflict(409), Internal Server Error(500)
|
Conflict(409), Internal Server Error(500)
|
||||||
|
@@ -36,10 +36,10 @@ class Rest(flask.Blueprint):
|
|||||||
def get(self, rule, status_code=200):
|
def get(self, rule, status_code=200):
|
||||||
return self._mroute('GET', rule, status_code)
|
return self._mroute('GET', rule, status_code)
|
||||||
|
|
||||||
def post(self, rule, status_code=202):
|
def post(self, rule, status_code=201):
|
||||||
return self._mroute('POST', rule, status_code)
|
return self._mroute('POST', rule, status_code)
|
||||||
|
|
||||||
def put(self, rule, status_code=202):
|
def put(self, rule, status_code=200):
|
||||||
return self._mroute('PUT', rule, status_code)
|
return self._mroute('PUT', rule, status_code)
|
||||||
|
|
||||||
def delete(self, rule, status_code=204):
|
def delete(self, rule, status_code=204):
|
||||||
|
@@ -127,7 +127,7 @@ class HostsController(extensions.BaseController):
|
|||||||
pecan.request.hosts_rpcapi.list_computehosts()]
|
pecan.request.hosts_rpcapi.list_computehosts()]
|
||||||
|
|
||||||
@policy.authorize('oshosts', 'post')
|
@policy.authorize('oshosts', 'post')
|
||||||
@wsme_pecan.wsexpose(Host, body=Host, status_code=202)
|
@wsme_pecan.wsexpose(Host, body=Host, status_code=201)
|
||||||
@trusts.use_trust_auth()
|
@trusts.use_trust_auth()
|
||||||
def post(self, host):
|
def post(self, host):
|
||||||
"""Creates a new host.
|
"""Creates a new host.
|
||||||
@@ -145,8 +145,7 @@ class HostsController(extensions.BaseController):
|
|||||||
raise exceptions.BlazarException(_("Host can't be created"))
|
raise exceptions.BlazarException(_("Host can't be created"))
|
||||||
|
|
||||||
@policy.authorize('oshosts', 'put')
|
@policy.authorize('oshosts', 'put')
|
||||||
@wsme_pecan.wsexpose(Host, types.IntegerType(), body=Host,
|
@wsme_pecan.wsexpose(Host, types.IntegerType(), body=Host)
|
||||||
status_code=202)
|
|
||||||
def put(self, id, host):
|
def put(self, id, host):
|
||||||
"""Update an existing host.
|
"""Update an existing host.
|
||||||
|
|
||||||
|
@@ -104,7 +104,7 @@ class LeasesController(extensions.BaseController):
|
|||||||
for lease in pecan.request.rpcapi.list_leases()]
|
for lease in pecan.request.rpcapi.list_leases()]
|
||||||
|
|
||||||
@policy.authorize('leases', 'post')
|
@policy.authorize('leases', 'post')
|
||||||
@wsme_pecan.wsexpose(Lease, body=Lease, status_code=202)
|
@wsme_pecan.wsexpose(Lease, body=Lease, status_code=201)
|
||||||
@trusts.use_trust_auth()
|
@trusts.use_trust_auth()
|
||||||
def post(self, lease):
|
def post(self, lease):
|
||||||
"""Creates a new lease.
|
"""Creates a new lease.
|
||||||
@@ -121,7 +121,7 @@ class LeasesController(extensions.BaseController):
|
|||||||
raise exceptions.BlazarException(_("Lease can't be created"))
|
raise exceptions.BlazarException(_("Lease can't be created"))
|
||||||
|
|
||||||
@policy.authorize('leases', 'put')
|
@policy.authorize('leases', 'put')
|
||||||
@wsme_pecan.wsexpose(Lease, types.UuidType(), body=Lease, status_code=202)
|
@wsme_pecan.wsexpose(Lease, types.UuidType(), body=Lease)
|
||||||
def put(self, id, sublease):
|
def put(self, id, sublease):
|
||||||
"""Update an existing lease.
|
"""Update an existing lease.
|
||||||
|
|
||||||
|
@@ -43,12 +43,12 @@ class UtilsTestCase(tests.TestCase):
|
|||||||
self.rest._mroute.called_once_with('GET', 'rule', 200)
|
self.rest._mroute.called_once_with('GET', 'rule', 200)
|
||||||
|
|
||||||
def test_post(self):
|
def test_post(self):
|
||||||
self.rest.post('rule', status_code=202)
|
self.rest.post('rule', status_code=201)
|
||||||
self.rest._mroute.called_once_with('POST', 'rule', 200)
|
self.rest._mroute.called_once_with('POST', 'rule', 201)
|
||||||
|
|
||||||
def test_put(self):
|
def test_put(self):
|
||||||
self.rest.put('rule', status_code=202)
|
self.rest.put('rule', status_code=200)
|
||||||
self.rest._mroute.called_once_with('PUT', 'rule', 202)
|
self.rest._mroute.called_once_with('PUT', 'rule', 200)
|
||||||
|
|
||||||
def test_delete(self):
|
def test_delete(self):
|
||||||
self.rest.delete('rule', status_code=204)
|
self.rest.delete('rule', status_code=204)
|
||||||
|
@@ -220,7 +220,7 @@ class TestCreateHost(api.APITest):
|
|||||||
def test_create_one(self):
|
def test_create_one(self):
|
||||||
response = self.post_json(self.path, self.fake_computehost_body,
|
response = self.post_json(self.path, self.fake_computehost_body,
|
||||||
headers=self.headers)
|
headers=self.headers)
|
||||||
self.assertEqual(202, response.status_int)
|
self.assertEqual(201, response.status_int)
|
||||||
self.assertEqual('application/json', response.content_type)
|
self.assertEqual('application/json', response.content_type)
|
||||||
self.assertEqual(self.fake_computehost, response.json)
|
self.assertEqual(self.fake_computehost, response.json)
|
||||||
|
|
||||||
@@ -308,7 +308,7 @@ class TestUpdateHost(api.APITest):
|
|||||||
response = self.put_json(self.path, fake_computehost_request_body(
|
response = self.put_json(self.path, fake_computehost_request_body(
|
||||||
exclude=['trust_id']),
|
exclude=['trust_id']),
|
||||||
headers=self.headers)
|
headers=self.headers)
|
||||||
self.assertEqual(202, response.status_int)
|
self.assertEqual(200, response.status_int)
|
||||||
self.assertEqual('application/json', response.content_type)
|
self.assertEqual('application/json', response.content_type)
|
||||||
self.assertEqual(self.fake_computehost, response.json)
|
self.assertEqual(self.fake_computehost, response.json)
|
||||||
|
|
||||||
|
@@ -189,7 +189,7 @@ class TestCreateLease(api.APITest):
|
|||||||
|
|
||||||
def test_create_one(self):
|
def test_create_one(self):
|
||||||
response = self.post_json(self.path, self.fake_lease_body)
|
response = self.post_json(self.path, self.fake_lease_body)
|
||||||
self.assertEqual(202, response.status_int)
|
self.assertEqual(201, response.status_int)
|
||||||
self.assertEqual('application/json', response.content_type)
|
self.assertEqual('application/json', response.content_type)
|
||||||
self.assertEqual(self.fake_lease, response.json)
|
self.assertEqual(self.fake_lease, response.json)
|
||||||
|
|
||||||
@@ -268,7 +268,7 @@ class TestUpdateLease(api.APITest):
|
|||||||
|
|
||||||
def test_update_one(self):
|
def test_update_one(self):
|
||||||
response = self.put_json(self.path, self.fake_lease_body)
|
response = self.put_json(self.path, self.fake_lease_body)
|
||||||
self.assertEqual(202, response.status_int)
|
self.assertEqual(200, response.status_int)
|
||||||
self.assertEqual('application/json', response.content_type)
|
self.assertEqual('application/json', response.content_type)
|
||||||
self.assertEqual(self.fake_lease, response.json)
|
self.assertEqual(self.fake_lease, response.json)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user