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)
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)
 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)
 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)
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)