summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Meade <alex.meade@rackspace.com>2012-01-23 21:30:20 +0000
committerAlex Meade <alex.meade@rackspace.com>2012-01-27 22:36:49 +0000
commit48c275da1271f47b43e1270a3bdd99c7e20dd122 (patch)
tree49e6ce57f65968744423a3fbd47fda43a65e2dde
parentaefed532691f92c2e4b418afbef54479ac18ae57 (diff)
Instances to be created with a bookmark link
Fixes bug 913545 Change-Id: I6401a631211d76a8942d3435fb7dd463630cac7a
-rw-r--r--nova/api/openstack/compute/servers.py7
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py40
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()