Exemplo n.º 1
0
    def test_CreateTemplate_SD(self):
        '''
        @summary: 创建模板,指定存储域
        @note: 操作成功,验证返回状态码和返回信息
        '''
        self.tempapi = TemplatesAPIs()
        LogPrint().info("Test: Create template %s." % self.dm.temp_name)
        r = self.tempapi.createTemplate(self.dm.temp_info)
        print r

        def is_temp_ok():
            return self.tempapi.getTemplateInfo(
                temp_name=self.dm.temp_name
            )['result']['template']['status']['state'] == 'ok'

        if r['status_code'] == self.dm.expected_status_code:
            if wait_until(is_temp_ok, 600, 10):
                LogPrint().info("PASS: Create Template ok.")
            else:
                LogPrint().error("FAIL: Create Template overtime")
                self.assertTrue(False)
        else:
            LogPrint().error(
                "FAIL: Create Template failed.Status-code is WRONG.")
            self.assertTrue(False)
Exemplo n.º 2
0
def smart_delete_template(temp_name):
    '''
    @summary: 删除模板
    @param temp_name: 模板名称
    @return: True or False
    '''

    tempapi = TemplatesAPIs()
    try:
        tempapi.getTemplateIdByName(temp_name)
        if tempapi.getTemplateStatus(temp_name) != 'ok':
            LogPrint().warning(
                "WARN: The template is not 'ok'. It cannot be deleted.")
            return False
        else:

            def is_temp_delete():
                return tempapi.is_Exist(temp_name) == False

            r = tempapi.delTemplate(temp_name)
            print r
            if r['status_code'] == 200:
                if wait_until(is_temp_delete, 300, 10):
                    LogPrint().info("Delete template success.")
                    return True
                else:
                    LogPrint().info("Delete template overtime.")
                    return False
            else:
                LogPrint().error("Status code is WRONG")
                return False
    except:
        LogPrint().warning("WARN: Template is not exist.")
        return True
Exemplo n.º 3
0
def smart_del_host(host_name, xml_host_del_option):
    '''
    @summary: 在不同的最终状态下删除Host
    @param host_name: 待删除的主机名称
    @param xml_host_del_option: 删除主机时所采用的删除配置项
    @return: True or False
    '''
    host_api = HostAPIs()
    def is_host_maintenance():
        return host_api.getHostStatus(host_name)=='maintenance'
    if host_api.searchHostByName(host_name)['result']['hosts']:
        host_state = host_api.getHostStatus(host_name)
        # 当主机状态为UP时,先设置为“维护”,然后再删除
        if host_state == 'up' or host_state == 'non_responsive':
            LogPrint().info("INFO: Deactivate host '%s' from 'up' to 'maintenance' state." % host_name)
            r = host_api.deactiveHost(host_name)
            if wait_until(is_host_maintenance, 120, 5):
                LogPrint().info("INFO: Delete host '%s' from cluster." % host_name)
                r = host_api.delHost(host_name, xml_host_del_option)
                return r['status_code']==200
        # 当主机状态为maintenance或install_failed时,直接删除
        elif host_state=='maintenance' or host_state=='install_failed':
            LogPrint().info("INFO: Delete host '%s' from cluster." % host_name)
            r = host_api.delHost(host_name, xml_host_del_option)
            return r['status_code']==200
    else:
        LogPrint().warning("INFO-WARN: Host '%s' not exist." % host_name)
        return True
Exemplo n.º 4
0
def smart_create_host(host_name, xml_host_info):
    '''
    @summary: 创建主机,并等待其变为UP状态。
    @param host_name: 新创建的主机名称
    @param xml_host_info: 创建主机的xml格式信息,用于向接口传参数
    @return: True or False
    '''
    host_api = HostAPIs()
    r = host_api.createHost(xml_host_info)

    def is_host_up():
        return host_api.getHostStatus(host_name) == 'up'

    if wait_until(is_host_up, 200, 5):
        if r['status_code'] == 201:
            LogPrint().info("INFO-PASS: Create host '%s' SUCCESS." % host_name)
            return True
        else:
            LogPrint().error(
                "INFO-FAIL: Create host '%s' FAILED. Returned status code is INCORRECT."
                % host_name)
            return False
    else:
        LogPrint().error(
            "INFO-FAIL: Create host '%s' FAILED. It's final state is not 'UP'."
            % host_name)
        return False
Exemplo n.º 5
0
    def test_CreateDisk_iscsi_raw(self): 
        '''
        @note: 在iscsi存储域内创建raw类型磁盘
        @note: 若format=raw,则sparse必须为false,否则报错
        '''
        self.flag = True
        diskapi = DiskAPIs()
        LogPrint().info("Test: Create raw type disk.")
        r = diskapi.createDisk(self.dm.disk_info_raw)
        def is_disk_ok():
            return diskapi.getDiskStatus(self.disk_id)=='ok'
        if r['status_code'] == self.dm.expected_status_code:
            self.disk_id = r['result']['disk']['@id']
            #如果磁盘状态在给定时间内变为ok状态,则继续验证状态码和磁盘信息
            if wait_until(is_disk_ok, 200, 5):
                dict_actual = r['result']
                dict_expected = xmltodict.parse(self.dm.disk_info_raw)
                dictCompare = DictCompare()
                if dictCompare.isSubsetDict(dict_expected, dict_actual):
                    LogPrint().info("PASS: Create raw disk SUCCESS." )
