예제 #1
0
    def test_attachNetworktoCluster(self):
        '''
        @summary: 测试用例执行步骤
        @note: (1)测试将网络附加到集群
        @note: (2)操作成功,验证返回状态码,验证网络是否附加到集群
        '''
        LogPrint().info("Test: Attach Network %s to Cluster %s. " %
                        (self.dm.nw_name, self.dm.cluster_name))
        clusterapi = ClusterAPIs()
        r = clusterapi.attachNetworkToCluster(self.dm.cluster_name,
                                              self.dm.nw_info)
        print r
        if r['status_code'] == self.dm.status_code:
            cluster_id = r['result']['network']['cluster']['@id']
            cluster_name = clusterapi.getClusterNameById(cluster_id)
            if cluster_name == self.dm.cluster_name:
                LogPrint().info(
                    "PASS: Attach Network %s to Cluster %s SUCCESS." %
                    (self.dm.nw_name, self.dm.cluster_name))


#                 return True
            else:
                LogPrint().error(
                    "FAIL: Attach Network %s to Cluster %s FAIL." %
                    (self.dm.nw_name, self.dm.cluster_name))
                self.flag = False
        else:
            LogPrint().error("FAIL: Returned status code is WRONG. ")
            self.flag = False
        self.assertTrue(self.flag)
예제 #2
0
 def test_GetTemplateDiskInfo(self):
     '''
     @summary: 获取模板的磁盘详情
     @note: 操作成功,验证返回状态码和返回信息
     '''
     self.flag = True
     tempdisk_api = TemplateDisksAPIs()
     LogPrint().info("Test: Get disk info of template %s." %
                     self.dm.temp_name)
     r = tempdisk_api.getTemplateDiskInfo(self.dm.temp_name,
                                          self.dm.disk_name)
     if r['status_code'] == self.dm.expected_status_code:
         dictCompare = DictCompare()
         sd_id = StorageDomainAPIs().getStorageDomainIdByName(
             ModuleData.data1_nfs_name)
         expected_result = xmltodict.parse(self.dm.disk_info % sd_id)
         actual_result = r['result']
         if dictCompare.isSubsetDict(expected_result, actual_result):
             LogPrint().info("PASS: Get disk info of template %s SUCCESS." %
                             self.dm.temp_name)
         else:
             LogPrint().error("FAIL: The disk_info is WRONG")
             self.flag = False
     else:
         LogPrint().error("FAIL: The status_code is WRONG")
         self.flag = False
     self.assertTrue(self.flag)
예제 #3
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
예제 #4
0
 def test_UpdateTemplateNic(self):
     '''
     @summary: 为模板编辑网络接口
     @note: 操作成功,验证返回状态码和返回信息
     '''
     self.flag = True
     tempnic_api = TemplateNicsAPIs()
     LogPrint().info("Test: Update nic %s for this template." %
                     self.dm.nic_name)
     r = tempnic_api.updateTemplateNic(self.dm.temp_name, self.dm.nic_name,
                                       self.dm.update_info, self.proid)
     if r['status_code'] == self.dm.expected_status_code:
         dictCompare = DictCompare()
         expected_result = xmltodict.parse(
             (self.dm.update_info % self.proid))
         actual_result = r['result']
         if dictCompare.isSubsetDict(expected_result, actual_result):
             LogPrint().info("PASS: UpdateTemplateNic SUCCESS.")
         else:
             LogPrint().error(
                 "FAIL: UpdateTemplateNic fail.The nic_info is WRONG")
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: UpdateTemplateNic fail.The status_code is WRONG")
         self.flag = False
     self.assertTrue(self.flag)
