Navigation Menu

Skip to content

Commit

Permalink
Instances to be created with a bookmark link
Browse files Browse the repository at this point in the history
Fixes bug 913545

Change-Id: I6401a631211d76a8942d3435fb7dd463630cac7a
  • Loading branch information
ameade committed Jan 27, 2012
1 parent aefed53 commit 48c275d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nova/api/openstack/compute/servers.py
Expand Up @@ -636,8 +636,11 @@ def create(self, req, body):

# 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')
Expand Down
40 changes: 40 additions & 0 deletions nova/tests/api/openstack/compute/test_servers.py
Expand Up @@ -1637,6 +1637,46 @@ def test_create_instance_with_admin_supplied_reservation_id(self):
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()
Expand Down

0 comments on commit 48c275d

Please sign in to comment.