diff --git a/ceilometer/compute/virt/libvirt/inspector.py b/ceilometer/compute/virt/libvirt/inspector.py index d22facfae..69734d86b 100644 --- a/ceilometer/compute/virt/libvirt/inspector.py +++ b/ceilometer/compute/virt/libvirt/inspector.py @@ -99,7 +99,7 @@ class LibvirtInspector(virt_inspector.Inspector): if domain_id != 0: domain = self._get_connection().lookupByID(domain_id) yield virt_inspector.Instance(name=domain.name(), - uuid=domain.UUIDString()) + UUID=domain.UUIDString()) except libvirt.libvirtError: # Instance was deleted while listing... ignore it pass diff --git a/tests/compute/virt/libvirt/test_inspector.py b/tests/compute/virt/libvirt/test_inspector.py index e37d0315f..29f8c46be 100644 --- a/tests/compute/virt/libvirt/test_inspector.py +++ b/tests/compute/virt/libvirt/test_inspector.py @@ -34,12 +34,35 @@ class TestLibvirtInspection(test.BaseTestCase): self.inspector = libvirt_inspector.LibvirtInspector() self.mox = self.useFixture(moxstubout.MoxStubout()).mox self.inspector.connection = self.mox.CreateMockAnything() - self.inspector.connection.getCapabilities() self.domain = self.mox.CreateMockAnything() - self.inspector.connection.lookupByName(self.instance_name).AndReturn( - self.domain) + + def test_inspect_instances(self): + class FakeDomain(object): + def name(self): + return 'fake_name' + + def UUIDString(self): + return 'uuid' + + fake_domain = FakeDomain() + self.inspector.connection.getCapabilities() + self.inspector.connection.numOfDomains().AndReturn(1) + self.inspector.connection.getCapabilities() + self.inspector.connection.listDomainsID().AndReturn([42]) + self.inspector.connection.getCapabilities() + self.inspector.connection.lookupByID(42).AndReturn(fake_domain) + self.mox.ReplayAll() + + inspected_instances = list(self.inspector.inspect_instances()) + self.assertEqual(len(inspected_instances), 1) + inspected_instance = inspected_instances[0] + self.assertEqual(inspected_instance.name, 'fake_name') + self.assertEqual(inspected_instance.UUID, 'uuid') def test_inspect_cpus(self): + self.inspector.connection.getCapabilities() + self.inspector.connection.lookupByName(self.instance_name).AndReturn( + self.domain) self.domain.info().AndReturn((0L, 0L, 0L, 2L, 999999L)) self.mox.ReplayAll() @@ -105,6 +128,9 @@ class TestLibvirtInspection(test.BaseTestCase): """ + self.inspector.connection.getCapabilities() + self.inspector.connection.lookupByName(self.instance_name).AndReturn( + self.domain) self.domain.XMLDesc(0).AndReturn(dom_xml) self.domain.interfaceStats('vnet0').AndReturn((1L, 2L, 0L, 0L, 3L, 4L, 0L, 0L)) @@ -171,6 +197,9 @@ class TestLibvirtInspection(test.BaseTestCase): """ + self.inspector.connection.getCapabilities() + self.inspector.connection.lookupByName(self.instance_name).AndReturn( + self.domain) self.domain.XMLDesc(0).AndReturn(dom_xml) self.domain.blockStats('vda').AndReturn((1L, 2L, 3L, 4L, -1))