def test_EditNfsSd_Normal(self):
     '''
     @summary: 测试步骤
     @note: (1)编辑存储域的名称;
     @note: (2)操作失败,验证接口返回的状态码、提示信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info(
         "Test: Edit NFS data storage '%s' in 'Unattached' state." %
         self.dm.data_name)
     r = sd_api.updateStorageDomain(self.dm.data_name,
                                    self.dm.xml_data_info_new)
     if r['status_code'] == self.dm.expected_status_code_edit_sd_unattached:
         if DictCompare().isSubsetDict(
                 xmltodict.parse(self.dm.expected_info_edit_sd_unattached),
                 r['result']):
             LogPrint().info(
                 "PASS: Returned status code and messages are INCORRECT while edit storage domain in 'unattached' state."
             )
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: Returned messages are INCORRECT while edit storage domain in 'unattached' state."
             )
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' are INCORRECT while edit storage domain in 'unattached' state."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
 def test_GetStorageDomainsInfo(self):
     '''
     @summary: 测试步骤
     @note: (1)调用相应接口,获取模块级测试环境中的存储域信息;
     @note: (2)操作成功,验证接口返回的状态码、存储域信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Get info of DataStorage '%s'." %
                     self.dm.data_storage_name)
     r = sd_api.getStorageDomainInfo(self.dm.data_storage_name)
     if r['status_code'] == self.dm.expected_statsu_code_get_sd_info:
         dictCompare = DictCompare()
         d1 = self.dm.xml_data_storage_info
         del d1['storage_domain']['host']
         d2 = r['result']
         if dictCompare.isSubsetDict(d1, d2):
             LogPrint().info("PASS: Get DataStorage '%s' info SUCCESS." %
                             self.dm.data_storage_name)
             self.flag = True
         else:
             LogPrint().error("FAIL: Get StorageDomain's info INCORRECT.")
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' is INCORRECT while Get sd's info."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
 def test_DestroySd_Unattached(self):
     '''
     @summary: 测试步骤
     @note: (1)对Unattached状态的ISO存储域进行销毁操作;
     @note: (2)操作成功,验证接口返回的状态码、提示信息是否正确。
     '''
     self.sd_api = StorageDomainAPIs()
     # 对ISO存储域进行Destroy操作(通过在删除项中设置destroy参数实现)
     LogPrint().info("Test: Destroy the ISO storage domain '%s'." %
                     self.dm.iso_name)
     r = self.sd_api.delStorageDomain(self.dm.iso_name,
                                      self.dm.xml_destroy_iso_option)
     print r
     if r['status_code'] == self.dm.expected_status_code_destroy_sd:
         if not self.sd_api.searchStorageDomainByName(
                 self.dm.iso_name)['result']['storage_domains']:
             LogPrint().info(
                 "PASS: Destroy the ISO storage domain '%s' SUCCESS." %
                 self.dm.iso_name)
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: The ISO storage domain '%s' still exists after destroyed."
                 % self.dm.iso_name)
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' is INCORRECT while destroying a storage domain."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
 def test_CreateIscsiSd_Normal(self):
     '''
     @summary: 测试步骤
     @note: (1)创建一个ISCSI类型的Data存储域;
     @note: (2)操作成功,验证接口返回的状态码、存储域信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Create ISCSI data storage '%s'." % self.dm.data1_name)
     r = sd_api.createStorageDomain(self.dm.data1_info_xml)
     if r['status_code'] == self.dm.expected_status_code_create_sd:
         d1 = xmltodict.parse(self.dm.data1_info_xml)
         del d1['storage_domain']['host']
         del d1['storage_domain']['storage']['override_luns']
         d2 = deepcopy(r['result'])
         del d2['storage_domain']['storage']['volume_group']
         d2['storage_domain']['storage']['logical_unit'] = r['result']['storage_domain']['storage']['volume_group']['logical_unit']
         if DictCompare().isSubsetDict(d1, d2):
             LogPrint().info("PASS: Create ISCSI storage '%s' SUCCESS." % self.dm.data1_name)
             self.flag = True
         else:
             LogPrint().error("FAIL: Create ISCSI storage '%s' FAILED. Returned sd info INCORRECT." % self.dm.data1_name)
             self.flag = False
     else:
         LogPrint().error("FAIL: Returned status code '%s' INCORRECT while creating ISCSI DataStorage." % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
 def test_EditNfsSd_Normal(self):
     """
     @summary: 测试步骤
     @note: (1)编辑存储域的名称;
     @note: (2)操作失败,验证接口返回的状态码、提示信息是否正确。
     """
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Edit NFS data storage '%s' in 'Unattached' state." % self.dm.data_name)
     r = sd_api.updateStorageDomain(self.dm.data_name, self.dm.xml_data_info_new)
     if r["status_code"] == self.dm.expected_status_code_edit_sd_unattached:
         if DictCompare().isSubsetDict(xmltodict.parse(self.dm.expected_info_edit_sd_unattached), r["result"]):
             LogPrint().info(
                 "PASS: Returned status code and messages are INCORRECT while edit storage domain in 'unattached' state."
             )
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: Returned messages are INCORRECT while edit storage domain in 'unattached' state."
             )
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' are INCORRECT while edit storage domain in 'unattached' state."
             % r["status_code"]
         )
         self.flag = False
     self.assertTrue(self.flag)
 def test_CreateIscsiSd_Normal(self):
     '''
     @summary: 测试步骤
     @note: (1)创建一个ISCSI类型的Data存储域;
     @note: (2)操作成功,验证接口返回的状态码、存储域信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Create ISCSI data storage '%s'." %
                     self.dm.data1_name)
     r = sd_api.createStorageDomain(self.dm.data1_info_xml)
     if r['status_code'] == self.dm.expected_status_code_create_sd:
         d1 = xmltodict.parse(self.dm.data1_info_xml)
         del d1['storage_domain']['host']
         del d1['storage_domain']['storage']['override_luns']
         d2 = deepcopy(r['result'])
         del d2['storage_domain']['storage']['volume_group']
         d2['storage_domain']['storage']['logical_unit'] = r['result'][
             'storage_domain']['storage']['volume_group']['logical_unit']
         if DictCompare().isSubsetDict(d1, d2):
             LogPrint().info("PASS: Create ISCSI storage '%s' SUCCESS." %
                             self.dm.data1_name)
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: Create ISCSI storage '%s' FAILED. Returned sd info INCORRECT."
                 % self.dm.data1_name)
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' INCORRECT while creating ISCSI DataStorage."
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
 def test_DelNfsSd_Unattached(self):
     '''
     @summary: 测试步骤
     @note: (1)删除处于Unattached状态的NFS类型Data存储域;
     @note: (2)操作成功,验证接口返回状态码、相关信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info(
         "Test: Delete NFS data storage '%s' in 'Unattached' state." %
         self.dm.data_name)
     r = sd_api.delStorageDomain(self.dm.data_name,
                                 self.dm.xml_del_sd_option)
     if r['status_code'] == self.dm.expected_status_code_del_sd:
         if not sd_api.searchStorageDomainByName(
                 self.dm.data_name)['result']['storage_domains']:
             LogPrint().info(
                 "PASS: Delete unattached Storage Domain '%s' SUCCESS." %
                 self.dm.data_name)
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: The deleted Storage Domain '%s' still exists." %
                 self.dm.data_name)
             self.flag = False
     else:
         LogPrint().error(
             "FAIL: Returned status code '%s' INCORRECT while deleting Storage Domain '%s'."
             % (r['status_code'], self.dm.data_name))
         self.flag = False
     self.assertTrue(self.flag)
Esempio n. 8
0
    def test_Scene(self):
        '''
        @summary: 测试场景描述
        '''
        volumeapi = GlusterVolumeAPIs()
        #创建一个distributed_replicate类型的卷disrep,Replica Count=2,brick=4
        LogPrint().info("Create volume disrep")
        r = volumeapi.createGlusterVolume(self.dm.cluster_name, self.dm.xml_volume_disrep)
        if r['status_code'] == self.dm.expected_status_code_create_volume:
            LogPrint().info("PASS:Create volume disrep success.")
            self.flag = True
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)
           
        LogPrint().info("Start volume disrep")
        r = volumeapi.startGlusterVolume(self.dm.cluster_name, "disrep")
        if r['status_code'] == self.dm.expected_status_code_start_volume:
            def is_volume_up():
                return volumeapi.getClusterVolumeStatus(self.dm.cluster_name, "disrep") == "up"
            if wait_until(is_volume_up, 600, 5):
                LogPrint().info("PASS:Start volume disrep success.")
                self.flag = True
            else:
                LogPrint().error("FAIL:Start volume failed.Status is not UP.")
                self.flag = False
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)
#       
#     #利用该卷创建一个glusterfs类型的存储域
        sdapi = StorageDomainAPIs()
        LogPrint().info("Create glusterfs storagedomain '%s'."%self.dm.sd_name)
        r = sdapi.createStorageDomain(self.dm.xml_sd_info)
        if r['status_code'] == self.dm.expected_status_code_create_sd:
            LogPrint().info("PASS:Create glusterfs storagedomain '%s' SUCCESS."%self.dm.sd_name)
            self.flag=True
        else:
            LogPrint().info("FAIL:Create glusterfs storagedomain '%s' FAIL."%self.dm.sd_name)
            self.flag=False
        self.assertTrue(self.flag)
#     #将存储域附加到数据中心
        LogPrint().info("Attach glusterfs storagedomain '%s'to DC '%s'."%(self.dm.sd_name, self.dm.dc_name))
        self.assertTrue(smart_attach_storage_domain(self.dm.dc_name, self.dm.sd_name))
#     #创建虚拟机,为虚拟机添加磁盘,启动虚拟机
        LogPrint().info("Create a VM '%s'."%self.dm.vm_name)
        self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.xml_vm_info))
        LogPrint().info("ADD DISK '%s' for VM '%s'."%(self.dm.disk_alias,self.dm.vm_name))
        self.assertTrue(smart_create_vmdisk(self.dm.vm_name, self.dm.xml_disk_info, self.dm.disk_alias)[0])
        LogPrint().info("Start VM '%s'."%(self.dm.vm_name))
        self.assertTrue(smart_start_vm(self.dm.vm_name))
#         #关闭虚拟机,创建模板,创建子模板
        LogPrint().info("Stop VM '%s'."%(self.dm.vm_name))
        self.assertTrue(smart_stop_vm(self.dm.vm_name))
        self.assertTrue(smart_create_template(self.dm.base_temp_name, self.dm.temp_info))
        self.assertTrue(smart_create_template(self.dm.base_temp_name, self.dm.zi_temp_info, self.dm.temp_name))
class ITC04010601_DestroySd_Unattached(BaseTestCase):
    """
    @summary: ITC-04存储域管理-01存储域操作-06销毁-01Unattached状态
    """

    def setUp(self):
        """
        @summary: 初始化测试数据、测试环境。
        """
        # 初始化测试数据
        self.dm = super(self.__class__, self).setUp()

        # 前提1:创建一个ISO存储域(Unattached状态)
        LogPrint().info("Pre-Test: Create a ISO storage domain '%s' for test." % self.dm.iso_name)
        self.assertTrue(smart_create_storage_domain(self.dm.iso_name, self.dm.xml_iso_info))

    def test_DestroySd_Unattached(self):
        """
        @summary: 测试步骤
        @note: (1)对Unattached状态的ISO存储域进行销毁操作;
        @note: (2)操作成功,验证接口返回的状态码、提示信息是否正确。
        """
        self.sd_api = StorageDomainAPIs()
        # 对ISO存储域进行Destroy操作(通过在删除项中设置destroy参数实现)
        LogPrint().info("Test: Destroy the ISO storage domain '%s'." % self.dm.iso_name)
        r = self.sd_api.delStorageDomain(self.dm.iso_name, self.dm.xml_destroy_iso_option)
        print r
        if r["status_code"] == self.dm.expected_status_code_destroy_sd:
            if not self.sd_api.searchStorageDomainByName(self.dm.iso_name)["result"]["storage_domains"]:
                LogPrint().info("PASS: Destroy the ISO storage domain '%s' SUCCESS." % self.dm.iso_name)
                self.flag = True
            else:
                LogPrint().error("FAIL: The ISO storage domain '%s' still exists after destroyed." % self.dm.iso_name)
                self.flag = False
        else:
            LogPrint().error(
                "FAIL: Returned status code '%s' is INCORRECT while destroying a storage domain." % r["status_code"]
            )
            self.flag = False
        self.assertTrue(self.flag)

    def tearDown(self):
        """
        @summary: 资源清理
        @note: (1)导入被销毁的存储域;
        @note: (2)删除该存储域(被销毁的存储域,只有在导入之后删除才能被再次被创建)。
        """
        # Post-Test-1:导入被销毁的存储域
        LogPrint().info("Post-Test-1: Import the destroyed storage domain '%s' for deleting." % self.dm.iso_name)
        r = self.sd_api.importStorageDomain(self.dm.xml_import_iso_info)
        self.assertTrue(r["status_code"] == self.dm.expected_status_code_import_sd)

        # Post-Test-2:删除该存储域(以便后续重复使用该存储创建存储域)
        LogPrint().info("Post-Test-2: Delete the imported storage domain '%s' for reusing." % self.dm.iso_name)
        r = self.sd_api.delStorageDomain(self.dm.iso_name, self.dm.xml_del_iso_option)
        self.assertTrue(r["status_code"] == self.dm.expected_status_code_del_sd)
Esempio n. 10
0
class ITC04010701_ImportSd_Unattached(BaseTestCase):
    '''
    @summary: ITC-04存储域管理-01存储域操作-07导入-01ISO域
    '''
    def setUp(self):
        '''
        @summary: 初始化测试数据、测试环境。
        '''
        # 初始化测试数据
        self.dm = super(self.__class__, self).setUp()
        self.sd_api = StorageDomainAPIs()
        
        # 前提1:创建一个ISO存储域(Unattached状态)
        LogPrint().info("Pre-Test-1: Create a ISO storage domain '%s' for import test." % self.dm.iso_name)
        self.assertTrue(smart_create_storage_domain(self.dm.iso_name, self.dm.xml_iso_info))
        
        # 前提2:销毁(destroy)该ISO存储域
        LogPrint().info("Pre-Test-2: Destroy the ISO storage domain '%s' for import test." % self.dm.iso_name)
        r = self.sd_api.delStorageDomain(self.dm.iso_name, self.dm.xml_destroy_iso_option)
        self.assertTrue(r['status_code'] == self.dm.expected_status_code_del_sd)
        
    def test_DestroySd_Unattached(self):
        '''
        @summary: 测试步骤
        @note: (1)导入一个已被销毁的ISO存储域;
        @note: (2)操作成功,验证接口返回的状态码、提示信息是否正确。
        '''
        # 对ISO存储域进行Destroy操作(通过在删除项中设置destroy参数实现)
        LogPrint().info("Test: Import the destroyed ISO storage domain '%s'." % self.dm.iso_name)
        r = self.sd_api.importStorageDomain(self.dm.xml_import_iso_info)
        if r['status_code'] == self.dm.expected_status_code_import_sd:
            if self.sd_api.searchStorageDomainByName(self.dm.iso_name)['result']['storage_domains']:
                LogPrint().info("PASS: Import the destroyed ISO storage domain '%s' SUCCESS." % self.dm.iso_name)
                self.flag = True
            else:
                LogPrint().error("FAIL: The storage domain '%s' does not exist after importing." % self.dm.iso_name)
                self.flag = False
        else:
            LogPrint().error("FAIL: Returned status code '%s' is INCORRECT while importing a destroyed storage domain." % r['status_code'])
            self.flag = False
        self.assertTrue(self.flag)
    
    def tearDown(self):
        '''
        @summary: 资源清理
        @note: (1)删除该存储域(被销毁的存储域,只有在导入之后删除才能被再次被创建)。
        '''      
        # Post-Test:删除该存储域(以便后续重复使用该存储创建存储域)
        LogPrint().info("Post-Test: Delete the imported storage domain '%s' for reusing later." % self.dm.iso_name)
        r = self.sd_api.delStorageDomain(self.dm.iso_name, self.dm.xml_del_iso_option)
        self.assertTrue(r['status_code']==self.dm.expected_status_code_del_sd)
Esempio n. 11
0
 def test_GetStorageDomainsList(self):
     '''
     @summary: 测试步骤
     @note: (1)获取全部存储域列表;
     @note: (2)操作成功,验证接口返回的状态码是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Get all Storage Domains list.")
     r = sd_api.getStorageDomainsList()
     if r['status_code']==200:
         LogPrint().info('PASS: Get StorageDomains list SUCCESS.')
     else:
         LogPrint().error('FAIL: Get StorageDomains list FAILED. Returned status code "%s" is incorrect.' % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
Esempio n. 12
0
 def test_GetTemplateDiskInfo(self):
     '''
     @summary: 获取模板的磁盘详情
     @note: 操作成功,验证返回状态码和返回信息
     '''
     self.flag = True
     tempdisk_api = TemplateDisksAPIs()
     LogPrint().info("Test: Get disk info of template %s." %
                     self.dm.temp_name)
     r = tempdisk_api.getTemplateDiskInfo(self.dm.temp_name,
                                          self.dm.disk_name)
     if r['status_code'] == self.dm.expected_status_code:
         dictCompare = DictCompare()
         sd_id = StorageDomainAPIs().getStorageDomainIdByName(
             ModuleData.data1_nfs_name)
         expected_result = xmltodict.parse(self.dm.disk_info % sd_id)
         actual_result = r['result']
         if dictCompare.isSubsetDict(expected_result, actual_result):
             LogPrint().info("PASS: Get disk info of template %s SUCCESS." %
                             self.dm.temp_name)
         else:
             LogPrint().error("FAIL: The disk_info is WRONG")
             self.flag = False
     else:
         LogPrint().error("FAIL: The status_code is WRONG")
         self.flag = False
     self.assertTrue(self.flag)
Esempio n. 13
0
    def test_CreateNfsSd_Normal(self):
        '''
        @summary: 测试步骤
        @note: (1)创建一个NFS的Data类型存储域,不附加到任何数据中心;
        @note: (2)操作成功,验证接口返回的状态码、提示信息是否正确。
        '''
        sd_api = StorageDomainAPIs()
        # 创建NFS的Data类型存储域(unattached状态)
        @BaseTestCase.drive_data(self, self.dm.data1_info_xml)
        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)

        do_test()
 def test_GetStorageDomainsList(self):
     '''
     @summary: 测试步骤
     @note: (1)获取全部存储域列表;
     @note: (2)操作成功,验证接口返回的状态码是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Get all Storage Domains list.")
     r = sd_api.getStorageDomainsList()
     if r['status_code'] == 200:
         LogPrint().info('PASS: Get StorageDomains list SUCCESS.')
     else:
         LogPrint().error(
             'FAIL: Get StorageDomains list FAILED. Returned status code "%s" is incorrect.'
             % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
Esempio n. 15
0
 def test_DelIscsiSd_Unattached(self):
     '''
     @summary: 测试步骤
     @note: (1)删除处于Unattached状态的ISCSI类型Data存储域;
     @note: (2)操作成功,验证接口返回状态码、相关信息是否正确。
     '''
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Delete ISCSI data storage '%s' in 'Unattached' state." % self.dm.data_name)
     r = sd_api.delStorageDomain(self.dm.data_name, self.dm.xml_del_sd_option)
     if r['status_code'] == self.dm.expected_status_code_del_sd:
         if not sd_api.searchStorageDomainByName(self.dm.data_name)['result']['storage_domains']:
             LogPrint().info("PASS: Delete unattached Storage Domain '%s' SUCCESS." % self.dm.data_name)
             self.flag = True
         else:
             LogPrint().error("FAIL: The deleted Storage Domain '%s' still exists." % self.dm.data_name)
             self.flag = False
     else:
         LogPrint().error("FAIL: Returned status code '%s' INCORRECT while deleting Storage Domain '%s'." % (r['status_code'], self.dm.data_name))
         self.flag = False
     self.assertTrue(self.flag)
 def test_GetStorageDomainsInfo(self):
     """
     @summary: 测试步骤
     @note: (1)调用相应接口,获取模块级测试环境中的存储域信息;
     @note: (2)操作成功,验证接口返回的状态码、存储域信息是否正确。
     """
     sd_api = StorageDomainAPIs()
     LogPrint().info("Test: Get info of DataStorage '%s'." % self.dm.data_storage_name)
     r = sd_api.getStorageDomainInfo(self.dm.data_storage_name)
     if r["status_code"] == self.dm.expected_statsu_code_get_sd_info:
         dictCompare = DictCompare()
         d1 = self.dm.xml_data_storage_info
         del d1["storage_domain"]["host"]
         d2 = r["result"]
         if dictCompare.isSubsetDict(d1, d2):
             LogPrint().info("PASS: Get DataStorage '%s' info SUCCESS." % self.dm.data_storage_name)
             self.flag = True
         else:
             LogPrint().error("FAIL: Get StorageDomain's info INCORRECT.")
             self.flag = False
     else:
         LogPrint().error("FAIL: Returned status code '%s' is INCORRECT while Get sd's info." % r["status_code"])
         self.flag = False
     self.assertTrue(self.flag)
    def setUp(self):
        '''
        @summary: 初始化测试数据、测试环境。
        '''
        # 初始化测试数据
        self.dm = super(self.__class__, self).setUp()
        self.sd_api = StorageDomainAPIs()

        # 前提1:创建一个ISO存储域(Unattached状态)
        LogPrint().info(
            "Pre-Test-1: Create a ISO storage domain '%s' for import test." %
            self.dm.iso_name)
        self.assertTrue(
            smart_create_storage_domain(self.dm.iso_name,
                                        self.dm.xml_iso_info))

        # 前提2:销毁(destroy)该ISO存储域
        LogPrint().info(
            "Pre-Test-2: Destroy the ISO storage domain '%s' for import test."
            % self.dm.iso_name)
        r = self.sd_api.delStorageDomain(self.dm.iso_name,
                                         self.dm.xml_destroy_iso_option)
        self.assertTrue(
            r['status_code'] == self.dm.expected_status_code_del_sd)
    def setUp(self):
        """
        @summary: 初始化测试数据、测试环境。
        """
        # 初始化测试数据
        self.dm = super(self.__class__, self).setUp()
        self.sd_api = StorageDomainAPIs()

        # 前提1:创建一个ISO存储域(Unattached状态)
        LogPrint().info("Pre-Test-1: Create a ISO storage domain '%s' for import test." % self.dm.iso_name)
        self.assertTrue(smart_create_storage_domain(self.dm.iso_name, self.dm.xml_iso_info))

        # 前提2:销毁(destroy)该ISO存储域
        LogPrint().info("Pre-Test-2: Destroy the ISO storage domain '%s' for import test." % self.dm.iso_name)
        r = self.sd_api.delStorageDomain(self.dm.iso_name, self.dm.xml_destroy_iso_option)
        self.assertTrue(r["status_code"] == self.dm.expected_status_code_del_sd)
Esempio n. 19
0
 def test_DestroySd_Unattached(self):
     '''
     @summary: 测试步骤
     @note: (1)对Unattached状态的ISO存储域进行销毁操作;
     @note: (2)操作成功,验证接口返回的状态码、提示信息是否正确。
     '''
     self.sd_api = StorageDomainAPIs()
     # 对ISO存储域进行Destroy操作(通过在删除项中设置destroy参数实现)
     LogPrint().info("Test: Destroy the ISO storage domain '%s'." % self.dm.iso_name)
     r = self.sd_api.delStorageDomain(self.dm.iso_name, self.dm.xml_destroy_iso_option)
     if r['status_code'] == self.dm.expected_status_code_destroy_sd:
         if not self.sd_api.searchStorageDomainByName(self.dm.iso_name)['result']['storage_domains']:
             LogPrint().info("PASS: Destroy the ISO storage domain '%s' SUCCESS." % self.dm.iso_name)
             self.flag = True
         else:
             LogPrint().error("FAIL: The ISO storage domain '%s' still exists after destroyed." % self.dm.iso_name)
             self.flag = False
     else:
         LogPrint().error("FAIL: Returned status code '%s' is INCORRECT while destroying a storage domain." % r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
    def test_CreateNfsSd_PathVerify(self):
        '''
        @summary: 测试步骤
        @note: (1)输入各种不合法的Path,创建存储域;
        @note: (2)操作失败,验证接口返回的状态码、提示信息是否正确。
        '''
        sd_api = StorageDomainAPIs()
        # 使用数据驱动,根据测试数据文件循环创建多个Path非法的存储域
        @BaseTestCase.drive_data(self, self.dm.xml_sd_info_list)
        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)

        do_test()
Esempio n. 21
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)
class ITC04010701_ImportSd_Unattached(BaseTestCase):
    '''
    @summary: ITC-04存储域管理-01存储域操作-07导入-01ISO域
    '''
    def setUp(self):
        '''
        @summary: 初始化测试数据、测试环境。
        '''
        # 初始化测试数据
        self.dm = super(self.__class__, self).setUp()
        self.sd_api = StorageDomainAPIs()

        # 前提1:创建一个ISO存储域(Unattached状态)
        LogPrint().info(
            "Pre-Test-1: Create a ISO storage domain '%s' for import test." %
            self.dm.iso_name)
        self.assertTrue(
            smart_create_storage_domain(self.dm.iso_name,
                                        self.dm.xml_iso_info))

        # 前提2:销毁(destroy)该ISO存储域
        LogPrint().info(
            "Pre-Test-2: Destroy the ISO storage domain '%s' for import test."
            % self.dm.iso_name)
        r = self.sd_api.delStorageDomain(self.dm.iso_name,
                                         self.dm.xml_destroy_iso_option)
        self.assertTrue(
            r['status_code'] == self.dm.expected_status_code_del_sd)

    def test_DestroySd_Unattached(self):
        '''
        @summary: 测试步骤
        @note: (1)导入一个已被销毁的ISO存储域;
        @note: (2)操作成功,验证接口返回的状态码、提示信息是否正确。
        '''
        # 对ISO存储域进行Destroy操作(通过在删除项中设置destroy参数实现)
        LogPrint().info("Test: Import the destroyed ISO storage domain '%s'." %
                        self.dm.iso_name)
        r = self.sd_api.importStorageDomain(self.dm.xml_import_iso_info)
        if r['status_code'] == self.dm.expected_status_code_import_sd:
            if self.sd_api.searchStorageDomainByName(
                    self.dm.iso_name)['result']['storage_domains']:
                LogPrint().info(
                    "PASS: Import the destroyed ISO storage domain '%s' SUCCESS."
                    % self.dm.iso_name)
                self.flag = True
            else:
                LogPrint().error(
                    "FAIL: The storage domain '%s' does not exist after importing."
                    % self.dm.iso_name)
                self.flag = False
        else:
            LogPrint().error(
                "FAIL: Returned status code '%s' is INCORRECT while importing a destroyed storage domain."
                % r['status_code'])
            self.flag = False
        self.assertTrue(self.flag)

    def tearDown(self):
        '''
        @summary: 资源清理
        @note: (1)删除该存储域(被销毁的存储域,只有在导入之后删除才能被再次被创建)。
        '''
        # Post-Test:删除该存储域(以便后续重复使用该存储创建存储域)
        LogPrint().info(
            "Post-Test: Delete the imported storage domain '%s' for reusing later."
            % self.dm.iso_name)
        r = self.sd_api.delStorageDomain(self.dm.iso_name,
                                         self.dm.xml_del_iso_option)
        self.assertTrue(
            r['status_code'] == self.dm.expected_status_code_del_sd)
Esempio n. 23
0
    def test_Scene(self):
        '''
        @summary: 测试场景描述
        '''
        volumeapi = GlusterVolumeAPIs()
        #创建一个distributed_replicate类型的卷disrep,Replica Count=2,brick=4
        LogPrint().info("Create volume disrep")
        r = volumeapi.createGlusterVolume(self.dm.cluster_name,
                                          self.dm.xml_volume_disrep)
        if r['status_code'] == self.dm.expected_status_code_create_volume:
            LogPrint().info("PASS:Create volume disrep success.")
            self.flag = True
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)

        LogPrint().info("Start volume disrep")
        r = volumeapi.startGlusterVolume(self.dm.cluster_name, "disrep")
        if r['status_code'] == self.dm.expected_status_code_start_volume:

            def is_volume_up():
                return volumeapi.getClusterVolumeStatus(
                    self.dm.cluster_name, "disrep") == "up"

            if wait_until(is_volume_up, 600, 5):
                LogPrint().info("PASS:Start volume disrep success.")
                self.flag = True
            else:
                LogPrint().error("FAIL:Start volume failed.Status is not UP.")
                self.flag = False
        else:
            LogPrint().error("FAIL:Status_code is WRONG.")
            self.flag = False
        self.assertTrue(self.flag)
        #
        #     #利用该卷创建一个glusterfs类型的存储域
        sdapi = StorageDomainAPIs()
        LogPrint().info("Create glusterfs storagedomain '%s'." %
                        self.dm.sd_name)
        r = sdapi.createStorageDomain(self.dm.xml_sd_info)
        if r['status_code'] == self.dm.expected_status_code_create_sd:
            LogPrint().info(
                "PASS:Create glusterfs storagedomain '%s' SUCCESS." %
                self.dm.sd_name)
            self.flag = True
        else:
            LogPrint().info("FAIL:Create glusterfs storagedomain '%s' FAIL." %
                            self.dm.sd_name)
            self.flag = False
        self.assertTrue(self.flag)
        #     #将存储域附加到数据中心
        LogPrint().info("Attach glusterfs storagedomain '%s'to DC '%s'." %
                        (self.dm.sd_name, self.dm.dc_name))
        self.assertTrue(
            smart_attach_storage_domain(self.dm.dc_name, self.dm.sd_name))
        #     #创建虚拟机,为虚拟机添加磁盘,启动虚拟机
        LogPrint().info("Create a VM '%s'." % self.dm.vm_name)
        self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.xml_vm_info))
        LogPrint().info("ADD DISK '%s' for VM '%s'." %
                        (self.dm.disk_alias, self.dm.vm_name))
        self.assertTrue(
            smart_create_vmdisk(self.dm.vm_name, self.dm.xml_disk_info,
                                self.dm.disk_alias)[0])
        LogPrint().info("Start VM '%s'." % (self.dm.vm_name))
        self.assertTrue(smart_start_vm(self.dm.vm_name))
        #         #关闭虚拟机,创建模板,创建子模板
        LogPrint().info("Stop VM '%s'." % (self.dm.vm_name))
        self.assertTrue(smart_stop_vm(self.dm.vm_name))
        self.assertTrue(
            smart_create_template(self.dm.base_temp_name, self.dm.temp_info))
        self.assertTrue(
            smart_create_template(self.dm.base_temp_name, self.dm.zi_temp_info,
                                  self.dm.temp_name))
#---------------------------------------------------------------------------------
# Version        Date                Desc                            Author
#---------------------------------------------------------------------------------
# V0.1           2014/10/17          初始版本                                                            Liu Fei 
#---------------------------------------------------------------------------------
'''

