# under the License.
import logging
+import webob
from webob import exc
raise exc.HTTPBadRequest(msg)
results[param_name] = param_value or param.get('default-value')
return results
+
+ def _build_response(self, req, res_data, status_code=200):
+ """ A function which builds an HTTP response
+ given a status code and a dictionary containing
+ the response body to be serialized
+
+ """
+ content_type = req.best_match_content_type()
+ default_xmlns = self.get_default_xmlns(req)
+ body = self._serialize(res_data, content_type, default_xmlns)
+
+ response = webob.Response()
+ response.status = status_code
+ response.headers['Content-Type'] = content_type
+ response.body = body
+ msg_dict = dict(url=req.url, status=response.status_int)
+ msg = _("%(url)s returned with HTTP %(status)d") % msg_dict
+ LOG.debug(msg)
+ return response
request_params['name'])
builder = networks_view.get_view_builder(request)
result = builder.build(network)['network']
- #MUST RETURN 202???
- return dict(network=result)
+ # Wsgi middleware allows us to build the response
+ # before returning the call.
+ # This will allow us to return a 202 status code.
+ return self._build_response(request, dict(network=result), 202)
def update(self, request, tenant_id, id):
""" Updates the name for the network with the given id """
request_params['state'])
builder = ports_view.get_view_builder(request)
result = builder.build(port)['port']
- return dict(port=result)
+ # Wsgi middleware allows us to build the response
+ # before returning the call.
+ # This will allow us to return a 202 status code.
+ return self._build_response(request, dict(port=result), 202)
except exception.NetworkNotFound as e:
return faults.Fault(faults.NetworkNotFound(e))
except exception.StateInvalid as e:
if self.logger:
self.logger.debug("Quantum Client Reply (code = %s) :\n %s" \
% (str(status_code), data))
-
if status_code in (httplib.OK,
httplib.CREATED,
httplib.ACCEPTED,
"""
Deserializes a an xml or json string into a dictionary
"""
- if status_code in (202, 204):
+ if status_code == 204:
return data
return Serializer(self._serialization_metadata).\
deserialize(data, self.content_type())
class APITest(unittest.TestCase):
def _create_network(self, format, name=None, custom_req_body=None,
- expected_res_status=200):
+ expected_res_status=202):
LOG.debug("Creating network")
content_type = "application/" + format
if name:
custom_req_body)
network_res = network_req.get_response(self.api)
self.assertEqual(network_res.status_int, expected_res_status)
- if expected_res_status == 200:
+ if expected_res_status in (200, 202):
network_data = Serializer().deserialize(network_res.body,
content_type)
return network_data['network']['id']
def _create_port(self, network_id, port_state, format,
- custom_req_body=None, expected_res_status=200):
+ custom_req_body=None, expected_res_status=202):
LOG.debug("Creating port for network %s", network_id)
content_type = "application/%s" % format
port_req = testlib.new_port_request(self.tenant_id, network_id,
custom_req_body)
port_res = port_req.get_response(self.api)
self.assertEqual(port_res.status_int, expected_res_status)
- if expected_res_status == 200:
+ if expected_res_status in (200, 202):
port_data = Serializer().deserialize(port_res.body, content_type)
return port_data['port']['id']