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

Proposed by William Wolf
Status: Merged
Approved by: Brian Lamar
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
nova/api/openstack/create_instance_helper.py (+8/-2)
nova/tests/api/openstack/test_servers.py (+32/-0)
To merge this branch: bzr merge lp:~rackspace-titan/nova/lp803615
Reviewer Review Type Date Requested Status
Brian Lamar (community) Approve
Brian Waldon (community) Approve
Devin Carlen (community) Approve
Alex Meade (community) Approve
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.
Revision history for this message
Alex Meade (alex-meade) wrote :

Looks good Will. Nice work

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

lgtm

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

Looks good, Will.

review: Approve
Revision history for this message
Brian Lamar (blamar) wrote :

Good here.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'nova/api/openstack/create_instance_helper.py'
--- nova/api/openstack/create_instance_helper.py 2011-07-21 14:02:16 +0000
+++ nova/api/openstack/create_instance_helper.py 2011-07-21 19:17:39 +0000
@@ -101,7 +101,11 @@
101 if personality:101 if personality:
102 injected_files = self._get_injected_files(personality)102 injected_files = self._get_injected_files(personality)
103103
104 flavor_id = self.controller._flavor_id_from_req_data(body)104 try:
105 flavor_id = self.controller._flavor_id_from_req_data(body)
106 except ValueError as error:
107 msg = _("Invalid flavorRef provided.")
108 raise exc.HTTPBadRequest(explanation=msg)
105109
106 if not 'name' in body['server']:110 if not 'name' in body['server']:
107 msg = _("Server name is not defined")111 msg = _("Server name is not defined")
@@ -153,7 +157,9 @@
153 except exception.ImageNotFound as error:157 except exception.ImageNotFound as error:
154 msg = _("Can not find requested image")158 msg = _("Can not find requested image")
155 raise exc.HTTPBadRequest(explanation=msg)159 raise exc.HTTPBadRequest(explanation=msg)
156160 except exception.FlavorNotFound as error:
161 msg = _("Invalid flavorRef provided.")
162 raise exc.HTTPBadRequest(explanation=msg)
157 # Let the caller deal with unhandled exceptions.163 # Let the caller deal with unhandled exceptions.
158164
159 def _handle_quota_error(self, error):165 def _handle_quota_error(self, error):
160166
=== modified file 'nova/tests/api/openstack/test_servers.py'
--- nova/tests/api/openstack/test_servers.py 2011-07-21 18:49:57 +0000
+++ nova/tests/api/openstack/test_servers.py 2011-07-21 19:17:39 +0000
@@ -997,6 +997,38 @@
997 self.assertEqual(flavor_ref, server['flavorRef'])997 self.assertEqual(flavor_ref, server['flavorRef'])
998 self.assertEqual(image_href, server['imageRef'])998 self.assertEqual(image_href, server['imageRef'])
999999
1000 def test_create_instance_v1_1_invalid_flavor_href(self):
1001 self._setup_for_create_instance()
1002
1003 image_href = 'http://localhost/v1.1/images/2'
1004 flavor_ref = 'http://localhost/v1.1/flavors/asdf'
1005 body = dict(server=dict(
1006 name='server_test', imageRef=image_href, flavorRef=flavor_ref,
1007 metadata={'hello': 'world', 'open': 'stack'},
1008 personality={}))
1009 req = webob.Request.blank('/v1.1/servers')
1010 req.method = 'POST'
1011 req.body = json.dumps(body)
1012 req.headers["content-type"] = "application/json"
1013 res = req.get_response(fakes.wsgi_app())
1014 self.assertEqual(res.status_int, 400)
1015
1016 def test_create_instance_v1_1_bad_flavor_href(self):
1017 self._setup_for_create_instance()
1018
1019 image_href = 'http://localhost/v1.1/images/2'
1020 flavor_ref = 'http://localhost/v1.1/flavors/17'
1021 body = dict(server=dict(
1022 name='server_test', imageRef=image_href, flavorRef=flavor_ref,
1023 metadata={'hello': 'world', 'open': 'stack'},
1024 personality={}))
1025 req = webob.Request.blank('/v1.1/servers')
1026 req.method = 'POST'
1027 req.body = json.dumps(body)
1028 req.headers["content-type"] = "application/json"
1029 res = req.get_response(fakes.wsgi_app())
1030 self.assertEqual(res.status_int, 400)
1031
1000 def test_create_instance_v1_1_bad_href(self):1032 def test_create_instance_v1_1_bad_href(self):
1001 self._setup_for_create_instance()1033 self._setup_for_create_instance()
10021034