From f97f6214dac7951cb4d91bf24e9ceb3a43e65938 Mon Sep 17 00:00:00 2001 From: Stanislaw Pitucha Date: Mon, 11 Mar 2013 17:54:47 +0000 Subject: Handle vcpu counting failures gracefully The virDomainGetVcpus() call in libvirt can fail in some cases. This should be handled properly in nova and not cause failures in starting up new instances. Fixes bug 1153694 Change-Id: I8e072c53ee2bafcb50083d793ceabe5292038ab6 --- nova/tests/test_libvirt.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/test_libvirt.py b/nova/tests/test_libvirt.py index 55b6aaec4..3e379a292 100644 --- a/nova/tests/test_libvirt.py +++ b/nova/tests/test_libvirt.py @@ -3532,6 +3532,35 @@ class LibvirtConnTestCase(test.TestCase): } self.assertEqual(actual, expect) + def test_failing_vcpu_count(self): + """Domain can fail to return the vcpu description in case it's + just starting up or shutting down. Make sure None is handled + gracefully. + """ + + class DiagFakeDomain(object): + def __init__(self, vcpus): + self._vcpus = vcpus + + def vcpus(self): + if self._vcpus is None: + return None + else: + return ([1] * self._vcpus, [True] * self._vcpus) + + driver = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) + conn = driver._conn + self.mox.StubOutWithMock(driver, 'list_instance_ids') + self.mox.StubOutWithMock(conn, 'lookupByID') + + driver.list_instance_ids().AndReturn([1, 2]) + conn.lookupByID(1).AndReturn(DiagFakeDomain(None)) + conn.lookupByID(2).AndReturn(DiagFakeDomain(5)) + + self.mox.ReplayAll() + + self.assertEqual(5, driver.get_vcpu_used()) + def test_get_instance_capabilities(self): conn = libvirt_driver.LibvirtDriver(fake.FakeVirtAPI(), True) -- cgit