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 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_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_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): 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 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 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 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): 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_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_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_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_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_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_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_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_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 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_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_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 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_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_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_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 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)
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_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_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_CreateTemplate_DupName(self): ''' @summary: 创建模板,重名 @note: 操作失败,验证返回状态码和返回信息 ''' self.tempapi = TemplatesAPIs() LogPrint().info("Test: Create dupname 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_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_GetNetworkInfo_name(self): ''' @summary: 测试用例执行步骤 @note: (1)根据名称获取指定逻辑网络的信息; @note: (2)验证接口返回的状态码、接口信息是否正确。 ''' # 测试1:根据网络名称和数据中心名称获取网络信息(在同一数据中心内网络名称是唯一的) LogPrint().info("Test: Get the network's ('%s') info by name." % self.dm.nw_name) r = self.nwapi.getNetworkInfo(nw_name=self.dm.nw_name,dc_name=ModuleData.dc_name) 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: Get Network's ('%s') info SUCCESS." % self.dm.nw_name ) self.flag = True else: LogPrint().error("FAIL: Get Network's ('%s') info INCORRECT." % self.dm.nw_name) self.flag = False else: LogPrint().error("FAIL: Get 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 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(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_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): 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 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_GetNetworkInfo_id(self): ''' @summary: 测试用例执行步骤 @note: (1)根据ID获取指定逻辑网络的信息; @note: (2)验证接口返回的状态码、接口信息是否正确。 ''' # 测试1:根据网络id获取网络信息 nw_id = self.nwapi.getNetworkIdByName(self.dm.nw_name, self.dm.dc_name) LogPrint().info("Test: Get the network's ('%s') info by id ('%s')." % (self.dm.nw_name, nw_id)) r = self.nwapi.getNetworkInfo(nw_id=nw_id) 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: Get Network info SUCCESS by ID." ) self.flag = True else: LogPrint().error("FAIL: Get Network info INCORRECT by ID.") self.flag = False else: LogPrint().error("FAIL: Get Network info FAILED. Returned status code '%s' is Wrong." % 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 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)