Skip to content

Commit

Permalink
Fetch volume_types by uuid and not by name in v2
Browse files Browse the repository at this point in the history
This was left over from the UUID switch. Looking up volume_types by name
is deprecated in v1 and removed in v2.

Fixes: bug #1087817
Change-Id: I02cc035565f9496cd5af228c55ced5cafef2ad81
  • Loading branch information
Thingee committed Mar 22, 2013
1 parent c38a347 commit f570631
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
3 changes: 1 addition & 2 deletions cinder/api/v2/views/volumes.py
Expand Up @@ -106,8 +106,7 @@ def _get_volume_type(self, volume):
if volume['volume_type_id'] and volume.get('volume_type'):
return volume['volume_type']['name']
else:
# TODO(bcwaldon): remove str cast once we use uuids
return str(volume['volume_type_id'])
return volume['volume_type_id']

def _list_view(self, func, request, volumes):
"""Provide a view for a list of volumes."""
Expand Down
2 changes: 1 addition & 1 deletion cinder/api/v2/volumes.py
Expand Up @@ -240,7 +240,7 @@ def create(self, req, body):
req_volume_type = volume.get('volume_type', None)
if req_volume_type:
try:
kwargs['volume_type'] = volume_types.get_volume_type_by_name(
kwargs['volume_type'] = volume_types.get_volume_type(
context, req_volume_type)
except exception.VolumeTypeNotFound:
explanation = 'Volume type not found.'
Expand Down
12 changes: 6 additions & 6 deletions cinder/tests/api/v2/test_volumes.py
Expand Up @@ -98,19 +98,19 @@ def test_volume_create(self):
self.assertEqual(res_dict, expected)

def test_volume_create_with_type(self):
vol_type = FLAGS.default_volume_type
db.volume_type_create(context.get_admin_context(),
dict(name=vol_type, extra_specs={}))
vol_type = db.volume_type_create(context.get_admin_context(),
dict(name=FLAGS.default_volume_type,
extra_specs={}))

db_vol_type = db.volume_type_get_by_name(context.get_admin_context(),
vol_type)
db_vol_type = db.volume_type_get(context.get_admin_context(),
vol_type.id)

vol = {
"size": 100,
"name": "Volume Test Name",
"description": "Volume Test Desc",
"availability_zone": "zone1:host1",
"volume_type": db_vol_type['name'],
"volume_type": db_vol_type['id'],
}
body = {"volume": vol}
req = fakes.HTTPRequest.blank('/v2/volumes')
Expand Down

0 comments on commit f570631

Please sign in to comment.