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_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 setUp(self): self.dm = super(self.__class__, self).setUp() #创建一个虚拟机 LogPrint().info("Pre-Test-1: Create vm %s for TC."% self.dm.vm_name) self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.vm_info)) #创建一块磁盘 ''' @note: 创建磁盘时,磁盘的sharable属性必须为false,因为共享磁盘不作为模板的一部份 ''' LogPrint().info("Pre-Test-2: Create a disk for TC.") r= smart_create_disk(self.dm.disk_info, self.dm.disk_name) self.assertTrue(r[0]) self.disk_id = r[1] #将该磁盘附加到虚拟机上 LogPrint().info("Pre-Test-3: Attach disk %s to vm %s for TC."% (self.dm.disk_name ,self.dm.vm_name)) self.vmdiskapi = VmDiskAPIs() r=self.vmdiskapi.attachDiskToVm(self.dm.vm_name, self.disk_id) if r['status_code'] == 200: LogPrint().info("Attach Disk to vm success.") else: LogPrint().error("Attach Disk to vm fail.Status-code is wrong.") self.assertTrue(False) #该虚拟机创建模板 LogPrint().info("Pre-Test-4: Create template for vm %s for TC."% self.dm.vm_name) self.tempapi = TemplatesAPIs() self.vm_id = VirtualMachineAPIs().getVmIdByName(self.dm.vm_name) r = self.tempapi.createTemplate(self.dm.temp_info, self.vm_id) def is_temp_ok(): return self.tempapi.getTemplateInfo(temp_name=self.dm.temp_name)['result']['template']['status']['state']=='ok' if r['status_code'] == 202: if wait_until(is_temp_ok, 600, 10): LogPrint().info("Create Template ok.") else: LogPrint().error("Create Template overtime") self.assertTrue(False) else: LogPrint().error("Create Template failed.Status-code is wrong.") self.assertTrue(False) #获得模板关联的磁盘id r = TemplateDisksAPIs().getTemplateDiskInfo(self.dm.temp_name, self.dm.disk_name) if r['status_code'] == 200: self.disk_id_temp = r['result']['disk']['@id'] else: self.assertTrue(False)
class ITC080404_DeleteDisk_AttachtoDownVm(BaseTestCase): ''' @summary: ITC-08磁盘管理-04删除磁盘-04磁盘附加到已关机的虚拟机 ''' def setUp(self): self.dm = super(self.__class__, self).setUp() #创建一个虚拟机 LogPrint().info("Pre-Test-1: Create vm %s for TC."% self.dm.vm_name) self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.vm_info)) #创建一块磁盘 ''' @note: 创建磁盘时,磁盘的sharable属性必须为false,因为共享磁盘不作为模板的一部份 ''' LogPrint().info("Pre-Test-2: Create a disk for TC.") r= smart_create_disk(self.dm.disk_info, self.dm.disk_name) self.assertTrue(r[0]) self.disk_id = r[1] #将该磁盘附加到虚拟机 LogPrint().info("Pre-Test-3: Attach disk %s to vm %s for TC."% (self.dm.disk_name ,self.dm.vm_name)) self.vmdiskapi = VmDiskAPIs() r=self.vmdiskapi.attachDiskToVm(self.dm.vm_name, self.disk_id) if r['status_code'] == 200: LogPrint().info("Attach Disk to vm success.") else: LogPrint().error("Attach Disk to vm fail.Status-code is wrong.") self.assertTrue(False) 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 tearDown(self): LogPrint().info("Post-Test: Delete vm %s."% self.dm.vm_name) VirtualMachineAPIs().delVm(self.dm.vm_name)
<type>spice</type> </display> <os> <boot dev="hd"/> </os> </vm> </action> """ """ --------------------------------------------------------------------------------------------------- @note: Test-Data --------------------------------------------------------------------------------------------------- """ vmapi = VirtualMachineAPIs() vmdiskapi = VmDiskAPIs() snapshot_vm_id = vmapi.getVmIdByName(ModuleData.snapshot_name) snapshot_disk_id = vmdiskapi.getVmDiskIdByName(ModuleData.snapshot_name, ModuleData.disk_alias) snapshot_description = "snapshotdisk" xml_snapshotOnline_info = """ <snapshot> <description>%s</description> <persist_memorystate>true</persist_memorystate> <vm id="%s"/> <disks> <disk id="%s"/> </disks> </snapshot>""" % ( snapshot_description, snapshot_vm_id,
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)
<display> <type>spice</type> </display> <os> <boot dev="hd"/> </os> </vm> </action> ''' ''' --------------------------------------------------------------------------------------------------- @note: Test-Data --------------------------------------------------------------------------------------------------- ''' vmapi = VirtualMachineAPIs() vmdiskapi = VmDiskAPIs() snapshot_vm_id = vmapi.getVmIdByName(ModuleData.snapshot_name) snapshot_disk_id = vmdiskapi.getVmDiskIdByName(ModuleData.snapshot_name, ModuleData.disk_alias) snapshot_description = 'snapshotdisk' xml_snapshotOnline_info = ''' <snapshot> <description>%s</description> <persist_memorystate>true</persist_memorystate> <vm id="%s"/> <disks> <disk id="%s"/> </disks> </snapshot>''' % (snapshot_description, snapshot_vm_id, snapshot_disk_id) '''
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))
class ITC080402_DeleteDisk_AttachtoTemp(BaseTestCase): ''' @summary: ITC-08磁盘管理-04删除磁盘-02磁盘附加到模板上 ''' def setUp(self): self.dm = super(self.__class__, self).setUp() #创建一个虚拟机 LogPrint().info("Pre-Test-1: Create vm %s for TC."% self.dm.vm_name) self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.vm_info)) #创建一块磁盘 ''' @note: 创建磁盘时,磁盘的sharable属性必须为false,因为共享磁盘不作为模板的一部份 ''' LogPrint().info("Pre-Test-2: Create a disk for TC.") r= smart_create_disk(self.dm.disk_info, self.dm.disk_name) self.assertTrue(r[0]) self.disk_id = r[1] #将该磁盘附加到虚拟机上 LogPrint().info("Pre-Test-3: Attach disk %s to vm %s for TC."% (self.dm.disk_name ,self.dm.vm_name)) self.vmdiskapi = VmDiskAPIs() r=self.vmdiskapi.attachDiskToVm(self.dm.vm_name, self.disk_id) if r['status_code'] == 200: LogPrint().info("Attach Disk to vm success.") else: LogPrint().error("Attach Disk to vm fail.Status-code is wrong.") self.assertTrue(False) #该虚拟机创建模板 LogPrint().info("Pre-Test-4: Create template for vm %s for TC."% self.dm.vm_name) self.tempapi = TemplatesAPIs() self.vm_id = VirtualMachineAPIs().getVmIdByName(self.dm.vm_name) r = self.tempapi.createTemplate(self.dm.temp_info, self.vm_id) def is_temp_ok(): return self.tempapi.getTemplateInfo(temp_name=self.dm.temp_name)['result']['template']['status']['state']=='ok' if r['status_code'] == 202: if wait_until(is_temp_ok, 600, 10): LogPrint().info("Create Template ok.") else: LogPrint().error("Create Template overtime") self.assertTrue(False) else: LogPrint().error("Create Template failed.Status-code is wrong.") self.assertTrue(False) #获得模板关联的磁盘id r = TemplateDisksAPIs().getTemplateDiskInfo(self.dm.temp_name, self.dm.disk_name) if r['status_code'] == 200: self.disk_id_temp = r['result']['disk']['@id'] else: self.assertTrue(False) 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 tearDown(self): LogPrint().info("Post-Test-1: Delete template %s."% self.dm.temp_name) self.assertTrue(smart_delete_template(self.dm.temp_name)) LogPrint().info("Post-Test-2: Delete vm %s."% self.dm.vm_name) self.assertTrue(smart_del_vm(self.dm.vm_name))
#--------------------------------------------------------------------------------- # Version Date Desc Author #--------------------------------------------------------------------------------- # V0.1 2014/10/09 初始版本 Wei Keke #--------------------------------------------------------------------------------- ''' from TestAPIs.StorageDomainAPIs import StorageDomainAPIs from TestData.Template import ITC07_SetUp as ModuleData from TestAPIs.VirtualMachineAPIs import VirtualMachineAPIs, VmDiskAPIs '''--------------------------------------------------------------------------------------------------- @note: TestData ---------------------------------------------------------------------------------------------------''' sd_name = ModuleData.data1_nfs_name sd_id = StorageDomainAPIs().getStorageDomainIdByName(sd_name) vm_id = VirtualMachineAPIs().getVmIdByName(ModuleData.vm_name) disk_id = VmDiskAPIs().getVmDiskIdByName(ModuleData.vm_name, ModuleData.disk_name) temp_name = 'Template-ITC0701030102' temp_info = ''' <template> <name>%s</name> <vm id="%s"> <disks> <disk id="%s"> <storage_domains> <storage_domain id="%s"/> </storage_domains> </disk> </disks> </vm> </template> ''' % (temp_name, vm_id, disk_id, sd_id)