ec2: use BlockDeviceMappingList object
Convert a direct use of the db API with the nova object equivalent. Some test fixes were needed to include fields the object expects to be preset in the fake db objects. Change-Id: I1d562aa2535af9e713c6486c5c50a2ffe625c198
This commit is contained in:
@@ -42,6 +42,7 @@ from nova.image import s3
|
||||
from nova import network
|
||||
from nova.network.security_group import neutron_driver
|
||||
from nova.objects import base as obj_base
|
||||
from nova.objects import block_device as block_device_obj
|
||||
from nova.objects import flavor as flavor_obj
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.objects import security_group as sec_group_obj
|
||||
@@ -1050,9 +1051,8 @@ class CloudController(object):
|
||||
"""Format InstanceBlockDeviceMappingResponseItemType."""
|
||||
root_device_type = 'instance-store'
|
||||
mapping = []
|
||||
for bdm in block_device.legacy_mapping(
|
||||
db.block_device_mapping_get_all_by_instance(context,
|
||||
instance_uuid)):
|
||||
get = block_device_obj.BlockDeviceMappingList.get_by_instance_uuid
|
||||
for bdm in block_device.legacy_mapping(get(context, instance_uuid)):
|
||||
volume_id = bdm['volume_id']
|
||||
if (volume_id is None or bdm['no_device']):
|
||||
continue
|
||||
|
||||
@@ -2548,8 +2548,8 @@ class CloudTestCase(test.TestCase):
|
||||
no_reboot=True)
|
||||
|
||||
@staticmethod
|
||||
def _fake_bdm_get(ctxt, id):
|
||||
return [{'volume_id': 87654321,
|
||||
def _fake_bdm_get(ctxt, id, use_slave=False):
|
||||
blockdms = [{'volume_id': 87654321,
|
||||
'source_type': 'volume',
|
||||
'destination_type': 'volume',
|
||||
'snapshot_id': None,
|
||||
@@ -2603,6 +2603,28 @@ class CloudTestCase(test.TestCase):
|
||||
'device_name': '/dev/sd3'},
|
||||
]
|
||||
|
||||
extra = {
|
||||
'created_at': None,
|
||||
'updated_at': None,
|
||||
'deleted_at': None,
|
||||
'deleted': 0,
|
||||
'id': 0,
|
||||
'destination_type': 0,
|
||||
'device_type': None,
|
||||
'disk_bus': None,
|
||||
'instance_uuid': '',
|
||||
'image_id': None,
|
||||
'volume_size': None,
|
||||
'connection_info': None,
|
||||
'boot_index': None,
|
||||
'guest_format': None,
|
||||
}
|
||||
|
||||
for bdm in blockdms:
|
||||
bdm.update(extra)
|
||||
|
||||
return blockdms
|
||||
|
||||
def test_describe_instance_attribute(self):
|
||||
# Make sure that describe_instance_attribute works.
|
||||
self.stubs.Set(db, 'block_device_mapping_get_all_by_instance',
|
||||
|
||||
@@ -162,7 +162,7 @@ class API(object):
|
||||
return v.vol
|
||||
|
||||
def get(self, context, volume_id):
|
||||
if volume_id == 87654321:
|
||||
if str(volume_id) == '87654321':
|
||||
return {'id': volume_id,
|
||||
'attach_time': '13:56:24',
|
||||
'attach_status': 'attached',
|
||||
|
||||
Reference in New Issue
Block a user