libvirt: handle NotSupportedError in compareCPU

In case of a NotSupportedError during the CPU comparison, the live
migration was aborted and rolled back because all libvirt errors were
treated equally.
If the target host has the same CPU architecture like the source host,
the live migration gets triggered now, despite no CPU comparison was
done.

Closes-Bug: 1434429

Change-Id: I9276f0a7ce9a9b58943e1ed9b9c7d8855482d9cd
This commit is contained in:
Markus Zoeller
2015-03-19 18:36:09 +01:00
parent e8707aa3b5
commit da9301fbc7
2 changed files with 25 additions and 3 deletions

View File

@@ -5327,6 +5327,21 @@ class LibvirtConnTestCase(test.NoDBTestCase):
ret = conn._compare_cpu(None, jsonutils.dumps(_fake_cpu_info))
self.assertIsNone(ret)
@mock.patch.object(host.Host, 'compare_cpu')
@mock.patch.object(nova.virt.libvirt, 'config')
def test_compare_cpu_handles_not_supported_error_gracefully(self,
mock_vconfig,
mock_conn):
not_supported_exc = fakelibvirt.make_libvirtError(
fakelibvirt.libvirtError,
'this function is not supported by the connection driver:'
' virCompareCPU',
error_code=fakelibvirt.VIR_ERR_NO_SUPPORT)
mock_conn.compareCPU.side_effect = not_supported_exc
conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), False)
ret = conn._compare_cpu(None, jsonutils.dumps(_fake_cpu_info))
self.assertIsNone(ret)
@mock.patch.object(host.Host, 'compare_cpu')
@mock.patch.object(nova.virt.libvirt.LibvirtDriver,
'_vcpu_model_to_cpu_config')

View File

@@ -5148,9 +5148,16 @@ class LibvirtDriver(driver.ComputeDriver):
try:
ret = self._host.compare_cpu(cpu.to_xml())
except libvirt.libvirtError as e:
LOG.error(m, {'ret': e, 'u': u})
raise exception.MigrationPreCheckError(
reason=m % {'ret': e, 'u': u})
error_code = e.get_error_code()
if error_code == libvirt.VIR_ERR_NO_SUPPORT:
LOG.debug("URI %(uri)s does not support cpu comparison. "
"It will be proceeded though. Error: %(error)s",
{'uri': self.uri(), 'error': e})
return
else:
LOG.error(m, {'ret': e, 'u': u})
raise exception.MigrationPreCheckError(
reason=m % {'ret': e, 'u': u})
if ret <= 0:
LOG.error(m, {'ret': ret, 'u': u})