Merge lp:~soren/nova/xmlns-match-request into lp:~hudson-openstack/nova/trunk

Proposed by Soren Hansen
Status: Merged
Approved by: Devin Carlen
Approved revision: 625
Merged at revision: 628
Proposed branch: lp:~soren/nova/xmlns-match-request
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 113 lines (+33/-9)
3 files modified
nova/api/ec2/__init__.py (+2/-1)
nova/api/ec2/apirequest.py (+3/-2)
nova/tests/test_api.py (+28/-6)
To merge this branch: bzr merge lp:~soren/nova/xmlns-match-request
Reviewer Review Type Date Requested Status
Devin Carlen (community) Approve
Thierry Carrez (community) Approve
Vish Ishaya (community) Approve
Review via email: mp+47600@code.launchpad.net

Commit message

Make xml namespace match the API version requested.

Description of the change

Make xml namespace match the API version requested.

To post a comment you must log in.
Revision history for this message
Soren Hansen (soren) wrote :

Sorry, accidentally proposed this for merge. I need to add unit tests first. Please ignore.

Revision history for this message
Vish Ishaya (vishvananda) wrote :

Is this a real merge proposal now? If so lgtm!

review: Approve
Revision history for this message
Thierry Carrez (ttx) wrote :

Sounds good to me, hopefully it won't break other clients in the process of fixing those.

review: Approve
Revision history for this message
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/ec2/__init__.py'
2--- nova/api/ec2/__init__.py 2011-01-26 00:09:08 +0000
3+++ nova/api/ec2/__init__.py 2011-01-27 14:47:07 +0000
4@@ -213,7 +213,8 @@
5 LOG.debug(_('arg: %(key)s\t\tval: %(value)s') % locals())
6
7 # Success!
8- api_request = apirequest.APIRequest(self.controller, action, args)
9+ api_request = apirequest.APIRequest(self.controller, action,
10+ req.params['Version'], args)
11 req.environ['ec2.request'] = api_request
12 req.environ['ec2.action_args'] = args
13 return self.application
14
15=== modified file 'nova/api/ec2/apirequest.py'
16--- nova/api/ec2/apirequest.py 2011-01-21 15:37:21 +0000
17+++ nova/api/ec2/apirequest.py 2011-01-27 14:47:07 +0000
18@@ -83,9 +83,10 @@
19
20
21 class APIRequest(object):
22- def __init__(self, controller, action, args):
23+ def __init__(self, controller, action, version, args):
24 self.controller = controller
25 self.action = action
26+ self.version = version
27 self.args = args
28
29 def invoke(self, context):
30@@ -132,7 +133,7 @@
31
32 response_el = xml.createElement(self.action + 'Response')
33 response_el.setAttribute('xmlns',
34- 'http://ec2.amazonaws.com/doc/2009-11-30/')
35+ 'http://ec2.amazonaws.com/doc/%s/' % self.version)
36 request_id_el = xml.createElement('requestId')
37 request_id_el.appendChild(xml.createTextNode(request_id))
38 response_el.appendChild(request_id_el)
39
40=== modified file 'nova/tests/test_api.py'
41--- nova/tests/test_api.py 2011-01-17 18:05:26 +0000
42+++ nova/tests/test_api.py 2011-01-27 14:47:07 +0000
43@@ -36,6 +36,7 @@
44 class FakeHttplibSocket(object):
45 """a fake socket implementation for httplib.HTTPResponse, trivial"""
46 def __init__(self, response_string):
47+ self.response_string = response_string
48 self._buffer = StringIO.StringIO(response_string)
49
50 def makefile(self, _mode, _other):
51@@ -66,13 +67,16 @@
52 # For some reason, the response doesn't have "HTTP/1.0 " prepended; I
53 # guess that's a function the web server usually provides.
54 resp = "HTTP/1.0 %s" % resp
55- sock = FakeHttplibSocket(resp)
56- self.http_response = httplib.HTTPResponse(sock)
57+ self.sock = FakeHttplibSocket(resp)
58+ self.http_response = httplib.HTTPResponse(self.sock)
59 self.http_response.begin()
60
61 def getresponse(self):
62 return self.http_response
63
64+ def getresponsebody(self):
65+ return self.sock.response_string
66+
67 def close(self):
68 """Required for compatibility with boto/tornado"""
69 pass
70@@ -104,7 +108,7 @@
71 self.app = ec2.Authenticate(ec2.Requestify(ec2.Executor(),
72 'nova.api.ec2.cloud.CloudController'))
73
74- def expect_http(self, host=None, is_secure=False):
75+ def expect_http(self, host=None, is_secure=False, api_version=None):
76 """Returns a new EC2 connection"""
77 self.ec2 = boto.connect_ec2(
78 aws_access_key_id='fake',
79@@ -113,13 +117,31 @@
80 region=regioninfo.RegionInfo(None, 'test', self.host),
81 port=8773,
82 path='/services/Cloud')
83+ if api_version:
84+ self.ec2.APIVersion = api_version
85
86 self.mox.StubOutWithMock(self.ec2, 'new_http_connection')
87- http = FakeHttplibConnection(
88+ self.http = FakeHttplibConnection(
89 self.app, '%s:8773' % (self.host), False)
90 # pylint: disable-msg=E1103
91- self.ec2.new_http_connection(host, is_secure).AndReturn(http)
92- return http
93+ self.ec2.new_http_connection(host, is_secure).AndReturn(self.http)
94+ return self.http
95+
96+ def test_xmlns_version_matches_request_version(self):
97+ self.expect_http(api_version='2010-10-30')
98+ self.mox.ReplayAll()
99+
100+ user = self.manager.create_user('fake', 'fake', 'fake')
101+ project = self.manager.create_project('fake', 'fake', 'fake')
102+
103+ # Any request should be fine
104+ self.ec2.get_all_instances()
105+ self.assertTrue(self.ec2.APIVersion in self.http.getresponsebody(),
106+ 'The version in the xmlns of the response does '
107+ 'not match the API version given in the request.')
108+
109+ self.manager.delete_project(project)
110+ self.manager.delete_user(user)
111
112 def test_describe_instances(self):
113 """Test that, after creating a user and a project, the describe