#                 return True
                else:
                    LogPrint().error("FAIL: The disk_info is WRONG")
                    self.flag = False
            else:
                LogPrint().error("FAIL: The disk status is not OK. " )
                self.flag = False
        else:
            LogPrint().error("FAIL: Returned status code is %s. "% r['status_code'])
            self.flag = False
Exemplo n.º 6
0
    def test_DeleteTemplate(self):
        '''
        @summary: 删除模板
        @note: 操作成功,验证返回状态码和返回信息
        '''
        self.flag = True
        self.tempapi = TemplatesAPIs()
        LogPrint().info("Test: Delete template %s." % self.dm.temp_name)
        r = self.tempapi.delTemplate(self.dm.temp_name)

        def temp_not_exist():
            return self.tempapi.searchTemplateByName(
                self.dm.temp_name)['result']['templates'] == None

        if r['status_code'] == self.dm.expected_status_code:
            if wait_until(temp_not_exist, 300, 5):
                LogPrint().info("PASS: Delete Template SUCCESS.")
            else:
                LogPrint().info(
                    "FAIL: Delete Template failed.The Template still exist")
                self.flag = False
        else:
            LogPrint().info(
                "FAIL: Delete Template failed.The status_code is WRONG")
            self.flag = False
        self.assertTrue(self.flag)
Exemplo n.º 7
0
def smart_create_template(temp_name, temp_info):
    '''
    @summary: 创建模板,并等待其变为ok状态。
    @param temp_name: 新创建的模板名称
    @param temp_info: 创建模板的xml格式信息,用于向接口传参数
    @return: True or False
    '''
    tempapi = TemplatesAPIs()
    r = tempapi.createTemplate(temp_info)

    def is_temp_ok():
        return tempapi.getTemplateInfo(
            temp_name=temp_name
        )['result']['template']['status']['state'] == 'ok'

    if r['status_code'] == 202:
        if wait_until(is_temp_ok, 600, 10):
            LogPrint().info("INFO:Create Template %s success" % temp_name)
            return True
        else:
            LogPrint().error("INFO:Create Template overtime")
            return False
    else:
        LogPrint().error("INFO:Create Template failed.Status-code is %s." %
                         r['status_code'])
        return False
Exemplo n.º 8
0
def smart_attach_storage_domain(dc_name, sd_name, data=None):
    '''
    @summary: 智能附加存储域到数据中心(附加,并判断存储域状态是否最终变为active)
    @param dc_name: 数据中心名称
    @param sd_name: 存储域名称
    @return: True or False
    @change: 修改了检查存储域状态是一个重复循环的过程
    '''
    dc_api = DataCenterAPIs()

    r = dc_api.attachStorageDomainToDC(dc_name, sd_name, data)
    #     print r['status_code']
    #     print dc_api.getDCStorageDomainStatus(dc_name, sd_name)
    if r['status_code'] == 201:
        #检查存储域最终状态是否为active
        def is_storage_up():
            return dc_api.getDCStorageDomainStatus(dc_name,
                                                   sd_name) == 'active'

        if wait_until(is_storage_up, 200, 5):
            LogPrint().info("PASS:Active storage ok.")
            return True
        else:
            LogPrint().info("FAIL:Active storage overtime.")
            return False
    else:
        LogPrint().info("FAIL:Returned status code is wrong.")
        return False
Exemplo n.º 9
0
def smart_attach_storage_domain(dc_name, sd_name, data=None):
    '''
    @summary: 智能附加存储域到数据中心(附加,并判断存储域状态是否最终变为active)
    @param dc_name: 数据中心名称
    @param sd_name: 存储域名称
    @return: True or False
    @change: 修改了检查存储域状态是一个重复循环的过程
    '''
    dc_api = DataCenterAPIs()
    
    r = dc_api.attachStorageDomainToDC(dc_name, sd_name, data)
#     print r['status_code']
#     print dc_api.getDCStorageDomainStatus(dc_name, sd_name)
    if r['status_code'] == 201:
        #检查存储域最终状态是否为active
        def is_storage_up():
            return dc_api.getDCStorageDomainStatus(dc_name, sd_name)=='active'
        if wait_until(is_storage_up, 200, 5):
            LogPrint().info("PASS:Active storage ok.")
            return True
        else:
            LogPrint().info("FAIL:Active storage overtime.")
            return False
    else:
        LogPrint().info("FAIL:Returned status code is wrong.")
        return False
Exemplo n.º 10
0
        def do_test(xml_info):
            self.flag = True
            LogPrint().info("Test: Create template %s." %
                            self.dm.temp_name[self.expected_result_index])
            r = self.tempapi.createTemplate(xml_info)

            def is_temp_ok():
                return self.tempapi.getTemplateInfo(
                    temp_name=self.dm.temp_name[self.expected_result_index]
                )['result']['template']['status']['state'] == 'ok'

            if r['status_code'] == self.dm.expected_status_code:
                if wait_until(is_temp_ok, 600, 10):
                    LogPrint().info(
                        "PASS: Create Template '%s'ok." %
                        self.dm.temp_name[self.expected_result_index])
                else:
                    LogPrint().error(
                        "FAIL: Create Template '%s'overtime" %
                        self.dm.temp_name[self.expected_result_index])
                    self.flag = False
            else:
                LogPrint().error(
                    "FAIL: Create Template '%s'failed.Status-code is WRONG." %
                    self.dm.temp_name[self.expected_result_index])
                self.flag = False
            self.assertTrue(self.flag)
            self.expected_result_index += 1
