示例#1
0
  def testAcquiringConnections(self):
    """Test acquiring libvirt connections when loading domain state.

    Also check that loadDomainState can reuse a connection it already
    has open.
    """
    doms = {('debmarshal-1', 'qemu'): 500,
            ('debmarshal-2', 'qemu'): 500}

    self.mox.StubOutWithMock(utils, '_clearLibvirtError')
    utils._clearLibvirtError()

    self.mox.StubOutWithMock(utils, 'loadState')
    utils.loadState('debmarshal-domains').AndReturn(doms)

    self.mox.StubOutWithMock(hypervisors.qemu.QEMU, 'open')
    qemu_con = self.mox.CreateMock(libvirt.virConnect)
    hypervisors.qemu.QEMU.open().AndReturn(qemu_con)

    virt_domain = self.mox.CreateMock(libvirt.virDomain)
    qemu_con.lookupByName('debmarshal-1').InAnyOrder().AndReturn(virt_domain)
    virt_domain = self.mox.CreateMock(libvirt.virDomain)
    qemu_con.lookupByName('debmarshal-2').InAnyOrder().AndReturn(virt_domain)

    self.mox.ReplayAll()

    self.assertEqual(domains.loadDomainState(), doms)
示例#2
0
  def testNonexistentDomain(self):
    """Test that loadDomainState can deal with nonexistent domains."""
    doms = {}
    for i in xrange(6):
      doms[('debmarshal-%d' % i, 'qemu')] = 500

    self.mox.StubOutWithMock(utils, '_clearLibvirtError')
    utils._clearLibvirtError()

    self.mox.StubOutWithMock(utils, 'loadState')
    utils.loadState('debmarshal-domains').AndReturn(dict(doms))

    self.mox.StubOutWithMock(hypervisors.qemu.QEMU, 'open')
    qemu_con = self.mox.CreateMock(libvirt.virConnect)
    hypervisors.qemu.QEMU.open().AndReturn(qemu_con)

    qemu_con.lookupByName('debmarshal-0').InAnyOrder()
    qemu_con.lookupByName('debmarshal-1').InAnyOrder()
    qemu_con.lookupByName('debmarshal-2').InAnyOrder().AndRaise(
        libvirt.libvirtError("Domain doesn't exist"))
    qemu_con.lookupByName('debmarshal-3').InAnyOrder()
    qemu_con.lookupByName('debmarshal-4').InAnyOrder().AndRaise(
        libvirt.libvirtError("Domain doesn't exist"))
    qemu_con.lookupByName('debmarshal-5').InAnyOrder()

    self.mox.ReplayAll()

    del doms[('debmarshal-2', 'qemu')]
    del doms[('debmarshal-4', 'qemu')]

    self.assertEqual(domains.loadDomainState(), doms)
示例#3
0
  def test(self):
    virt_con = self.mox.CreateMock(libvirt.virConnect)

    self.mox.StubOutWithMock(utils, '_clearLibvirtError')
    utils._clearLibvirtError()

    name = 'debmarshal-0'
    virt_con.lookupByName(name)

    name = 'debmarshal-1'
    virt_con.lookupByName(name).AndRaise(libvirt.libvirtError(
      "Network doesn't exist"))

    self.mox.ReplayAll()

    self.assertEqual(domains._findUnusedName(virt_con), name)