예제 #1
0
 def test_CreateModuleTestEnv(self):
     '''
     @summary: 创建Disk模块测试环境
     '''
     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)。
     @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附加到NFS/ISCSI数据中心里(data2/Iso/Export处于游离状态)。
     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))
예제 #2
0
 def test_SetUp_ENV(self):
     '''
     @summary: 创建一个数据中心
     '''
     dcapi = DataCenterAPIs()
     # 创建1个数据中心(共享类型)
     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)
     capi = ClusterAPIs()
     # 创建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_host1_info))
     self.assertTrue(smart_create_host(self.dm.host2_name, self.dm.xml_host2_info))
  
     # 为数据中心创建Data域。
     @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、iso域附加到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.assertTrue(smart_attach_storage_domain(self.dm.dc_nfs_name, self.dm.iso1_name))
예제 #3
0
 def test_CreateCluster_Dup(self):
     '''
     @summary: 测试步骤
     @note: (1)创建一个重名的Cluster;
     @note: (2)操作失败,验证接口返回的状态码、提示信息是否正确。
     '''
     clusterapi = ClusterAPIs()
     LogPrint().info("Test: Create a cluster with dup name.")
     r = clusterapi.createCluster(self.dm.cluster_info)
     if r['status_code'] == self.dm.status_code:
         dict_actual = r['result']
         dict_expected = xmltodict.parse(self.dm.error_info)
         dictCompare = DictCompare()
         if dictCompare.isSubsetDict(dict_expected, dict_actual):
             LogPrint().info(
                 "PASS: Returned status code and info are CORRECT while creating cluster with dup name."
             )
             self.flag = True
         else:
             LogPrint().error(
                 "FAIL: Returned info are INCORRECT while creating cluster with dup name."
             )
             self.flag = False
     else:
         LogPrint().error("FAIL: Returned status code '%s' is WRONG. " %
                          r['status_code'])
         self.flag = False
     self.assertTrue(self.flag)
예제 #4
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)
예제 #5
0
    def test_Create_DcAndCluster(self):
        '''
        @summary: 创建3个数据中心和3个集群
        '''
        dcapi = DataCenterAPIs()
        capi = ClusterAPIs()
        # 创建1个共享数据中心
        LogPrint().info("Pre-Module-Test-1: Create DataCenter '%s'." %
                        self.dm.dc_name)
        self.assertTrue(
            dcapi.createDataCenter(self.dm.dc_info)['status_code'] ==
            self.dm.expected_status_code_create_dc)
        # 创建集群
        LogPrint().info(
            "Pre-Module-Test-2: Create Cluster '%s' in DataCenter '%s'." %
            (self.dm.cluster_name, self.dm.dc_name))
        self.assertTrue(
            capi.createCluster(self.dm.cluster_info)['status_code'] ==
            self.dm.expected_status_code_create_cluster)
        # 在数据中心中创建两个主机,并等待主机UP。
        @BaseTestCase.drive_data(self, self.dm.hosts_info_xml)
        def create_hosts(xml_host_info):
            LogPrint().info(
                "Pre-Module-Test-3: Create Host '%s' in Cluster '%s'." %
                (xmltodict.parse(xml_host_info)['host']['name'],
                 xmltodict.parse(xml_host_info)['host']['cluster']['name']))
            self.assertTrue(
                smart_create_host(
                    xmltodict.parse(xml_host_info)['host']['name'],
                    xml_host_info))

        create_hosts()

        # 为数据中心创建一个nfs类型Data域、ISO/Export域。
        @BaseTestCase.drive_data(self, self.dm.xml_datas_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()

        # 将创建的的Data域分别附加到数据中心。
        LogPrint().info(
            "Pre-Module-Test-5: Attach the data storages to data centers.")
        self.assertTrue(
            smart_attach_storage_domain(self.dm.dc_name,
                                        self.dm.data1_nfs_name))
        #         self.assertTrue(smart_attach_storage_domain(self.dm.dc_name, self.dm.data1_iscsi_name))
        self.assertTrue(
            smart_attach_storage_domain(self.dm.dc_name, self.dm.iso1_name))
        self.assertTrue(
            smart_attach_storage_domain(self.dm.dc_name, self.dm.export1_name))
예제 #6
0
    def test_SetUp_ENV(self):
        '''
        @summary: 创建一个数据中心
        '''
        dcapi = DataCenterAPIs()
        # 创建1个数据中心(共享类型)
        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)
        capi = ClusterAPIs()
        # 创建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_host1_info))
        self.assertTrue(
            smart_create_host(self.dm.host2_name, self.dm.xml_host2_info))

        # 为数据中心创建Data域。
        @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、iso域附加到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.assertTrue(
            smart_attach_storage_domain(self.dm.dc_nfs_name,
                                        self.dm.iso1_name))