Exemplo n.º 11
0
def smart_delete_disk(disk_id, status_code=200):
    '''
    @summary: 智能删除磁盘,并等待其状态为ok;
    @param disk_id:待删除的磁盘id
    @param status_code: 成功删除磁盘后,接口返回的状态码,缺省为200
    @return: True or False
    '''
    disk_api = DiskAPIs()
    tmp_disk_id = disk_id
    def is_disk_deleted(disk_id=tmp_disk_id):
        return not disk_api.isExist(disk_id)
    if DiskAPIs().isExist(disk_id):
        if disk_api.getDiskStatus(disk_id) != 'ok':
            LogPrint().warning("WARN: The disk is not 'ok'. It cannot be deleted.")
            return False
        else:
            r = disk_api.deleteDisk(disk_id)
            # 2014/11/13: Modified by LiuFei: add 'int' before status_code.
            if r['status_code'] == 200:
                if wait_until(is_disk_deleted, 60, 10):
                    LogPrint().info("INFO: Delete disk SUCCESS.")
                    return True
                else:
                    LogPrint().error("INFO: Disk is still exist.")
                    return False
            else:
                LogPrint().error("INFO: Returned status code '%s' is WRONG while deleting disk." % r['status_code'])
                return False
    else:
        LogPrint().warning("INFO: Disk is not exist.")
        return True
Exemplo n.º 12
0
def smart_delete_template(temp_name,version_name=None):  
    '''
    @summary: 删除模板
    @param temp_name: 模板名称
    @paran version_name:子模板名称
    @return: True or False
    ''' 
    
    tempapi = TemplatesAPIs()
    try:    
        tempapi.getTemplateIdByName(temp_name, version_name)
        if tempapi.getTemplateStatus(temp_name,version_name)!='ok':
            LogPrint().warning("WARN: The template is not 'ok'. It cannot be deleted.")
            return False
        else:
            def is_temp_delete():
                return tempapi.is_Exist(temp_name,version_name) == False   
            r = tempapi.delTemplate(temp_name,version_name)
            if r['status_code'] == 200:
                if wait_until(is_temp_delete, 60, 10):
                    LogPrint().info("Delete template success.")
                    return True
                else:
                    LogPrint().info("Delete template overtime.")
                    return False
            else:
                LogPrint().error("Status code is WRONG")
                return False
    except:
        LogPrint().warning("WARN: Template is not exist.")
        return True
Exemplo n.º 13
0
 def test_CreateModuleTestEnv(self):
     dcapi = DataCenterAPIs()
     capi = ClusterAPIs()
       
     # 创建1个数据中心(nfs类型)
     LogPrint().info("Pre-Module-Test-1: Create DataCenter '%s'." % self.dm.dc_nfs_name)
     self.assertTrue(dcapi.createDataCenter(self.dm.xml_dc_info)['status_code']==self.dm.expected_status_code_create_dc)
   
     # 创建1个集群
     LogPrint().info("Pre-Module-Test-2: Create Cluster '%s' in DataCenter '%s'." % (self.dm.cluster_nfs_name, self.dm.dc_nfs_name))
     self.assertTrue(capi.createCluster(self.dm.xml_cluster_info)['status_code']==self.dm.expected_status_code_create_cluster)
   
     # 在NFS数据中心中创建一个主机,并等待主机UP。
     LogPrint().info("Pre-Module-Test-3: Create Host '%s' in Cluster '%s'." % (self.dm.host1_name, self.dm.cluster_nfs_name))
     self.assertTrue(smart_create_host(self.dm.host1_name, self.dm.xml_host_info))
   
     # 为NFS数据中心创建Data(data1/data2/export)。
     @BaseTestCase.drive_data(self, self.dm.xml_storage_info)
     def create_storage_domains(xml_storage_domain_info):
         sd_name = xmltodict.parse(xml_storage_domain_info)['storage_domain']['name']
         LogPrint().info("Pre-Module-Test-4: Create Data Storage '%s'." % sd_name)
         self.assertTrue(smart_create_storage_domain(sd_name, xml_storage_domain_info))
     create_storage_domains()
       
     # 将创建的的data1、data2和export域附加到NFS/ISCSI数据中心里。
     LogPrint().info("Pre-Module-Test-5: Attach the data storages to data centers.")
     self.assertTrue(smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.data1_nfs_name))
     self.assertTrue(smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.data2_nfs_name))
     #self.assertTrue(smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.export1_name))
     #创建一个虚拟机
     self.vmapi = VirtualMachineAPIs()
     r = self.vmapi.createVm(self.dm.vm_info)
     if r['status_code'] == 201:
         self.vm_name = r['result']['vm']['name']
     else:
         LogPrint().error("Create vm failed.Status-code is WRONG.")
         self.assertTrue(False)
     #创建一个磁盘    
     self.diskapi = DiskAPIs()
     sd_id = StorageDomainAPIs().getStorageDomainIdByName(ModuleData.data1_nfs_name)
     r = self.diskapi.createDisk(self.dm.disk_info, sd_id)
     def is_disk_ok():
         return self.diskapi.getDiskStatus(self.disk_id)=='ok'
     if r['status_code'] == 202:
         self.disk_id = r['result']['disk']['@id']
         if wait_until(is_disk_ok, 200, 5):
             LogPrint().info("Create disk ok.")
     else:
         LogPrint().error("Create disk failed.Status-code is WRONG.")
         self.assertTrue(False)
     #将磁盘附加到虚拟机    
     self.vmdiskapi = VmDiskAPIs()
     r=self.vmdiskapi.attachDiskToVm(self.vm_name, self.disk_id)
     if r['status_code'] == 200:
         LogPrint().info("Attach Disk to vm SUCCESS.")
     else:
         LogPrint().error("Attach Disk to vm fail.Status-code is WRONG.")
         self.assertTrue(False)
