diff options
| author | Stanislaw Pitucha <stanislaw.pitucha@hp.com> | 2013-03-11 17:54:47 +0000 |
|---|---|---|
| committer | Stanislaw Pitucha <stanislaw.pitucha@hp.com> | 2013-03-11 20:57:13 +0000 |
| commit | f97f6214dac7951cb4d91bf24e9ceb3a43e65938 (patch) | |
| tree | f8bd5472f2c27c306c8d458be1d3091620f978c6 /nova/tests | |
| parent | 554ecca217916949753f693891c344f4c6f640c9 (diff) | |
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
Diffstat (limited to 'nova/tests')
| -rw-r--r-- | nova/tests/test_libvirt.py | 29 |
1 files changed, 29 insertions, 0 deletions
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) |
