diff options
| author | William Wolf <throughnothing@gmail.com> | 2011-07-21 12:02:01 -0400 |
|---|---|---|
| committer | William Wolf <throughnothing@gmail.com> | 2011-07-21 12:02:01 -0400 |
| commit | dc616cd633007aa83d7576ae74cf807aa0df6776 (patch) | |
| tree | d93c30b3088b00e66d3158ccfede23e197416c03 | |
| parent | 9a843b10f3145405ebc01ded5d32ce68d02fdd8d (diff) | |
| download | nova-dc616cd633007aa83d7576ae74cf807aa0df6776.tar.gz nova-dc616cd633007aa83d7576ae74cf807aa0df6776.tar.xz nova-dc616cd633007aa83d7576ae74cf807aa0df6776.zip | |
fixed another issue with invalid flavor_id parsing, and added tests
| -rw-r--r-- | nova/api/openstack/create_instance_helper.py | 6 | ||||
| -rw-r--r-- | nova/tests/api/openstack/test_servers.py | 32 |
2 files changed, 37 insertions, 1 deletions
diff --git a/nova/api/openstack/create_instance_helper.py b/nova/api/openstack/create_instance_helper.py index 10aaa23b1..2b9256896 100644 --- a/nova/api/openstack/create_instance_helper.py +++ b/nova/api/openstack/create_instance_helper.py @@ -102,7 +102,11 @@ class CreateInstanceHelper(object): if personality: injected_files = self._get_injected_files(personality) - flavor_id = self.controller._flavor_id_from_req_data(body) + try: + flavor_id = self.controller._flavor_id_from_req_data(body) + except ValueError as error: + msg = _("Invalid flavorRef provided.") + raise faults.Fault(exc.HTTPBadRequest(explanation=msg)) if not 'name' in body['server']: msg = _("Server name is not defined") diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py index 3fc38b73c..7ceb0c075 100644 --- a/nova/tests/api/openstack/test_servers.py +++ b/nova/tests/api/openstack/test_servers.py @@ -997,6 +997,38 @@ class ServersTest(test.TestCase): self.assertEqual(flavor_ref, server['flavorRef']) self.assertEqual(image_href, server['imageRef']) + def test_create_instance_v1_1_invalid_flavor_href(self): + self._setup_for_create_instance() + + image_href = 'http://localhost/v1.1/images/2' + flavor_ref = 'http://localhost/v1.1/flavors/asdf' + body = dict(server=dict( + name='server_test', imageRef=image_href, flavorRef=flavor_ref, + metadata={'hello': 'world', 'open': 'stack'}, + personality={})) + req = webob.Request.blank('/v1.1/servers') + req.method = 'POST' + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 400) + + def test_create_instance_v1_1_bad_flavor_href(self): + self._setup_for_create_instance() + + image_href = 'http://localhost/v1.1/images/2' + flavor_ref = 'http://localhost/v1.1/flavors/17' + body = dict(server=dict( + name='server_test', imageRef=image_href, flavorRef=flavor_ref, + metadata={'hello': 'world', 'open': 'stack'}, + personality={})) + req = webob.Request.blank('/v1.1/servers') + req.method = 'POST' + req.body = json.dumps(body) + req.headers["content-type"] = "application/json" + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 400) + def test_create_instance_v1_1_bad_href(self): self._setup_for_create_instance() |