예제 #5
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)
예제 #6
0
 def test_GetDiskInfoFromDataStorage(self):
     '''
     @summary: 测试步骤
     @note: (1)查询指定存储域中磁盘信息;
     @note: (2)操作成功,验证接口返回的状态码、磁盘信息是否正确。
     '''
     ds_api = DataStorageAPIs()
     LogPrint().info(
         "Test: Get disk '%s' info from the data storage '%s'." %
         (self.dm.disk_name, self.dm.data1_name))
     r = ds_api.getDiskInfoFromDataStorage(self.dm.data1_name, self.disk_id)
     if r['status_code'] == self.dm.expected_status_code_get_disk_info:
         d1 = xmltodict.parse(self.dm.xml_disk_info)
         if DictCompare().isSubsetDict(d1, r['result']):
             LogPrint().info(
                 "PASS: Get disk '%s' info from the data storage '%s' SUCCESS."
                 % (self.dm.disk_name, self.dm.data1_name))
             self.flag = True
         else:
             LogPrint().error("FAIL: Get disk info INCORRECT.")
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' INCORRECT while get disk info from data storage."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
예제 #7
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
예제 #8
0
 def test_TearDown(self):
     dcapi = DataCenterAPIs()
     capi = ClusterAPIs()
     time.sleep(30)
     # Step1:将data1存储域设置为Maintenance状态
     LogPrint().info("Post-Module-Test-1: Deactivate data storage domains '%s'." % self.dm.data1_nfs_name)
     self.assertTrue(smart_deactive_storage_domain(self.dm.dc_nfs_name, self.dm.data1_nfs_name))
     
     # Step2:删除数据中心dc1(非强制,之后存储域变为Unattached状态)
     if dcapi.searchDataCenterByName(self.dm.dc_nfs_name)['result']['data_centers']:
         LogPrint().info("Post-Module-Test-2: Delete DataCenter '%s'." % self.dm.dc_nfs_name)
         self.assertTrue(dcapi.delDataCenter(self.dm.dc_nfs_name)['status_code']==self.dm.expected_status_code_del_dc)
             
     # Step3:删除4个Unattached状态存储域(data1/data2/iso1/export1)
     LogPrint().info("Post-Module-Test-3: Delete all unattached storage domains.")
     dict_sd_to_host = [self.dm.data1_nfs_name, self.dm.data2_nfs_name]
     for sd in dict_sd_to_host:
         smart_del_storage_domain(sd, self.dm.xml_del_sd_option, host_name=self.dm.host1_name)
     
     # Step4:删除主机(host1)
     LogPrint().info("Post-Module-Test-6: Delete host '%s'." % self.dm.host1_name)
     self.assertTrue(smart_del_host(self.dm.host1_name, self.dm.xml_del_host_option))
     
     # Step5:删除集群cluster1
     if capi.searchClusterByName(self.dm.cluster_nfs_name)['result']['clusters']:
         LogPrint().info("Post-Module-Test-5: Delete Cluster '%s'." % self.dm.cluster_nfs_name)
         self.assertTrue(capi.delCluster(self.dm.cluster_nfs_name)['status_code']==self.dm.expected_status_code_del_dc)
예제 #9
0
 def test_Scene(self):
     '''
     @summary: 测试场景描述
     '''
     #step3:为虚拟机创建子模板
     self.assertTrue(
         smart_create_template(self.dm.temp_name, self.dm.xml_zi_temp_info1,
                               self.dm.version_name1))
     #step4:使用步骤2模板的最新版本创建虚拟机
     self.assertTrue(
         smart_create_vm(self.dm.vm_name_new, self.dm.xml_vm_info_temp))
     #step5:为虚拟机增加一个网络接口
     self.assertTrue(
         smart_create_vmnic(self.dm.vm_name, self.dm.nic_info,
                            self.dm.nic_name))
     #step6:为虚拟机创建一个新的子模板
     self.assertTrue(
         smart_create_template(self.dm.temp_name, self.dm.xml_zi_temp_info2,
                               self.dm.version_name2))
     #step7:检查虚拟机信息应该包含网络接口
     if VmNicAPIs().isVmNicExist(self.dm.vm_name_new, self.dm.nic_name):
         LogPrint().info("PASS:ITC1004_scene4.")
         self.assertTrue(True)
     else:
         LogPrint().error("FAIL:ITC1004_scene4.")
         self.assertTrue(False)
예제 #10
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
예제 #11
0
 def test_CreateModuleTestEnv(self):
     '''
     @summary: 创建Disk模块测试环境
     '''
     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)。
     @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附加到NFS/ISCSI数据中心里(data2/Iso/Export处于游离状态)。
     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))
예제 #12
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
예제 #13
0
 def test_GetClusterInfo(self):
     '''
     @summary: 测试用例执行步骤
     @note: (1)获取指定集群的信息;
     @note: (2)验证接口返回的状态码、集群信息是否正确。
     '''
     # 测试1:获取集群的信息,并与期望结果进行对比
     self.clusterapi = ClusterAPIs()
     LogPrint().info("Test: Get cluster's ('%s') info." %
                     self.dm.cluster_name)
     r = self.clusterapi.getClusterInfo(self.dm.cluster_name)
     if r['status_code'] == self.dm.status_code:
         dict_actual = r['result']
         dict_expected = xmltodict.parse(self.dm.cluster_info)
         dictCompare = DictCompare()
         if dictCompare.isSubsetDict(dict_expected, dict_actual):
             LogPrint().info("PASS: Get Cluster '%s' info SUCCESS." %
                             self.dm.cluster_name)
             self.flag = True
         else:
             LogPrint().error("FAIL: Get Cluster '%s' info INCORRECT." %
                              self.dm.cluster_name)
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Get Cluster '%s' info FAILED. Returned status code '%s' is WRONG."
             % (self.dm.cluster_name, r['status_code']))
         self.flag = False
     self.assertTrue(self.flag)
