Beispiel #1
0
def boot(domain, bootdev="hd",
         overwrite_disks=[],
         recreate_networks=[]):

    """Boot a domain"""

    cloubed = Cloubed()
    cloubed.boot_vm(domain, bootdev, overwrite_disks, recreate_networks)
Beispiel #2
0
    def setUp(self):

        patcher_open = mock.patch('libvirt.open', libvirt_mod_m.open)
        patcher_openro = mock.patch('libvirt.openReadOnly',
                                    libvirt_mod_m.openReadOnly)
        patcher_conn = mock.patch('libvirt.virConnect', libvirt_conn_m)
        patcher_open.start()
        patcher_conn.start()
        patcher_openro.start()
        self.addCleanup(patcher_open.stop)
        self.addCleanup(patcher_openro.stop)
        self.addCleanup(patcher_conn.stop)
        self.loader = MockConfigurationLoader(conf)
        self.tbd = Cloubed(conf_loader=self.loader)
Beispiel #3
0
def cleanup():

    """ Destroys all resources in libvirt """

    cloubed = Cloubed()
    cloubed.cleanup()
Beispiel #4
0
def create_network(network_name, recreate):

    """ Creates network in libvirt """

    cloubed = Cloubed()
    cloubed.create_network(network_name, recreate)
Beispiel #5
0
def resume(domain_name):

    """ Resume a previously suspended domain """

    cloubed = Cloubed()
    cloubed.resume(domain_name)
Beispiel #6
0
def suspend(domain_name):

    """ Suspend-to-RAM (into ACPI S3 state) a domain """

    cloubed = Cloubed()
    cloubed.suspend(domain_name)
Beispiel #7
0
def reset(domain_name):

    """ Cold-reset a domain telling nothing to the OS """

    cloubed = Cloubed()
    cloubed.reset(domain_name)
Beispiel #8
0
def reboot(domain_name):

    """ Reboot gracefully a domain using ACPI """

    cloubed = Cloubed()
    cloubed.reboot(domain_name)
Beispiel #9
0
def storage_pools():

    """ Returns the list of storage pools names """

    cloubed = Cloubed()
    return cloubed.storage_pools()
Beispiel #10
0
def shutdown(domain_name):

    """ Shutdown a domain using ACPI """

    cloubed = Cloubed()
    cloubed.shutdown(domain_name)
Beispiel #11
0
def gen(domain, template):

    """Generates a file for a domain based on template"""

    cloubed = Cloubed()
    cloubed.gen_file(domain, template)
Beispiel #12
0
def _clean_exit():

    if Cloubed.initialized():
        # get the singleton instance
        cloubed = Cloubed()
        cloubed.clean_exit()
Beispiel #13
0
def domains():

    """ Returns the list of domains names """

    cloubed = Cloubed()
    return cloubed.domains()
Beispiel #14
0
def networks():

    """ Returns the list of networks names """

    cloubed = Cloubed()
    return cloubed.networks()
Beispiel #15
0
def storage_volumes():

    """ Returns the list of storage volumes names """

    cloubed = Cloubed()
    return cloubed.storage_volumes()
