]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Remove vol_type_id cast to str
authorIvan Kolodyazhny <e0ne@e0ne.info>
Mon, 13 Oct 2014 08:57:58 +0000 (11:57 +0300)
committerIvan Kolodyazhny <e0ne@e0ne.info>
Tue, 14 Oct 2014 13:17:32 +0000 (16:17 +0300)
Volume Type ID is string field, so we don't need to cast it
to str one more time

Change-Id: I8dcbfb770c412624d59c80bebe00d8c27ab0f823

cinder/api/v1/types.py
cinder/api/v1/volumes.py
cinder/api/v2/types.py
cinder/tests/api/v1/test_types.py
cinder/tests/api/v1/test_volumes.py
cinder/tests/api/v2/test_types.py

index aa1256b33eaafc5bfd6dc144dfd081239cd52147..52fa4cae26603d2ef2ae39353f7cee0a1602d468 100644 (file)
@@ -69,8 +69,6 @@ class VolumeTypesController(wsgi.Controller):
         except exception.NotFound:
             raise exc.HTTPNotFound()
 
-        # TODO(bcwaldon): remove str cast once we use uuids
-        vol_type['id'] = str(vol_type['id'])
         return self._view_builder.show(req, vol_type)
 
 
index 5e6968f7b319d1b3017a4a5883956f1331ab83c5..88895c667db9225b08c7e5c139b47a802a714581 100644 (file)
@@ -102,8 +102,7 @@ def _translate_volume_summary_view(context, vol, image_id=None):
     if vol['volume_type_id'] and vol.get('volume_type'):
         d['volume_type'] = vol['volume_type']['name']
     else:
-        # TODO(bcwaldon): remove str cast once we use uuids
-        d['volume_type'] = str(vol['volume_type_id'])
+        d['volume_type'] = vol['volume_type_id']
 
     d['snapshot_id'] = vol['snapshot_id']
     d['source_volid'] = vol['source_volid']
index fa37dc56ae3e4056e389b1f306ba2df0fb10a1d7..75f8ee75a0d04391915ca648d35b91c30733c2fa 100644 (file)
@@ -71,8 +71,6 @@ class VolumeTypesController(wsgi.Controller):
             msg = _("Volume type not found")
             raise exc.HTTPNotFound(explanation=msg)
 
-        # TODO(bcwaldon): remove str cast once we use uuids
-        vol_type['id'] = str(vol_type['id'])
         return self._view_builder.show(req, vol_type)
 
 
index 3f72989de7794a1cf44d3cf8e0a69cc5351d1e2f..47c80be9846e88051c467f21341f399f97736b0d 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import uuid
+
 from lxml import etree
 import webob
 
@@ -47,7 +49,7 @@ def return_empty_volume_types_get_all_types(context):
 def return_volume_types_get_volume_type(context, id):
     if id == "777":
         raise exception.VolumeTypeNotFound(volume_type_id=id)
-    return stub_volume_type(int(id))
+    return stub_volume_type(id)
 
 
 def return_volume_types_get_by_name(context, name):
@@ -89,12 +91,14 @@ class VolumeTypesApiTest(test.TestCase):
         self.stubs.Set(volume_types, 'get_volume_type',
                        return_volume_types_get_volume_type)
 
-        req = fakes.HTTPRequest.blank('/v1/fake/types/1')
-        res_dict = self.controller.show(req, 1)
+        type_id = str(uuid.uuid4())
+        req = fakes.HTTPRequest.blank('/v1/fake/types/' + type_id)
+        res_dict = self.controller.show(req, type_id)
 
         self.assertEqual(1, len(res_dict))
-        self.assertEqual('1', res_dict['volume_type']['id'])
-        self.assertEqual('vol_type_1', res_dict['volume_type']['name'])
+        self.assertEqual(type_id, res_dict['volume_type']['id'])
+        vol_type_name = 'vol_type_' + type_id
+        self.assertEqual(vol_type_name, res_dict['volume_type']['name'])
 
     def test_volume_types_show_not_found(self):
         self.stubs.Set(volume_types, 'get_volume_type',
index 9eb8b011adb64ae42ce29c6d4ad7be0311a4bdf5..0a50c2b1e84b3c8a236ef38a5e2f987b5258fe4c 100644 (file)
@@ -352,7 +352,7 @@ class VolumeApiTest(test.TestCase):
                 'device': '/'
             }],
             'bootable': 'false',
-            'volume_type': 'None',
+            'volume_type': None,
             'snapshot_id': None,
             'source_volid': None,
             'metadata': {'key': 'value',
@@ -446,7 +446,7 @@ class VolumeApiTest(test.TestCase):
                                                   'id': '1',
                                                   'volume_id': '1'}],
                                  'bootable': 'false',
-                                 'volume_type': 'None',
+                                 'volume_type': None,
                                  'snapshot_id': None,
                                  'source_volid': None,
                                  'metadata': {'key': 'value',
@@ -515,7 +515,7 @@ class VolumeApiTest(test.TestCase):
                                                   'id': '1',
                                                   'volume_id': '1'}],
                                  'bootable': 'false',
-                                 'volume_type': 'None',
+                                 'volume_type': None,
                                  'snapshot_id': None,
                                  'source_volid': None,
                                  'metadata': {'key': 'value',
@@ -677,7 +677,7 @@ class VolumeApiTest(test.TestCase):
                                                 'id': '1',
                                                 'volume_id': '1'}],
                                'bootable': 'false',
-                               'volume_type': 'None',
+                               'volume_type': None,
                                'snapshot_id': None,
                                'source_volid': None,
                                'metadata': {'key': 'value',
index 1af532f0b3fb54a9dab86afdcb6d25e7a3540a01..dc82b1c86ba7367055836aad3aed366ad2f887c5 100644 (file)
@@ -13,6 +13,8 @@
 #    License for the specific language governing permissions and limitations
 #    under the License.
 
+import uuid
+
 from lxml import etree
 import webob
 
@@ -55,7 +57,7 @@ def return_empty_volume_types_get_all_types(context):
 def return_volume_types_get_volume_type(context, id):
     if id == "777":
         raise exception.VolumeTypeNotFound(volume_type_id=id)
-    return stub_volume_type(int(id))
+    return stub_volume_type(id)
 
 
 def return_volume_types_get_by_name(context, name):
@@ -97,12 +99,14 @@ class VolumeTypesApiTest(test.TestCase):
         self.stubs.Set(volume_types, 'get_volume_type',
                        return_volume_types_get_volume_type)
 
-        req = fakes.HTTPRequest.blank('/v2/fake/types/1')
-        res_dict = self.controller.show(req, 1)
+        type_id = str(uuid.uuid4())
+        req = fakes.HTTPRequest.blank('/v2/fake/types/' + type_id)
+        res_dict = self.controller.show(req, type_id)
 
         self.assertEqual(1, len(res_dict))
-        self.assertEqual('1', res_dict['volume_type']['id'])
-        self.assertEqual('vol_type_1', res_dict['volume_type']['name'])
+        self.assertEqual(type_id, res_dict['volume_type']['id'])
+        type_name = 'vol_type_' + type_id
+        self.assertEqual(type_name, res_dict['volume_type']['name'])
 
     def test_volume_types_show_not_found(self):
         self.stubs.Set(volume_types, 'get_volume_type',