From da9301fbc7877529bc2b099ffeb622e02ef54f0e Mon Sep 17 00:00:00 2001 From: Markus Zoeller Date: Thu, 19 Mar 2015 18:36:09 +0100 Subject: [PATCH] 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 --- nova/tests/unit/virt/libvirt/test_driver.py | 15 +++++++++++++++ nova/virt/libvirt/driver.py | 13 ++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/test_driver.py b/nova/tests/unit/virt/libvirt/test_driver.py index b98baf02bf..6e061dbfe1 100644 --- a/nova/tests/unit/virt/libvirt/test_driver.py +++ b/nova/tests/unit/virt/libvirt/test_driver.py @@ -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') diff --git a/nova/virt/libvirt/driver.py b/nova/virt/libvirt/driver.py index 312f5a3305..e01b7acabb 100644 --- a/nova/virt/libvirt/driver.py +++ b/nova/virt/libvirt/driver.py @@ -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})