Skip to content

Commit

Permalink
Cast volume-related ids to str
Browse files Browse the repository at this point in the history
* This is preparing the interface for uuids
* Fixes bug 943006

Change-Id: I7d27506118a830ae7257755032354ae7411567d3
  • Loading branch information
bcwaldon committed Feb 29, 2012
1 parent 2fa6e23 commit 5ab7378
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 deletions.
5 changes: 3 additions & 2 deletions nova/api/openstack/volume/snapshots.py
Expand Up @@ -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']
Expand Down
2 changes: 2 additions & 0 deletions nova/api/openstack/volume/types.py
Expand Up @@ -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}


Expand Down
13 changes: 10 additions & 3 deletions nova/api/openstack/volume/volumes.py
Expand Up @@ -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
Expand Down Expand Up @@ -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']
Expand All @@ -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'):
Expand Down
13 changes: 6 additions & 7 deletions nova/tests/api/openstack/volume/test_snapshots.py
Expand Up @@ -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"}
Expand All @@ -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"}
Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions nova/tests/api/openstack/volume/test_types.py
Expand Up @@ -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):
Expand Down
24 changes: 12 additions & 12 deletions nova/tests/api/openstack/volume/test_volumes.py
Expand Up @@ -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}}
Expand All @@ -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}]}
Expand All @@ -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}]}
Expand All @@ -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}}
Expand Down
12 changes: 6 additions & 6 deletions nova/tests/integrated/test_volumes.py
Expand Up @@ -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."""
Expand Down

0 comments on commit 5ab7378

Please sign in to comment.