예제 #7
0
    def test_Create_DcAndCluster(self):
        """
        @summary: 创建3个数据中心和3个集群
        """
        dcapi = DataCenterAPIs()
        capi = ClusterAPIs()
        # 创建1个共享数据中心
        LogPrint().info("Pre-Module-Test-1: Create DataCenter '%s'." % self.dm.dc_name)
        self.assertTrue(
            dcapi.createDataCenter(self.dm.dc_info)["status_code"] == self.dm.expected_status_code_create_dc
        )
        # 创建集群
        LogPrint().info(
            "Pre-Module-Test-2: Create Cluster '%s' in DataCenter '%s'." % (self.dm.cluster_name, self.dm.dc_name)
        )
        self.assertTrue(
            capi.createCluster(self.dm.cluster_info)["status_code"] == self.dm.expected_status_code_create_cluster
        )
        # 在数据中心中创建两个主机,并等待主机UP。
        @BaseTestCase.drive_data(self, self.dm.hosts_info_xml)
        def create_hosts(xml_host_info):
            LogPrint().info(
                "Pre-Module-Test-3: Create Host '%s' in Cluster '%s'."
                % (
                    xmltodict.parse(xml_host_info)["host"]["name"],
                    xmltodict.parse(xml_host_info)["host"]["cluster"]["name"],
                )
            )
            self.assertTrue(smart_create_host(xmltodict.parse(xml_host_info)["host"]["name"], xml_host_info))

        create_hosts()

        # 为数据中心创建一个nfs类型Data域、ISO/Export域。
        @BaseTestCase.drive_data(self, self.dm.xml_datas_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()

        # 将创建的的Data域分别附加到数据中心。
        LogPrint().info("Pre-Module-Test-5: Attach the data storages to data centers.")
        self.assertTrue(smart_attach_storage_domain(self.dm.dc_name, self.dm.data1_nfs_name))
        #         self.assertTrue(smart_attach_storage_domain(self.dm.dc_name, self.dm.data1_iscsi_name))
        self.assertTrue(smart_attach_storage_domain(self.dm.dc_name, self.dm.iso1_name))
        self.assertTrue(smart_attach_storage_domain(self.dm.dc_name, self.dm.export1_name))
예제 #8
0
class ITC02010301_CreateCluster(BaseTestCase):
    '''
    @summary: ITC-02集群管理-01集群操作-03创建一个集群-01创建成功
    '''
    def setUp(self):
        '''
        @summary: 测试用例执行前的环境初始化(前提)
        '''
        # 初始化测试数据
        self.dm = super(self.__class__, self).setUp()
        self.clusterapi = ClusterAPIs()

    def test_CreateCluster(self):
        '''
        @summary: 测试步骤
        @note: (1)创建一个集群;
        @note: (2)操作成功,验证接口返回的状态码、集群信息是否正确。
        '''
        LogPrint().info("Test: Create a cluster '%s'." % self.dm.cluster_name)
        r = self.clusterapi.createCluster(self.dm.cluster_info)
        if r['status_code'] == self.dm.status_code:
            dict_actual = r['result']
            dict_expected = xmltodict.parse(self.dm.cluster_info)
            dictCompare = DictCompare()
            if dictCompare.isSubsetDict(dict_expected, dict_actual):
                LogPrint().info("PASS: Create Cluster '%s' SUCCESS." %
                                self.dm.cluster_name)
                self.flag = True
            else:
                LogPrint().error("FAIL: Create Cluster '%s'  INCORRECT." %
                                 self.dm.cluster_name)
                self.flag = False
        else:
            LogPrint().error("FAIL: Returned status code '%s' is WRONG." %
                             r['status_code'])
            self.flag = False
        self.assertTrue(self.flag)

    def tearDown(self):
        '''
        @summary: 测试结束后的资源清理(恢复初始环境)
        '''
        LogPrint().info("Post-Test: Delete cluster '%s'." %
                        self.dm.cluster_name)
        self.assertTrue(smart_delete_cluster(self.dm.cluster_name))
예제 #9
0
class ITC02010301_CreateCluster(BaseTestCase):
    """
    @summary: ITC-02集群管理-01集群操作-03创建一个集群-01创建成功
    """

    def setUp(self):
        """
        @summary: 测试用例执行前的环境初始化(前提)
        """
        # 初始化测试数据
        self.dm = super(self.__class__, self).setUp()
        self.clusterapi = ClusterAPIs()

    def test_CreateCluster(self):
        """
        @summary: 测试步骤
        @note: (1)创建一个集群;
        @note: (2)操作成功,验证接口返回的状态码、集群信息是否正确。
        """
        LogPrint().info("Test: Create a cluster '%s'." % self.dm.cluster_name)
        r = self.clusterapi.createCluster(self.dm.cluster_info)
        if r["status_code"] == self.dm.status_code:
            dict_actual = r["result"]
            dict_expected = xmltodict.parse(self.dm.cluster_info)
            dictCompare = DictCompare()
            if dictCompare.isSubsetDict(dict_expected, dict_actual):
                LogPrint().info("PASS: Create Cluster '%s' SUCCESS." % self.dm.cluster_name)
                self.flag = True
            else:
                LogPrint().error("FAIL: Create Cluster '%s'  INCORRECT." % self.dm.cluster_name)
                self.flag = False
        else:
            LogPrint().error("FAIL: Returned status code '%s' is WRONG." % r["status_code"])
            self.flag = False
        self.assertTrue(self.flag)

    def tearDown(self):
        """
        @summary: 测试结束后的资源清理(恢复初始环境)
        """
        LogPrint().info("Post-Test: Delete cluster '%s'." % self.dm.cluster_name)
        self.assertTrue(smart_delete_cluster(self.dm.cluster_name))
예제 #10
0
 def test_CreateCluster_Dup(self):
     """
     @summary: 测试步骤
     @note: (1)创建一个重名的Cluster;
     @note: (2)操作失败,验证接口返回的状态码、提示信息是否正确。
     """
     clusterapi = ClusterAPIs()
     LogPrint().info("Test: Create a cluster with dup name.")
     r = clusterapi.createCluster(self.dm.cluster_info)
     if r["status_code"] == self.dm.status_code:
         dict_actual = r["result"]
         dict_expected = xmltodict.parse(self.dm.error_info)
         dictCompare = DictCompare()
         if dictCompare.isSubsetDict(dict_expected, dict_actual):
             LogPrint().info("PASS: Returned status code and info are CORRECT while creating cluster with dup name.")
             self.flag = True
         else:
             LogPrint().error("FAIL: Returned info are INCORRECT while creating cluster with dup name.")
             self.flag = False
     else:
         LogPrint().error("FAIL: Returned status code '%s' is WRONG. " % r["status_code"])
         self.flag = False
     self.assertTrue(self.flag)
예제 #11
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)