Exemplo n.º 14
0
    def test_Scene(self):
        '''
        @summary: 测试场景描述
        '''
        volumeapi = GlusterVolumeAPIs()
        #创建一个distributed_replicate类型的卷disrep,Replica Count=2,brick=4
        LogPrint().info("Create volume disrep")
        r = volumeapi.createGlusterVolume(self.dm.cluster_name, self.dm.xml_volume_disrep)
        if r['status_code'] == self.dm.expected_status_code_create_volume:
            LogPrint().info("PASS:Create volume disrep success.")
            self.flag = True
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)
           
        LogPrint().info("Start volume disrep")
        r = volumeapi.startGlusterVolume(self.dm.cluster_name, "disrep")
        if r['status_code'] == self.dm.expected_status_code_start_volume:
            def is_volume_up():
                return volumeapi.getClusterVolumeStatus(self.dm.cluster_name, "disrep") == "up"
            if wait_until(is_volume_up, 600, 5):
                LogPrint().info("PASS:Start volume disrep success.")
                self.flag = True
            else:
                LogPrint().error("FAIL:Start volume failed.Status is not UP.")
                self.flag = False
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)
#       
#     #利用该卷创建一个glusterfs类型的存储域
        sdapi = StorageDomainAPIs()
        LogPrint().info("Create glusterfs storagedomain '%s'."%self.dm.sd_name)
        r = sdapi.createStorageDomain(self.dm.xml_sd_info)
        if r['status_code'] == self.dm.expected_status_code_create_sd:
            LogPrint().info("PASS:Create glusterfs storagedomain '%s' SUCCESS."%self.dm.sd_name)
            self.flag=True
        else:
            LogPrint().info("FAIL:Create glusterfs storagedomain '%s' FAIL."%self.dm.sd_name)
            self.flag=False
        self.assertTrue(self.flag)
#     #将存储域附加到数据中心
        LogPrint().info("Attach glusterfs storagedomain '%s'to DC '%s'."%(self.dm.sd_name, self.dm.dc_name))
        self.assertTrue(smart_attach_storage_domain(self.dm.dc_name, self.dm.sd_name))
#     #创建虚拟机,为虚拟机添加磁盘,启动虚拟机
        LogPrint().info("Create a VM '%s'."%self.dm.vm_name)
        self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.xml_vm_info))
        LogPrint().info("ADD DISK '%s' for VM '%s'."%(self.dm.disk_alias,self.dm.vm_name))
        self.assertTrue(smart_create_vmdisk(self.dm.vm_name, self.dm.xml_disk_info, self.dm.disk_alias)[0])
        LogPrint().info("Start VM '%s'."%(self.dm.vm_name))
        self.assertTrue(smart_start_vm(self.dm.vm_name))
#         #关闭虚拟机,创建模板,创建子模板
        LogPrint().info("Stop VM '%s'."%(self.dm.vm_name))
        self.assertTrue(smart_stop_vm(self.dm.vm_name))
        self.assertTrue(smart_create_template(self.dm.base_temp_name, self.dm.temp_info))
        self.assertTrue(smart_create_template(self.dm.base_temp_name, self.dm.zi_temp_info, self.dm.temp_name))
