Check host cpu_info if no cpu_model for guest

When no cpu_model specified to guest, we should use host cpu_info to
check for live migration.

Change-Id: I410f53f6e54a698a48d8d5566ce192cda0365c98
Closes-Bug: #1082414
This commit is contained in:
yunhong jiang 2015-03-05 15:09:49 -08:00 committed by Matt Riedemann
parent d67cee9eea
commit 5653bd2916
2 changed files with 24 additions and 1 deletions
nova
tests/unit/virt/libvirt
virt/libvirt

@ -5099,6 +5099,29 @@ class LibvirtConnTestCase(test.NoDBTestCase):
"disk_available_mb": None},
matchers.DictMatches(return_value))
@mock.patch.object(libvirt_driver.LibvirtDriver,
'_create_shared_storage_test_file',
return_value='fake')
@mock.patch.object(libvirt_driver.LibvirtDriver, '_compare_cpu')
def test_check_can_live_migrate_guest_cpu_none_model(
self, mock_cpu, mock_test_file):
# Tests that when instance.vcpu_model.model is None, the host cpu
# model is used for live migration.
instance_ref = objects.Instance(**self.test_instance)
instance_ref.vcpu_model = test_vcpu_model.fake_vcpumodel
instance_ref.vcpu_model.model = None
drvr = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
compute_info = {'cpu_info': 'asdf'}
result = drvr.check_can_live_migrate_destination(
self.context, instance_ref, compute_info, compute_info)
mock_cpu.assert_called_once_with(None, 'asdf')
expected_result = {"filename": 'fake',
"image_type": CONF.libvirt.images_type,
"block_migration": False,
"disk_over_commit": False,
"disk_available_mb": None}
self.assertDictEqual(expected_result, result)
@mock.patch.object(libvirt_driver.LibvirtDriver,
'_create_shared_storage_test_file')
@mock.patch.object(fakelibvirt.Connection, 'compareCPU')

@ -4944,7 +4944,7 @@ class LibvirtDriver(driver.ComputeDriver):
(disk_available_gb * units.Ki) - CONF.reserved_host_disk_mb
# Compare CPU
if not instance.vcpu_model:
if not instance.vcpu_model or not instance.vcpu_model.model:
source_cpu_info = src_compute_info['cpu_info']
self._compare_cpu(None, source_cpu_info)
else: