Merge lp:~rackspace-titan/nova/v11_image_create into lp:~hudson-openstack/nova/trunk

Proposed by Dan Prince
Status: Merged
Approved by: Brian Waldon
Approved revision: 1148
Merged at revision: 1155
Proposed branch: lp:~rackspace-titan/nova/v11_image_create
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 157 lines (+87/-3)
3 files modified
nova/api/openstack/images.py (+11/-2)
nova/tests/api/openstack/fakes.py (+2/-1)
nova/tests/api/openstack/test_images.py (+74/-0)
To merge this branch: bzr merge lp:~rackspace-titan/nova/v11_image_create
Reviewer Review Type Date Requested Status
Brian Waldon (community) Approve
Paul Voccio (community) Approve
William Wolf (community) Approve
Review via email: mp+63382@code.launchpad.net

Description of the change

Update the OSAPI images controller to use 'serverRef' for image create requests.

To post a comment you must log in.
Revision history for this message
Brian Lamar (blamar) wrote :

Can you add an XML serialization test? Looks great!

Revision history for this message
Dan Prince (dan-prince) wrote :

> Can you add an XML serialization test? Looks great!

Sure. Just added. Should be all set.

1147. By Dan Prince

Merge w/ trunk.

1148. By Dan Prince

Added a test case for XML serialization.

Revision history for this message
William Wolf (throughnothing) wrote :

Looks good!

review: Approve
Revision history for this message
Paul Voccio (pvo) wrote :

lgtm

review: Approve
Revision history for this message
Brian Waldon (bcwaldon) wrote :

