Merge "Remove _legacy_dict methods"

This commit is contained in:
Zuul 2019-02-23 00:43:34 +00:00 committed by Gerrit Code Review
commit 6040e66887
5 changed files with 121 additions and 508 deletions

View File

@ -120,36 +120,6 @@ class LiveMigrateData(obj_base.NovaObject):
'vifs': fields.ListOfObjectsField('VIFMigrateData'),
}
def to_legacy_dict(self, pre_migration_result=False):
legacy = {}
if self.obj_attr_is_set('is_volume_backed'):
legacy['is_volume_backed'] = self.is_volume_backed
if self.obj_attr_is_set('migration'):
legacy['migration'] = self.migration
if pre_migration_result:
legacy['pre_live_migration_result'] = {}
return legacy
def from_legacy_dict(self, legacy):
if 'is_volume_backed' in legacy:
self.is_volume_backed = legacy['is_volume_backed']
if 'migration' in legacy:
self.migration = legacy['migration']
@classmethod
def detect_implementation(cls, legacy_dict):
if 'instance_relative_path' in legacy_dict:
obj = LibvirtLiveMigrateData()
elif 'image_type' in legacy_dict:
obj = LibvirtLiveMigrateData()
elif 'migrate_data' in legacy_dict:
obj = XenapiLiveMigrateData()
else:
obj = LiveMigrateData()
obj.from_legacy_dict(legacy_dict)
return obj
@obj_base.NovaObjectRegistry.register
class LibvirtLiveMigrateBDMInfo(obj_base.NovaObject):
@ -296,52 +266,6 @@ class LibvirtLiveMigrateData(LiveMigrateData):
bdmi.boot_index = int(vol['disk_info']['boot_index'])
self.bdms.append(bdmi)
def to_legacy_dict(self, pre_migration_result=False):
LOG.debug('Converting to legacy: %s', self)
legacy = super(LibvirtLiveMigrateData, self).to_legacy_dict()
keys = (set(self.fields.keys()) -
set(LiveMigrateData.fields.keys()) - {'bdms'})
legacy.update({k: getattr(self, k) for k in keys
if self.obj_attr_is_set(k)})
graphics_vnc = legacy.pop('graphics_listen_addr_vnc', None)
graphics_spice = legacy.pop('graphics_listen_addr_spice', None)
transport_target = legacy.pop('target_connect_addr', None)
live_result = {
'graphics_listen_addrs': {
'vnc': graphics_vnc and str(graphics_vnc),
'spice': graphics_spice and str(graphics_spice),
},
'serial_listen_addr': legacy.pop('serial_listen_addr', None),
'target_connect_addr': transport_target,
}
if pre_migration_result:
legacy['pre_live_migration_result'] = live_result
self._bdms_to_legacy(live_result)
LOG.debug('Legacy result: %s', legacy)
return legacy
def from_legacy_dict(self, legacy):
LOG.debug('Converting legacy dict to obj: %s', legacy)
super(LibvirtLiveMigrateData, self).from_legacy_dict(legacy)
keys = set(self.fields.keys()) - set(LiveMigrateData.fields.keys())
for k in keys - {'bdms'}:
if k in legacy:
setattr(self, k, legacy[k])
if 'pre_live_migration_result' in legacy:
pre_result = legacy['pre_live_migration_result']
self.graphics_listen_addr_vnc = \
pre_result['graphics_listen_addrs'].get('vnc')
self.graphics_listen_addr_spice = \
pre_result['graphics_listen_addrs'].get('spice')
self.target_connect_addr = pre_result.get('target_connect_addr')
if 'serial_listen_addr' in pre_result:
self.serial_listen_addr = pre_result['serial_listen_addr']
self._bdms_from_legacy(pre_result)
LOG.debug('Converted object: %s', self)
def is_on_shared_storage(self):
return self.is_shared_block_storage or self.is_shared_instance_path
@ -365,42 +289,6 @@ class XenapiLiveMigrateData(LiveMigrateData):
'vif_uuid_map': fields.DictOfStringsField(),
}
def to_legacy_dict(self, pre_migration_result=False):
legacy = super(XenapiLiveMigrateData, self).to_legacy_dict()
if self.obj_attr_is_set('block_migration'):
legacy['block_migration'] = self.block_migration
if self.obj_attr_is_set('migrate_send_data'):
legacy['migrate_data'] = {
'migrate_send_data': self.migrate_send_data,
'destination_sr_ref': self.destination_sr_ref,
}
live_result = {
'sr_uuid_map': ('sr_uuid_map' in self and self.sr_uuid_map
or {}),
'vif_uuid_map': ('vif_uuid_map' in self and self.vif_uuid_map
or {}),
}
if pre_migration_result:
legacy['pre_live_migration_result'] = live_result
return legacy
def from_legacy_dict(self, legacy):
super(XenapiLiveMigrateData, self).from_legacy_dict(legacy)
if 'block_migration' in legacy:
self.block_migration = legacy['block_migration']
else:
self.block_migration = False
if 'migrate_data' in legacy:
self.migrate_send_data = \
legacy['migrate_data']['migrate_send_data']
self.destination_sr_ref = \
legacy['migrate_data']['destination_sr_ref']
if 'pre_live_migration_result' in legacy:
self.sr_uuid_map = \
legacy['pre_live_migration_result']['sr_uuid_map']
self.vif_uuid_map = \
legacy['pre_live_migration_result'].get('vif_uuid_map', {})
def obj_make_compatible(self, primitive, target_version):
super(XenapiLiveMigrateData, self).obj_make_compatible(
primitive, target_version)
@ -443,18 +331,6 @@ class HyperVLiveMigrateData(LiveMigrateData):
if 'is_shared_instance_path' in primitive:
del primitive['is_shared_instance_path']
def to_legacy_dict(self, pre_migration_result=False):
legacy = super(HyperVLiveMigrateData, self).to_legacy_dict()
if self.obj_attr_is_set('is_shared_instance_path'):
legacy['is_shared_instance_path'] = self.is_shared_instance_path
return legacy
def from_legacy_dict(self, legacy):
super(HyperVLiveMigrateData, self).from_legacy_dict(legacy)
if 'is_shared_instance_path' in legacy:
self.is_shared_instance_path = legacy['is_shared_instance_path']
@obj_base.NovaObjectRegistry.register
class PowerVMLiveMigrateData(LiveMigrateData):
@ -491,19 +367,6 @@ class PowerVMLiveMigrateData(LiveMigrateData):
if 'vea_vlan_mappings' in primitive:
del primitive['vea_vlan_mappings']
def to_legacy_dict(self, pre_migration_result=False):
legacy = super(PowerVMLiveMigrateData, self).to_legacy_dict()
for field in self.fields:
if self.obj_attr_is_set(field):
legacy[field] = getattr(self, field)
return legacy
def from_legacy_dict(self, legacy):
super(PowerVMLiveMigrateData, self).from_legacy_dict(legacy)
for field in self.fields:
if field in legacy:
setattr(self, field, legacy[field])
@obj_base.NovaObjectRegistry.register
class VMwareLiveMigrateData(LiveMigrateData):

