From: Mike Perez <thingee@gmail.com>
Date: Fri, 22 Mar 2013 02:55:48 +0000 (-0700)
Subject: Fetch volume_types by uuid and not by name in v2
X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=2c2cd8847cdbe702a62f1637d0f2e89723aa1491;p=openstack-build%2Fcinder-build.git

Fetch volume_types by uuid and not by name in v2

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
(cherry picked from commit f5706319365dbd11cbc91bd69b09238afa51a626)
---

diff --git a/cinder/api/v2/views/volumes.py b/cinder/api/v2/views/volumes.py
index c7b6eb7d4..c1deec466 100644
--- a/cinder/api/v2/views/volumes.py
+++ b/cinder/api/v2/views/volumes.py
@@ -106,8 +106,7 @@ class ViewBuilder(common.ViewBuilder):
         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."""
diff --git a/cinder/api/v2/volumes.py b/cinder/api/v2/volumes.py
index 3db80e7e2..e78d0207c 100644
--- a/cinder/api/v2/volumes.py
+++ b/cinder/api/v2/volumes.py
@@ -240,7 +240,7 @@ class VolumeController(wsgi.Controller):
         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.'
diff --git a/cinder/tests/api/v2/test_volumes.py b/cinder/tests/api/v2/test_volumes.py
index df2d92f3d..baba2bdc8 100644
--- a/cinder/tests/api/v2/test_volumes.py
+++ b/cinder/tests/api/v2/test_volumes.py
@@ -98,19 +98,19 @@ class VolumeApiTest(test.TestCase):
         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')