Exemplo n.º 15
0
    def test_Scene(self):
        '''
        @summary: 测试场景描述
        '''
        #step1:创建一个distributed类型的卷
        volumeapi = GlusterVolumeAPIs()
        LogPrint().info("Create volume dis")
        r = volumeapi.createGlusterVolume(self.dm.cluster_name,
                                          self.dm.xml_volume_dis)
        print r
        if r['status_code'] == self.dm.expected_status_code_create_volume:
            LogPrint().info("PASS:Create volume dis success.")
            self.flag = True
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)
        #step2:添加两个brick
        volume_id = GlusterVolumeAPIs().getVolumeIdByName(
            self.dm.cluster_name, 'dis')
        r = volumeapi.addbrick(self.dm.cluster_id, volume_id,
                               self.dm.xml_brick_info)
        if r['status_code'] == self.expected_status_code_add_brick:
            LogPrint().info("PASS:ADD brick to volume dis success.")
            self.flag = True
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)
        #step3:启动卷
        LogPrint().info("Start volume dis")
        r = volumeapi.startGlusterVolume(self.dm.cluster_name, "dis")
        if r['status_code'] == self.dm.expected_status_code_start_volume:

            def is_volume_up():
                return volumeapi.getClusterVolumeStatus(
                    self.dm.cluster_name, "dis") == "up"

            if wait_until(is_volume_up, 600, 5):
                LogPrint().info("PASS:Start volume dis success.")
                self.flag = True
            else:
                LogPrint().error("FAIL:Start volume failed.Status is not UP.")
                self.flag = False
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)
Exemplo n.º 16
0
    def test_CopyTemplateDisk_async(self):
        '''
        @summary: 拷贝模板磁盘,异步
        @note: 操作成功,验证返回状态码,检查磁盘的存储域变化
        '''
        LogPrint().info("Test: Copy disk of template %s async." %
                        self.dm.temp_name)
        self.flag = True
        tempdisk_api = TemplateDisksAPIs()
        r = tempdisk_api.copyTemplateDisk(self.dm.temp_name, self.dm.disk_name,
                                          self.dm.copy_data)
        print r

        def is_tempdisk_ok():
            return tempdisk_api.getTemplateDiskStatus(
                self.dm.temp_name, self.dm.disk_name) == 'ok'

        def check_tempdisk_sd(temp_name, disk_name, sd_id):
            '''
            @summary: 检查模板磁盘所在的存储域是否包含源和目的存储域
            @param temp_name: 模板名称
            @param disk_name: 磁盘名称
            @param sd_id:存储域id 
            @return: True or False
            '''
            sd_list = tempdisk_api.getTemplateDiskSdList(temp_name, disk_name)
            flag = False
            for index in range(len(sd_list)):
                if sd_list[index]['@id'] == sd_id:
                    flag = True
            return flag

        if r['status_code'] == self.dm.expected_status_code:
            if wait_until(is_tempdisk_ok, 300, 10):
                if check_tempdisk_sd(self.dm.temp_name, self.dm.disk_name,
                                     self.dm.des_sd_id):
                    LogPrint().info("PASS: Copy Template Disk sync SUCCESS")
                else:
                    LogPrint().error("FAIL: The des sd is not %s." %
                                     self.dm.des_sd_name)
                    self.flag = False
            else:
                LogPrint().error("FAIL: CopyTemplateDisk overtime")
                self.flag = False
        else:
            LogPrint().error("FAIL: The status_code is WRONG")
            self.flag = False
        self.assertTrue(self.flag)
Exemplo n.º 17
0
 def do_test(xml_info):
     self.flag=True
     LogPrint().info("Test: Create template %s."%self.dm.temp_name[self.expected_result_index])
     r = self.tempapi.createTemplate(xml_info)
     def is_temp_ok():
         return self.tempapi.getTemplateInfo(temp_name=self.dm.temp_name[self.expected_result_index])['result']['template']['status']['state']=='ok'
     if r['status_code'] == self.dm.expected_status_code:
         if wait_until(is_temp_ok, 600, 10):
             LogPrint().info("PASS: Create Template '%s'ok."%self.dm.temp_name[self.expected_result_index])
         else:
             LogPrint().error("FAIL: Create Template '%s'overtime"%self.dm.temp_name[self.expected_result_index])
             self.flag=False
     else:
         LogPrint().error("FAIL: Create Template '%s'failed.Status-code is WRONG."%self.dm.temp_name[self.expected_result_index])
         self.flag=False
     self.assertTrue(self.flag)
     self.expected_result_index += 1
Exemplo n.º 18
0
 def setUp(self):
     self.dm = super(self.__class__, self).setUp()
     #创建一个虚拟机
     LogPrint().info("Pre-Test-1: Create vm %s for TC."% self.dm.vm_name)
     self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.vm_info))    
     #创建一块磁盘
     '''
     @note: 创建磁盘时,磁盘的sharable属性必须为false,因为共享磁盘不作为模板的一部份
     '''
     LogPrint().info("Pre-Test-2: Create a disk for TC.")
     r= smart_create_disk(self.dm.disk_info, self.dm.disk_name)
     self.assertTrue(r[0])
     self.disk_id = r[1]    
     #将该磁盘附加到虚拟机上
     LogPrint().info("Pre-Test-3: Attach disk %s to vm %s for TC."% (self.dm.disk_name
                                                              ,self.dm.vm_name))
     self.vmdiskapi = VmDiskAPIs()
     r=self.vmdiskapi.attachDiskToVm(self.dm.vm_name, self.disk_id)
     if r['status_code'] == 200:
         LogPrint().info("Attach Disk to vm success.")
     else:
         LogPrint().error("Attach Disk to vm fail.Status-code is wrong.")
         self.assertTrue(False)    
     #该虚拟机创建模板   
     LogPrint().info("Pre-Test-4: Create template for vm %s for TC."% self.dm.vm_name)
     self.tempapi = TemplatesAPIs()
     self.vm_id = VirtualMachineAPIs().getVmIdByName(self.dm.vm_name)
     r = self.tempapi.createTemplate(self.dm.temp_info, self.vm_id)
     def is_temp_ok():
         return self.tempapi.getTemplateInfo(temp_name=self.dm.temp_name)['result']['template']['status']['state']=='ok'
     if r['status_code'] == 202:
         if wait_until(is_temp_ok, 600, 10):
             LogPrint().info("Create Template ok.")
         else:
             LogPrint().error("Create Template overtime")
             self.assertTrue(False)
     else:
         LogPrint().error("Create Template failed.Status-code is wrong.")
         self.assertTrue(False)
     #获得模板关联的磁盘id
     r = TemplateDisksAPIs().getTemplateDiskInfo(self.dm.temp_name, self.dm.disk_name) 
     if r['status_code'] == 200:
         self.disk_id_temp = r['result']['disk']['@id']
     else:
         self.assertTrue(False)
