summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--nova/api/ec2/__init__.py3
-rw-r--r--nova/api/ec2/apirequest.py5
-rw-r--r--nova/tests/test_api.py34
3 files changed, 33 insertions, 9 deletions
diff --git a/nova/api/ec2/__init__.py b/nova/api/ec2/__init__.py
index fc9a37908..be9751256 100644
--- a/nova/api/ec2/__init__.py
+++ b/nova/api/ec2/__init__.py
@@ -213,7 +213,8 @@ class Requestify(wsgi.Middleware):
LOG.debug(_('arg: %(key)s\t\tval: %(value)s') % locals())
# Success!
- api_request = apirequest.APIRequest(self.controller, action, args)
+ api_request = apirequest.APIRequest(self.controller, action,
+ req.params['Version'], args)
req.environ['ec2.request'] = api_request
req.environ['ec2.action_args'] = args
return self.application
diff --git a/nova/api/ec2/apirequest.py b/nova/api/ec2/apirequest.py
index d8a2b5f53..7e72d67fb 100644
--- a/nova/api/ec2/apirequest.py
+++ b/nova/api/ec2/apirequest.py
@@ -83,9 +83,10 @@ def _try_convert(value):
class APIRequest(object):
- def __init__(self, controller, action, args):
+ def __init__(self, controller, action, version, args):
self.controller = controller
self.action = action
+ self.version = version
self.args = args
def invoke(self, context):
@@ -132,7 +133,7 @@ class APIRequest(object):
response_el = xml.createElement(self.action + 'Response')
response_el.setAttribute('xmlns',
- 'http://ec2.amazonaws.com/doc/2009-11-30/')
+ 'http://ec2.amazonaws.com/doc/%s/' % self.version)
request_id_el = xml.createElement('requestId')
request_id_el.appendChild(xml.createTextNode(request_id))
response_el.appendChild(request_id_el)
diff --git a/nova/tests/test_api.py b/nova/tests/test_api.py
index 66a16b0cb..2569e262b 100644
--- a/nova/tests/test_api.py
+++ b/nova/tests/test_api.py
@@ -36,6 +36,7 @@ from nova.auth import manager
class FakeHttplibSocket(object):
"""a fake socket implementation for httplib.HTTPResponse, trivial"""
def __init__(self, response_string):
+ self.response_string = response_string
self._buffer = StringIO.StringIO(response_string)
def makefile(self, _mode, _other):
@@ -66,13 +67,16 @@ class FakeHttplibConnection(object):
# For some reason, the response doesn't have "HTTP/1.0 " prepended; I
# guess that's a function the web server usually provides.
resp = "HTTP/1.0 %s" % resp
- sock = FakeHttplibSocket(resp)
- self.http_response = httplib.HTTPResponse(sock)
+ self.sock = FakeHttplibSocket(resp)
+ self.http_response = httplib.HTTPResponse(self.sock)
self.http_response.begin()
def getresponse(self):
return self.http_response
+ def getresponsebody(self):
+ return self.sock.response_string
+
def close(self):
"""Required for compatibility with boto/tornado"""
pass
@@ -104,7 +108,7 @@ class ApiEc2TestCase(test.TestCase):
self.app = ec2.Authenticate(ec2.Requestify(ec2.Executor(),
'nova.api.ec2.cloud.CloudController'))
- def expect_http(self, host=None, is_secure=False):
+ def expect_http(self, host=None, is_secure=False, api_version=None):
"""Returns a new EC2 connection"""
self.ec2 = boto.connect_ec2(
aws_access_key_id='fake',
@@ -113,13 +117,31 @@ class ApiEc2TestCase(test.TestCase):
region=regioninfo.RegionInfo(None, 'test', self.host),
port=8773,
path='/services/Cloud')
+ if api_version:
+ self.ec2.APIVersion = api_version
self.mox.StubOutWithMock(self.ec2, 'new_http_connection')
- http = FakeHttplibConnection(
+ self.http = FakeHttplibConnection(
self.app, '%s:8773' % (self.host), False)
# pylint: disable-msg=E1103
- self.ec2.new_http_connection(host, is_secure).AndReturn(http)
- return http
+ self.ec2.new_http_connection(host, is_secure).AndReturn(self.http)
+ return self.http
+
+ def test_xmlns_version_matches_request_version(self):
+ self.expect_http(api_version='2010-10-30')
+ self.mox.ReplayAll()
+
+ user = self.manager.create_user('fake', 'fake', 'fake')
+ project = self.manager.create_project('fake', 'fake', 'fake')
+
+ # Any request should be fine
+ self.ec2.get_all_instances()
+ self.assertTrue(self.ec2.APIVersion in self.http.getresponsebody(),
+ 'The version in the xmlns of the response does '
+ 'not match the API version given in the request.')
+
+ self.manager.delete_project(project)
+ self.manager.delete_user(user)
def test_describe_instances(self):
"""Test that, after creating a user and a project, the describe