From 5ab7378357312a8f326bf82cf2b6076d14b53d6b Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 28 Feb 2012 17:48:49 -0800 Subject: [PATCH] Cast volume-related ids to str * This is preparing the interface for uuids * Fixes bug 943006 Change-Id: I7d27506118a830ae7257755032354ae7411567d3 --- nova/api/openstack/volume/snapshots.py | 5 ++-- nova/api/openstack/volume/types.py | 2 ++ nova/api/openstack/volume/volumes.py | 13 +++++++--- .../api/openstack/volume/test_snapshots.py | 13 +++++----- nova/tests/api/openstack/volume/test_types.py | 1 + .../api/openstack/volume/test_volumes.py | 24 +++++++++---------- nova/tests/integrated/test_volumes.py | 12 +++++----- 7 files changed, 40 insertions(+), 30 deletions(-) diff --git a/nova/api/openstack/volume/snapshots.py b/nova/api/openstack/volume/snapshots.py index b6dc831708b..abfdd602ec5 100644 --- a/nova/api/openstack/volume/snapshots.py +++ b/nova/api/openstack/volume/snapshots.py @@ -46,8 +46,9 @@ def _translate_snapshot_summary_view(context, vol): """Maps keys for snapshots summary view.""" d = {} - d['id'] = vol['id'] - d['volumeId'] = vol['volume_id'] + # TODO(bcwaldon): remove str cast once we use uuids + d['id'] = str(vol['id']) + d['volumeId'] = str(vol['volume_id']) d['status'] = vol['status'] # NOTE(gagupta): We map volume_size as the snapshot size d['size'] = vol['volume_size'] diff --git a/nova/api/openstack/volume/types.py b/nova/api/openstack/volume/types.py index 80875e06fb1..0b55e6ebce0 100644 --- a/nova/api/openstack/volume/types.py +++ b/nova/api/openstack/volume/types.py @@ -67,6 +67,8 @@ def show(self, req, id): except exception.NotFound: raise exc.HTTPNotFound() + # TODO(bcwaldon): remove str cast once we use uuids + vol_type['id'] = str(vol_type['id']) return {'volume_type': vol_type} diff --git a/nova/api/openstack/volume/volumes.py b/nova/api/openstack/volume/volumes.py index 10d83a000e6..45ad297a488 100644 --- a/nova/api/openstack/volume/volumes.py +++ b/nova/api/openstack/volume/volumes.py @@ -48,7 +48,8 @@ def _translate_attachment_summary_view(_context, vol): """Maps keys for attachment summary view.""" d = {} - volume_id = vol['id'] + # TODO(bcwaldon): remove str cast once we use uuids + volume_id = str(vol['id']) # NOTE(justinsb): We use the volume id as the id of the attachment object d['id'] = volume_id @@ -76,7 +77,8 @@ def _translate_volume_summary_view(context, vol): """Maps keys for volumes summary view.""" d = {} - d['id'] = vol['id'] + # TODO(bcwaldon): remove str cast once we use uuids + d['id'] = str(vol['id']) d['status'] = vol['status'] d['size'] = vol['size'] d['availabilityZone'] = vol['availability_zone'] @@ -93,9 +95,14 @@ def _translate_volume_summary_view(context, vol): if vol['volume_type_id'] and vol.get('volume_type'): d['volumeType'] = vol['volume_type']['name'] else: - d['volumeType'] = vol['volume_type_id'] + # TODO(bcwaldon): remove str cast once we use uuids + d['volumeType'] = str(vol['volume_type_id']) d['snapshotId'] = vol['snapshot_id'] + # TODO(bcwaldon): remove str cast once we use uuids + if d['snapshotId'] is not None: + d['snapshotId'] = str(d['snapshotId']) + LOG.audit(_("vol=%s"), vol, context=context) if vol.get('volume_metadata'): diff --git a/nova/tests/api/openstack/volume/test_snapshots.py b/nova/tests/api/openstack/volume/test_snapshots.py index 0ef112ee940..95efc539ba8 100644 --- a/nova/tests/api/openstack/volume/test_snapshots.py +++ b/nova/tests/api/openstack/volume/test_snapshots.py @@ -81,7 +81,7 @@ def setUp(self): def test_snapshot_create(self): self.stubs.Set(volume.api.API, "create_snapshot", stub_snapshot_create) self.stubs.Set(volume.api.API, 'get', fakes.stub_volume_get) - snapshot = {"volume_id": 12, + snapshot = {"volume_id": '12', "force": False, "display_name": "Snapshot Test Name", "display_description": "Snapshot Test Desc"} @@ -99,7 +99,7 @@ def test_snapshot_create_force(self): self.stubs.Set(volume.api.API, "create_snapshot_force", stub_snapshot_create) self.stubs.Set(volume.api.API, 'get', fakes.stub_volume_get) - snapshot = {"volume_id": 12, + snapshot = {"volume_id": '12', "force": True, "display_name": "Snapshot Test Name", "display_description": "Snapshot Test Desc"} @@ -131,12 +131,11 @@ def test_snapshot_delete_invalid_id(self): snapshot_id) def test_snapshot_show(self): - snapshot_id = 123 - req = fakes.HTTPRequest.blank('/v1/snapshots/%d' % snapshot_id) - resp_dict = self.controller.show(req, snapshot_id) + req = fakes.HTTPRequest.blank('/v1/snapshots/123') + resp_dict = self.controller.show(req, 123) self.assertTrue('snapshot' in resp_dict) - self.assertEqual(resp_dict['snapshot']['id'], snapshot_id) + self.assertEqual(resp_dict['snapshot']['id'], '123') def test_snapshot_show_invalid_id(self): snapshot_id = 234 @@ -155,7 +154,7 @@ def test_snapshot_detail(self): self.assertEqual(len(resp_snapshots), 1) resp_snapshot = resp_snapshots.pop() - self.assertEqual(resp_snapshot['id'], 123) + self.assertEqual(resp_snapshot['id'], '123') class SnapshotSerializerTest(test.TestCase): diff --git a/nova/tests/api/openstack/volume/test_types.py b/nova/tests/api/openstack/volume/test_types.py index e16d853e5de..4628804431f 100644 --- a/nova/tests/api/openstack/volume/test_types.py +++ b/nova/tests/api/openstack/volume/test_types.py @@ -112,6 +112,7 @@ def test_volume_types_show(self): res_dict = self.controller.show(req, 1) self.assertEqual(1, len(res_dict)) + self.assertEqual('1', res_dict['volume_type']['id']) self.assertEqual('vol_type_1', res_dict['volume_type']['name']) def test_volume_types_show_not_found(self): diff --git a/nova/tests/api/openstack/volume/test_volumes.py b/nova/tests/api/openstack/volume/test_volumes.py index e22e8ac1346..9e9b5ff7107 100644 --- a/nova/tests/api/openstack/volume/test_volumes.py +++ b/nova/tests/api/openstack/volume/test_volumes.py @@ -56,12 +56,12 @@ def test_volume_create(self): 'displayName': 'Volume Test Name', 'attachments': [{'device': '/', 'serverId': 'fakeuuid', - 'id': 1, - 'volumeId': 1}], + 'id': '1', + 'volumeId': '1'}], 'volumeType': 'vol_type_name', 'snapshotId': None, 'metadata': {}, - 'id': 1, + 'id': '1', 'createdAt': datetime.datetime(1, 1, 1, 1, 1, 1), 'size': 100}} @@ -84,12 +84,12 @@ def test_volume_list(self): 'displayName': 'displayname', 'attachments': [{'device': '/', 'serverId': 'fakeuuid', - 'id': 1, - 'volumeId': 1}], + 'id': '1', + 'volumeId': '1'}], 'volumeType': 'vol_type_name', 'snapshotId': None, 'metadata': {}, - 'id': 1, + 'id': '1', 'createdAt': datetime.datetime(1, 1, 1, 1, 1, 1), 'size': 1}]} @@ -104,12 +104,12 @@ def test_volume_list_detail(self): 'displayName': 'displayname', 'attachments': [{'device': '/', 'serverId': 'fakeuuid', - 'id': 1, - 'volumeId': 1}], + 'id': '1', + 'volumeId': '1'}], 'volumeType': 'vol_type_name', 'snapshotId': None, 'metadata': {}, - 'id': 1, + 'id': '1', 'createdAt': datetime.datetime(1, 1, 1, 1, 1, 1), 'size': 1}]} @@ -124,12 +124,12 @@ def test_volume_show(self): 'displayName': 'displayname', 'attachments': [{'device': '/', 'serverId': 'fakeuuid', - 'id': 1, - 'volumeId': 1}], + 'id': '1', + 'volumeId': '1'}], 'volumeType': 'vol_type_name', 'snapshotId': None, 'metadata': {}, - 'id': 1, + 'id': '1', 'createdAt': datetime.datetime(1, 1, 1, 1, 1, 1), 'size': 1}} diff --git a/nova/tests/integrated/test_volumes.py b/nova/tests/integrated/test_volumes.py index 8a0721ca10b..8a6089595b4 100644 --- a/nova/tests/integrated/test_volumes.py +++ b/nova/tests/integrated/test_volumes.py @@ -118,29 +118,29 @@ def test_create_and_delete_volume(self): create_actions = driver.LoggingVolumeDriver.logs_like( 'create_volume', - id=created_volume_id) + id=int(created_volume_id)) LOG.debug("Create_Actions: %s" % create_actions) self.assertEquals(1, len(create_actions)) create_action = create_actions[0] - self.assertEquals(create_action['id'], created_volume_id) + self.assertEquals(create_action['id'], int(created_volume_id)) self.assertEquals(create_action['availability_zone'], 'nova') self.assertEquals(create_action['size'], 1) export_actions = driver.LoggingVolumeDriver.logs_like( 'create_export', - id=created_volume_id) + id=int(created_volume_id)) self.assertEquals(1, len(export_actions)) export_action = export_actions[0] - self.assertEquals(export_action['id'], created_volume_id) + self.assertEquals(export_action['id'], int(created_volume_id)) self.assertEquals(export_action['availability_zone'], 'nova') delete_actions = driver.LoggingVolumeDriver.logs_like( 'delete_volume', - id=created_volume_id) + id=int(created_volume_id)) self.assertEquals(1, len(delete_actions)) delete_action = export_actions[0] - self.assertEquals(delete_action['id'], created_volume_id) + self.assertEquals(delete_action['id'], int(created_volume_id)) def test_create_volume_with_metadata(self): """Creates a volume with metadata."""