From bf17f8bd2dcab3364cb47a3a148121dcd8b3284d Mon Sep 17 00:00:00 2001 From: Ivan Kolodyazhny Date: Mon, 13 Oct 2014 11:57:58 +0300 Subject: [PATCH] Remove vol_type_id cast to str 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 | 2 -- cinder/api/v1/volumes.py | 3 +-- cinder/api/v2/types.py | 2 -- cinder/tests/api/v1/test_types.py | 14 +++++++++----- cinder/tests/api/v1/test_volumes.py | 8 ++++---- cinder/tests/api/v2/test_types.py | 14 +++++++++----- 6 files changed, 23 insertions(+), 20 deletions(-) diff --git a/cinder/api/v1/types.py b/cinder/api/v1/types.py index aa1256b33..52fa4cae2 100644 --- a/cinder/api/v1/types.py +++ b/cinder/api/v1/types.py @@ -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) diff --git a/cinder/api/v1/volumes.py b/cinder/api/v1/volumes.py index 5e6968f7b..88895c667 100644 --- a/cinder/api/v1/volumes.py +++ b/cinder/api/v1/volumes.py @@ -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'] diff --git a/cinder/api/v2/types.py b/cinder/api/v2/types.py index fa37dc56a..75f8ee75a 100644 --- a/cinder/api/v2/types.py +++ b/cinder/api/v2/types.py @@ -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) diff --git a/cinder/tests/api/v1/test_types.py b/cinder/tests/api/v1/test_types.py index 3f72989de..47c80be98 100644 --- a/cinder/tests/api/v1/test_types.py +++ b/cinder/tests/api/v1/test_types.py @@ -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', diff --git a/cinder/tests/api/v1/test_volumes.py b/cinder/tests/api/v1/test_volumes.py index 9eb8b011a..0a50c2b1e 100644 --- a/cinder/tests/api/v1/test_volumes.py +++ b/cinder/tests/api/v1/test_volumes.py @@ -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', diff --git a/cinder/tests/api/v2/test_types.py b/cinder/tests/api/v2/test_types.py index 1af532f0b..dc82b1c86 100644 --- a/cinder/tests/api/v2/test_types.py +++ b/cinder/tests/api/v2/test_types.py @@ -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', -- 2.45.2