Exemplo n.º 19
0
 def test_Scene(self):
     '''
     @summary: 测试场景描述
     '''
     #step1:创建一个distributed类型的卷
     volumeapi = GlusterVolumeAPIs()
     LogPrint().info("Create volume dis")
     r = volumeapi.createGlusterVolume(self.dm.cluster_name, self.dm.xml_volume_dis)
     print r
     if r['status_code'] == self.dm.expected_status_code_create_volume:
         LogPrint().info("PASS:Create volume dis success.")
         self.flag = True
     else:
         LogPrint().error("FAIL:Status_code is WRONG.")
         self.flag = False
     self.assertTrue(self.flag)
     #step2:添加两个brick
     volume_id = GlusterVolumeAPIs().getVolumeIdByName(self.dm.cluster_name, 'dis')
     r = volumeapi.addbrick(self.dm.cluster_id, volume_id, self.dm.xml_brick_info)
     if r['status_code'] == self.expected_status_code_add_brick:
         LogPrint().info("PASS:ADD brick to volume dis success.")
         self.flag = True
     else:
         LogPrint().error("FAIL:Status_code is WRONG.")
         self.flag = False
     self.assertTrue(self.flag)
     #step3:启动卷
     LogPrint().info("Start volume dis")
     r = volumeapi.startGlusterVolume(self.dm.cluster_name, "dis")
     if r['status_code'] == self.dm.expected_status_code_start_volume:
         def is_volume_up():
             return volumeapi.getClusterVolumeStatus(self.dm.cluster_name, "dis") == "up"
         if wait_until(is_volume_up, 600, 5):
             LogPrint().info("PASS:Start volume dis success.")
             self.flag = True
         else:
             LogPrint().error("FAIL:Start volume failed.Status is not UP.")
             self.flag = False
     else:
         LogPrint().error("FAIL:Status_code is WRONG.")
         self.flag = False
     self.assertTrue(self.flag)
Exemplo n.º 20
0
 def test_CreateTemplate_SD(self):
     '''
     @summary: 创建模板,指定存储域
     @note: 操作成功,验证返回状态码和返回信息
     '''
     self.tempapi = TemplatesAPIs()
     LogPrint().info("Test: Create template %s."%self.dm.temp_name)
     r = self.tempapi.createTemplate(self.dm.temp_info)
     print r
     def is_temp_ok():
         return self.tempapi.getTemplateInfo(temp_name=self.dm.temp_name)['result']['template']['status']['state']=='ok'
     if r['status_code'] == self.dm.expected_status_code:
         if wait_until(is_temp_ok, 600, 10):
             LogPrint().info("PASS: Create Template ok.")
         else:
             LogPrint().error("FAIL: Create Template overtime")
             self.assertTrue(False)
     else:
         LogPrint().error("FAIL: Create Template failed.Status-code is WRONG.")
         self.assertTrue(False)
Exemplo n.º 21
0
 def test_DeleteTemplate(self):
     '''
     @summary: 删除模板
     @note: 操作成功,验证返回状态码和返回信息
     '''
     self.flag=True
     self.tempapi = TemplatesAPIs()
     LogPrint().info("Test: Delete template %s."%self.dm.temp_name)
     r = self.tempapi.delTemplate(self.dm.temp_name)
     def temp_not_exist():
         return self.tempapi.searchTemplateByName(self.dm.temp_name)['result']['templates'] ==None
     if r['status_code'] == self.dm.expected_status_code:
         if wait_until(temp_not_exist,300, 5):
             LogPrint().info("PASS: Delete Template SUCCESS.")
         else:
             LogPrint().info("FAIL: Delete Template failed.The Template still exist")
             self.flag=False
     else:
         LogPrint().info("FAIL: Delete Template failed.The status_code is WRONG")
         self.flag=False
     self.assertTrue(self.flag)
Exemplo n.º 22
0
def smart_create_template(temp_name,temp_info):
    '''
    @summary: 创建模板,并等待其变为ok状态。
    @param temp_name: 新创建的模板名称
    @param temp_info: 创建模板的xml格式信息,用于向接口传参数
    @return: True or False
    '''
    tempapi = TemplatesAPIs()
    r = tempapi.createTemplate(temp_info)
    def is_temp_ok():
        return tempapi.getTemplateInfo(temp_name=temp_name)['result']['template']['status']['state']=='ok'
    if r['status_code'] == 202:
        if wait_until(is_temp_ok, 600, 10):
            LogPrint().info("INFO:Create Template %s success"%temp_name)
            return True
        else:
            LogPrint().error("INFO:Create Template overtime")
            return False
    else:
        LogPrint().error("INFO:Create Template failed.Status-code is %s."%r['status_code'])
        return False
