Skip to content

Commit

Permalink
Force imageRef to be a string
Browse files Browse the repository at this point in the history
Fixes lp930409

Change-Id: Iff07a9b70210a43eb9442222e4d6cac60dd8f375
  • Loading branch information
jkoelker committed Feb 10, 2012
1 parent 6fb0adc commit cfa774e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion nova/api/openstack/compute/servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,7 +961,7 @@ def _get_key_name(self, req, body):

def _image_ref_from_req_data(self, data):
try:
return data['server']['imageRef']
return unicode(data['server']['imageRef'])
except (TypeError, KeyError):
msg = _("Missing imageRef attribute")
raise exc.HTTPBadRequest(explanation=msg)
Expand Down
21 changes: 21 additions & 0 deletions nova/tests/api/openstack/compute/test_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,27 @@ def _test_create_instance(self):
self._check_admin_pass_len(server)
self.assertEqual(FAKE_UUID, server['id'])

def test_create_server_bad_image_href(self):
image_href = 1
flavor_ref = 'http://localhost/123/flavors/3'

body = {
'server': {
'min_count': 1,
'name': 'server_test',
'imageRef': image_href,
'flavorRef': flavor_ref,
}
}
req = fakes.HTTPRequest.blank('/v2/fake/servers')
req.method = 'POST'
req.body = json.dumps(body)
req.headers["content-type"] = "application/json"
self.assertRaises(webob.exc.HTTPBadRequest,
self.controller.create,
req,
body)

def test_create_multiple_instances(self):
"""Test creating multiple instances but not asking for
reservation_id
Expand Down

0 comments on commit cfa774e

Please sign in to comment.