예제 #14
0
 def test_UpdateNetworkofCluster(self):
     '''
     @summary: 测试用例执行步骤
     @note: 更新集群网络信息
     @note: 操作成功,验证返回状态码,验证更新信息是否正确
     '''
     LogPrint().info("Test: Update Network %s of Cluster %s. " %
                     (self.dm.nw_name, self.dm.cluster_name))
     r = self.clusterapi.updateNetworkOfCluster(self.dm.cluster_name,
                                                self.dm.nw_name,
                                                self.dm.nw_info_new)
     if r['status_code'] == self.dm.status_code:
         dict_actual = self.clusterapi.getClusterNetworkInfo(
             self.dm.cluster_name, self.dm.nw_name)
         #dict_expected = {'network':xmltodict.parse(self.dm.nw_info_new)['network']}
         dict_expected = xmltodict.parse(self.dm.nw_info_new)
         dictCompare = DictCompare()
         if dictCompare.isSubsetDict(dict_expected, dict_actual):
             LogPrint().info(
                 "PASS: Detach Network %s from Cluster %s SUCCESS. " %
                 (self.dm.nw_name, self.dm.cluster_name))
         else:
             LogPrint().info("FAIL: Returned message is WRONG. ")
     else:
         LogPrint().info("FAIL: Returned status code is WRONG.")
