Fix for bug 921743
Response codes for create ops in API v1.0 not compliant with spec Change-Id: I7723e46b05ffd7b29940327b9c7362f843e01817
This commit is contained in:
@@ -62,7 +62,10 @@ def create_resource(version, controller_dict):
|
|||||||
# and also the function for building the fault body
|
# and also the function for building the fault body
|
||||||
fault_body_function = faults.fault_body_function(version)
|
fault_body_function = faults.fault_body_function(version)
|
||||||
|
|
||||||
headers_serializer = HeaderSerializer()
|
headers_serializers = {
|
||||||
|
'1.0': HeaderSerializer10(),
|
||||||
|
'1.1': HeaderSerializer11()
|
||||||
|
}
|
||||||
xml_serializer = wsgi.XMLDictSerializer(metadata, xmlns)
|
xml_serializer = wsgi.XMLDictSerializer(metadata, xmlns)
|
||||||
json_serializer = wsgi.JSONDictSerializer()
|
json_serializer = wsgi.JSONDictSerializer()
|
||||||
xml_deserializer = wsgi.XMLDeserializer(metadata)
|
xml_deserializer = wsgi.XMLDeserializer(metadata)
|
||||||
@@ -78,7 +81,8 @@ def create_resource(version, controller_dict):
|
|||||||
'application/json': json_deserializer,
|
'application/json': json_deserializer,
|
||||||
}
|
}
|
||||||
|
|
||||||
serializer = wsgi.ResponseSerializer(body_serializers, headers_serializer)
|
serializer = wsgi.ResponseSerializer(body_serializers,
|
||||||
|
headers_serializers[version])
|
||||||
deserializer = wsgi.RequestDeserializer(body_deserializers)
|
deserializer = wsgi.RequestDeserializer(body_deserializers)
|
||||||
|
|
||||||
return wsgi.Resource(controller,
|
return wsgi.Resource(controller,
|
||||||
@@ -116,10 +120,10 @@ def APIFaultWrapper(errors=None):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class HeaderSerializer(wsgi.ResponseHeaderSerializer):
|
class HeaderSerializer10(wsgi.ResponseHeaderSerializer):
|
||||||
"""
|
"""
|
||||||
Defines default respone status codes for Quantum API operations
|
Defines default respone status codes for Quantum API 1.0 operations
|
||||||
create - 202 ACCEPTED
|
create - 200 OK
|
||||||
update - 204 NOCONTENT
|
update - 204 NOCONTENT
|
||||||
delete - 204 NOCONTENT
|
delete - 204 NOCONTENT
|
||||||
others - 200 OK (defined in base class)
|
others - 200 OK (defined in base class)
|
||||||
@@ -127,7 +131,7 @@ class HeaderSerializer(wsgi.ResponseHeaderSerializer):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def create(self, response, data):
|
def create(self, response, data):
|
||||||
response.status_int = 202
|
response.status_int = 200
|
||||||
|
|
||||||
def delete(self, response, data):
|
def delete(self, response, data):
|
||||||
response.status_int = 204
|
response.status_int = 204
|
||||||
@@ -142,6 +146,20 @@ class HeaderSerializer(wsgi.ResponseHeaderSerializer):
|
|||||||
response.status_int = 204
|
response.status_int = 204
|
||||||
|
|
||||||
|
|
||||||
|
class HeaderSerializer11(HeaderSerializer10):
|
||||||
|
"""
|
||||||
|
Defines default respone status codes for Quantum API 1.0 operations
|
||||||
|
create - 202 ACCEPTED
|
||||||
|
update - 204 NOCONTENT
|
||||||
|
delete - 204 NOCONTENT
|
||||||
|
others - 200 OK (defined in base class)
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def create(self, response, data):
|
||||||
|
response.status_int = 202
|
||||||
|
|
||||||
|
|
||||||
class QuantumController(object):
|
class QuantumController(object):
|
||||||
""" Base controller class for Quantum API """
|
""" Base controller class for Quantum API """
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class AbstractAPITest(unittest.TestCase):
|
|||||||
return port_data
|
return port_data
|
||||||
|
|
||||||
def _create_network(self, fmt, name=None, custom_req_body=None,
|
def _create_network(self, fmt, name=None, custom_req_body=None,
|
||||||
expected_res_status=202):
|
expected_res_status=None):
|
||||||
LOG.debug("Creating network")
|
LOG.debug("Creating network")
|
||||||
content_type = "application/" + fmt
|
content_type = "application/" + fmt
|
||||||
if name:
|
if name:
|
||||||
@@ -64,20 +64,24 @@ class AbstractAPITest(unittest.TestCase):
|
|||||||
net_name, fmt,
|
net_name, fmt,
|
||||||
custom_req_body)
|
custom_req_body)
|
||||||
network_res = network_req.get_response(self.api)
|
network_res = network_req.get_response(self.api)
|
||||||
|
expected_res_status = expected_res_status or \
|
||||||
|
self._successful_create_code
|
||||||
self.assertEqual(network_res.status_int, expected_res_status)
|
self.assertEqual(network_res.status_int, expected_res_status)
|
||||||
if expected_res_status in (200, 202):
|
if expected_res_status in (200, 202):
|
||||||
network_data = self._deserialize_net_response(content_type,
|
network_data = self._deserialize_net_response(content_type,
|
||||||
network_res)
|
network_res)
|
||||||
return network_data['network']['id']
|
return network_data['network']['id']
|
||||||
|
|
||||||
def _create_port(self, network_id, port_state, fmt,
|
def _create_port(self, network_id, port_state, fmt, custom_req_body=None,
|
||||||
custom_req_body=None, expected_res_status=202):
|
expected_res_status=None):
|
||||||
LOG.debug("Creating port for network %s", network_id)
|
LOG.debug("Creating port for network %s", network_id)
|
||||||
content_type = "application/%s" % fmt
|
content_type = "application/%s" % fmt
|
||||||
port_req = testlib.new_port_request(self.tenant_id, network_id,
|
port_req = testlib.new_port_request(self.tenant_id, network_id,
|
||||||
port_state, fmt,
|
port_state, fmt,
|
||||||
custom_req_body)
|
custom_req_body)
|
||||||
port_res = port_req.get_response(self.api)
|
port_res = port_req.get_response(self.api)
|
||||||
|
expected_res_status = expected_res_status or \
|
||||||
|
self._successful_create_code
|
||||||
self.assertEqual(port_res.status_int, expected_res_status)
|
self.assertEqual(port_res.status_int, expected_res_status)
|
||||||
if expected_res_status in (200, 202):
|
if expected_res_status in (200, 202):
|
||||||
port_data = self._deserialize_port_response(content_type,
|
port_data = self._deserialize_port_response(content_type,
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ class APITestV10(test_api.BaseAPIOperationsTest):
|
|||||||
{test_api.NETS: nets.ControllerV10._serialization_metadata,
|
{test_api.NETS: nets.ControllerV10._serialization_metadata,
|
||||||
test_api.PORTS: ports.ControllerV10._serialization_metadata,
|
test_api.PORTS: ports.ControllerV10._serialization_metadata,
|
||||||
test_api.ATTS: atts.ControllerV10._serialization_metadata})
|
test_api.ATTS: atts.ControllerV10._serialization_metadata})
|
||||||
|
self._successful_create_code = exc.HTTPOk.code
|
||||||
self._network_not_found_code = 420
|
self._network_not_found_code = 420
|
||||||
self._network_in_use_code = 421
|
self._network_in_use_code = 421
|
||||||
self._port_not_found_code = 430
|
self._port_not_found_code = 430
|
||||||
@@ -107,6 +108,7 @@ class APITestV11(test_api.BaseAPIOperationsTest):
|
|||||||
{test_api.NETS: nets.ControllerV11._serialization_metadata,
|
{test_api.NETS: nets.ControllerV11._serialization_metadata,
|
||||||
test_api.PORTS: ports.ControllerV11._serialization_metadata,
|
test_api.PORTS: ports.ControllerV11._serialization_metadata,
|
||||||
test_api.ATTS: atts.ControllerV11._serialization_metadata})
|
test_api.ATTS: atts.ControllerV11._serialization_metadata})
|
||||||
|
self._successful_create_code = exc.HTTPAccepted.code
|
||||||
self._network_not_found_code = exc.HTTPNotFound.code
|
self._network_not_found_code = exc.HTTPNotFound.code
|
||||||
self._network_in_use_code = exc.HTTPConflict.code
|
self._network_in_use_code = exc.HTTPConflict.code
|
||||||
self._port_not_found_code = exc.HTTPNotFound.code
|
self._port_not_found_code = exc.HTTPNotFound.code
|
||||||
@@ -146,6 +148,7 @@ class APIFiltersTest(test_api.AbstractAPITest):
|
|||||||
{test_api.NETS: nets.ControllerV11._serialization_metadata,
|
{test_api.NETS: nets.ControllerV11._serialization_metadata,
|
||||||
test_api.PORTS: ports.ControllerV11._serialization_metadata,
|
test_api.PORTS: ports.ControllerV11._serialization_metadata,
|
||||||
test_api.ATTS: atts.ControllerV11._serialization_metadata})
|
test_api.ATTS: atts.ControllerV11._serialization_metadata})
|
||||||
|
self._successful_create_code = exc.HTTPAccepted.code
|
||||||
self.net_op_status = test_config.get('default_net_op_status',
|
self.net_op_status = test_config.get('default_net_op_status',
|
||||||
'UNKNOWN')
|
'UNKNOWN')
|
||||||
self.port_op_status = test_config.get('default_port_op_status',
|
self.port_op_status = test_config.get('default_port_op_status',
|
||||||
|
|||||||
Reference in New Issue
Block a user