summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorJosh Durgin <joshd@hq.newdream.net>2011-09-15 11:10:33 -0700
committerJosh Durgin <joshd@hq.newdream.net>2011-09-15 11:10:33 -0700
commitc31a892e167f81d5816ecb48faae3947bf424b89 (patch)
tree6544b3a321959a0f7265e6fd559cbdb2519823ea /nova
parent6cd4e1dadda93d2e8fa4ed26f3e8d83ea22292d3 (diff)
parentc3654d48f8278d96003bf1d7d3a4bcbe2354f0b5 (diff)
downloadnova-c31a892e167f81d5816ecb48faae3947bf424b89.tar.gz
nova-c31a892e167f81d5816ecb48faae3947bf424b89.tar.xz
nova-c31a892e167f81d5816ecb48faae3947bf424b89.zip
Merge trunk.
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/versions.py4
-rw-r--r--nova/api/openstack/wsgi.py43
-rw-r--r--nova/db/api.py8
-rw-r--r--nova/db/sqlalchemy/api.py5
-rw-r--r--nova/network/manager.py3
-rw-r--r--nova/tests/api/openstack/test_api.py25
-rw-r--r--nova/tests/api/openstack/test_wsgi.py57
-rw-r--r--nova/tests/db/fakes.py4
8 files changed, 115 insertions, 34 deletions
diff --git a/nova/api/openstack/versions.py b/nova/api/openstack/versions.py
index 31dd9dc11..75a1d0ba4 100644
--- a/nova/api/openstack/versions.py
+++ b/nova/api/openstack/versions.py
@@ -107,7 +107,9 @@ class Versions(wsgi.Resource):
headers_serializer=headers_serializer)
supported_content_types = ('application/json',
+ 'application/vnd.openstack.compute+json',
'application/xml',
+ 'application/vnd.openstack.compute+xml',
'application/atom+xml')
deserializer = VersionsRequestDeserializer(
supported_content_types=supported_content_types)
@@ -308,7 +310,9 @@ def create_resource(version='1.0'):
serializer = wsgi.ResponseSerializer(body_serializers)
supported_content_types = ('application/json',
+ 'application/vnd.openstack.compute+json',
'application/xml',
+ 'application/vnd.openstack.compute+xml',
'application/atom+xml')
deserializer = wsgi.RequestDeserializer(
supported_content_types=supported_content_types)
diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py
index bdcadcb99..fad516d4d 100644
--- a/nova/api/openstack/wsgi.py
+++ b/nova/api/openstack/wsgi.py
@@ -1,3 +1,19 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2011 OpenStack LLC.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
import json
from lxml import etree
@@ -19,6 +35,21 @@ XMLNS_ATOM = 'http://www.w3.org/2005/Atom'
LOG = logging.getLogger('nova.api.openstack.wsgi')
+# The vendor content types should serialize identically to the non-vendor
+# content types. So to avoid littering the code with both options, we
+# map the vendor to the other when looking up the type
+_CONTENT_TYPE_MAP = {
+ 'application/vnd.openstack.compute+json': 'application/json',
+ 'application/vnd.openstack.compute+xml': 'application/xml',
+}
+
+_SUPPORTED_CONTENT_TYPES = (
+ 'application/json',
+ 'application/vnd.openstack.compute+json',
+ 'application/xml',
+ 'application/vnd.openstack.compute+xml',
+)
+
class Request(webob.Request):
"""Add some Openstack API-specific logic to the base webob.Request."""
@@ -30,7 +61,7 @@ class Request(webob.Request):
"""
supported_content_types = supported_content_types or \
- ('application/json', 'application/xml')
+ _SUPPORTED_CONTENT_TYPES
parts = self.path.rsplit('.', 1)
if len(parts) > 1:
@@ -52,7 +83,7 @@ class Request(webob.Request):
if not "Content-Type" in self.headers:
return None
- allowed_types = ("application/xml", "application/json")
+ allowed_types = _SUPPORTED_CONTENT_TYPES
content_type = self.content_type
if content_type not in allowed_types:
@@ -192,7 +223,7 @@ class RequestDeserializer(object):
supported_content_types=None):
self.supported_content_types = supported_content_types or \
- ('application/json', 'application/xml')
+ _SUPPORTED_CONTENT_TYPES
self.body_deserializers = {
'application/xml': XMLDeserializer(),
@@ -250,7 +281,8 @@ class RequestDeserializer(object):
def get_body_deserializer(self, content_type):
try:
- return self.body_deserializers[content_type]
+ ctype = _CONTENT_TYPE_MAP.get(content_type, content_type)
+ return self.body_deserializers[ctype]
except (KeyError, TypeError):
raise exception.InvalidContentType(content_type=content_type)
@@ -444,7 +476,8 @@ class ResponseSerializer(object):
def get_body_serializer(self, content_type):
try:
- return self.body_serializers[content_type]
+ ctype = _CONTENT_TYPE_MAP.get(content_type, content_type)
+ return self.body_serializers[ctype]
except (KeyError, TypeError):
raise exception.InvalidContentType(content_type=content_type)
diff --git a/nova/db/api.py b/nova/db/api.py
index a9d2dc065..05d81d8b2 100644
--- a/nova/db/api.py
+++ b/nova/db/api.py
@@ -261,11 +261,13 @@ def floating_ip_disassociate(context, address):
return IMPL.floating_ip_disassociate(context, address)
-def floating_ip_fixed_ip_associate(context, floating_address, fixed_address):
+def floating_ip_fixed_ip_associate(context, floating_address,
+ fixed_address, host):
"""Associate an floating ip to a fixed_ip by address."""
return IMPL.floating_ip_fixed_ip_associate(context,
floating_address,
- fixed_address)
+ fixed_address,
+ host)
def floating_ip_get_all(context):
@@ -367,7 +369,7 @@ def fixed_ip_get_all(context):
def fixed_ip_get_all_by_instance_host(context, host):
"""Get all allocated fixed ips filtered by instance host."""
- return IMPL.fixed_ip_get_all_instance_by_host(context, host)
+ return IMPL.fixed_ip_get_all_by_instance_host(context, host)
def fixed_ip_get_by_address(context, address):
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index e5a661c7f..8ea154490 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -529,7 +529,8 @@ def floating_ip_count_by_project(context, project_id):
@require_context
-def floating_ip_fixed_ip_associate(context, floating_address, fixed_address):
+def floating_ip_fixed_ip_associate(context, floating_address,
+ fixed_address, host):
session = get_session()
with session.begin():
# TODO(devcamcar): How to ensure floating_id belongs to user?
@@ -540,6 +541,7 @@ def floating_ip_fixed_ip_associate(context, floating_address, fixed_address):
fixed_address,
session=session)
floating_ip_ref.fixed_ip = fixed_ip_ref
+ floating_ip_ref.host = host
floating_ip_ref.save(session=session)
@@ -583,6 +585,7 @@ def floating_ip_disassociate(context, address):
else:
fixed_ip_address = None
floating_ip_ref.fixed_ip = None
+ floating_ip_ref.host = None
floating_ip_ref.save(session=session)
return fixed_ip_address
diff --git a/nova/network/manager.py b/nova/network/manager.py
index da360720b..70e51888f 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -289,7 +289,8 @@ class FloatingIP(object):
self.db.floating_ip_fixed_ip_associate(context,
floating_address,
- fixed_address)
+ fixed_address,
+ self.host)
self.driver.bind_floating_ip(floating_address)
self.driver.ensure_floating_forward(floating_address, fixed_address)
diff --git a/nova/tests/api/openstack/test_api.py b/nova/tests/api/openstack/test_api.py
index 7321c329f..b7a0b01ef 100644
--- a/nova/tests/api/openstack/test_api.py
+++ b/nova/tests/api/openstack/test_api.py
@@ -20,6 +20,7 @@ import json
import webob.exc
import webob.dec
+from lxml import etree
from webob import Request
from nova import test
@@ -52,6 +53,30 @@ class APITest(test.TestCase):
res = req.get_response(fakes.wsgi_app())
self.assertEqual(res.status_int, 400)
+ def test_vendor_content_type_json(self):
+ ctype = 'application/vnd.openstack.compute+json'
+
+ req = webob.Request.blank('/')
+ req.headers['Accept'] = ctype
+
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, ctype)
+
+ body = json.loads(res.body)
+
+ def test_vendor_content_type_xml(self):
+ ctype = 'application/vnd.openstack.compute+xml'
+
+ req = webob.Request.blank('/')
+ req.headers['Accept'] = ctype
+
+ res = req.get_response(fakes.wsgi_app())
+ self.assertEqual(res.status_int, 200)
+ self.assertEqual(res.content_type, ctype)
+
+ body = etree.XML(res.body)
+
def test_exceptions_are_converted_to_faults(self):
@webob.dec.wsgify
diff --git a/nova/tests/api/openstack/test_wsgi.py b/nova/tests/api/openstack/test_wsgi.py
index 6dea78d17..74b9ce853 100644
--- a/nova/tests/api/openstack/test_wsgi.py
+++ b/nova/tests/api/openstack/test_wsgi.py
@@ -27,17 +27,17 @@ class RequestTest(test.TestCase):
result = request.get_content_type()
self.assertEqual(result, "application/json")
- def test_content_type_from_accept_xml(self):
- request = wsgi.Request.blank('/tests/123')
- request.headers["Accept"] = "application/xml"
- result = request.best_match_content_type()
- self.assertEqual(result, "application/xml")
-
- request = wsgi.Request.blank('/tests/123')
- request.headers["Accept"] = "application/json"
- result = request.best_match_content_type()
- self.assertEqual(result, "application/json")
-
+ def test_content_type_from_accept(self):
+ for content_type in ('application/xml',
+ 'application/vnd.openstack.compute+xml',
+ 'application/json',
+ 'application/vnd.openstack.compute+json'):
+ request = wsgi.Request.blank('/tests/123')
+ request.headers["Accept"] = content_type
+ result = request.best_match_content_type()
+ self.assertEqual(result, content_type)
+
+ def test_content_type_from_accept_best(self):
request = wsgi.Request.blank('/tests/123')
request.headers["Accept"] = "application/xml, application/json"
result = request.best_match_content_type()
@@ -231,7 +231,7 @@ class ResponseSerializerTest(test.TestCase):
self.body_serializers = {
'application/json': JSONSerializer(),
- 'application/XML': XMLSerializer(),
+ 'application/xml': XMLSerializer(),
}
self.serializer = wsgi.ResponseSerializer(self.body_serializers,
@@ -250,15 +250,24 @@ class ResponseSerializerTest(test.TestCase):
self.serializer.get_body_serializer,
'application/unknown')
- def test_serialize_response(self):
- response = self.serializer.serialize({}, 'application/json')
- self.assertEqual(response.headers['Content-Type'], 'application/json')
- self.assertEqual(response.body, 'pew_json')
- self.assertEqual(response.status_int, 404)
+ def test_serialize_response_json(self):
+ for content_type in ('application/json',
+ 'application/vnd.openstack.compute+json'):
+ response = self.serializer.serialize({}, content_type)
+ self.assertEqual(response.headers['Content-Type'], content_type)
+ self.assertEqual(response.body, 'pew_json')
+ self.assertEqual(response.status_int, 404)
+
+ def test_serialize_response_xml(self):
+ for content_type in ('application/xml',
+ 'application/vnd.openstack.compute+xml'):
+ response = self.serializer.serialize({}, content_type)
+ self.assertEqual(response.headers['Content-Type'], content_type)
+ self.assertEqual(response.body, 'pew_xml')
+ self.assertEqual(response.status_int, 404)
def test_serialize_response_None(self):
response = self.serializer.serialize(None, 'application/json')
- print response
self.assertEqual(response.headers['Content-Type'], 'application/json')
self.assertEqual(response.body, '')
self.assertEqual(response.status_int, 404)
@@ -281,7 +290,7 @@ class RequestDeserializerTest(test.TestCase):
self.body_deserializers = {
'application/json': JSONDeserializer(),
- 'application/XML': XMLDeserializer(),
+ 'application/xml': XMLDeserializer(),
}
self.deserializer = wsgi.RequestDeserializer(self.body_deserializers)
@@ -290,8 +299,9 @@ class RequestDeserializerTest(test.TestCase):
pass
def test_get_deserializer(self):
- expected = self.deserializer.get_body_deserializer('application/json')
- self.assertEqual(expected, self.body_deserializers['application/json'])
+ ctype = 'application/json'
+ expected = self.deserializer.get_body_deserializer(ctype)
+ self.assertEqual(expected, self.body_deserializers[ctype])
def test_get_deserializer_unknown_content_type(self):
self.assertRaises(exception.InvalidContentType,
@@ -299,10 +309,11 @@ class RequestDeserializerTest(test.TestCase):
'application/unknown')
def test_get_expected_content_type(self):
+ ctype = 'application/json'
request = wsgi.Request.blank('/')
- request.headers['Accept'] = 'application/json'
+ request.headers['Accept'] = ctype
self.assertEqual(self.deserializer.get_expected_content_type(request),
- 'application/json')
+ ctype)
def test_get_action_args(self):
env = {
diff --git a/nova/tests/db/fakes.py b/nova/tests/db/fakes.py
index 19028a451..cdbfba63a 100644
--- a/nova/tests/db/fakes.py
+++ b/nova/tests/db/fakes.py
@@ -125,10 +125,11 @@ def stub_out_db_network_api(stubs):
if ips[0]['fixed_ip']:
fixed_ip_address = ips[0]['fixed_ip']['address']
ips[0]['fixed_ip'] = None
+ ips[0]['host'] = None
return fixed_ip_address
def fake_floating_ip_fixed_ip_associate(context, floating_address,
- fixed_address):
+ fixed_address, host):
float = filter(lambda i: i['address'] == floating_address,
floating_ips)
fixed = filter(lambda i: i['address'] == fixed_address,
@@ -136,6 +137,7 @@ def stub_out_db_network_api(stubs):
if float and fixed:
float[0]['fixed_ip'] = fixed[0]
float[0]['fixed_ip_id'] = fixed[0]['id']
+ float[0]['host'] = host
def fake_floating_ip_get_all_by_host(context, host):
# TODO(jkoelker): Once we get the patches that remove host from