예제 #15
0
 def test_DestroySd_Unattached(self):
     '''
     @summary: 测试步骤
     @note: (1)对Unattached状态的ISO存储域进行销毁操作;
     @note: (2)操作成功,验证接口返回的状态码、提示信息是否正确。
     '''
     self.sd_api = StorageDomainAPIs()
     # 对ISO存储域进行Destroy操作(通过在删除项中设置destroy参数实现)
     LogPrint().info("Test: Destroy the ISO storage domain '%s'." %
                     self.dm.iso_name)
     r = self.sd_api.delStorageDomain(self.dm.iso_name,
                                      self.dm.xml_destroy_iso_option)
     print r
     if r['status_code'] == self.dm.expected_status_code_destroy_sd:
         if not self.sd_api.searchStorageDomainByName(
                 self.dm.iso_name)['result']['storage_domains']:
             LogPrint().info(
                 "PASS: Destroy the ISO storage domain '%s' SUCCESS." %
                 self.dm.iso_name)
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: The ISO storage domain '%s' still exists after destroyed."
                 % self.dm.iso_name)
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' is INCORRECT while destroying a storage domain."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
예제 #16
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
예제 #17
0
 def test_DestroySd_Unattached(self):
     '''
     @summary: 测试步骤
     @note: (1)导入一个已被销毁的ISO存储域;
     @note: (2)操作成功,验证接口返回的状态码、提示信息是否正确。
     '''
     # 对ISO存储域进行Destroy操作(通过在删除项中设置destroy参数实现)
     LogPrint().info("Test: Import the destroyed ISO storage domain '%s'." %
                     self.dm.iso_name)
     r = self.sd_api.importStorageDomain(self.dm.xml_import_iso_info)
     if r['status_code'] == self.dm.expected_status_code_import_sd:
         if self.sd_api.searchStorageDomainByName(
                 self.dm.iso_name)['result']['storage_domains']:
             LogPrint().info(
                 "PASS: Import the destroyed ISO storage domain '%s' SUCCESS."
                 % self.dm.iso_name)
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: The storage domain '%s' does not exist after importing."
                 % self.dm.iso_name)
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' is INCORRECT while importing a destroyed storage domain."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
예제 #18
0
 def test_CreateIscsiSd_Normal(self):
     '''
     @summary: 测试步骤
     @note: (1)创建一个ISCSI类型的Data存储域;
     @note: (2)操作成功,验证接口返回的状态码、存储域信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Create ISCSI data storage '%s'." %
                     self.dm.data1_name)
     r = sd_api.createStorageDomain(self.dm.data1_info_xml)
     if r['status_code'] == self.dm.expected_status_code_create_sd:
         d1 = xmltodict.parse(self.dm.data1_info_xml)
         del d1['storage_domain']['host']
         del d1['storage_domain']['storage']['override_luns']
         d2 = deepcopy(r['result'])
         del d2['storage_domain']['storage']['volume_group']
         d2['storage_domain']['storage']['logical_unit'] = r['result'][
             'storage_domain']['storage']['volume_group']['logical_unit']
         if DictCompare().isSubsetDict(d1, d2):
             LogPrint().info("PASS: Create ISCSI storage '%s' SUCCESS." %
                             self.dm.data1_name)
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: Create ISCSI storage '%s' FAILED. Returned sd info INCORRECT."
                 % self.dm.data1_name)
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' INCORRECT while creating ISCSI DataStorage."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
예제 #19
0
 def test_DelDiskFromDataStorage_OK(self):
     '''
     @summary: 测试步骤
     @note: (1)调用相应接口,删除创建的磁盘;
     @note: (2)操作成功,验证接口返回的状态码、相关信息是否正确。
     '''
     ds_api = DataStorageAPIs()
     disk_api = DiskAPIs()
     LogPrint().info("Test: Delete  the disk '%s' in 'OK' state." %
                     self.dm.disk_name)
     r = ds_api.delDiskFromDataStorage(self.dm.data1_name,
                                       disk_id=self.disk_id)
     if r['status_code'] == self.dm.expected_status_code_del_disk:
         try:
             disk_api.getDiskInfo(self.disk_id)
             LogPrint().error("FAIL: Delete disk FAILED, still exist.")
             self.flag = False
         except:
             LogPrint().info(
                 "PASS: Delete disk '%s' from Data Storage '%s' SUCCESS." %
                 (self.dm.disk_name, self.dm.data1_name))
             self.flag = True
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' is WRONG while deleting disk."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
예제 #20
0
 def test_GetStorageDomainsInfo(self):
     '''
     @summary: 测试步骤
     @note: (1)调用相应接口,获取模块级测试环境中的存储域信息;
     @note: (2)操作成功,验证接口返回的状态码、存储域信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Get info of DataStorage '%s'." %
                     self.dm.data_storage_name)
     r = sd_api.getStorageDomainInfo(self.dm.data_storage_name)
     if r['status_code'] == self.dm.expected_statsu_code_get_sd_info:
         dictCompare = DictCompare()
         d1 = self.dm.xml_data_storage_info
         del d1['storage_domain']['host']
         d2 = r['result']
         if dictCompare.isSubsetDict(d1, d2):
             LogPrint().info("PASS: Get DataStorage '%s' info SUCCESS." %
                             self.dm.data_storage_name)
             self.flag = True
         else:
             LogPrint().error("FAIL: Get StorageDomain's info INCORRECT.")
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' is INCORRECT while Get sd's info."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
예제 #21
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
예제 #22
0
 def do_test(xml_info):
     dictCompare = DictCompare()
     d1 = xmltodict.parse(xml_info)
     LogPrint().info(
         "Test: Start creating Data/ISO/Export DataStorages '%s' with NFS type."
         % d1['storage_domain']['name'])
     r = sd_api.createStorageDomain(xml_info)
     print r['result']
     if r['status_code'] == self.dm.expected_status_code_create_sd:
         del d1['storage_domain']['host']
         if dictCompare.isSubsetDict(d1, r['result']):
             LogPrint().info(
                 "PASS: Create NFS type StorageDomain '%s' SUCCESS." %
                 d1['storage_domain']['name'])
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: Created StorageDomain's info are INCORRECT.")
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' is INCORRECT when creating new DataStorage."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
예제 #23
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
예제 #24
0
 def do_test(xml_info):
     r = sd_api.createStorageDomain(xml_info)
     # 验证接口返回状态码是否正确
     if r['status_code'] == self.dm.expected_status_code_create_sd_fail:
         # 验证接口返回提示信息是否正确
         sd_path = xmltodict.parse(
             xml_info)['storage_domain']['storage']['path']
         dictCompare = DictCompare()
         if dictCompare.isSubsetDict(
                 xmltodict.parse(self.dm.expected_info_create_sd_fail),
                 r['result']):
             LogPrint().info(
                 "PASS: Returned status code and messages are CORRECT when create storage domain with invalid Path '%s'."
                 % sd_path)
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: Returned messages are INCORRECT when create storage domain with the invalid Path '%s'."
                 % sd_path)
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' is INCORRECT." %
             (r['status_code']))
         self.flag = False
     self.assertTrue(self.flag)
