Example #1
0
    def add_test_by_name(self, name):
        self.test_name = name
        loader = unittest.TestLoader()
        print "Loadding...", 'case.' + name

        try:
            try:
                self.suite = loader.loadTestsFromName('cases.' + name)
            except ImportError:
                raise error.CommonError("Load test case failed: %s" % name)
            print "Done."
        except AttributeError:
            msg = "The test case %s cannot be load!" % name
            raise error.CommonError(msg)
Example #2
0
    def backup_vm(self,
                  vm,
                  dest,
                  tp=0,
                  level="low",
                  descr="",
                  baktype="manul"):
        params = {}

        params['vmUuid'] = vm.get_vmUuid()
        params['uuid'] = vm.get_storage_uuid()
        params['parentUuid'] = vm.get_parentUuid()
        params['storage_path'] = vm.get_storage_path()
        params['copy_Level'] = level
        params['bakdsc'] = descr
        params['baktype'] = baktype

        if vm.host.get_storage_path(dest):
            params['targetstorage_path'] = vm.host.get_storage_path(dest)
        else:
            raise error.CommonError("Target storage does not exist.")
        if not tp:
            params['backup_type'] = "diff_backup"
        elif tp == 1:
            params['backup_type'] = "complete_backup"

        action_id = CODE['backup_vm']
        host = vm.get_hostname()
        m_id = self.executor.run(action_id, params, host, 'vm',
                                 'VmnoclusterchangeTask')

        self.executor.wait_for_done(m_id, host, timeout=1800)
Example #3
0
    def create(self,
               name,
               host,
               storage_name='defaultlocal',
               cfg=None,
               img=None):
        #avoid duplicated name
        if self.is_name_dupliacted(name, host):
            raise error.CommonError("Create vm: name duplicated!")

        m_vm = vm.VMS(name)

        #Set vm config info
        if cfg:
            m_vm.update_cfg(cfg)

        m_vm.cfg['storage_path'] = self.get_storage_path(host, storage_name)
        m_vm.cfg['storage_uuid'] = self.get_storage_uuid(host, storage_name)
        m_vm.cfg['hostUuid'] = self.get_host_uuid(host)

        if not img:
            m_vm.add_hd()
        else:
            vhd = {'baseimg': img, 'createvhd': 'no'}
            m_vm.add_hd(vhd)

        m_vm.add_netcard()
        action_id = CODE['create_vms']
        m_id = self.executor.run(action_id, m_vm.cfg, host, 'vm',
                                 'VmnoclusterchangeTask')
        self.executor.wait_for_done(m_id, host, 120)
        m_vm.initialize(host, self.executor)
        return m_vm
Example #4
0
def get_storage_uuid(host, storage):
    qurey = databases.DBQuery(host)
    keyword = "description=\'" + storage + "\'"
    if not qurey.get_storagepath(keyword):
        raise error.CommonError("Storage not found")

    return qurey.get_storageUuid(keyword)
Example #5
0
    def get_vnc_port(self, timeout=30):
        if self.name:
            current = time.time()
            endtime = current + timeout

            while current < endtime:
                port = self.query.get_vnc_port(self.name)
                if port:
                    return port
                current = time.time()
                time.sleep(1)

            raise error.CommonError("Get vm vnc port failed!")
Example #6
0
    def clone_vm(self,
                 src_vm,
                 dest_name,
                 dest_st,
                 to_temp=False,
                 level='high',
                 del_snapshot='yes',
                 cfg=None):
        params = {}
        host_name = src_vm.get_hostname()
        if self.is_name_dupliacted(dest_name, host_name):
            raise error.CommonError("Create vm: name duplicated!")

        params.update(vmd_port.CLONE_VMS)
        m_vm = vm.VMS(dest_name)

        if cfg:
            params.update(cfg)
        else:
            dest_path = storage.get_storage_path(host_name, dest_st)
            dest_uuid = storage.get_storage_uuid(host_name, dest_st)
            params.update({
                'parentUuid': src_vm.get_parentUuid(),
                'targetVmdesc': dest_name,
                'targetVmuuid': dest_name,
                'bsstorage_uuid': src_vm.get_storage_uuid(),
                'bsstorage_path': src_vm.get_storage_path(),
                'vmUuid': src_vm.get_vmUuid(),
                'storage_path': dest_path,
                'storageUuid': dest_uuid,
                'copy_level': level,
                'del_snapshot': del_snapshot,
                'to_template': 'yes' if to_temp else 'no'
            })

        action_id = CODE['clone_vms']
        m_id = self.executor.run(action_id, params, host_name, 'vm',
                                 'VmnoclusterchangeTask')
        self.executor.wait_for_done(m_id, host_name, 120)
        m_vm.initialize(host_name, self.executor)
        return m_vm
Example #7
0
 def run_test(self):
     self.get_test_name()
     if not self.suite.countTestCases():
         raise error.CommonError("No tests to run, load the test!")
     self.result =  \
     unittest.TextTestRunner(stream = sys.stdout).run(self.suite)