Beispiel #16
0
class TestCloubed(CloubedTestCase):

    def setUp(self):

        patcher_open = mock.patch('libvirt.open', libvirt_mod_m.open)
        patcher_openro = mock.patch('libvirt.openReadOnly',
                                    libvirt_mod_m.openReadOnly)
        patcher_conn = mock.patch('libvirt.virConnect', libvirt_conn_m)
        patcher_open.start()
        patcher_conn.start()
        patcher_openro.start()
        self.addCleanup(patcher_open.stop)
        self.addCleanup(patcher_openro.stop)
        self.addCleanup(patcher_conn.stop)
        self.loader = MockConfigurationLoader(conf)
        self.tbd = Cloubed(conf_loader=self.loader)

    def test_storage_pools(self):
        """Cloubed.storage_pools() should return the list of names of storage
           pools
        """

        self.assertEquals(self.tbd.storage_pools(), ['test_storage_pool',])

    def test_storage_volumes(self):
        """Cloubed.storage_volumes() should return the list of names of storage
           volumes
        """

        self.assertEquals(self.tbd.storage_volumes(),
                          ['test_storage_volume1', 'test_storage_volume2'])

    def test_networks(self):
        """Cloubed.networks() should return the list of names of networks"""

        self.assertEquals(self.tbd.networks(),
                          ['test_network1', 'test_network2'])

    def test_domains(self):
        """Cloubed.domains() should return of names of domains"""

        self.assertEquals(self.tbd.domains(), ['test_domain1', 'test_domain2'])

    def test_get_domain_by_name(self):
        """Cloubed.get_domain_by_name() shoud find the Domain with name in
           parameter and return it else raise CloubedException
        """

        self.assertIsInstance(self.tbd.get_domain_by_name('test_domain1'), Domain)
        self.assertRaisesRegexp(CloubedException,
                                'domain fail not found in configuration',
                                self.tbd.get_domain_by_name,
                                'fail')

    def test_get_domain_by_libvirt_name(self):
        """Cloubed.get_domain_by_libvirt_name() shoud find the Domain with
           libvirt name in parameter and return it else raise CloubedException
        """

        self.assertIsInstance(
            self.tbd.get_domain_by_libvirt_name("{user}:test_testbed:test_domain1" \
                                                  .format(user=getuser())),
            Domain)
        self.assertRaisesRegexp(CloubedException,
                                'domain fail not found in configuration',
                                self.tbd.get_domain_by_libvirt_name,
                                'fail')

    def test_get_network_by_name(self):
        """Cloubed.get_network_by_name() shoud find the Network with name in
           parameter and return it else raise CloubedException
        """

        self.assertIsInstance(self.tbd.get_network_by_name('test_network1'), Network)
        self.assertRaisesRegexp(CloubedException,
                                'network fail not found in configuration',
                                self.tbd.get_network_by_name,
                                'fail')

    def test_get_storage_volume_by_name(self):
        """Cloubed.get_storage_volume_by_name() shoud find the StorageVolume
           with name in parameter and return it else raise CloubedException
        """

        self.assertIsInstance(self.tbd.get_storage_volume_by_name('test_storage_volume1'), StorageVolume)
        self.assertRaisesRegexp(CloubedException,
                                'storage volume fail not found in configuration',
                                self.tbd.get_storage_volume_by_name,
                                'fail')

    def test_get_storage_pool_by_name(self):
        """Cloubed.get_storage_pool_by_name() shoud find the StoragePool
           with name in parameter and return it else raise CloubedException
        """

        self.assertIsInstance(self.tbd.get_storage_pool_by_name('test_storage_pool'), StoragePool)
        self.assertRaisesRegexp(CloubedException,
                                'storage pool fail not found in configuration',
                                self.tbd.get_storage_pool_by_name,
                                'fail')

    def test_get_templates_dict(self):
        """Cloubed.get_templates_dict() shoud return a dict with all parameters
           in configuration but if the domain name given in parameter could not
           be found a CloubedException should be raised
        """

        self.maxDiff = None
        d1 = self.tbd.get_templates_dict('test_domain1')
        d2 = {'self.name': 'test_domain1',
              'testbed': 'test_testbed' }
        self.assertTrue(set(d2.items()).issubset(set(d1.items())))

        self.assertRaisesRegexp(CloubedException,
                                'domain fail not found in configuration',
                                self.tbd.get_templates_dict,
                                'fail')

    def test_boot_vm(self):
        """Cloubed.boot_vm() shoud run without trouble
        """

        self.tbd.boot_vm('test_domain1')
        self.tbd.boot_vm('test_domain1',
                         overwrite_disks=True,
                         recreate_networks=True)
        self.tbd.boot_vm('test_domain2')

    def test_shutdown(self):
        """Cloubed.shutdown() shoud run without trouble
        """

        domain = 'test_domain1'
        self.tbd.boot_vm(domain)
        self.tbd.shutdown(domain)

    def test_destroy(self):
        """Cloubed.destroy() shoud run without trouble
        """

        domain = 'test_domain1'
        self.tbd.boot_vm(domain)
        self.tbd.destroy(domain)

    def test_reboot(self):
        """Cloubed.reboot() shoud run without trouble
        """

        domain = 'test_domain1'
        self.tbd.boot_vm(domain)
        self.tbd.reboot(domain)

    def test_reset(self):
        """Cloubed.reset() shoud run without trouble
        """

        domain = 'test_domain1'
        self.tbd.boot_vm(domain)
        self.tbd.destroy(domain)

    def test_suspend(self):
        """Cloubed.suspend() shoud run without trouble
        """

        domain = 'test_domain1'
        self.tbd.boot_vm(domain)
        self.tbd.suspend(domain)

    def test_resume(self):
        """Cloubed.resume() shoud run without trouble
        """

        domain = 'test_domain1'
        self.tbd.boot_vm(domain)
        self.tbd.resume(domain)

    def test_get_infos(self):
        """Cloubed.get_infos() shoud run without trouble
        """

        self.tbd.boot_vm('test_domain1')
        self.tbd.boot_vm('test_domain2')
        self.tbd.get_infos()

    def test_cleanup(self):
        """Cloubed.cleanup() shoud run without trouble
        """

        self.tbd.boot_vm('test_domain1')
        self.tbd.cleanup()

    def test_xml(self):
        """Cloubed.xml() shoud run without trouble except if the type of
           resource is not valid and CloubedException should be raised
        """

        self.tbd.xml('domain','test_domain2')
        self.tbd.xml('network','test_network2')
        self.tbd.xml('storagevolume','test_storage_volume2')
        self.tbd.xml('storagepool','test_storage_pool')
        self.assertRaisesRegexp(CloubedException,
                                "cannot dump XML of invalid resource type fail",
                                self.tbd.xml,
                                'fail', 'test_fail')
Beispiel #17
0
def destroy(domain_name):

    """ Destroy a domain telling nothing to the OS """

    cloubed = Cloubed()
    cloubed.destroy(domain_name)
Beispiel #18
0
def wait(domain, event, detail, enable_http=False):

    """Wait for an event on a domain"""

    cloubed = Cloubed()
    cloubed.wait_event(domain, event, detail, enable_http)