예제 #25
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)
예제 #26
0
 def test_EditNfsSd_Normal(self):
     '''
     @summary: 测试步骤
     @note: (1)编辑存储域的名称;
     @note: (2)操作失败,验证接口返回的状态码、提示信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info(
         "Test: Edit NFS data storage '%s' in 'Unattached' state." %
         self.dm.data_name)
     r = sd_api.updateStorageDomain(self.dm.data_name,
                                    self.dm.xml_data_info_new)
     if r['status_code'] == self.dm.expected_status_code_edit_sd_unattached:
         if DictCompare().isSubsetDict(
                 xmltodict.parse(self.dm.expected_info_edit_sd_unattached),
                 r['result']):
             LogPrint().info(
                 "PASS: Returned status code and messages are INCORRECT while edit storage domain in 'unattached' state."
             )
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: Returned messages are INCORRECT while edit storage domain in 'unattached' state."
             )
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' are INCORRECT while edit storage domain in 'unattached' state."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
예제 #27
0
 def test_CreateTemplateNic_proid(self):
     '''
     @summary: 为模板创建网络接口,指定配置集
     @note: 操作成功,验证返回状态码和返回信息
     '''
     tempnic_api = TemplateNicsAPIs()
     LogPrint().info(
         "Test-: Create a nic %s with profile %s for template %s." %
         (self.dm.nic_name, self.dm.profile_name, self.dm.temp_name))
     r = tempnic_api.createTemplateNic(self.dm.temp_name, self.dm.nic_data,
                                       self.proid)
     if r['status_code'] == self.dm.expected_status_code:
         dictCompare = DictCompare()
         expected_result = xmltodict.parse((self.dm.nic_data % self.proid))
         actual_result = r['result']
         if dictCompare.isSubsetDict(expected_result, actual_result):
             LogPrint().info(
                 "PASS: Create a nic %s with profile %s for template %s SUCCESS."
                 % (self.dm.nic_name, self.dm.profile_name,
                    self.dm.temp_name))
         else:
             LogPrint().error("FAIL: The nic_info is WRONG")
             self.flag = False
     else:
         LogPrint().error("FAIL: The status_code is WRONG")
         self.flag = False
     self.assertTrue(self.flag)
예제 #28
0
 def test_DelNfsSd_Unattached(self):
     '''
     @summary: 测试步骤
     @note: (1)删除处于Unattached状态的NFS类型Data存储域;
     @note: (2)操作成功,验证接口返回状态码、相关信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info(
         "Test: Delete NFS data storage '%s' in 'Unattached' state." %
         self.dm.data_name)
     r = sd_api.delStorageDomain(self.dm.data_name,
                                 self.dm.xml_del_sd_option)
     if r['status_code'] == self.dm.expected_status_code_del_sd:
         if not sd_api.searchStorageDomainByName(
                 self.dm.data_name)['result']['storage_domains']:
             LogPrint().info(
                 "PASS: Delete unattached Storage Domain '%s' SUCCESS." %
                 self.dm.data_name)
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: The deleted Storage Domain '%s' still exists." %
                 self.dm.data_name)
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' INCORRECT while deleting Storage Domain '%s'."
             % (r['status_code'], self.dm.data_name))
         self.flag = False
     self.assertTrue(self.flag)
예제 #29
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
예제 #30
0
 def test_DeleteCluster_host(self):
     '''
     @summary: 测试用例执行步骤
     @note: (1)删除包含主机的集群
     @note: (2)操作失败,验证返回状态码,验证报错信息
     '''
     clusterapi = ClusterAPIs()
     LogPrint().info("Test: Delete cluster %s." % self.dm.cluster_name)
     r = clusterapi.delCluster(self.dm.cluster_name)
     #         print r
     if r['status_code'] == self.dm.status_code:
         dict_actual = r['result']
         dict_expected = xmltodict.parse(self.dm.expected_info)
         dictCompare = DictCompare()
         if dictCompare.isSubsetDict(dict_expected, dict_actual):
             LogPrint().info(
                 "PASS: Returned status code and messages are CORRECT.")
             self.flag = True
         else:
             LogPrint().error("FAIL: Returned message is  INCORRECT.")
             self.flag = False
     else:
         LogPrint().error("FAIL: Returned status code is wrong. ")
         self.flag = False
     self.assertTrue(self.flag)