Exemplo n.º 23
0
def smart_create_host(host_name, xml_host_info):
    '''
    @summary: 创建主机,并等待其变为UP状态。
    @param host_name: 新创建的主机名称
    @param xml_host_info: 创建主机的xml格式信息,用于向接口传参数
    @return: True or False
    '''
    host_api = HostAPIs()
    r = host_api.createHost(xml_host_info)
    def is_host_up():
        return host_api.getHostStatus(host_name)=='up'
    if wait_until(is_host_up, 200, 5):
        if r['status_code'] == 201:
            LogPrint().info("INFO-PASS: Create host '%s' SUCCESS." % host_name)
            return True
        else:
            LogPrint().error("INFO-FAIL: Create host '%s' FAILED. Returned status code is INCORRECT." % host_name)
            return False
    else:
        LogPrint().error("INFO-FAIL: Create host '%s' FAILED. It's final state is not 'UP'." % host_name)
        return False
Exemplo n.º 24
0
 def test_CopyTemplateDisk_async(self):
     '''
     @summary: 拷贝模板磁盘,异步
     @note: 操作成功,验证返回状态码,检查磁盘的存储域变化
     '''
     LogPrint().info("Test: Copy disk of template %s async."%self.dm.temp_name)
     self.flag = True
     tempdisk_api = TemplateDisksAPIs()
     r = tempdisk_api.copyTemplateDisk(self.dm.temp_name, self.dm.disk_name, self.dm.copy_data)  
     print r
     def is_tempdisk_ok():
         return tempdisk_api.getTemplateDiskStatus(self.dm.temp_name, self.dm.disk_name)=='ok'
     def check_tempdisk_sd(temp_name,disk_name,sd_id):
         '''
         @summary: 检查模板磁盘所在的存储域是否包含源和目的存储域
         @param temp_name: 模板名称
         @param disk_name: 磁盘名称
         @param sd_id:存储域id 
         @return: True or False
         '''
         sd_list = tempdisk_api.getTemplateDiskSdList(temp_name, disk_name)
         flag = False
         for index in range(len(sd_list)):
             if sd_list[index]['@id'] == sd_id:
                 flag = True
         return flag 
     if r['status_code'] == self.dm.expected_status_code:
         if wait_until(is_tempdisk_ok, 300, 10):
             if check_tempdisk_sd(self.dm.temp_name, self.dm.disk_name, self.dm.des_sd_id):
                 LogPrint().info("PASS: Copy Template Disk sync SUCCESS")
             else:
                 LogPrint().error("FAIL: The des sd is not %s."%self.dm.des_sd_name)
                 self.flag= False
         else:
             LogPrint().error("FAIL: CopyTemplateDisk overtime")
             self.flag= False
     else:
         LogPrint().error("FAIL: The status_code is WRONG")
         self.flag= False
     self.assertTrue(self.flag) 
Exemplo n.º 25
0
def smart_create_disk(xml_disk_info, disk_alias=None, status_code=202):
    '''
    @summary: 智能创建磁盘,并等待其状态为ok;
    @param disk_alias: 磁盘别名,缺省为空(若在XML中已经提供)
    @param xml_disk_info: 创建磁盘的XML信息
    @param status_code: 成功创建磁盘后,接口返回的状态码,缺省为202
    @return: True or False
    '''
    disk_api = DiskAPIs()  
    r = disk_api.createDisk(xml_disk_info)
    def is_disk_ok():
        return disk_api.getDiskStatus(disk_id)=='ok'
    if r['status_code'] == status_code:
        disk_id = r['result']['disk']['@id']
        #如果磁盘状态在给定时间内变为ok状态,则继续验证状态码和磁盘信息
        if wait_until(is_disk_ok, 500, 5):
            LogPrint().info("INFO: Create disk '%s' SUCCESS and it's state is 'ok'." % disk_alias)
            return [True, disk_id]
        else:
            LogPrint().error("ERROR: Create Disk FAIED, it's status is not 'ok'." )
            return False
    else:
        LogPrint().error("ERROR: Create Disk FAIED, returned status code '%s' is wrong." % r['status_code'])
        return False