View File

@ -25,58 +25,6 @@ from nova.tests.unit.objects import test_objects
class _TestLiveMigrateData(object):
def test_to_legacy_dict(self):
obj = migrate_data.LiveMigrateData(is_volume_backed=False)
self.assertEqual({'is_volume_backed': False},
obj.to_legacy_dict())
def test_from_legacy_dict(self):
obj = migrate_data.LiveMigrateData()
obj.from_legacy_dict({'is_volume_backed': False, 'ignore': 'foo'})
self.assertFalse(obj.is_volume_backed)
def test_from_legacy_dict_migration(self):
migration = objects.Migration()
obj = migrate_data.LiveMigrateData()
obj.from_legacy_dict({'is_volume_backed': False, 'ignore': 'foo',
'migration': migration})
self.assertFalse(obj.is_volume_backed)
self.assertIsInstance(obj.migration, objects.Migration)
def test_legacy_with_pre_live_migration_result(self):
obj = migrate_data.LiveMigrateData(is_volume_backed=False)
self.assertEqual({'pre_live_migration_result': {},
'is_volume_backed': False},
obj.to_legacy_dict(pre_migration_result=True))
def test_detect_implementation_none(self):
legacy = migrate_data.LiveMigrateData().to_legacy_dict()
self.assertIsInstance(
migrate_data.LiveMigrateData.detect_implementation(legacy),
migrate_data.LiveMigrateData)
def test_detect_implementation_libvirt(self):
legacy = migrate_data.LibvirtLiveMigrateData(
instance_relative_path='foo').to_legacy_dict()
self.assertIsInstance(
migrate_data.LiveMigrateData.detect_implementation(legacy),
migrate_data.LibvirtLiveMigrateData)
def test_detect_implementation_libvirt_early(self):
legacy = migrate_data.LibvirtLiveMigrateData(
image_type='foo').to_legacy_dict()
self.assertIsInstance(
migrate_data.LiveMigrateData.detect_implementation(legacy),
migrate_data.LibvirtLiveMigrateData)
def test_detect_implementation_xenapi(self):
legacy = migrate_data.XenapiLiveMigrateData(
migrate_send_data={},
destination_sr_ref='foo').to_legacy_dict()
self.assertIsInstance(
migrate_data.LiveMigrateData.detect_implementation(legacy),
migrate_data.XenapiLiveMigrateData)
def test_obj_make_compatible(self):
props = {
'serial_listen_addr': '127.0.0.1',
@ -120,121 +68,6 @@ class _TestLibvirtLiveMigrateData(object):
expected_info['boot_index'] = '1'
self.assertEqual(expected_info, obj.as_disk_info())
def test_to_legacy_dict(self):
obj = migrate_data.LibvirtLiveMigrateData(
is_volume_backed=False,
filename='foo',
image_type='rbd',
block_migration=False,
disk_over_commit=False,
disk_available_mb=123,
is_shared_instance_path=False,
is_shared_block_storage=False,
instance_relative_path='foo/bar')
expected = {
'is_volume_backed': False,
'filename': 'foo',
'image_type': 'rbd',
'block_migration': False,
'disk_over_commit': False,
'disk_available_mb': 123,
'is_shared_instance_path': False,
'is_shared_block_storage': False,
'instance_relative_path': 'foo/bar',
}
self.assertEqual(expected, obj.to_legacy_dict())
def test_from_legacy_dict(self):
obj = migrate_data.LibvirtLiveMigrateData(
is_volume_backed=False,
filename='foo',
image_type='rbd',
block_migration=False,
disk_over_commit=False,
disk_available_mb=123,
is_shared_instance_path=False,
is_shared_block_storage=False,
instance_relative_path='foo/bar')
legacy = obj.to_legacy_dict()
legacy['ignore_this_thing'] = True
obj2 = migrate_data.LibvirtLiveMigrateData()
obj2.from_legacy_dict(legacy)
self.assertEqual(obj.filename, obj2.filename)
def test_to_legacy_dict_with_pre_result(self):
test_bdmi = migrate_data.LibvirtLiveMigrateBDMInfo(
serial='123',
bus='scsi',
dev='/dev/sda',
type='disk',
format='qcow2',
boot_index=1,
connection_info='myinfo')
obj = migrate_data.LibvirtLiveMigrateData(
is_volume_backed=False,
filename='foo',
image_type='rbd',
block_migration=False,
disk_over_commit=False,
disk_available_mb=123,
is_shared_instance_path=False,
is_shared_block_storage=False,
instance_relative_path='foo/bar',
graphics_listen_addr_vnc='127.0.0.1',
serial_listen_addr='127.0.0.1',
bdms=[test_bdmi])
legacy = obj.to_legacy_dict(pre_migration_result=True)
self.assertIn('pre_live_migration_result', legacy)
expected = {
'graphics_listen_addrs': {'vnc': '127.0.0.1',
'spice': None},
'target_connect_addr': None,
'serial_listen_addr': '127.0.0.1',
'volume': {
'123': {
'connection_info': 'myinfo',
'disk_info': {
'bus': 'scsi',
'dev': '/dev/sda',
'type': 'disk',
'format': 'qcow2',
'boot_index': '1',
}
}
}
}
self.assertEqual(expected, legacy['pre_live_migration_result'])
def test_from_legacy_with_pre_result(self):
test_bdmi = migrate_data.LibvirtLiveMigrateBDMInfo(
serial='123',
bus='scsi',
dev='/dev/sda',
type='disk',
format='qcow2',
boot_index=1,
connection_info='myinfo')
obj = migrate_data.LibvirtLiveMigrateData(
is_volume_backed=False,
filename='foo',
image_type='rbd',
block_migration=False,
disk_over_commit=False,
disk_available_mb=123,
is_shared_instance_path=False,
is_shared_block_storage=False,
instance_relative_path='foo/bar',
graphics_listen_addrs={'vnc': '127.0.0.1'},
serial_listen_addr='127.0.0.1',
bdms=[test_bdmi],
dst_wants_file_backed_memory=True,
file_backed_memory_discard=True)
obj2 = migrate_data.LibvirtLiveMigrateData()
obj2.from_legacy_dict(obj.to_legacy_dict(pre_migration_result=True))
self.assertEqual(obj.to_legacy_dict(),
obj2.to_legacy_dict())
self.assertEqual(obj.bdms[0].serial, obj2.bdms[0].serial)
def test_obj_make_compatible(self):
obj = migrate_data.LibvirtLiveMigrateData(
src_supports_native_luks=True,
@ -325,93 +158,6 @@ class TestRemoteLibvirtLiveMigrateData(test_objects._RemoteTest,
class _TestXenapiLiveMigrateData(object):
def test_to_legacy_dict(self):
obj = migrate_data.XenapiLiveMigrateData(
is_volume_backed=False,
block_migration=False,
destination_sr_ref='foo',
migrate_send_data={'key': 'val'},
sr_uuid_map={'apple': 'banana'},
vif_uuid_map={'orange': 'lemon'})
expected = {
'is_volume_backed': False,
'block_migration': False,
'migrate_data': {
'destination_sr_ref': 'foo',
'migrate_send_data': {'key': 'val'},
}
}
self.assertEqual(expected, obj.to_legacy_dict())
def test_from_legacy_dict(self):
obj = migrate_data.XenapiLiveMigrateData(
is_volume_backed=False,
block_migration=False,
destination_sr_ref='foo',
migrate_send_data={'key': 'val'},
sr_uuid_map={'apple': 'banana'},
vif_uuid_map={'orange': 'lemon'})
legacy = obj.to_legacy_dict()
legacy['ignore_this_thing'] = True
obj2 = migrate_data.XenapiLiveMigrateData()
obj2.from_legacy_dict(legacy)
self.assertEqual(obj.destination_sr_ref, obj2.destination_sr_ref)
def test_to_legacy_dict_missing_attrs(self):
obj = migrate_data.XenapiLiveMigrateData(
is_volume_backed=False,
destination_sr_ref='foo',
sr_uuid_map={'apple': 'banana'},
vif_uuid_map={'orange': 'lemon'})
expected = {
'is_volume_backed': False,
}
self.assertEqual(expected, obj.to_legacy_dict())
obj = migrate_data.XenapiLiveMigrateData(
is_volume_backed=False,
destination_sr_ref='foo')
expected = {
'is_volume_backed': False,
'pre_live_migration_result': {
'sr_uuid_map': {},
'vif_uuid_map': {},
},
}
self.assertEqual(expected, obj.to_legacy_dict(True))
def test_from_legacy_dict_missing_attrs(self):
obj = migrate_data.XenapiLiveMigrateData(
is_volume_backed=False,
destination_sr_ref='foo',
sr_uuid_map={'apple': 'banana'},
vif_uuid_map={'orange': 'lemon'})
legacy = obj.to_legacy_dict()
obj2 = migrate_data.XenapiLiveMigrateData()
obj2.from_legacy_dict(legacy)
self.assertFalse(obj2.block_migration)
self.assertNotIn('migrate_send_data', obj2)
self.assertNotIn('sr_uuid_map', obj2)
self.assertNotIn('vif_uuid_map', obj2)
def test_to_legacy_with_pre_result(self):
obj = migrate_data.XenapiLiveMigrateData(
sr_uuid_map={'a': 'b'},
vif_uuid_map={'c': 'd'})
self.assertNotIn('sr_uuid_map', obj.to_legacy_dict())
self.assertNotIn('vi_uuid_map', obj.to_legacy_dict())
legacy = obj.to_legacy_dict(True)
self.assertEqual(
{'a': 'b'},
legacy['pre_live_migration_result']['sr_uuid_map'])
self.assertEqual(
{'c': 'd'},
legacy['pre_live_migration_result']['vif_uuid_map']
)
obj2 = migrate_data.XenapiLiveMigrateData()
obj2.from_legacy_dict(legacy)
self.assertEqual({'a': 'b'}, obj2.sr_uuid_map)
self.assertEqual({'c': 'd'}, obj2.vif_uuid_map)
def test_obj_make_compatible(self):
obj = migrate_data.XenapiLiveMigrateData(
is_volume_backed=False,
@ -459,23 +205,6 @@ class _TestHyperVLiveMigrateData(object):
primitive = data(obj.obj_to_primitive(target_version='1.2'))
self.assertNotIn('wait_for_vif_plugged', primitive)
def test_to_legacy_dict(self):
obj = migrate_data.HyperVLiveMigrateData(
is_shared_instance_path=False)
expected = {
'is_shared_instance_path': False,
}
self.assertEqual(expected, obj.to_legacy_dict())
def test_from_legacy_dict(self):
obj = migrate_data.HyperVLiveMigrateData(
is_shared_instance_path=False)
legacy = obj.to_legacy_dict()
obj2 = migrate_data.HyperVLiveMigrateData()
obj2.from_legacy_dict(legacy)
self.assertEqual(obj.is_shared_instance_path,
obj2.is_shared_instance_path)
class TestHyperVLiveMigrateData(test_objects._LocalTest,
_TestHyperVLiveMigrateData):
@ -537,17 +266,6 @@ class _TestPowerVMLiveMigrateData(object):
primitive = data(obj.obj_to_primitive(target_version='1.2'))
self.assertNotIn('wait_for_vif_plugged', primitive)
def test_to_legacy_dict(self):
self.assertEqual(self._mk_leg(), self._mk_obj().to_legacy_dict())
def test_from_legacy_dict(self):
obj = self._mk_obj()
leg = self._mk_leg()
obj2 = migrate_data.PowerVMLiveMigrateData()
obj2.from_legacy_dict(leg)
for field in leg:
self.assertEqual(getattr(obj, field), getattr(obj2, field))
class TestPowerVMLiveMigrateData(test_objects._LocalTest,
_TestPowerVMLiveMigrateData):

View File

@ -8759,15 +8759,18 @@ class LibvirtConnTestCase(test.NoDBTestCase,
return_value = drvr.check_can_live_migrate_destination(self.context,
instance_ref, None, compute_info, True)
return_value.is_volume_backed = False
self.assertThat({"filename": "file",
'image_type': 'default',
'disk_available_mb': 409600,
"disk_over_commit": False,
"block_migration": True,
"is_volume_backed": False,
"dst_wants_file_backed_memory": False,
"file_backed_memory_discard": False},
matchers.DictMatches(return_value.to_legacy_dict()))
self.assertEqual({'filename': 'file',
'image_type': 'default',
'disk_available_mb': 409600,
'disk_over_commit': False,
'block_migration': True,
'is_volume_backed': False,
'dst_wants_file_backed_memory': False,
'file_backed_memory_discard': False,
'graphics_listen_addr_spice': '127.0.0.1',
'graphics_listen_addr_vnc': '127.0.0.1',
'serial_listen_addr': None},
return_value.obj_to_primitive()['nova_object.data'])
@mock.patch.object(objects.Service, 'get_by_compute_host')
@mock.patch.object(libvirt_driver.LibvirtDriver,
@ -8794,15 +8797,18 @@ class LibvirtConnTestCase(test.NoDBTestCase,
return_value = drvr.check_can_live_migrate_destination(self.context,
instance_ref, None, compute_info, True, True)
return_value.is_volume_backed = False
self.assertThat({"filename": "file",
'image_type': 'default',
'disk_available_mb': 51200,
"disk_over_commit": True,
"block_migration": True,
"is_volume_backed": False,
"dst_wants_file_backed_memory": False,
"file_backed_memory_discard": False},
matchers.DictMatches(return_value.to_legacy_dict()))
self.assertEqual({'filename': 'file',
'image_type': 'default',
'disk_available_mb': 51200,
'disk_over_commit': True,
'block_migration': True,
'is_volume_backed': False,
'dst_wants_file_backed_memory': False,
'file_backed_memory_discard': False,
'graphics_listen_addr_spice': '127.0.0.1',
'graphics_listen_addr_vnc': '127.0.0.1',
'serial_listen_addr': None},
return_value.obj_to_primitive()['nova_object.data'])
@mock.patch.object(objects.Service, 'get_by_compute_host')
@mock.patch.object(libvirt_driver.LibvirtDriver,
@ -8826,15 +8832,18 @@ class LibvirtConnTestCase(test.NoDBTestCase,
return_value = drvr.check_can_live_migrate_destination(self.context,
instance_ref, None, compute_info, False)
return_value.is_volume_backed = False
self.assertThat({"filename": "file",
"image_type": 'default',
"block_migration": False,
"disk_over_commit": False,
"disk_available_mb": 409600,
"is_volume_backed": False,
"dst_wants_file_backed_memory": False,
"file_backed_memory_discard": False},
matchers.DictMatches(return_value.to_legacy_dict()))
self.assertEqual({'filename': 'file',
'image_type': 'default',
'block_migration': False,
'disk_over_commit': False,
'disk_available_mb': 409600,
'is_volume_backed': False,
'dst_wants_file_backed_memory': False,
'file_backed_memory_discard': False,
'graphics_listen_addr_spice': '127.0.0.1',
'graphics_listen_addr_vnc': '127.0.0.1',
'serial_listen_addr': None},
return_value.obj_to_primitive()['nova_object.data'])
@mock.patch.object(objects.Service, 'get_by_compute_host')
@mock.patch.object(libvirt_driver.LibvirtDriver,
@ -8900,15 +8909,18 @@ class LibvirtConnTestCase(test.NoDBTestCase,
self.context, instance_ref, compute_info, compute_info)
result.is_volume_backed = False
mock_cpu.assert_called_once_with(None, 'asdf', instance_ref)
expected_result = {"filename": 'fake',
"image_type": CONF.libvirt.images_type,
"block_migration": False,
"disk_over_commit": False,
"disk_available_mb": 1024,
"is_volume_backed": False,
"dst_wants_file_backed_memory": False,
"file_backed_memory_discard": False}
self.assertEqual(expected_result, result.to_legacy_dict())
self.assertEqual({'filename': 'fake',
'image_type': CONF.libvirt.images_type,
'block_migration': False,
'disk_over_commit': False,
'disk_available_mb': 1024,
'is_volume_backed': False,
'dst_wants_file_backed_memory': False,
'file_backed_memory_discard': False,
'graphics_listen_addr_spice': '127.0.0.1',
'graphics_listen_addr_vnc': '127.0.0.1',
'serial_listen_addr': None},
result.obj_to_primitive()['nova_object.data'])
@mock.patch.object(objects.Service, 'get_by_compute_host')
@mock.patch.object(libvirt_driver.LibvirtDriver,
@ -8936,15 +8948,18 @@ class LibvirtConnTestCase(test.NoDBTestCase,
instance_ref, compute_info, compute_info, False)
# NOTE(danms): Compute manager would have set this, so set it here
return_value.is_volume_backed = False
self.assertThat({"filename": "file",
"image_type": 'default',
"block_migration": False,
"disk_over_commit": False,
"disk_available_mb": 1024,
"is_volume_backed": False,
"dst_wants_file_backed_memory": False,
"file_backed_memory_discard": False},
matchers.DictMatches(return_value.to_legacy_dict()))
self.assertEqual({'filename': 'file',
'image_type': 'default',
'block_migration': False,
'disk_over_commit': False,
'disk_available_mb': 1024,
'is_volume_backed': False,
'dst_wants_file_backed_memory': False,
'file_backed_memory_discard': False,
'graphics_listen_addr_spice': '127.0.0.1',
'graphics_listen_addr_vnc': '127.0.0.1',
'serial_listen_addr': None},
return_value.obj_to_primitive()['nova_object.data'])
@mock.patch.object(objects.Service, 'get_by_compute_host')
@mock.patch.object(libvirt_driver.LibvirtDriver,
@ -11653,25 +11668,42 @@ class LibvirtConnTestCase(test.NoDBTestCase,
'/fake/instance/dir', None)
self.assertFalse(mock_fetch.called)
def _migrate_data_to_dict(self, migrate_data):
primitive = migrate_data.obj_to_primitive()['nova_object.data']
primitive['bdms'] = [bdm['nova_object.data'] for bdm in
primitive['bdms']]
return primitive
def _generate_target_ret(self, target_connect_addr=None):
target_ret = {
'graphics_listen_addrs': {'spice': '127.0.0.1', 'vnc': '127.0.0.1'},
'target_connect_addr': target_connect_addr,
'serial_listen_addr': '127.0.0.1',
'volume': {
'12345': {'connection_info': {u'data': {'device_path':
u'/dev/disk/by-path/ip-1.2.3.4:3260-iqn.abc.12345.opst-lun-X'},
'serial': '12345'},
'disk_info': {'bus': 'scsi',
'dev': 'sda',
'type': 'disk'}},
'67890': {'connection_info': {u'data': {'device_path':
u'/dev/disk/by-path/ip-1.2.3.4:3260-iqn.cde.67890.opst-lun-Z'},
'serial': '67890'},
'disk_info': {'bus': 'scsi',
'dev': 'sdb',
'type': 'disk'}}}}
return target_ret
return self._migrate_data_to_dict(objects.LibvirtLiveMigrateData(
block_migration=False,
instance_relative_path='foo',
is_shared_block_storage=False,
is_shared_instance_path=False,
serial_listen_ports=[],
src_supports_native_luks=True,
supported_perf_events=[],
graphics_listen_addr_spice='127.0.0.1',
graphics_listen_addr_vnc='127.0.0.1',
serial_listen_addr='127.0.0.1',
target_connect_addr=target_connect_addr,
bdms=[
objects.LibvirtLiveMigrateBDMInfo(
serial='12345', bus='scsi', dev='sda', type='disk',
boot_index=None, format=None,
connection_info_json=jsonutils.dumps({
'serial': '12345',
'data': {
'device_path': '/dev/disk/by-path/ip-1.2.3.4:3260'
'-iqn.abc.12345.opst-lun-X'}})),
objects.LibvirtLiveMigrateBDMInfo(
serial='67890', bus='scsi', dev='sdb', type='disk',
boot_index=None, format=None,
connection_info_json=jsonutils.dumps({
'serial': '67890',
'data': {
'device_path': '/dev/disk/by-path/ip-1.2.3.4:3260'
'-iqn.cde.67890.opst-lun-Z'}}))]))
def test_pre_live_migration_works_correctly_mocked(self):
self._test_pre_live_migration_works_correctly_mocked()
@ -11772,18 +11804,23 @@ class LibvirtConnTestCase(test.NoDBTestCase,
serial_listen_addr='127.0.0.1',
)
if not target_ret:
target_ret = self._generate_target_ret()
if src_supports_native_luks:
migrate_data.src_supports_native_luks = True
else:
target_ret.pop('src_supports_native_luks')
result = drvr.pre_live_migration(
c, instance, block_device_info, nw_info, None,
migrate_data=migrate_data)
if not target_ret:
target_ret = self._generate_target_ret()
self.assertEqual(
target_ret,
result.to_legacy_dict(
pre_migration_result=True)['pre_live_migration_result'])
result_dict = self._migrate_data_to_dict(result)
# connection_info_json is a string, needs special handling
for bdms in zip(target_ret.pop('bdms'), result_dict.pop('bdms')):
conninfo0 = jsonutils.loads(bdms[0].pop('connection_info_json'))
conninfo1 = jsonutils.loads(bdms[1].pop('connection_info_json'))
self.assertEqual(conninfo0, conninfo1)
self.assertThat(bdms[0], matchers.DictMatches(bdms[1]))
self.assertThat(target_ret, matchers.DictMatches(result_dict))
mock_connect.assert_has_calls(expected_connect_calls)
self.assertEqual(len(expected_connect_calls), mock_connect.call_count)
mock_plug.assert_called_once_with(test.MatchType(objects.Instance),
@ -11854,18 +11891,21 @@ class LibvirtConnTestCase(test.NoDBTestCase,
)
res_data = drvr.pre_live_migration(
self.context, instance, vol, [], None, migrate_data)
res_data = res_data.to_legacy_dict(pre_migration_result=True)
block_device_info_get_mapping.assert_called_once_with(
{'block_device_mapping': [
{'connection_info': 'dummy', 'mount_device': '/dev/sda'},
{'connection_info': 'dummy', 'mount_device': '/dev/sdb'}
]}
)
self.assertEqual({'graphics_listen_addrs': {'spice': None,
'vnc': None},
self.assertEqual({'block_migration': False,
'instance_relative_path': 'foo',
'is_shared_block_storage': False,
'is_shared_instance_path': False,
'serial_listen_ports': [],
'supported_perf_events': [],
'target_connect_addr': None,
'serial_listen_addr': None,
'volume': {}}, res_data['pre_live_migration_result'])
'bdms': []},
res_data.obj_to_primitive()['nova_object.data'])
def _test_pre_live_migration_volume_backed(self, encrypted_volumes=False):
inst_ref = objects.Instance(root_device_name='/dev/vda',

View File

@ -3587,18 +3587,17 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
fake_get_network_ref.return_value = 'fake_network_ref'
expected = {'block_migration': True,
'is_volume_backed': False,
'migrate_data': {
'migrate_send_data': {'value':
'fake_migrate_data'},
'destination_sr_ref': 'asdf'}
}
'migrate_send_data': {'value': 'fake_migrate_data'},
'destination_sr_ref': 'asdf',
'vif_uuid_map': {'': 'fake_network_ref'}}
result = self.conn.check_can_live_migrate_destination(
self.context,
fake_instance,
{}, {},
True, False)
result.is_volume_backed = False
self.assertEqual(expected, result.to_legacy_dict())
self.assertEqual(expected,
result.obj_to_primitive()['nova_object.data'])
def test_check_live_migrate_destination_verifies_ip(self):
stubs.stubout_session(self, stubs.FakeSessionForVMTests)
@ -3690,8 +3689,7 @@ class XenAPILiveMigrateTestCase(stubs.XenAPITestBaseNoDB):
result = self.conn.check_can_live_migrate_source(self.context,
{'host': 'host'},
dest_check_data)
self.assertEqual(dest_check_data.to_legacy_dict(),
result.to_legacy_dict())
self.assertEqual(dest_check_data, result)
@mock.patch.object(session.XenAPISession, 'is_xsm_sr_check_relaxed',
return_value=False)

View File

@ -88,7 +88,6 @@ from nova.network import model as network_model
from nova import objects
from nova.objects import diagnostics as diagnostics_obj
from nova.objects import fields
from nova.objects import migrate_data as migrate_data_obj
from nova.pci import manager as pci_manager
from nova.pci import utils as pci_utils
import nova.privsep.libvirt
@ -6760,11 +6759,6 @@ class LibvirtDriver(driver.ComputeDriver):
:param block_device_info: result of _get_instance_block_device_info
:returns: a LibvirtLiveMigrateData object
"""
if not isinstance(dest_check_data, migrate_data_obj.LiveMigrateData):
md_obj = objects.LibvirtLiveMigrateData()
md_obj.from_legacy_dict(dest_check_data)
dest_check_data = md_obj
# Checking shared storage connectivity
# if block migration, instances_path should not be on shared storage.
source = CONF.host