diff options
| author | Jenkins <jenkins@review.openstack.org> | 2012-02-01 19:54:19 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2012-02-01 19:54:19 +0000 |
| commit | ecbc3322082a0c054a61cb2bcaa5969aa1e3e974 (patch) | |
| tree | 40e336ca03bfb91038ef669faa48fa62b26e1ec8 | |
| parent | c6251e8811de82357dee58ffc14c4c1789061876 (diff) | |
| parent | 48c275da1271f47b43e1270a3bdd99c7e20dd122 (diff) | |
Merge "Instances to be created with a bookmark link"
| -rw-r--r-- | nova/api/openstack/compute/servers.py | 7 | ||||
| -rw-r--r-- | nova/tests/api/openstack/compute/test_servers.py | 40 |
2 files changed, 45 insertions, 2 deletions
diff --git a/nova/api/openstack/compute/servers.py b/nova/api/openstack/compute/servers.py index d0e771e22..925c6d42c 100644 --- a/nova/api/openstack/compute/servers.py +++ b/nova/api/openstack/compute/servers.py @@ -636,8 +636,11 @@ class Controller(wsgi.Controller): # If the image href was generated by nova api, strip image_href # down to an id and use the default glance connection params - if str(image_href).startswith(req.application_url): - image_href = image_href.split('/').pop() + image_href = image_href.split('/').pop() + + if not utils.is_uuid_like(str(image_href)): + msg = _("Invalid imageRef provided.") + raise exc.HTTPBadRequest(explanation=msg) personality = server_dict.get('personality') config_drive = server_dict.get('config_drive') diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py index c6c7fcc43..c8aa876c6 100644 --- a/nova/tests/api/openstack/compute/test_servers.py +++ b/nova/tests/api/openstack/compute/test_servers.py @@ -1637,6 +1637,46 @@ class ServersControllerCreateTest(test.TestCase): reservation_id = res['reservation_id'] self.assertEqual(reservation_id, "myresid") + def test_create_instance_image_ref_is_bookmark(self): + image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6' + image_href = 'http://localhost/fake/images/%s' % image_uuid + flavor_ref = 'http://localhost/fake/flavors/3' + body = { + 'server': { + '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" + res = self.controller.create(req, body).obj + + server = res['server'] + self.assertEqual(FAKE_UUID, server['id']) + + def test_create_instance_image_ref_is_invalid(self): + image_uuid = 'this_is_not_a_valid_uuid' + image_href = 'http://localhost/fake/images/%s' % image_uuid + flavor_ref = 'http://localhost/fake/flavors/3' + body = { + 'server': { + '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_instance_no_key_pair(self): fakes.stub_out_key_pair_funcs(self.stubs, have_key_pair=False) self._test_create_instance() |
