Example #1
0
 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)
Example #2
0
    def test_TearDown(self):
        vmapi=VirtualMachineAPIs()
        #Step1:删除虚拟机
        vmapi.delVm(self.dm.vm_name)
        dcapi = DataCenterAPIs()
        capi = ClusterAPIs()
        # Step2:将export存储域和data2存储域设置为Maintenance状态,然后从数据中心分离
#         LogPrint().info("Post-Module-Test-1: Deactivate storage domains '%s'." % self.dm.export1_name)
#         self.assertTrue(smart_deactive_storage_domain(self.dm.dc_nfs_name, self.dm.export1_name))
#         LogPrint().info("Post-Module-Test-2: Detach storage domains '%s'." % self.dm.export1_name)
#         self.assertTrue(smart_detach_storage_domain(self.dm.dc_nfs_name, self.dm.export1_name))
        
        LogPrint().info("Post-Module-Test-3: Deactivate data storage domains '%s'." % self.dm.data2_nfs_name)
        self.assertTrue(smart_deactive_storage_domain(self.dm.dc_nfs_name, self.dm.data2_nfs_name))
        LogPrint().info("Post-Module-Test-4: Detach data storage domains '%s'." % self.dm.data2_nfs_name)
        self.assertTrue(smart_detach_storage_domain(self.dm.dc_nfs_name, self.dm.data2_nfs_name))
        # Step3:将data1存储域设置为Maintenance状态
        LogPrint().info("Post-Module-Test-5: Deactivate data storage domains '%s'." % self.dm.data1_nfs_name)
        self.assertTrue(smart_deactive_storage_domain(self.dm.dc_nfs_name, self.dm.data1_nfs_name))
         
        # Step4:删除数据中心dc1(非强制,之后存储域变为Unattached状态)
        if dcapi.searchDataCenterByName(self.dm.dc_nfs_name)['result']['data_centers']:
            LogPrint().info("Post-Module-Test-6: Delete DataCenter '%s'." % self.dm.dc_nfs_name)
            self.assertTrue(dcapi.delDataCenter(self.dm.dc_nfs_name)['status_code']==self.dm.expected_status_code_del_dc)
                 
        # Step5:删除3个Unattached状态存储域(data1/data2/export1)
        LogPrint().info("Post-Module-Test-7: Delete all unattached storage domains.")
        dict_sd_to_host = [self.dm.data1_nfs_name, self.dm.data2_nfs_name]
        for sd in dict_sd_to_host:
            smart_del_storage_domain(sd, self.dm.xml_del_sd_option, host_name=self.dm.host1_name)
         
        # Step6:删除主机(host1)
        LogPrint().info("Post-Module-Test-8: Delete host '%s'." % self.dm.host1_name)
        self.assertTrue(smart_del_host(self.dm.host1_name, self.dm.xml_del_host_option))
         
        # Step7:删除集群cluster1
        if capi.searchClusterByName(self.dm.cluster_nfs_name)['result']['clusters']:
            LogPrint().info("Post-Module-Test-9: Delete Cluster '%s'." % self.dm.cluster_nfs_name)
            self.assertTrue(capi.delCluster(self.dm.cluster_nfs_name)['status_code']==self.dm.expected_status_code_del_dc)
Example #3
0
 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)
__version__ = "V0.1"
'''
# ChangeLog:
#---------------------------------------------------------------------------------
# Version        Date                Desc                            Author
#---------------------------------------------------------------------------------
# V0.1           2014/10/09          初始版本                                                            Wei Keke 
#---------------------------------------------------------------------------------
'''

from TestData.Template import ITC07_SetUp as ModuleData
from TestAPIs.VirtualMachineAPIs import VirtualMachineAPIs
'''---------------------------------------------------------------------------------------------------
@note: PreData
---------------------------------------------------------------------------------------------------'''
vm_id = VirtualMachineAPIs().getVmIdByName(ModuleData.vm_name)
temp_name = 'Template-ITC0703030203'
temp_info = '''
<template>
    <name>%s</name>
    <vm id="%s"/>
</template>
''' % (temp_name, vm_id)
'''---------------------------------------------------------------------------------------------------
@note: TestData
---------------------------------------------------------------------------------------------------'''
nic_data = '''
<nic>

</nic>
'''
        <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,
Example #6
0
    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)
