From be1dab22247a3c02194945a7d4429ea1169cbd97 Mon Sep 17 00:00:00 2001 From: Cyril Roelandt Date: Thu, 17 Oct 2013 22:45:24 +0000 Subject: [PATCH] compute: virt: Fix Instance creation Instance is a namedtuple defined in ceilometer/compute/virt/inspector.py. Its fields are 'name' and 'UUID'. Therefore, the 'uuid' field used in inspect_instances should be 'UUID'. Change-Id: I844b457bc75603d6325bfe3eb239012cec12c6b9 --- ceilometer/compute/virt/libvirt/inspector.py | 2 +- tests/compute/virt/libvirt/test_inspector.py | 35 ++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) 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 47fd18002..b3860c3fa 100644 --- a/tests/compute/virt/libvirt/test_inspector.py +++ b/tests/compute/virt/libvirt/test_inspector.py @@ -32,12 +32,35 @@ class TestLibvirtInspection(test_base.TestCase): self.instance_name = 'instance-00000001' self.inspector = libvirt_inspector.LibvirtInspector() 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() @@ -103,6 +126,9 @@ class TestLibvirtInspection(test_base.TestCase): """ + 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)) @@ -169,6 +195,9 @@ class TestLibvirtInspection(test_base.TestCase): """ + 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))