Volumes API now uses underscores for attrs
* Fixes bug 943053 Change-Id: I7066e963b4377a4a1f8a3c259e6273e6a0ca073f
This commit is contained in:
@@ -48,13 +48,13 @@ 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
|
||||
|
||||
|
||||
@@ -62,10 +62,10 @@ 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):
|
||||
|
||||
@@ -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']
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -118,8 +118,8 @@ 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')
|
||||
|
||||
|
||||
@@ -127,12 +127,12 @@ 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',
|
||||
|
||||
@@ -90,9 +90,9 @@ class SnapshotApiTest(test.TestCase):
|
||||
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):
|
||||
@@ -108,9 +108,9 @@ class SnapshotApiTest(test.TestCase):
|
||||
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):
|
||||
@@ -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):
|
||||
@@ -171,10 +171,10 @@ class SnapshotSerializerTest(test.TestCase):
|
||||
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))
|
||||
|
||||
@@ -189,19 +189,19 @@ class SnapshotSerializerTest(test.TestCase):
|
||||
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))
|
||||
|
||||
|
||||
@@ -48,18 +48,18 @@ class VolumeApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v1/volumes')
|
||||
res_dict = self.controller.create(req, body)
|
||||
expected = {'volume': {'status': 'fakestatus',
|
||||
'displayDescription': 'Volume Test Desc',
|
||||
'availabilityZone': 'zone1:host1',
|
||||
'displayName': 'Volume Test Name',
|
||||
'display_description': 'Volume Test Desc',
|
||||
'availability_zone': 'zone1:host1',
|
||||
'display_name': 'Volume Test Name',
|
||||
'attachments': [{'device': '/',
|
||||
'serverId': 'fakeuuid',
|
||||
'server_id': 'fakeuuid',
|
||||
'id': '1',
|
||||
'volumeId': '1'}],
|
||||
'volumeType': 'vol_type_name',
|
||||
'snapshotId': None,
|
||||
'volume_id': '1'}],
|
||||
'volume_type': 'vol_type_name',
|
||||
'snapshot_id': None,
|
||||
'metadata': {},
|
||||
'id': '1',
|
||||
'createdAt': datetime.datetime(1, 1, 1,
|
||||
'created_at': datetime.datetime(1, 1, 1,
|
||||
1, 1, 1),
|
||||
'size': 100}}
|
||||
self.assertEqual(res_dict, expected)
|
||||
@@ -76,18 +76,18 @@ class VolumeApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v1/volumes')
|
||||
res_dict = self.controller.index(req)
|
||||
expected = {'volumes': [{'status': 'fakestatus',
|
||||
'displayDescription': 'displaydesc',
|
||||
'availabilityZone': 'fakeaz',
|
||||
'displayName': 'displayname',
|
||||
'display_description': 'displaydesc',
|
||||
'availability_zone': 'fakeaz',
|
||||
'display_name': 'displayname',
|
||||
'attachments': [{'device': '/',
|
||||
'serverId': 'fakeuuid',
|
||||
'server_id': 'fakeuuid',
|
||||
'id': '1',
|
||||
'volumeId': '1'}],
|
||||
'volumeType': 'vol_type_name',
|
||||
'snapshotId': None,
|
||||
'volume_id': '1'}],
|
||||
'volume_type': 'vol_type_name',
|
||||
'snapshot_id': None,
|
||||
'metadata': {},
|
||||
'id': '1',
|
||||
'createdAt': datetime.datetime(1, 1, 1,
|
||||
'created_at': datetime.datetime(1, 1, 1,
|
||||
1, 1, 1),
|
||||
'size': 1}]}
|
||||
self.assertEqual(res_dict, expected)
|
||||
@@ -96,18 +96,18 @@ class VolumeApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v1/volumes/detail')
|
||||
res_dict = self.controller.index(req)
|
||||
expected = {'volumes': [{'status': 'fakestatus',
|
||||
'displayDescription': 'displaydesc',
|
||||
'availabilityZone': 'fakeaz',
|
||||
'displayName': 'displayname',
|
||||
'display_description': 'displaydesc',
|
||||
'availability_zone': 'fakeaz',
|
||||
'display_name': 'displayname',
|
||||
'attachments': [{'device': '/',
|
||||
'serverId': 'fakeuuid',
|
||||
'server_id': 'fakeuuid',
|
||||
'id': '1',
|
||||
'volumeId': '1'}],
|
||||
'volumeType': 'vol_type_name',
|
||||
'snapshotId': None,
|
||||
'volume_id': '1'}],
|
||||
'volume_type': 'vol_type_name',
|
||||
'snapshot_id': None,
|
||||
'metadata': {},
|
||||
'id': '1',
|
||||
'createdAt': datetime.datetime(1, 1, 1,
|
||||
'created_at': datetime.datetime(1, 1, 1,
|
||||
1, 1, 1),
|
||||
'size': 1}]}
|
||||
self.assertEqual(res_dict, expected)
|
||||
@@ -116,18 +116,18 @@ class VolumeApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v1/volumes/1')
|
||||
res_dict = self.controller.show(req, 1)
|
||||
expected = {'volume': {'status': 'fakestatus',
|
||||
'displayDescription': 'displaydesc',
|
||||
'availabilityZone': 'fakeaz',
|
||||
'displayName': 'displayname',
|
||||
'display_description': 'displaydesc',
|
||||
'availability_zone': 'fakeaz',
|
||||
'display_name': 'displayname',
|
||||
'attachments': [{'device': '/',
|
||||
'serverId': 'fakeuuid',
|
||||
'server_id': 'fakeuuid',
|
||||
'id': '1',
|
||||
'volumeId': '1'}],
|
||||
'volumeType': 'vol_type_name',
|
||||
'snapshotId': None,
|
||||
'volume_id': '1'}],
|
||||
'volume_type': 'vol_type_name',
|
||||
'snapshot_id': None,
|
||||
'metadata': {},
|
||||
'id': '1',
|
||||
'createdAt': datetime.datetime(1, 1, 1,
|
||||
'created_at': datetime.datetime(1, 1, 1,
|
||||
1, 1, 1),
|
||||
'size': 1}}
|
||||
self.assertEqual(res_dict, expected)
|
||||
@@ -141,15 +141,15 @@ class VolumeApiTest(test.TestCase):
|
||||
req = fakes.HTTPRequest.blank('/v1/volumes/1')
|
||||
res_dict = self.controller.show(req, 1)
|
||||
expected = {'volume': {'status': 'fakestatus',
|
||||
'displayDescription': 'displaydesc',
|
||||
'availabilityZone': 'fakeaz',
|
||||
'displayName': 'displayname',
|
||||
'display_description': 'displaydesc',
|
||||
'availability_zone': 'fakeaz',
|
||||
'display_name': 'displayname',
|
||||
'attachments': [],
|
||||
'volumeType': 'vol_type_name',
|
||||
'snapshotId': None,
|
||||
'volume_type': 'vol_type_name',
|
||||
'snapshot_id': None,
|
||||
'metadata': {},
|
||||
'id': '1',
|
||||
'createdAt': datetime.datetime(1, 1, 1,
|
||||
'created_at': datetime.datetime(1, 1, 1,
|
||||
1, 1, 1),
|
||||
'size': 1}}
|
||||
self.assertEqual(res_dict, expected)
|
||||
@@ -180,15 +180,15 @@ class VolumeApiTest(test.TestCase):
|
||||
|
||||
class VolumeSerializerTest(test.TestCase):
|
||||
def _verify_volume_attachment(self, attach, tree):
|
||||
for attr in ('id', 'volumeId', 'serverId', 'device'):
|
||||
for attr in ('id', 'volume_id', 'server_id', 'device'):
|
||||
self.assertEqual(str(attach[attr]), tree.get(attr))
|
||||
|
||||
def _verify_volume(self, vol, tree):
|
||||
self.assertEqual(tree.tag, 'volume')
|
||||
|
||||
for attr in ('id', 'status', 'size', 'availabilityZone', 'createdAt',
|
||||
'displayName', 'displayDescription', 'volumeType',
|
||||
'snapshotId'):
|
||||
for attr in ('id', 'status', 'size', 'availability_zone', 'created_at',
|
||||
'display_name', 'display_description', 'volume_type',
|
||||
'snapshot_id'):
|
||||
self.assertEqual(str(vol[attr]), tree.get(attr))
|
||||
|
||||
for child in tree:
|
||||
@@ -212,17 +212,17 @@ class VolumeSerializerTest(test.TestCase):
|
||||
id='vol_id',
|
||||
status='vol_status',
|
||||
size=1024,
|
||||
availabilityZone='vol_availability',
|
||||
createdAt=datetime.datetime.now(),
|
||||
availability_zone='vol_availability',
|
||||
created_at=datetime.datetime.now(),
|
||||
attachments=[dict(
|
||||
id='vol_id',
|
||||
volumeId='vol_id',
|
||||
serverId='instance_uuid',
|
||||
volume_id='vol_id',
|
||||
server_id='instance_uuid',
|
||||
device='/foo')],
|
||||
displayName='vol_name',
|
||||
displayDescription='vol_desc',
|
||||
volumeType='vol_type',
|
||||
snapshotId='snap_id',
|
||||
display_name='vol_name',
|
||||
display_description='vol_desc',
|
||||
volume_type='vol_type',
|
||||
snapshot_id='snap_id',
|
||||
metadata=dict(
|
||||
foo='bar',
|
||||
baz='quux',
|
||||
@@ -241,17 +241,17 @@ class VolumeSerializerTest(test.TestCase):
|
||||
id='vol1_id',
|
||||
status='vol1_status',
|
||||
size=1024,
|
||||
availabilityZone='vol1_availability',
|
||||
createdAt=datetime.datetime.now(),
|
||||
availability_zone='vol1_availability',
|
||||
created_at=datetime.datetime.now(),
|
||||
attachments=[dict(
|
||||
id='vol1_id',
|
||||
volumeId='vol1_id',
|
||||
serverId='instance_uuid',
|
||||
volume_id='vol1_id',
|
||||
server_id='instance_uuid',
|
||||
device='/foo1')],
|
||||
displayName='vol1_name',
|
||||
displayDescription='vol1_desc',
|
||||
volumeType='vol1_type',
|
||||
snapshotId='snap1_id',
|
||||
display_name='vol1_name',
|
||||
display_description='vol1_desc',
|
||||
volume_type='vol1_type',
|
||||
snapshot_id='snap1_id',
|
||||
metadata=dict(
|
||||
foo='vol1_foo',
|
||||
bar='vol1_bar',
|
||||
@@ -261,17 +261,17 @@ class VolumeSerializerTest(test.TestCase):
|
||||
id='vol2_id',
|
||||
status='vol2_status',
|
||||
size=1024,
|
||||
availabilityZone='vol2_availability',
|
||||
createdAt=datetime.datetime.now(),
|
||||
availability_zone='vol2_availability',
|
||||
created_at=datetime.datetime.now(),
|
||||
attachments=[dict(
|
||||
id='vol2_id',
|
||||
volumeId='vol2_id',
|
||||
serverId='instance_uuid',
|
||||
volume_id='vol2_id',
|
||||
server_id='instance_uuid',
|
||||
device='/foo2')],
|
||||
displayName='vol2_name',
|
||||
displayDescription='vol2_desc',
|
||||
volumeType='vol2_type',
|
||||
snapshotId='snap2_id',
|
||||
display_name='vol2_name',
|
||||
display_description='vol2_desc',
|
||||
volume_type='vol2_type',
|
||||
snapshot_id='snap2_id',
|
||||
metadata=dict(
|
||||
foo='vol2_foo',
|
||||
bar='vol2_bar',
|
||||
|
||||
@@ -175,7 +175,7 @@ class VolumesTest(integrated_helpers._IntegratedTestBase):
|
||||
# Check it's there and availability zone present
|
||||
found_volume = self.api.get_volume(created_volume_id)
|
||||
self.assertEqual(created_volume_id, found_volume['id'])
|
||||
self.assertEqual(availability_zone, found_volume['availabilityZone'])
|
||||
self.assertEqual(availability_zone, found_volume['availability_zone'])
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user