Exemplo n.º 26
0
    def test_Scene(self):
        '''
        @summary: 测试场景描述
        '''
        volumeapi = GlusterVolumeAPIs()
        #创建一个distributed_replicate类型的卷disrep,Replica Count=2,brick=4
        LogPrint().info("Create volume disrep")
        r = volumeapi.createGlusterVolume(self.dm.cluster_name,
                                          self.dm.xml_volume_disrep)
        if r['status_code'] == self.dm.expected_status_code_create_volume:
            LogPrint().info("PASS:Create volume disrep success.")
            self.flag = True
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)

        LogPrint().info("Start volume disrep")
        r = volumeapi.startGlusterVolume(self.dm.cluster_name, "disrep")
        if r['status_code'] == self.dm.expected_status_code_start_volume:

            def is_volume_up():
                return volumeapi.getClusterVolumeStatus(
                    self.dm.cluster_name, "disrep") == "up"

            if wait_until(is_volume_up, 600, 5):
                LogPrint().info("PASS:Start volume disrep success.")
                self.flag = True
            else:
                LogPrint().error("FAIL:Start volume failed.Status is not UP.")
                self.flag = False
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)
        #
        #     #利用该卷创建一个glusterfs类型的存储域
        sdapi = StorageDomainAPIs()
        LogPrint().info("Create glusterfs storagedomain '%s'." %
                        self.dm.sd_name)
        r = sdapi.createStorageDomain(self.dm.xml_sd_info)
        if r['status_code'] == self.dm.expected_status_code_create_sd:
            LogPrint().info(
                "PASS:Create glusterfs storagedomain '%s' SUCCESS." %
                self.dm.sd_name)
            self.flag = True
        else:
            LogPrint().info("FAIL:Create glusterfs storagedomain '%s' FAIL." %
                            self.dm.sd_name)
            self.flag = False
        self.assertTrue(self.flag)
        #     #将存储域附加到数据中心
        LogPrint().info("Attach glusterfs storagedomain '%s'to DC '%s'." %
                        (self.dm.sd_name, self.dm.dc_name))
        self.assertTrue(
            smart_attach_storage_domain(self.dm.dc_name, self.dm.sd_name))
        #     #创建虚拟机,为虚拟机添加磁盘,启动虚拟机
        LogPrint().info("Create a VM '%s'." % self.dm.vm_name)
        self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.xml_vm_info))
        LogPrint().info("ADD DISK '%s' for VM '%s'." %
                        (self.dm.disk_alias, self.dm.vm_name))
        self.assertTrue(
            smart_create_vmdisk(self.dm.vm_name, self.dm.xml_disk_info,
                                self.dm.disk_alias)[0])
        LogPrint().info("Start VM '%s'." % (self.dm.vm_name))
        self.assertTrue(smart_start_vm(self.dm.vm_name))
        #         #关闭虚拟机,创建模板,创建子模板
        LogPrint().info("Stop VM '%s'." % (self.dm.vm_name))
        self.assertTrue(smart_stop_vm(self.dm.vm_name))
        self.assertTrue(
            smart_create_template(self.dm.base_temp_name, self.dm.temp_info))
        self.assertTrue(
            smart_create_template(self.dm.base_temp_name, self.dm.zi_temp_info,
                                  self.dm.temp_name))
Exemplo n.º 27
0
    def test_CreateModuleTestEnv(self):
        dcapi = DataCenterAPIs()
        capi = ClusterAPIs()

        # 创建1个数据中心(nfs类型)
        LogPrint().info("Pre-Module-Test-1: Create DataCenter '%s'." %
                        self.dm.dc_nfs_name)
        self.assertTrue(
            dcapi.createDataCenter(self.dm.xml_dc_info)['status_code'] ==
            self.dm.expected_status_code_create_dc)

        # 创建1个集群
        LogPrint().info(
            "Pre-Module-Test-2: Create Cluster '%s' in DataCenter '%s'." %
            (self.dm.cluster_nfs_name, self.dm.dc_nfs_name))
        self.assertTrue(
            capi.createCluster(self.dm.xml_cluster_info)['status_code'] ==
            self.dm.expected_status_code_create_cluster)

        # 在NFS数据中心中创建一个主机,并等待主机UP。
        LogPrint().info(
            "Pre-Module-Test-3: Create Host '%s' in Cluster '%s'." %
            (self.dm.host1_name, self.dm.cluster_nfs_name))
        self.assertTrue(
            smart_create_host(self.dm.host1_name, self.dm.xml_host_info))

        # 为NFS数据中心创建Data(data1/data2/export)。
        @BaseTestCase.drive_data(self, self.dm.xml_storage_info)
        def create_storage_domains(xml_storage_domain_info):
            sd_name = xmltodict.parse(
                xml_storage_domain_info)['storage_domain']['name']
            LogPrint().info("Pre-Module-Test-4: Create Data Storage '%s'." %
                            sd_name)
            self.assertTrue(
                smart_create_storage_domain(sd_name, xml_storage_domain_info))

        create_storage_domains()

        # 将创建的的data1、data2和export域附加到NFS/ISCSI数据中心里。
        LogPrint().info(
            "Pre-Module-Test-5: Attach the data storages to data centers.")
        self.assertTrue(
            smart_attach_storage_domain(self.dm.dc_nfs_name,
                                        self.dm.data1_nfs_name))
        self.assertTrue(
            smart_attach_storage_domain(self.dm.dc_nfs_name,
                                        self.dm.data2_nfs_name))
        #self.assertTrue(smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.export1_name))
        #创建一个虚拟机
        self.vmapi = VirtualMachineAPIs()
        r = self.vmapi.createVm(self.dm.vm_info)
        if r['status_code'] == 201:
            self.vm_name = r['result']['vm']['name']
        else:
            LogPrint().error("Create vm failed.Status-code is WRONG.")
            self.assertTrue(False)
        #创建一个磁盘
        self.diskapi = DiskAPIs()
        sd_id = StorageDomainAPIs().getStorageDomainIdByName(
            ModuleData.data1_nfs_name)
        r = self.diskapi.createDisk(self.dm.disk_info, sd_id)

        def is_disk_ok():
            return self.diskapi.getDiskStatus(self.disk_id) == 'ok'

        if r['status_code'] == 202:
            self.disk_id = r['result']['disk']['@id']
            if wait_until(is_disk_ok, 200, 5):
                LogPrint().info("Create disk ok.")
        else:
            LogPrint().error("Create disk failed.Status-code is WRONG.")
            self.assertTrue(False)
        #将磁盘附加到虚拟机
        self.vmdiskapi = VmDiskAPIs()
        r = self.vmdiskapi.attachDiskToVm(self.vm_name, self.disk_id)
        if r['status_code'] == 200:
            LogPrint().info("Attach Disk to vm SUCCESS.")
        else:
            LogPrint().error("Attach Disk to vm fail.Status-code is WRONG.")
            self.assertTrue(False)