Example #7
0
    def test_TearDown(self):
        vmapi = VirtualMachineAPIs()
        #Step1:删除虚拟机
        vmapi.delVm(self.dm.vm_name)
        dcapi = DataCenterAPIs()
        capi = ClusterAPIs()
        # Step2:将export存储域和data2存储域设置为Maintenance状态,然后从数据中心分离
        #         LogPrint().info("Post-Module-Test-1: Deactivate storage domains '%s'." % self.dm.export1_name)
        #         self.assertTrue(smart_deactive_storage_domain(self.dm.dc_nfs_name, self.dm.export1_name))
        #         LogPrint().info("Post-Module-Test-2: Detach storage domains '%s'." % self.dm.export1_name)
        #         self.assertTrue(smart_detach_storage_domain(self.dm.dc_nfs_name, self.dm.export1_name))

        LogPrint().info(
            "Post-Module-Test-3: Deactivate data storage domains '%s'." %
            self.dm.data2_nfs_name)
        self.assertTrue(
            smart_deactive_storage_domain(self.dm.dc_nfs_name,
                                          self.dm.data2_nfs_name))
        LogPrint().info(
            "Post-Module-Test-4: Detach data storage domains '%s'." %
            self.dm.data2_nfs_name)
        self.assertTrue(
            smart_detach_storage_domain(self.dm.dc_nfs_name,
                                        self.dm.data2_nfs_name))
        # Step3:将data1存储域设置为Maintenance状态
        LogPrint().info(
            "Post-Module-Test-5: Deactivate data storage domains '%s'." %
            self.dm.data1_nfs_name)
        self.assertTrue(
            smart_deactive_storage_domain(self.dm.dc_nfs_name,
                                          self.dm.data1_nfs_name))

        # Step4:删除数据中心dc1(非强制,之后存储域变为Unattached状态)
        if dcapi.searchDataCenterByName(
                self.dm.dc_nfs_name)['result']['data_centers']:
            LogPrint().info("Post-Module-Test-6: Delete DataCenter '%s'." %
                            self.dm.dc_nfs_name)
            self.assertTrue(
                dcapi.delDataCenter(self.dm.dc_nfs_name)['status_code'] ==
                self.dm.expected_status_code_del_dc)

        # Step5:删除3个Unattached状态存储域(data1/data2/export1)
        LogPrint().info(
            "Post-Module-Test-7: Delete all unattached storage domains.")
        dict_sd_to_host = [self.dm.data1_nfs_name, self.dm.data2_nfs_name]
        for sd in dict_sd_to_host:
            smart_del_storage_domain(sd,
                                     self.dm.xml_del_sd_option,
                                     host_name=self.dm.host1_name)

        # Step6:删除主机(host1)
        LogPrint().info("Post-Module-Test-8: Delete host '%s'." %
                        self.dm.host1_name)
        self.assertTrue(
            smart_del_host(self.dm.host1_name, self.dm.xml_del_host_option))

        # Step7:删除集群cluster1
        if capi.searchClusterByName(
                self.dm.cluster_nfs_name)['result']['clusters']:
            LogPrint().info("Post-Module-Test-9: Delete Cluster '%s'." %
                            self.dm.cluster_nfs_name)
            self.assertTrue(
                capi.delCluster(self.dm.cluster_nfs_name)['status_code'] ==
                self.dm.expected_status_code_del_dc)
        <monitors>1</monitors>
        <smartcard_enabled>true</smartcard_enabled>
    </display>
    <stateless>false</stateless>
    <placement_policy>
        <affinity>migratable</affinity>
    </placement_policy>
    <memory_policy>
        <guaranteed>536870912</guaranteed>
    </memory_policy>
    <usb>
        <enabled>false</enabled>
    </usb>
</vm>
''' % (vm_name, cluster_id, template_id)
vm_id = VirtualMachineAPIs().getVmIdByName(vm_name)
#模板信息
temp_name = 'temp_ITC1003'
version_name1 = 'version1'
version_name2 = 'version2'
xml_temp_info = '''
<template>
        <name>temp_ITC1003</name>
        <vm id="%s"/>
</template>
'''

base_temp_id = TemplatesAPIs().getTemplateIdByName(temp_name)
xml_zi_temp_info1 = '''
<template>
        <name>temp_ITC1003</name>
Example #9
0
    <vm>
        <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)
Example #10
0
 def test(self):
     #step1:创建一个虚拟机
     self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.xml_vm_info))
     #step2:为虚拟机创建模板
     vm_id = VirtualMachineAPIs().getVmIdByName(self.dm.vm_name)
     TemplatesAPIs().createTemplate(self.dm.xml_temp_info, vm_id)
Example #11
0
 def tearDown(self):
     LogPrint().info("Post-Test: Delete vm %s."% self.dm.vm_name)
     VirtualMachineAPIs().delVm(self.dm.vm_name)