merge salv's branch for bug834013
This commit is contained in:
commit
9aa632fc47
@ -16,6 +16,7 @@
|
||||
# under the License.
|
||||
|
||||
import logging
|
||||
import webob
|
||||
|
||||
from webob import exc
|
||||
|
||||
@ -61,3 +62,22 @@ class QuantumController(wsgi.Controller):
|
||||
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
|
||||
|
@ -107,8 +107,10 @@ class Controller(common.QuantumController):
|
||||
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 """
|
||||
|
@ -116,7 +116,10 @@ class Controller(common.QuantumController):
|
||||
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:
|
||||
|
@ -187,7 +187,6 @@ class Client(object):
|
||||
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,
|
||||
@ -237,7 +236,7 @@ class Client(object):
|
||||
"""
|
||||
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())
|
||||
|
@ -33,7 +33,7 @@ LOG = logging.getLogger('quantum.tests.test_api')
|
||||
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:
|
||||
@ -45,13 +45,13 @@ class APITest(unittest.TestCase):
|
||||
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,
|
||||
@ -59,7 +59,7 @@ class APITest(unittest.TestCase):
|
||||
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']
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user