from TestData.StorageDomain import ITC04_SetUp as ModuleData
from TestAPIs.StorageDomainAPIs import StorageDomainAPIs
'''
-------------------------------------------------------------------------------------------------
@note: Pre-Test-Data
-------------------------------------------------------------------------------------------------
'''
data1_name = ModuleData.data1_nfs_name
data1_id = StorageDomainAPIs().getStorageDomainIdByName(data1_name)
disk_name = 'disk-ITC04020301-1'
xml_disk_info = '''
<disk>
    <alias>%s</alias>
    <storage_domains>
        <storage_domain id="%s"/>
    </storage_domains>
    <size>105906176</size>
    <interface>virtio</interface>
    <format>cow</format>
</disk>
''' % (disk_name, data1_id)
'''
-------------------------------------------------------------------------------------------------
@note: Test-Data
#encoding:utf-8
from TestAPIs.StorageDomainAPIs import StorageDomainAPIs
from TestAPIs.ProfilesAPIs import ProfilesAPIs
from TestAPIs.NetworkAPIs import NetworkAPIs
import TestData.VirtualMachine.ITC05_SetUp as ModuleData
'''
@note: PreData
'''
'''
@note: 存储域名称应该由该模块的Setup用例初始化获得,这里暂时用字符串代替
'''
nic_name = 'nic-ITC05'
sd_id = StorageDomainAPIs().getStorageDomainIdByName(ModuleData.data1_nfs_name)

nic_info='''
<nic>
    <name>%s</name>
    <interface>virtio</interface>
    <linked>false</linked>
    <plugged>false</plugged>
