Merge "compute: virt: Fix Instance creation"

This commit is contained in:
Jenkins 2013-10-25 12:07:54 +00:00 committed by Gerrit Code Review
commit 7ba4986af1
2 changed files with 33 additions and 4 deletions

View File

@ -99,7 +99,7 @@ class LibvirtInspector(virt_inspector.Inspector):
if domain_id != 0: if domain_id != 0:
domain = self._get_connection().lookupByID(domain_id) domain = self._get_connection().lookupByID(domain_id)
yield virt_inspector.Instance(name=domain.name(), yield virt_inspector.Instance(name=domain.name(),
uuid=domain.UUIDString()) UUID=domain.UUIDString())
except libvirt.libvirtError: except libvirt.libvirtError:
# Instance was deleted while listing... ignore it # Instance was deleted while listing... ignore it
pass pass

View File

@ -34,12 +34,35 @@ class TestLibvirtInspection(test.BaseTestCase):
self.inspector = libvirt_inspector.LibvirtInspector() self.inspector = libvirt_inspector.LibvirtInspector()
self.mox = self.useFixture(moxstubout.MoxStubout()).mox self.mox = self.useFixture(moxstubout.MoxStubout()).mox
self.inspector.connection = self.mox.CreateMockAnything() self.inspector.connection = self.mox.CreateMockAnything()
self.inspector.connection.getCapabilities()
self.domain = self.mox.CreateMockAnything() 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): 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.domain.info().AndReturn((0L, 0L, 0L, 2L, 999999L))
self.mox.ReplayAll() self.mox.ReplayAll()
@ -105,6 +128,9 @@ class TestLibvirtInspection(test.BaseTestCase):
</domain> </domain>
""" """
self.inspector.connection.getCapabilities()
self.inspector.connection.lookupByName(self.instance_name).AndReturn(
self.domain)
self.domain.XMLDesc(0).AndReturn(dom_xml) self.domain.XMLDesc(0).AndReturn(dom_xml)
self.domain.interfaceStats('vnet0').AndReturn((1L, 2L, 0L, 0L, self.domain.interfaceStats('vnet0').AndReturn((1L, 2L, 0L, 0L,
3L, 4L, 0L, 0L)) 3L, 4L, 0L, 0L))
@ -171,6 +197,9 @@ class TestLibvirtInspection(test.BaseTestCase):
</domain> </domain>
""" """
self.inspector.connection.getCapabilities()
self.inspector.connection.lookupByName(self.instance_name).AndReturn(
self.domain)
self.domain.XMLDesc(0).AndReturn(dom_xml) self.domain.XMLDesc(0).AndReturn(dom_xml)
self.domain.blockStats('vda').AndReturn((1L, 2L, 3L, 4L, -1)) self.domain.blockStats('vda').AndReturn((1L, 2L, 3L, 4L, -1))