objects: Add attachment_id to BlockDeviceMapping
This change introduces attachment_id into the BlockDeviceMapping Object as required by the new cinderv3 attachment API introduced in Ocata : Ie15233c99d91de67279b56d27a5508c5ea98d769 Implements: blueprint cinder-new-attach-apis Change-Id: Ieb43099a31689e1b509cbffb9aeb7cc9948f1a18
This commit is contained in:
parent
7653261efc
commit
d8c532d538
|
@ -62,7 +62,8 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
|
|||
# Version 1.16: Deprecate get_by_volume_id(), add
|
||||
# get_by_volume() and get_by_volume_and_instance()
|
||||
# Version 1.17: Added tag field
|
||||
VERSION = '1.17'
|
||||
# Version 1.18: Added attachment_id
|
||||
VERSION = '1.18'
|
||||
|
||||
fields = {
|
||||
'id': fields.IntegerField(),
|
||||
|
@ -84,10 +85,13 @@ class BlockDeviceMapping(base.NovaPersistentObject, base.NovaObject,
|
|||
'no_device': fields.BooleanField(default=False),
|
||||
'connection_info': fields.SensitiveStringField(nullable=True),
|
||||
'tag': fields.StringField(nullable=True),
|
||||
'attachment_id': fields.UUIDField(nullable=True),
|
||||
}
|
||||
|
||||
def obj_make_compatible(self, primitive, target_version):
|
||||
target_version = versionutils.convert_version_to_tuple(target_version)
|
||||
if target_version < (1, 18) and 'attachment_id' in primitive:
|
||||
del primitive['attachment_id']
|
||||
if target_version < (1, 17) and 'tag' in primitive:
|
||||
del primitive['tag']
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ class FakeDbBlockDeviceDict(block_device.BlockDeviceDict):
|
|||
'deleted': 0}
|
||||
if not anon:
|
||||
fake_db_fields['id'] = db_id
|
||||
fake_db_fields['attachment_id'] = None
|
||||
fake_db_fields['created_at'] = timeutils.utcnow()
|
||||
fake_db_fields['updated_at'] = timeutils.utcnow()
|
||||
self.update(fake_db_fields)
|
||||
|
|
|
@ -33,6 +33,7 @@ class _TestBlockDeviceMappingObject(object):
|
|||
fake_bdm = fake_block_device.FakeDbBlockDeviceDict({
|
||||
'id': 123,
|
||||
'instance_uuid': instance.get('uuid') or uuids.instance,
|
||||
'attachment_id': None,
|
||||
'device_name': '/dev/sda2',
|
||||
'source_type': 'snapshot',
|
||||
'destination_type': 'volume',
|
||||
|
@ -215,7 +216,8 @@ class _TestBlockDeviceMappingObject(object):
|
|||
self.flags(enable=False, group='cells')
|
||||
values = {'source_type': 'volume', 'volume_id': 'fake-vol-id',
|
||||
'destination_type': 'volume',
|
||||
'instance_uuid': uuids.instance}
|
||||
'instance_uuid': uuids.instance,
|
||||
'attachment_id': None}
|
||||
if device_name:
|
||||
values['device_name'] = device_name
|
||||
fake_bdm = fake_block_device.FakeDbBlockDeviceDict(values)
|
||||
|
@ -370,6 +372,15 @@ class _TestBlockDeviceMappingObject(object):
|
|||
primitive = bdm.obj_to_primitive(target_version='1.16')
|
||||
self.assertNotIn('tag', primitive)
|
||||
|
||||
def test_obj_make_compatible_pre_1_18(self):
|
||||
values = {'source_type': 'volume', 'volume_id': 'fake-vol-id',
|
||||
'destination_type': 'volume',
|
||||
'instance_uuid': uuids.instance,
|
||||
'attachment_id': uuids.attachment_id}
|
||||
bdm = objects.BlockDeviceMapping(context=self.context, **values)
|
||||
primitive = bdm.obj_to_primitive(target_version='1.17')
|
||||
self.assertNotIn('attachment_id', primitive)
|
||||
|
||||
|
||||
class TestBlockDeviceMappingObject(test_objects._LocalTest,
|
||||
_TestBlockDeviceMappingObject):
|
||||
|
@ -387,6 +398,7 @@ class _TestBlockDeviceMappingListObject(object):
|
|||
'id': bdm_id,
|
||||
'boot_index': boot_index,
|
||||
'instance_uuid': instance_uuid,
|
||||
'attachment_id': None,
|
||||
'device_name': '/dev/sda2',
|
||||
'source_type': 'snapshot',
|
||||
'destination_type': 'volume',
|
||||
|
|
|
@ -1066,7 +1066,7 @@ object_data = {
|
|||
'AllocationList': '1.2-15ecf022a68ddbb8c2a6739cfc9f8f5e',
|
||||
'BandwidthUsage': '1.2-c6e4c779c7f40f2407e3d70022e3cd1c',
|
||||
'BandwidthUsageList': '1.2-5fe7475ada6fe62413cbfcc06ec70746',
|
||||
'BlockDeviceMapping': '1.17-5e094927f1251770dcada6ab05adfcdb',
|
||||
'BlockDeviceMapping': '1.18-ad87cece6f84c65f5ec21615755bc6d3',
|
||||
'BlockDeviceMappingList': '1.17-1e568eecb91d06d4112db9fd656de235',
|
||||
'BuildRequest': '1.2-532d95a88c5fd33e85878e408e5d6e8d',
|
||||
'BuildRequestList': '1.0-cd95608eccb89fbc702c8b52f38ec738',
|
||||
|
|
Loading…
Reference in New Issue