Skip to content

Commit

Permalink
Volumes API now uses underscores for attrs
Browse files Browse the repository at this point in the history
* Fixes bug 943053

Change-Id: I7066e963b4377a4a1f8a3c259e6273e6a0ca073f
  • Loading branch information
bcwaldon committed Mar 26, 2012
1 parent 4e02ba1 commit fb370c3
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 112 deletions.
16 changes: 8 additions & 8 deletions nova/api/openstack/volume/snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,24 @@ def _translate_snapshot_summary_view(context, vol):

# TODO(bcwaldon): remove str cast once we use uuids
d['id'] = str(vol['id'])
d['volumeId'] = str(vol['volume_id'])
d['volume_id'] = str(vol['volume_id'])
d['status'] = vol['status']
# NOTE(gagupta): We map volume_size as the snapshot size
d['size'] = vol['volume_size']
d['createdAt'] = vol['created_at']
d['displayName'] = vol['display_name']
d['displayDescription'] = vol['display_description']
d['created_at'] = vol['created_at']
d['display_name'] = vol['display_name']
d['display_description'] = vol['display_description']
return d


def make_snapshot(elem):
elem.set('id')
elem.set('status')
elem.set('size')
elem.set('createdAt')
elem.set('displayName')
elem.set('displayDescription')
elem.set('volumeId')
elem.set('created_at')
elem.set('display_name')
elem.set('display_description')
elem.set('volume_id')


class SnapshotTemplate(xmlutil.TemplateBuilder):
Expand Down
38 changes: 19 additions & 19 deletions nova/api/openstack/volume/volumes.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def _translate_attachment_summary_view(_context, vol):
# NOTE(justinsb): We use the volume id as the id of the attachment object
d['id'] = volume_id

d['volumeId'] = volume_id
d['volume_id'] = volume_id
if vol.get('instance'):
d['serverId'] = vol['instance']['uuid']
d['server_id'] = vol['instance']['uuid']
if vol.get('mountpoint'):
d['device'] = vol['mountpoint']

Expand All @@ -81,27 +81,27 @@ def _translate_volume_summary_view(context, vol):
d['id'] = str(vol['id'])
d['status'] = vol['status']
d['size'] = vol['size']
d['availabilityZone'] = vol['availability_zone']
d['createdAt'] = vol['created_at']
d['availability_zone'] = vol['availability_zone']
d['created_at'] = vol['created_at']

d['attachments'] = []
if vol['attach_status'] == 'attached':
attachment = _translate_attachment_detail_view(context, vol)
d['attachments'].append(attachment)

d['displayName'] = vol['display_name']
d['displayDescription'] = vol['display_description']
d['display_name'] = vol['display_name']
d['display_description'] = vol['display_description']

if vol['volume_type_id'] and vol.get('volume_type'):
d['volumeType'] = vol['volume_type']['name']
d['volume_type'] = vol['volume_type']['name']
else:
# TODO(bcwaldon): remove str cast once we use uuids
d['volumeType'] = str(vol['volume_type_id'])
d['volume_type'] = str(vol['volume_type_id'])

d['snapshotId'] = vol['snapshot_id']
d['snapshot_id'] = vol['snapshot_id']
# TODO(bcwaldon): remove str cast once we use uuids
if d['snapshotId'] is not None:
d['snapshotId'] = str(d['snapshotId'])
if d['snapshot_id'] is not None:
d['snapshot_id'] = str(d['snapshot_id'])

LOG.audit(_("vol=%s"), vol, context=context)

Expand All @@ -118,21 +118,21 @@ def _translate_volume_summary_view(context, vol):

def make_attachment(elem):
elem.set('id')
elem.set('serverId')
elem.set('volumeId')
elem.set('server_id')
elem.set('volume_id')
elem.set('device')


def make_volume(elem):
elem.set('id')
elem.set('status')
elem.set('size')
elem.set('availabilityZone')
elem.set('createdAt')
elem.set('displayName')
elem.set('displayDescription')
elem.set('volumeType')
elem.set('snapshotId')
elem.set('availability_zone')
elem.set('created_at')
elem.set('display_name')
elem.set('display_description')
elem.set('volume_type')
elem.set('snapshot_id')

attachments = xmlutil.SubTemplateElement(elem, 'attachments')
attachment = xmlutil.SubTemplateElement(attachments, 'attachment',
Expand Down
36 changes: 18 additions & 18 deletions nova/tests/api/openstack/volume/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ def test_snapshot_create(self):
resp_dict = self.controller.create(req, body)

self.assertTrue('snapshot' in resp_dict)
self.assertEqual(resp_dict['snapshot']['displayName'],
self.assertEqual(resp_dict['snapshot']['display_name'],
snapshot['display_name'])
self.assertEqual(resp_dict['snapshot']['displayDescription'],
self.assertEqual(resp_dict['snapshot']['display_description'],
snapshot['display_description'])

def test_snapshot_create_force(self):
Expand All @@ -108,9 +108,9 @@ def test_snapshot_create_force(self):
resp_dict = self.controller.create(req, body)

self.assertTrue('snapshot' in resp_dict)
self.assertEqual(resp_dict['snapshot']['displayName'],
self.assertEqual(resp_dict['snapshot']['display_name'],
snapshot['display_name'])
self.assertEqual(resp_dict['snapshot']['displayDescription'],
self.assertEqual(resp_dict['snapshot']['display_description'],
snapshot['display_description'])

def test_snapshot_delete(self):
Expand Down Expand Up @@ -161,8 +161,8 @@ class SnapshotSerializerTest(test.TestCase):
def _verify_snapshot(self, snap, tree):
self.assertEqual(tree.tag, 'snapshot')

for attr in ('id', 'status', 'size', 'createdAt',
'displayName', 'displayDescription', 'volumeId'):
for attr in ('id', 'status', 'size', 'created_at',
'display_name', 'display_description', 'volume_id'):
self.assertEqual(str(snap[attr]), tree.get(attr))

def test_snapshot_show_create_serializer(self):
Expand All @@ -171,10 +171,10 @@ def test_snapshot_show_create_serializer(self):
id='snap_id',
status='snap_status',
size=1024,
createdAt=datetime.datetime.now(),
displayName='snap_name',
displayDescription='snap_desc',
volumeId='vol_id',
created_at=datetime.datetime.now(),
display_name='snap_name',
display_description='snap_desc',
volume_id='vol_id',
)
text = serializer.serialize(dict(snapshot=raw_snapshot))

Expand All @@ -189,19 +189,19 @@ def test_snapshot_index_detail_serializer(self):
id='snap1_id',
status='snap1_status',
size=1024,
createdAt=datetime.datetime.now(),
displayName='snap1_name',
displayDescription='snap1_desc',
volumeId='vol1_id',
created_at=datetime.datetime.now(),
display_name='snap1_name',
display_description='snap1_desc',
volume_id='vol1_id',
),
dict(
id='snap2_id',
status='snap2_status',
size=1024,
createdAt=datetime.datetime.now(),
displayName='snap2_name',
displayDescription='snap2_desc',
volumeId='vol2_id',
created_at=datetime.datetime.now(),
display_name='snap2_name',
display_description='snap2_desc',
volume_id='vol2_id',
)]
text = serializer.serialize(dict(snapshots=raw_snapshots))

Expand Down

0 comments on commit fb370c3

Please sign in to comment.