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)
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 setUp(self): self.dm = super(self.__class__, self).setUp() self.diskapi = DiskAPIs() #创建一个虚拟机 LogPrint().info("Pre-Test-1: Create vm %s for TC."% self.dm.vm_name) self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.vm_info)) #创建一块磁盘 ''' @note: 创建磁盘时,磁盘的sharable属性必须为false,因为共享磁盘不作为模板的一部份 ''' LogPrint().info("Pre-Test-2: Create a disk for TC.") r= smart_create_disk(self.dm.disk_info, self.dm.disk_name) self.assertTrue(r[0]) self.disk_id = r[1] #将该磁盘附加到虚拟机 LogPrint().info("Pre-Test-3: Attach disk %s to vm %s for TC."% (self.dm.disk_name ,self.dm.vm_name)) self.vmdiskapi = VmDiskAPIs() r=self.vmdiskapi.attachDiskToVm(self.dm.vm_name, self.disk_id) if r['status_code'] == 200: LogPrint().info("Attach Disk to vm success.") else: LogPrint().error("Attach Disk to vm fail.Status-code is wrong.") self.assertTrue(False) #启动虚拟机 LogPrint().info("Pre-Test-4: Start vm for TC.") self.assertTrue(smart_start_vm(self.dm.vm_name)) #激活磁盘 LogPrint().info("Pre-Test-5: Active vmdisk for TC.") self.assertTrue(smart_active_vmdisk(self.dm.vm_name,self.disk_id))
def test_GetDiskList(self): LogPrint().info("Test: Get disk list.") diskapi = DiskAPIs() r = diskapi.getDisksList() if r['status_code'] == 200: LogPrint().info('PASS: Get Disk list SUCCESS.') self.flag = True else: LogPrint().error("FAIL: Returned status code is %s. "% r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_GetStaticsofDisk(self): ''' @summary: 获取磁盘的统计信息 @note: 操作成功,验证返回状态码 ''' self.flag=True diskapi = DiskAPIs() LogPrint().info("Test: Get statics of disk.") r = diskapi.getStaticsofDisk(self.disk_id) if r['status_code'] == self.dm.expected_status_code: LogPrint().info("PASS: Get statics of disk SUCCESS.") else: LogPrint().error("FAIL: Returned status code is %s. "% r['status_code']) self.flag=False self.assertTrue(self.flag)
def test_CreateModuleTestEnv(self): dcapi = DataCenterAPIs() capi = ClusterAPIs() # 创建1个数据中心(nfs类型) LogPrint().info("Pre-Module-Test-1: Create DataCenter '%s'." % self.dm.dc_nfs_name) self.assertTrue(dcapi.createDataCenter(self.dm.xml_dc_info)['status_code']==self.dm.expected_status_code_create_dc) # 创建1个集群 LogPrint().info("Pre-Module-Test-2: Create Cluster '%s' in DataCenter '%s'." % (self.dm.cluster_nfs_name, self.dm.dc_nfs_name)) self.assertTrue(capi.createCluster(self.dm.xml_cluster_info)['status_code']==self.dm.expected_status_code_create_cluster) # 在NFS数据中心中创建一个主机,并等待主机UP。 LogPrint().info("Pre-Module-Test-3: Create Host '%s' in Cluster '%s'." % (self.dm.host1_name, self.dm.cluster_nfs_name)) self.assertTrue(smart_create_host(self.dm.host1_name, self.dm.xml_host_info)) # 为NFS数据中心创建Data(data1/data2/export)。 @BaseTestCase.drive_data(self, self.dm.xml_storage_info) def create_storage_domains(xml_storage_domain_info): sd_name = xmltodict.parse(xml_storage_domain_info)['storage_domain']['name'] LogPrint().info("Pre-Module-Test-4: Create Data Storage '%s'." % sd_name) self.assertTrue(smart_create_storage_domain(sd_name, xml_storage_domain_info)) create_storage_domains() # 将创建的的data1、data2和export域附加到NFS/ISCSI数据中心里。 LogPrint().info("Pre-Module-Test-5: Attach the data storages to data centers.") self.assertTrue(smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.data1_nfs_name)) self.assertTrue(smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.data2_nfs_name)) #self.assertTrue(smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.export1_name)) #创建一个虚拟机 self.vmapi = VirtualMachineAPIs() r = self.vmapi.createVm(self.dm.vm_info) if r['status_code'] == 201: self.vm_name = r['result']['vm']['name'] else: LogPrint().error("Create vm failed.Status-code is WRONG.") self.assertTrue(False) #创建一个磁盘 self.diskapi = DiskAPIs() sd_id = StorageDomainAPIs().getStorageDomainIdByName(ModuleData.data1_nfs_name) r = self.diskapi.createDisk(self.dm.disk_info, sd_id) def is_disk_ok(): return self.diskapi.getDiskStatus(self.disk_id)=='ok' if r['status_code'] == 202: self.disk_id = r['result']['disk']['@id'] if wait_until(is_disk_ok, 200, 5): LogPrint().info("Create disk ok.") else: LogPrint().error("Create disk failed.Status-code is WRONG.") self.assertTrue(False) #将磁盘附加到虚拟机 self.vmdiskapi = VmDiskAPIs() r=self.vmdiskapi.attachDiskToVm(self.vm_name, self.disk_id) if r['status_code'] == 200: LogPrint().info("Attach Disk to vm SUCCESS.") else: LogPrint().error("Attach Disk to vm fail.Status-code is WRONG.") self.assertTrue(False)
def test_DeleteDisk_AttachtoDownVm(self): ''' @summary: 删除附加到运行虚拟机的磁盘 @note: 操作成功,验证返回状态码,验证磁盘是否存在 ''' diskapi = DiskAPIs() self.flag = True LogPrint().info("Test: Delete disk %s attached to down vm %s."% (self.dm.disk_name, self.dm.vm_name)) r = diskapi.deleteDisk(self.disk_id) if r['status_code'] == self.dm.expected_status_code: if not diskapi.isExist(self.disk_id): LogPrint().info("PASS: Delete Disk attached to down vm SUCCESS." ) else: LogPrint().error("FAIL: Disk is still exist. " ) self.flag = False else: LogPrint().error("FAIL: Returned status code is %s. "% r['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(self): ''' @summary: 测试执行步骤 @note: 删除一个独立的磁盘,即没有附加在虚拟机和模板上 @note: 操作成功,验证返回状态码,验证磁盘是否存在 ''' disk_api = DiskAPIs() self.flag = True LogPrint().info("Test: Delete disk %s."% self.disk_id) r = disk_api.deleteDisk(self.disk_id) if r['status_code'] == self.dm.expected_status_code: if not disk_api.isExist(self.disk_id): LogPrint().info("PASS: Delete Disk SUCCESS." ) else: LogPrint().error("FAIL: Disk is still exist. " ) self.flag = False else: LogPrint().error("FAIL: Returned status code is %s. "% r['status_code']) self.flag = False self.assertTrue(self.flag)
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)
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_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_NoRequired(self): ''' @summary: 分为四种情况,1)缺少存储域 2)缺少大小 3)缺少interface 4)缺少format @note: 操作失败,验证错误验证码及错误信息 ''' self.expected_result_index = 0 diskapi = DiskAPIs() @BaseTestCase.drive_data(self, self.dm.disk_info) 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 do_test()
def test_CreateModuleTestEnv(self): dcapi = DataCenterAPIs() capi = ClusterAPIs() # 创建1个数据中心(nfs类型) LogPrint().info("Pre-Module-Test-1: Create DataCenter '%s'." % self.dm.dc_nfs_name) self.assertTrue( dcapi.createDataCenter(self.dm.xml_dc_info)['status_code'] == self.dm.expected_status_code_create_dc) # 创建1个集群 LogPrint().info( "Pre-Module-Test-2: Create Cluster '%s' in DataCenter '%s'." % (self.dm.cluster_nfs_name, self.dm.dc_nfs_name)) self.assertTrue( capi.createCluster(self.dm.xml_cluster_info)['status_code'] == self.dm.expected_status_code_create_cluster) # 在NFS数据中心中创建一个主机,并等待主机UP。 LogPrint().info( "Pre-Module-Test-3: Create Host '%s' in Cluster '%s'." % (self.dm.host1_name, self.dm.cluster_nfs_name)) self.assertTrue( smart_create_host(self.dm.host1_name, self.dm.xml_host_info)) # 为NFS数据中心创建Data(data1/data2/export)。 @BaseTestCase.drive_data(self, self.dm.xml_storage_info) def create_storage_domains(xml_storage_domain_info): sd_name = xmltodict.parse( xml_storage_domain_info)['storage_domain']['name'] LogPrint().info("Pre-Module-Test-4: Create Data Storage '%s'." % sd_name) self.assertTrue( smart_create_storage_domain(sd_name, xml_storage_domain_info)) create_storage_domains() # 将创建的的data1、data2和export域附加到NFS/ISCSI数据中心里。 LogPrint().info( "Pre-Module-Test-5: Attach the data storages to data centers.") self.assertTrue( smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.data1_nfs_name)) self.assertTrue( smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.data2_nfs_name)) #self.assertTrue(smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.export1_name)) #创建一个虚拟机 self.vmapi = VirtualMachineAPIs() r = self.vmapi.createVm(self.dm.vm_info) if r['status_code'] == 201: self.vm_name = r['result']['vm']['name'] else: LogPrint().error("Create vm failed.Status-code is WRONG.") self.assertTrue(False) #创建一个磁盘 self.diskapi = DiskAPIs() sd_id = StorageDomainAPIs().getStorageDomainIdByName( ModuleData.data1_nfs_name) r = self.diskapi.createDisk(self.dm.disk_info, sd_id) def is_disk_ok(): return self.diskapi.getDiskStatus(self.disk_id) == 'ok' if r['status_code'] == 202: self.disk_id = r['result']['disk']['@id'] if wait_until(is_disk_ok, 200, 5): LogPrint().info("Create disk ok.") else: LogPrint().error("Create disk failed.Status-code is WRONG.") self.assertTrue(False) #将磁盘附加到虚拟机 self.vmdiskapi = VmDiskAPIs() r = self.vmdiskapi.attachDiskToVm(self.vm_name, self.disk_id) if r['status_code'] == 200: LogPrint().info("Attach Disk to vm SUCCESS.") else: LogPrint().error("Attach Disk to vm fail.Status-code is WRONG.") self.assertTrue(False)
class ITC080403_DeleteDisk_AttachtoRunVm(BaseTestCase): ''' @summary: ITC-08磁盘管理-04删除磁盘-03磁盘附加到运行的虚拟机上 ''' def setUp(self): self.dm = super(self.__class__, self).setUp() self.diskapi = DiskAPIs() #创建一个虚拟机 LogPrint().info("Pre-Test-1: Create vm %s for TC."% self.dm.vm_name) self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.vm_info)) #创建一块磁盘 ''' @note: 创建磁盘时,磁盘的sharable属性必须为false,因为共享磁盘不作为模板的一部份 ''' LogPrint().info("Pre-Test-2: Create a disk for TC.") r= smart_create_disk(self.dm.disk_info, self.dm.disk_name) self.assertTrue(r[0]) self.disk_id = r[1] #将该磁盘附加到虚拟机 LogPrint().info("Pre-Test-3: Attach disk %s to vm %s for TC."% (self.dm.disk_name ,self.dm.vm_name)) self.vmdiskapi = VmDiskAPIs() r=self.vmdiskapi.attachDiskToVm(self.dm.vm_name, self.disk_id) if r['status_code'] == 200: LogPrint().info("Attach Disk to vm success.") else: LogPrint().error("Attach Disk to vm fail.Status-code is wrong.") self.assertTrue(False) #启动虚拟机 LogPrint().info("Pre-Test-4: Start vm for TC.") self.assertTrue(smart_start_vm(self.dm.vm_name)) #激活磁盘 LogPrint().info("Pre-Test-5: Active vmdisk for TC.") self.assertTrue(smart_active_vmdisk(self.dm.vm_name,self.disk_id)) 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 tearDown(self): self.flag = True LogPrint().info("Post-Test-1: Stop vm %s."%self.dm.vm_name) self.assertTrue(smart_stop_vm(self.dm.vm_name)) LogPrint().info("Post-Test-2: Delete vm %s."%self.dm.vm_name) self.assertTrue(smart_del_vm(self.dm.vm_name))