diff options
| author | Jason Kölker <jason@koelker.net> | 2012-02-10 15:10:47 -0600 |
|---|---|---|
| committer | Jason Kölker <jason@koelker.net> | 2012-02-10 15:23:24 -0600 |
| commit | cfa774eecee8f1fa800e9028f2c7f52a2ae028f6 (patch) | |
| tree | 0f7a4b7a8f691988fe541654239a518034fff11e | |
| parent | 6fb0adc066f0f8a64a5ec1fdcbe374b26935485a (diff) | |
| download | nova-cfa774eecee8f1fa800e9028f2c7f52a2ae028f6.tar.gz nova-cfa774eecee8f1fa800e9028f2c7f52a2ae028f6.tar.xz nova-cfa774eecee8f1fa800e9028f2c7f52a2ae028f6.zip | |
Force imageRef to be a string
Fixes lp930409
Change-Id: Iff07a9b70210a43eb9442222e4d6cac60dd8f375
| -rw-r--r-- | nova/api/openstack/compute/servers.py | 2 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/test_servers.py | 21 |
2 files changed, 22 insertions, 1 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index 57adf22ae..b38a6321f 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -961,7 +961,7 @@ class Controller(wsgi.Controller): 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) diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index 14f49684f..36027e5db 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1505,6 +1505,27 @@ class ServersControllerCreateTest(test.TestCase): 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 |
