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)
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)
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)
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)
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.")
def test_UpdateCluster_host(self): ''' @summary: 测试步骤 @note: (1) @note: (2) ''' clusterapi = ClusterAPIs() LogPrint().info( "Test: Improve cluster's CPU level while there are hosts in cluster." ) r = clusterapi.updateCluster(self.dm.cluster_name, self.dm.cluster_info_new) 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: ITC0201040202_test_UpdateCluster_host_upcpu SUCCESS." ) self.flag = True else: LogPrint().error( "FAIL: ITC0201040202_test_UpdateCluster_host_upcpu. Error-info INCORRECT." ) self.flag = False else: LogPrint().error("FAIL: Returned tatus_code '%s' is WRONG." % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_UpdateCluster_host(self): ''' @summary: 测试步骤 @note: (1) @note: (2) ''' clusterapi = ClusterAPIs() LogPrint().info( "Test: Edit cluster's name while there are hosts in cluster.") r = clusterapi.updateCluster(self.dm.cluster_name, self.dm.cluster_info_new) if r['status_code'] == self.dm.status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(self.dm.cluster_info_new) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: ITC0201040203_test_UpdateCluster_host_name SUCCESS." ) self.flag = True else: LogPrint().error( "FAIL: ITC0201040203_test_UpdateCluster_host_name. Error-info INCORRECT." ) self.flag = False else: LogPrint().error( "FAIL: ITC0201040203_test_UpdateCluster_host_name.Status_code is wrong. " ) self.flag = False self.assertTrue(self.flag)
def test_UpdateCluster_host(self): ''' @summary: 测试步骤 @note: (1)更改含有主机的集群CPU类型; @note: (2)操作成功,验证接口返回的状态码、相关信息是否正确。 ''' clusterapi = ClusterAPIs() LogPrint().info( "Test: Edit cluster's cpu type if there are hosts in this cluster." ) r = clusterapi.updateCluster(self.dm.cluster_name, self.dm.cluster_info_new) 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: ITC0201040201_test_UpdateCluster_host_cputype SUCCESS." ) self.flag = True else: LogPrint().error( "FAIL: ITC0201040201_test_UpdateCluster_host_cputype .Error-info INCORRECT." ) self.flag = False else: LogPrint().error("FAIL: Returned status code '%s' is WRONG." % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_CreateCluster_Dup(self): ''' @summary: 测试步骤 @note: (1)创建一个重名的Cluster; @note: (2)操作失败,验证接口返回的状态码、提示信息是否正确。 ''' clusterapi = ClusterAPIs() LogPrint().info("Test: Create a cluster with dup name.") r = clusterapi.createCluster(self.dm.cluster_info) if r['status_code'] == self.dm.status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(self.dm.error_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: Returned status code and info are CORRECT while creating cluster with dup name." ) self.flag = True else: LogPrint().error( "FAIL: Returned info are INCORRECT while creating cluster with dup name." ) self.flag = False else: LogPrint().error("FAIL: Returned status code '%s' is WRONG. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_CreateCluster(self): ''' @summary: 测试步骤 @note: (1)创建一个集群; @note: (2)操作成功,验证接口返回的状态码、集群信息是否正确。 ''' LogPrint().info("Test: Create a cluster '%s'." % self.dm.cluster_name) r = self.clusterapi.createCluster(self.dm.cluster_info) 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: Create Cluster '%s' SUCCESS." % self.dm.cluster_name) self.flag = True else: LogPrint().error("FAIL: Create Cluster '%s' INCORRECT." % self.dm.cluster_name) self.flag = False else: LogPrint().error("FAIL: Returned status code '%s' is WRONG." % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_CreateProfile(self): """ @summary: 创建配置集 @note: 操作成功,验证返回状态码,验证接口返回信息 """ self.flag = True self.proapi = ProfilesAPIs() LogPrint().info("Test: Create a profile %s for network %s." % (self.dm.profile_name, self.dm.nw_name)) r = self.proapi.createProfiles(self.dm.profile_info, self.nw_id) if r["status_code"] == self.dm.expected_status_code: dict_actual = r["result"] dict_expected = xmltodict.parse((self.dm.profile_info % self.nw_id)) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: Create profile %s for network %s SUCCESS." % (self.dm.profile_name, self.dm.nw_name) ) # return True else: LogPrint().error("FAIL:Returned Profile info INCORRECT.") self.flag = False else: LogPrint().error( "FAIL: Returned status code is %s not %s. " % (r["status_code"], self.dm.expected_status_code) ) self.flag = False self.assertTrue(self.flag)
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)
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)
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)
def test_GetProfileInfo_id(self): """ @summary: 根据配置集id获取信息 @note: 操作成功,验证返回状态码,验证接口返回信息 """ # 测试1:根据网络id获取网络信息 self.flag = True LogPrint().info("Test-2: Get profile %s by ID." % self.dm.profile_name) profile_id = self.proapi.getProfileIdByName(self.dm.profile_name, self.nw_id) r = self.proapi.getProfileInfo(profile_id=profile_id) if r["status_code"] == self.dm.expected_status_code: dict_actual = r["result"] dict_expected = xmltodict.parse((self.dm.profile_info % self.nw_id)) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get Profile info SUCCESS.") else: LogPrint().error("FAIL:Returned Profile info INCORRECT.") self.flag = False else: LogPrint().error( "FAIL: Returned status code is %s not %s. " % (r["status_code"], self.dm.expected_status_code) ) self.flag = False self.assertTrue(self.flag)
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)
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
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)
def do_test(xml_info): self.flag = True r = diskapi.createDisk(xml_info) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(xmltodict.parse(self.dm.expected_info_list[self.expected_result_index]), r['result']): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: The returned messages are INCORRECT.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s' while it should be '%s'." % (r['status_code'], self.dm.expected_status_code)) self.flag = False self.assertTrue(self.flag) self.expected_result_index += 1
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)
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)
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)
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) 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)
def test_GetClusterNetworkInfo(self): """ @summary: 测试用例执行步骤 @note: 操作成功,验证网络信息 """ LogPrint().info("Test: Get the cluster %s's network info. " % self.dm.cluster_name) r = self.clusterapi.getClusterNetworkInfo(self.dm.cluster_name, self.dm.nw_name) dict_actual = r dict_expected = xmltodict.parse(self.dm.nw_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get ClusterNetwork '%s' info SUCCESS." % self.dm.nw_name) # return True else: LogPrint().error("FAIL: Returned message is WRONG. ") self.flag = False self.assertTrue(self.flag)
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)
def test_CreateProfile_DupName(self): ''' @note: 操作失败,检查返回状态码和提示信息 ''' self.flag = True LogPrint().info("Test: Create a dupname profile for network %s."% self.dm.nw_name) r = self.proapi.createProfiles(self.dm.profile_info, self.nw_id) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(r['result'], xmltodict.parse(self.dm.expected_info)): LogPrint().info("PASS: The returned status code and messages are CORRECT when create dup profile.") else: LogPrint().error("FAIL: The returned messages are INCORRECCT when create dup profile.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s', INCORRECT. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def do_test(xml_info): LogPrint().info("Test: Create nic %s for template %s."%(self.dm.nic_name[self.expected_result_index], self.dm.temp_name)) r = tempnic_api.createTemplateNic(self.dm.temp_name, xml_info) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() print xml_info expected_result = xmltodict.parse(xml_info) actual_result = r['result'] if dictCompare.isSubsetDict(expected_result,actual_result): LogPrint().info("PASS: Create Nic %s SUCCESS."%self.dm.nic_name[self.expected_result_index]) else: LogPrint().error("FAIL: The nic %s info is WRONG"%self.dm.nic_name[self.expected_result_index]) self.flag = False else: LogPrint().error("FAIL: The status_code is WRONG") self.flag = False self.assertTrue(self.flag) self.expected_result_index += 1
def do_test(xml_info): self.flag = True r = clusterapi.updateCluster(self.dm.cluster_name, xml_info) if r["status_code"] == self.dm.status_code: dict_actual = r["result"] dict_expected = xmltodict.parse(xml_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: ITC02010401_UpdateCluster_nohost SUCCESS.") self.flag = True else: LogPrint().error("FAIL: ITC02010401_UpdateCluster_nohost.Error-info INCORRECT.") self.flag = False else: LogPrint().error("FAIL: ITC02010401_UpdateCluster_nohost FAILED.Status-code WRONG. ") self.flag = False self.assertTrue(self.flag) self.expected_result_index += 1
def test_CreateProfile_DupName(self): """ @note: 操作失败,检查返回状态码和提示信息 """ self.flag = True LogPrint().info("Test: Create a dupname profile for network %s." % self.dm.nw_name) r = self.proapi.createProfiles(self.dm.profile_info, self.nw_id) if r["status_code"] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(r["result"], xmltodict.parse(self.dm.expected_info)): LogPrint().info("PASS: The returned status code and messages are CORRECT when create dup profile.") else: LogPrint().error("FAIL: The returned messages are INCORRECCT when create dup profile.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s', INCORRECT. " % r["status_code"]) self.flag = False self.assertTrue(self.flag)
def test_UpdateNetwork(self): """ @summary: 编辑配置集,更改所属网络 @note: 操作失败,验证返回状态码,验证报错信息 """ self.flag = True LogPrint().info("Test: Update profile %s.Change its network." % self.dm.profile_name) r = self.proapi.updateProfile(self.dm.profile_name, self.nw_id, self.dm.update_info) if r["status_code"] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(r["result"], xmltodict.parse(self.dm.expected_info)): LogPrint().info("PASS: The returned status code and messages are CORRECT when update dup network.") else: LogPrint().error("FAIL: The returned messages are INCORRECCT when update dup network.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s', INCORRECT. " % r["status_code"]) self.flag = False self.assertTrue(self.flag)
def test_UpdateNetwork(self): ''' @summary: 编辑配置集,更改所属网络 @note: 操作失败,验证返回状态码,验证报错信息 ''' self.flag = True LogPrint().info("Test: Update profile %s.Change its network."%self.dm.profile_name) r = self.proapi.updateProfile(self.dm.profile_name, self.nw_id, self.dm.update_info) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(r['result'], xmltodict.parse(self.dm.expected_info)): LogPrint().info("PASS: The returned status code and messages are CORRECT when update dup network.") else: LogPrint().error("FAIL: The returned messages are INCORRECCT when update dup network.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s', INCORRECT. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_CreateTemplate_VerifyName(self): ''' @summary: 创建模板,名称不合法 @note: 操作失败,验证返回状态码和返回信息 ''' self.tempapi = TemplatesAPIs() LogPrint().info("Test: Create template %s."%self.dm.temp_name) r = self.tempapi.createTemplate(self.dm.temp_info) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() d1 = xmltodict.parse(self.dm.expected_info) if dictCompare.isSubsetDict(d1, r['result']): LogPrint().info("PASS: Returned status code and messages are CORRECT when create host with dup name.") else: LogPrint().error("FAIL: Returned messages are incorrectly.") self.flag = False else: LogPrint().error("FAIL: Status-code is WRONG.") self.assertTrue(False)
def test_CreateNetwork_DupVlan(self): ''' @summary: 创建网络,vlan id重复 @note: 操作失败,检查返回状态码和报错信息 ''' LogPrint().info("Test: Create network %s.Set its vlan id 2."%self.dm.nw_name2) r = self.nwapi.createNetwork(self.dm.nw_info2) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(r['result'], xmltodict.parse(self.dm.expected_info)): LogPrint().info("PASS: Returned status code and messages are CORRECT when create dup_vlan network.") self.flag = True else: LogPrint().error("FAIL: Returned messages are INCORRECCT when create dup_vlan network.") self.flag = False else: LogPrint().error("FAIL: Returned status code is '%s', INCORRECT. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_DeleteDisk_AttachtoRunVm(self): ''' @summary: 删除附加到运行虚拟机的磁盘 @note: 操作失败,验证返回状态码和报错信息 ''' self.flag = True LogPrint().info("Test: Delete disk %s attached to running vm %s."% (self.dm.disk_name, self.dm.vm_name)) r = self.diskapi.deleteDisk(self.disk_id) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(xmltodict.parse(self.dm.expected_info), r['result']): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: The returned messages are INCORRECT.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s' while it should be '%s'." % (r['status_code'], self.dm.expected_status_code)) self.flag = False self.assertTrue(self.flag)
def test_DeleteDisk_AttachtoTemp(self): ''' @summary: 删除附加到模板的磁盘 @note: 操作失败,验证返回验证码及报错信息 ''' self.flag = True LogPrint().info("Test: Delete disk attached to template.") r = DiskAPIs().deleteDisk(self.disk_id_temp) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(xmltodict.parse(self.dm.expected_info), r['result']): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: The returned messages are INCORRECT.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s' while it should be '%s'." % (r['status_code'], self.dm.expected_status_code)) self.flag = False self.assertTrue(self.flag)
def test_CreateDisk_VerifyName(self): ''' @summary: 验证名称合法性:包含非法字符 @note: 操作失败,验证返回状态码及报错信息 ''' diskapi = DiskAPIs() LogPrint().info("Test: Create disk and verify name.") r = diskapi.createDisk(self.dm.disk_info) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(xmltodict.parse(self.dm.expected_info), r['result']): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: The returned messages are INCORRECT.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s' while it should be '%s'." % (r['status_code'], self.dm.expected_status_code)) self.flag = False self.assertTrue(self.flag)
def test_CreateProfile_VerifyName(self): ''' @summary: 验证名称合法性:包含非法字符 @note: 操作失败,验证返回状态码和报错信息 ''' self.proapi = ProfilesAPIs() self.flag = True LogPrint().info("Test: Create a profile for network %s."%self.dm.nw_name) r = self.proapi.createProfiles(self.dm.profile_info, self.nw_id) if r['status_code']==self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(xmltodict.parse(self.dm.expected_info), r['result']): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: The returned messages are INCORRECT.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s' while it should be '%s'." % (r['status_code'], self.dm.expected_status_code)) self.flag = False self.assertTrue(self.flag)
def test_UpdateNetwork(self): #对network001进行编辑:名称修改为network002 ''' @summary: 编辑网络重名 @note: 操作失败,检查返回状态码和报错信息 ''' LogPrint().info("Test: Update network %s.Set its name be %s."%(self.dm.nw_name1, self.dm.nw_name2)) r = self.nwapi.updateNetwork(self.dm.nw_name1, self.dm.dc_name, self.dm.update_info) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(r['result'], xmltodict.parse(self.dm.expected_info)): LogPrint().info("PASS: The returned status code and messages are CORRECT when update dup network.") self.flag = True else: LogPrint().error("FAIL: The returned messages are INCORRECCT when update dup network.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s', INCORRECT. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_CopyTemplateDisk_nosd(self): ''' @summary: 拷贝模板磁盘,未指定存储域 @note: 操作失败,验证返回状态码和返回信息 ''' self.flag = True tempdisk_api = TemplateDisksAPIs() LogPrint().info("Test: Copy disk of template %s without SD."%self.dm.temp_name) r = tempdisk_api.copyTemplateDisk(self.dm.temp_name, self.dm.disk_name, self.dm.copy_data) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(xmltodict.parse(self.dm.expected_info), r['result']): LogPrint().info("PASS: Returned status code ans messages are CORRECT.") else: LogPrint().error("FAIL: The error_log is WRONG.") self.flag = False else: LogPrint().error("FAIL: The status_code is WRONG.") self.flag = False self.assertTrue(self.flag)
def test_GetProfileInfo_byname(self): ''' @summary: 根据配置集名称获取其信息 @note: 操作成功,验证返回状态码,验证接口返回信息 ''' self.flag = True r = self.proapi.getProfileInfo(profile_name=self.dm.profile_name, nw_id=self.nw_id) LogPrint().info("Test-1: Get profile %s by NAME."%self.dm.profile_name) if r['status_code'] == self.dm.expected_status_code: dict_actual = r['result'] dict_expected = xmltodict.parse((self.dm.profile_info %self.nw_id)) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get Profile info SUCCESS." ) else: LogPrint().error("FAIL:Returned Profile info INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Returned status code is %s not %s. "% (r['status_code'], self.dm.expected_status_code) ) self.flag = False self.assertTrue(self.flag)
def test_CreateTemplate_VerifyName(self): ''' @summary: 创建模板,名称不合法 @note: 操作失败,验证返回状态码和返回信息 ''' self.tempapi = TemplatesAPIs() LogPrint().info("Test: Create template %s." % self.dm.temp_name) r = self.tempapi.createTemplate(self.dm.temp_info) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() d1 = xmltodict.parse(self.dm.expected_info) if dictCompare.isSubsetDict(d1, r['result']): LogPrint().info( "PASS: Returned status code and messages are CORRECT when create host with dup name." ) else: LogPrint().error("FAIL: Returned messages are incorrectly.") self.flag = False else: LogPrint().error("FAIL: Status-code is WRONG.") self.assertTrue(False)
def test_GetTemplateNicInfo(self): ''' @summary: 获取模板的网络接口详情 @note: 操作成功,验证返回状态码和返回信息 ''' tempnic_api = TemplateNicsAPIs() LogPrint().info("Test: Get nic %s info of template %s."%(self.dm.nic_name, self.dm.temp_name)) r = tempnic_api.getTemplateNicInfo(self.dm.temp_name, self.dm.nic_name) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() expected_result = xmltodict.parse(self.dm.nic_data) actual_result = r['result'] if dictCompare.isSubsetDict(expected_result,actual_result): LogPrint().info("PASS: Get nic %s info of template %s SUCCESS."%(self.dm.nic_name, self.dm.temp_name)) else: LogPrint().error("FAIL: Returned nic info is WRONG") self.flag = False else: LogPrint().error("FAIL: The status_code is WRONG") self.flag = False self.assertTrue(self.flag)
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.")
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)
def test_CreateTemplateNic_NoRequired(self): ''' @summary: 为模板创建网络接口,缺少必填项 @note: 操作失败,验证返回状态码和返回信息 ''' tempnic_api = TemplateNicsAPIs() LogPrint().info("Test: Create nic for this template.") r = tempnic_api.createTemplateNic(self.dm.temp_name, self.dm.nic_data) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() expected_result = xmltodict.parse(self.dm.expected_info) actual_result = r['result'] if dictCompare.isSubsetDict(expected_result,actual_result): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: Returned messages are incorrectly.") self.flag = False else: LogPrint().error("FAIL: The status_code is WRONG") self.flag = False self.assertTrue(self.flag)
def test_UpdateNetwork(self): ''' @summary: 编辑网络 @note: 操作成功,检查返回状态码和网络信息 ''' LogPrint().info("Test: Update network %s."%self.dm.nw_name) r = self.nwapi.updateNetwork(self.dm.nw_name, self.dm.dc_name, self.dm.update_info) if r['status_code'] == self.dm.expected_status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(self.dm.update_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Update Network info SUCCESS." ) self.flag = True else: LogPrint().error("FAIL: Update Network info INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Update Network info FAILED. Returned status code '%s' is WRONG." % r['status_code'] ) self.flag = False self.assertTrue(self.flag)
def do_test(xml_info): self.flag = True LogPrint().info("Test: Create a profile for network %s." % self.dm.nw_name) r = self.proapi.createProfiles(xml_info) if r["status_code"] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict( xmltodict.parse(self.dm.expected_info_list[self.expected_result_index]), r["result"] ): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: The returned messages are INCORRECT.") self.flag = False else: LogPrint().error( "FAIL: The returned status code is '%s' while it should be '%s'." % (r["status_code"], self.dm.expected_status_code) ) self.flag = False self.assertTrue(self.flag) self.expected_result_index += 1
def test_CreateCluster(self): """ @summary: 测试步骤 @note: (1)创建一个集群; @note: (2)操作成功,验证接口返回的状态码、集群信息是否正确。 """ LogPrint().info("Test: Create a cluster '%s'." % self.dm.cluster_name) r = self.clusterapi.createCluster(self.dm.cluster_info) 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: Create Cluster '%s' SUCCESS." % self.dm.cluster_name) self.flag = True else: LogPrint().error("FAIL: Create Cluster '%s' INCORRECT." % self.dm.cluster_name) self.flag = False else: LogPrint().error("FAIL: Returned status code '%s' is WRONG." % r["status_code"]) self.flag = False self.assertTrue(self.flag)
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)
def test_CreateNetwork(self): ''' @summary: 测试用例执行步骤 @note: (1)新建网络; @note: (2)验证接口返回的状态码、接口信息是否正确。 ''' LogPrint().info("Test: Create network %s."%self.dm.nw_name) r = self.nwapi.createNetwork(self.dm.nw_info) if r['status_code'] == self.dm.expected_status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(self.dm.nw_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Create Network SUCCESS." ) self.flag = True else: LogPrint().error("FAIL: Network's info INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Create Network FAILED. Returned status code '%s' is Wrong." % r['status_code'] ) self.flag = False self.assertTrue(self.flag)
def test_GetNetworkProfileInfo(self): ''' @summary: 获取网络的配置集信息 @note: 操作成功,验证返回码和接口信息 ''' self.nwproapi = NetworkProfilesAPIs() LogPrint().info("Test: Get network %s's profile %s info." % (self.dm.nw_name, self.dm.profile_name)) r = self.nwproapi.getNetworkProfileInfo(self.nw_id, self.dm.profile_name) if r['status_code']==self.dm.expected_status_code: dict_actual = r['result'] dict_expected = xmltodict.parse((self.dm.profile_info %self.nw_id)) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get network %s's profile %s info SUCCESS." % (self.dm.nw_name, self.dm.profile_name) ) self.flag = True else: LogPrint().error("FAIL: Returned messages are INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Get NetworkProfile Info FAILED. Returned status code '%s' is WRONG." % r['status_code'] ) self.flag = False self.assertTrue(self.flag)
def test_GetDiskInfo(self): ''' @summary: 根据磁盘id获取磁盘信息 @note: 操作成功,验证返回状态码,验证磁盘信息 ''' LogPrint().info("Test: Get disk %s info."% self.dm.disk_name) diskapi = DiskAPIs() r = diskapi.getDiskInfo(self.disk_id) if r['status_code'] == self.dm.expected_status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(self.dm.disk_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS:Get disk %s info SUCCESS."% self.dm.disk_name) # return True else: LogPrint().error("FAIL:Returned disk info is WRONG.") self.flag = False else: LogPrint().error("FAIL: Returned status code is %s. "% r['status_code']) self.flag = False self.assertTrue(self.flag)