Looks good, Daniel.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'nova/api/openstack/images.py'
2--- nova/api/openstack/images.py 2011-06-02 17:00:17 +0000
3+++ nova/api/openstack/images.py 2011-06-03 15:37:31 +0000
4@@ -123,7 +123,7 @@
5 raise webob.exc.HTTPBadRequest()
6
7 try:
8- server_id = body["image"]["serverId"]
9+ server_id = self._server_id_from_req_data(body)
10 image_name = body["image"]["name"]
11 except KeyError:
12 raise webob.exc.HTTPBadRequest()
13@@ -135,6 +135,9 @@
14 """Indicates that you must use a Controller subclass."""
15 raise NotImplementedError
16
17+ def _server_id_from_req_data(self, data):
18+ raise NotImplementedError()
19+
20
21 class ControllerV10(Controller):
22 """Version 1.0 specific controller logic."""
23@@ -144,6 +147,9 @@
24 base_url = request.application_url
25 return images_view.ViewBuilderV10(base_url)
26
27+ def _server_id_from_req_data(self, data):
28+ return data['image']['serverId']
29+
30
31 class ControllerV11(Controller):
32 """Version 1.1 specific controller logic."""
33@@ -153,6 +159,9 @@
34 base_url = request.application_url
35 return images_view.ViewBuilderV11(base_url)
36
37+ def _server_id_from_req_data(self, data):
38+ return data['image']['serverRef']
39+
40
41 def create_resource(version='1.0'):
42 controller = {
43@@ -168,7 +177,7 @@
44 metadata = {
45 "attributes": {
46 "image": ["id", "name", "updated", "created", "status",
47- "serverId", "progress"],
48+ "serverId", "progress", "serverRef"],
49 "link": ["rel", "type", "href"],
50 },
51 }
52
53=== modified file 'nova/tests/api/openstack/fakes.py'
54--- nova/tests/api/openstack/fakes.py 2011-06-03 15:11:01 +0000
55+++ nova/tests/api/openstack/fakes.py 2011-06-03 15:37:31 +0000
56@@ -142,7 +142,8 @@
57
58 def stub_out_compute_api_snapshot(stubs):
59 def snapshot(self, context, instance_id, name):
60- return 123
61+ return dict(id='123', status='ACTIVE',
62+ properties=dict(instance_id='123'))
63 stubs.Set(nova.compute.API, 'snapshot', snapshot)
64
65
66
67=== modified file 'nova/tests/api/openstack/test_images.py'
68--- nova/tests/api/openstack/test_images.py 2011-06-02 21:23:05 +0000
69+++ nova/tests/api/openstack/test_images.py 2011-06-03 15:37:31 +0000
70@@ -248,6 +248,7 @@
71 fakes.stub_out_key_pair_funcs(self.stubs)
72 self.fixtures = self._make_image_fixtures()
73 fakes.stub_out_glance(self.stubs, initial_fixtures=self.fixtures)
74+ fakes.stub_out_compute_api_snapshot(self.stubs)
75
76 def tearDown(self):
77 """Run after each test."""
78@@ -870,6 +871,79 @@
79 res = req.get_response(fakes.wsgi_app())
80 self.assertEqual(res.status_int, 404)
81
82+ def test_create_image(self):
83+
84+ body = dict(image=dict(serverId='123', name='Backup 1'))
85+ req = webob.Request.blank('/v1.0/images')
86+ req.method = 'POST'
87+ req.body = json.dumps(body)
88+ req.headers["content-type"] = "application/json"
89+ response = req.get_response(fakes.wsgi_app())
90+ self.assertEqual(200, response.status_int)
91+
92+ def test_create_image_no_server_id(self):
93+
94+ body = dict(image=dict(name='Backup 1'))
95+ req = webob.Request.blank('/v1.0/images')
96+ req.method = 'POST'
97+ req.body = json.dumps(body)
98+ req.headers["content-type"] = "application/json"
99+ response = req.get_response(fakes.wsgi_app())
100+ self.assertEqual(400, response.status_int)
101+
102+ def test_create_image_v1_1(self):
103+
104+ body = dict(image=dict(serverRef='123', name='Backup 1'))
105+ req = webob.Request.blank('/v1.1/images')
106+ req.method = 'POST'
107+ req.body = json.dumps(body)
108+ req.headers["content-type"] = "application/json"
109+ response = req.get_response(fakes.wsgi_app())
110+ self.assertEqual(200, response.status_int)
111+
112+ def test_create_image_v1_1_xml_serialization(self):
113+
114+ body = dict(image=dict(serverRef='123', name='Backup 1'))
115+ req = webob.Request.blank('/v1.1/images')
116+ req.method = 'POST'
117+ req.body = json.dumps(body)
118+ req.headers["content-type"] = "application/json"
119+ req.headers["accept"] = "application/xml"
120+ response = req.get_response(fakes.wsgi_app())
121+ self.assertEqual(200, response.status_int)
122+ resp_xml = minidom.parseString(response.body.replace(" ", ""))
123+ expected_href = "http://localhost/v1.1/images/123"
124+ expected_image = minidom.parseString("""
125+ <image
126+ created="None"
127+ id="123"
128+ name="None"
129+ serverRef="http://localhost/v1.1/servers/123"
130+ status="ACTIVE"
131+ updated="None"
132+ xmlns="http://docs.openstack.org/compute/api/v1.1">
133+ <links>
134+ <link href="%(expected_href)s" rel="self"/>
135+ <link href="%(expected_href)s" rel="bookmark"
136+ type="application/json" />
137+ <link href="%(expected_href)s" rel="bookmark"
138+ type="application/xml" />
139+ </links>
140+ </image>
141+ """.replace(" ", "") % (locals()))
142+
143+ self.assertEqual(expected_image.toxml(), resp_xml.toxml())
144+
145+ def test_create_image_v1_1_no_server_ref(self):
146+
147+ body = dict(image=dict(name='Backup 1'))
148+ req = webob.Request.blank('/v1.1/images')
149+ req.method = 'POST'
150+ req.body = json.dumps(body)
151+ req.headers["content-type"] = "application/json"
152+ response = req.get_response(fakes.wsgi_app())
153+ self.assertEqual(400, response.status_int)
154+
155 @classmethod
156 def _make_image_fixtures(cls):
157 image_id = 123