def test_duplicate_volume(self):
        virtcon = libvirt.open()
        c = Cluster("integration", None, virtcon)
        original = c.create_volume("cephlvc-test_duplicate_volume-original.img", 8)
        duplicate = c.duplicate_volume(original, "cephlvc-test_duplicate_volume-duplicate.img")

        self.assertEquals("cephlvc-test_duplicate_volume-duplicate.img", duplicate.name())
        self.assertEquals(0, original.delete())
        self.assertEquals(0, duplicate.delete())
    def test_domain_name_increment(self):
        vc = libvirt.virConnect()
        d = libvirt.virDomain(vc)

        c = Cluster('unittest', 'template_domain', vc)

        vc.listAllDomains = MagicMock(return_value=[])
        self.assertEqual('unittest-00', c.next_domain_name())

        d.name = MagicMock(return_value='unittest-00')
        vc.listAllDomains = MagicMock(return_value=[d])
        self.assertEqual('unittest-01', c.next_domain_name())
def setUpModule():
    image_name = 'cirros-0.3.4-x86_64-disk.img'
    virt = libvirt.open()
    c = Cluster(CLUSTER_NAME, TEMPLATE_NAME, virt)
    vol = c.load_volume(image_name)

    if vol is None:
        create_cirros_volume(virt, image_name)
    try:
        domain = c.template_domain
    except:
        with open("%s/domain-template.xml" % os.path.dirname(__file__), "r") as domain_xml_file:
            domain_etree = ET.fromstring(domain_xml_file.read())
            src_volume = c.load_volume(image_name)
            volume = c.duplicate_volume(src_volume, "%s.img" % TEMPLATE_NAME)
            domain = c.create_domain(TEMPLATE_NAME, domain_etree, volume)
 def test_next_mac_address(self):
     vc = libvirt.virConnect()
     c = Cluster('unittest', 'template_domain', vc)
     next_mac = c.next_mac_address('00:00:00:00:00:09')
     self.assertEquals('00:00:00:00:00:0a', next_mac)