예제 #1
0
    def test_CreateTemplate_NoRequired(self):
        '''
        @summary: 创建模板,缺少必填项
        @note: 操作失败,验证返回状态码和返回信息
        '''
        self.tempapi = TemplatesAPIs()
        self.expected_result_index = 0

        @BaseTestCase.drive_data(self, self.dm.temp_info)
        def do_test(xml_info):
            self.flag = True
            r = self.tempapi.createTemplate(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()
예제 #2
0
    def test_DeleteTemplate(self):
        '''
        @summary: 删除模板
        @note: 操作成功,验证返回状态码和返回信息
        '''
        self.flag = True
        self.tempapi = TemplatesAPIs()
        LogPrint().info("Test: Delete template %s." % self.dm.temp_name)
        r = self.tempapi.delTemplate(self.dm.temp_name)

        def temp_not_exist():
            return self.tempapi.searchTemplateByName(
                self.dm.temp_name)['result']['templates'] == None

        if r['status_code'] == self.dm.expected_status_code:
            if wait_until(temp_not_exist, 300, 5):
                LogPrint().info("PASS: Delete Template SUCCESS.")
            else:
                LogPrint().info(
                    "FAIL: Delete Template failed.The Template still exist")
                self.flag = False
        else:
            LogPrint().info(
                "FAIL: Delete Template failed.The status_code is WRONG")
            self.flag = False
        self.assertTrue(self.flag)
예제 #3
0
    def test_CreateTemplate_SD(self):
        '''
        @summary: 创建模板,指定存储域
        @note: 操作成功,验证返回状态码和返回信息
        '''
        self.tempapi = TemplatesAPIs()
        LogPrint().info("Test: Create template %s." % self.dm.temp_name)
        r = self.tempapi.createTemplate(self.dm.temp_info)
        print r

        def is_temp_ok():
            return self.tempapi.getTemplateInfo(
                temp_name=self.dm.temp_name
            )['result']['template']['status']['state'] == 'ok'

        if r['status_code'] == self.dm.expected_status_code:
            if wait_until(is_temp_ok, 600, 10):
                LogPrint().info("PASS: Create Template ok.")
            else:
                LogPrint().error("FAIL: Create Template overtime")
                self.assertTrue(False)
        else:
            LogPrint().error(
                "FAIL: Create Template failed.Status-code is WRONG.")
            self.assertTrue(False)
예제 #4
0
 def setUp(self):
     self.dm = super(self.__class__, self).setUp()
     self.temp_api = TemplatesAPIs()
     LogPrint().info("Pre-Test: Create a template %s for TC." %
                     self.dm.temp_name)
     self.assertTrue(
         smart_create_template(self.dm.temp_name, self.dm.temp_info))
예제 #5
0
 def test_GetTemplateList(self):
     '''
     @summary: 获取模板列表
     @note: 操作成功,验证返回状态码
     '''
     temp_api = TemplatesAPIs()
     LogPrint().info("Test: Get template list.")
     r = temp_api.getTemplatesList()
     if r['status_code'] == 200:
         LogPrint().info("PASS: Get TemplateList SUCCESS.")
         self.assertTrue(True)
     else:
         LogPrint().error("FAIL: Returned status code is WRONG.")
         self.assertTrue(False)
예제 #6
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)
예제 #7
0
 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)
예제 #8
0
    def test_CreateTemplate(self):
        '''
        @summary: 创建模板
        @note: 操作成功,验证返回状态码和返回信息
        '''
        self.tempapi = TemplatesAPIs()
        self.expected_result_index = 0

        @BaseTestCase.drive_data(self, self.dm.temp_info)
        def do_test(xml_info):
            self.flag = True
            LogPrint().info("Test: Create template %s." %
                            self.dm.temp_name[self.expected_result_index])
            r = self.tempapi.createTemplate(xml_info)

            def is_temp_ok():
                return self.tempapi.getTemplateInfo(
                    temp_name=self.dm.temp_name[self.expected_result_index]
                )['result']['template']['status']['state'] == 'ok'

            if r['status_code'] == self.dm.expected_status_code:
                if wait_until(is_temp_ok, 600, 10):
                    LogPrint().info(
                        "PASS: Create Template '%s'ok." %
                        self.dm.temp_name[self.expected_result_index])
                else:
                    LogPrint().error(
                        "FAIL: Create Template '%s'overtime" %
                        self.dm.temp_name[self.expected_result_index])
                    self.flag = False
            else:
                LogPrint().error(
                    "FAIL: Create Template '%s'failed.Status-code is WRONG." %
                    self.dm.temp_name[self.expected_result_index])
                self.flag = False
            self.assertTrue(self.flag)
            self.expected_result_index += 1

        do_test()
from TestAPIs.HostAPIs import HostAPIs
from TestAPIs.ClusterAPIs import ClusterAPIs
from TestAPIs.TemplatesAPIs import TemplatesAPIs
from TestData.VirtualMachine.ITC05010502_DelVm_WithoutDisk import disk_alias
from TestAPIs.StorageDomainAPIs import StorageDomainAPIs
from TestAPIs.VirtualMachineAPIs import VirtualMachineAPIs
'''
---------------------------------------------------------------------------------------------------
@note: ModuleTestData
---------------------------------------------------------------------------------------------------
'''

#虚拟机信息
vm_name = 'vm-ITC1003'
cluster_id = ClusterAPIs().getClusterIdByName('Cluster-ITC05-NFS')
template_id = TemplatesAPIs().getTemplateIdByName('Blank')
#使用blank模板创建虚拟机xml
xml_vm_info = '''
<vm>
    <name>%s</name>
    <description>Test for ITC1003</description>
    <type>server</type>
    <memory>536870912</memory>
    <cluster id="%s"/>
    <template id="%s"/>
    <cpu>
        <topology sockets="1" cores="1"/>
    </cpu>
    <os type="NKAS6x64">
        <boot dev="hd"/>
    </os>
'''
---------------------------------------------------------------------------------------------------
@note: Pre-Test-Data
---------------------------------------------------------------------------------------------------
'''



'''
---------------------------------------------------------------------------------------------------
@note: Test-Data
---------------------------------------------------------------------------------------------------
'''
vm_name = 'vm-ITC05010301'
cluster_id = ClusterAPIs().getClusterIdByName(ModuleData.cluster_nfs_name)
template_id = TemplatesAPIs().getTemplateIdByName('Blank')

xml_vm_info='''
<vm>
    <name>%s</name>
    <description>Test for ITC050102</description>
    <type>server</type>
    <memory>536870912</memory>
    <cluster id="%s"/>
    <template id="%s"/>
    <cpu>
        <topology sockets="1" cores="1"/>
    </cpu>
    <os type="NKAS6x64">
        <boot dev="hd"/>
    </os>
예제 #11
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)