OpenStack Compute (Nova)

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

Proposed by William Wolf on 2011-07-21
Status: Merged
Approved by: Brian Lamar on 2011-07-21
Approved revision: 1235
Merged at revision: 1302
Proposed branch: lp:~rackspace-titan/nova/lp803615
Merge into: lp:~hudson-openstack/nova/trunk
Diff against target: 69 lines (+40/-2) 2 files modified
To merge this branch: bzr merge lp:~rackspace-titan/nova/lp803615
Reviewer Review Type Date Requested Status
Brian Lamar (community) 2011-07-21 Approve on 2011-07-21
Brian Waldon (community) Approve on 2011-07-21
Devin Carlen (community) 2011-07-21 Approve on 2011-07-21
Alex Meade (community) Approve on 2011-07-21
Review via email: mp+68717@code.launchpad.net

Description of the Change

This fixes issues with invalid flavorRef's being passed in returning a 500 instead of a 400, and adds tests to verify that two separate cases work.

To post a comment you must log in.
Alex Meade (alex-meade) wrote :

Looks good Will. Nice work

review: Approve
Devin Carlen (devcamcar) wrote :

lgtm

review: Approve
Brian Waldon (bcwaldon) wrote :

Looks good, Will.

review: Approve
Brian Lamar (blamar) wrote :

Good here.

review: Approve

Preview Diff

1=== modified file 'nova/api/openstack/create_instance_helper.py'
2--- nova/api/openstack/create_instance_helper.py 2011-07-21 14:02:16 +0000
3+++ nova/api/openstack/create_instance_helper.py 2011-07-21 19:17:39 +0000
4@@ -101,7 +101,11 @@
5 if personality:
6 injected_files = self._get_injected_files(personality)
7
8- flavor_id = self.controller._flavor_id_from_req_data(body)
9+ try:
10+ flavor_id = self.controller._flavor_id_from_req_data(body)
11+ except ValueError as error:
12+ msg = _("Invalid flavorRef provided.")
13+ raise exc.HTTPBadRequest(explanation=msg)
14
15 if not 'name' in body['server']:
16 msg = _("Server name is not defined")
17@@ -153,7 +157,9 @@
18 except exception.ImageNotFound as error:
19 msg = _("Can not find requested image")
20 raise exc.HTTPBadRequest(explanation=msg)
21-
22+ except exception.FlavorNotFound as error:
23+ msg = _("Invalid flavorRef provided.")
24+ raise exc.HTTPBadRequest(explanation=msg)
25 # Let the caller deal with unhandled exceptions.
26
27 def _handle_quota_error(self, error):
28
29=== modified file 'nova/tests/api/openstack/test_servers.py'
30--- nova/tests/api/openstack/test_servers.py 2011-07-21 18:49:57 +0000
31+++ nova/tests/api/openstack/test_servers.py 2011-07-21 19:17:39 +0000
32@@ -997,6 +997,38 @@
33 self.assertEqual(flavor_ref, server['flavorRef'])
34 self.assertEqual(image_href, server['imageRef'])
35
36+ def test_create_instance_v1_1_invalid_flavor_href(self):
37+ self._setup_for_create_instance()
38+
39+ image_href = 'http://localhost/v1.1/images/2'
40+ flavor_ref = 'http://localhost/v1.1/flavors/asdf'
41+ body = dict(server=dict(
42+ name='server_test', imageRef=image_href, flavorRef=flavor_ref,
43+ metadata={'hello': 'world', 'open': 'stack'},
44+ personality={}))
45+ req = webob.Request.blank('/v1.1/servers')
46+ req.method = 'POST'
47+ req.body = json.dumps(body)
48+ req.headers["content-type"] = "application/json"
49+ res = req.get_response(fakes.wsgi_app())
50+ self.assertEqual(res.status_int, 400)
51+
52+ def test_create_instance_v1_1_bad_flavor_href(self):
53+ self._setup_for_create_instance()
54+
55+ image_href = 'http://localhost/v1.1/images/2'
56+ flavor_ref = 'http://localhost/v1.1/flavors/17'
57+ body = dict(server=dict(
58+ name='server_test', imageRef=image_href, flavorRef=flavor_ref,
59+ metadata={'hello': 'world', 'open': 'stack'},
60+ personality={}))
61+ req = webob.Request.blank('/v1.1/servers')
62+ req.method = 'POST'
63+ req.body = json.dumps(body)
64+ req.headers["content-type"] = "application/json"
65+ res = req.get_response(fakes.wsgi_app())
66+ self.assertEqual(res.status_int, 400)
67+
68 def test_create_instance_v1_1_bad_href(self):
69 self._setup_for_create_instance()
70