</nic>
'''%(nic_name)
disk_name = 'disk-ITC05'
disk_info='''
<disk>
    <alias>%s</alias>
    <name>%s</name>
    <storage_domains>
        <storage_domain id = "%s"/>
    </storage_domains>
    <size>1059061760</size>
# ChangeLog:
#---------------------------------------------------------------------------------
# Version        Date                Desc                            Author
#---------------------------------------------------------------------------------
# V0.1           2014/10/09          初始版本                                                            Wei Keke 
#---------------------------------------------------------------------------------
'''

from TestAPIs.StorageDomainAPIs import StorageDomainAPIs
import TestData.Disk.ITC08_SetUp as ModuleData
'''---------------------------------------------------------------------------------------------------
@note: PreData
---------------------------------------------------------------------------------------------------'''
disk_name = 'DISK-ITC080401'
sd_name = ModuleData.data1_nfs_name
sd_id = StorageDomainAPIs().getStorageDomainIdByName(sd_name)
disk_info = '''
<disk>
    <alias>%s</alias>
    <name>%s</name>
    <storage_domains>
        <storage_domain id = "%s"/>
    </storage_domains>
    <size>2147483648</size>
    <sparse>false</sparse>
    <interface>virtio</interface>
    <format>raw</format>
    <bootable>true</bootable>
    <shareable>true</shareable>
    <wipe_after_delete>false</wipe_after_delete>
</disk>