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))
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))
def test_attachNetworktoCluster(self): ''' @summary: 测试用例执行步骤 @note: (1)测试将网络附加到集群 @note: (2)操作成功,验证返回状态码,验证网络是否附加到集群 ''' LogPrint().info("Test: Attach Network %s to Cluster %s. " % (self.dm.nw_name, self.dm.cluster_name)) clusterapi = ClusterAPIs() r = clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info) print r if r['status_code'] == self.dm.status_code: cluster_id = r['result']['network']['cluster']['@id'] cluster_name = clusterapi.getClusterNameById(cluster_id) if cluster_name == self.dm.cluster_name: LogPrint().info( "PASS: Attach Network %s to Cluster %s SUCCESS." % (self.dm.nw_name, self.dm.cluster_name)) # return True else: LogPrint().error( "FAIL: Attach Network %s to Cluster %s FAIL." % (self.dm.nw_name, self.dm.cluster_name)) self.flag = False else: LogPrint().error("FAIL: Returned status code is WRONG. ") self.flag = False self.assertTrue(self.flag)
class ITC020202_GetClusterNetworkInfo(BaseTestCase): ''' @summary: ITC-02集群管理-01集群操作-02获取指定集群的网络信息 ''' def setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # step1:创建一个集群 LogPrint().info("Pre-Test-1: Create cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue( smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) # step2:创建一个逻辑网络 LogPrint().info("Pre-Test-2: Create network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_create_network(self.dm.nw_info, self.dm.nw_name)) # step3:附加该网络到集群上 LogPrint().info( "Pre-Test-3: Attach network '%s'to cluster '%s' for this TC." % (self.dm.nw_name, self.dm.cluster_name)) self.clusterapi = ClusterAPIs() self.clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info) def test_GetClusterNetworkInfo(self): ''' @summary: 测试用例执行步骤 @note: 操作成功,验证网络信息 ''' LogPrint().info("Test: Get the cluster %s's network info. " % self.dm.cluster_name) r = self.clusterapi.getClusterNetworkInfo(self.dm.cluster_name, self.dm.nw_name) dict_actual = r dict_expected = xmltodict.parse(self.dm.nw_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get ClusterNetwork '%s' info SUCCESS." % self.dm.nw_name) # return True else: LogPrint().error("FAIL: Returned message is WRONG. ") self.flag = False self.assertTrue(self.flag) def tearDown(self): ''' @summary: 测试结束后的资源清理(恢复初始环境) ''' LogPrint().info("Post-Test-1: Delete network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_delete_network(self.dm.nw_name, self.dm.dc_name)) LogPrint().info("Post-Test-2: Delete cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_delete_cluster(self.dm.cluster_name))
def test_DeleteCluster(self): ''' @summary: 测试用例执行步骤 @note: (1)删除一个干净的集群; @note: (2)操作成功,验证接口返回的状态码是否正确,验证被删除的集群不再存在。 ''' clusterapi = ClusterAPIs() # 测试1:获取集群的信息,并与期望结果进行对比 LogPrint().info("Test: Delete the clean cluster '%s'." % self.dm.cluster_name) r = clusterapi.delCluster(self.dm.cluster_name) if r['status_code'] == self.dm.status_code: # print self.clusterapi.searchClusterByName(self.dm.cluster_name)['result']['clusters'] if not clusterapi.searchClusterByName( self.dm.cluster_name)['result']['clusters']: LogPrint().info("PASS: Delete Cluster '%s' info SUCCESS." % self.dm.cluster_name) self.flag = True else: LogPrint().error("FAIL: The Cluster '%s' is still exist ." % 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 test_DeleteCluster_host(self): ''' @summary: 测试用例执行步骤 @note: (1)删除包含主机的集群 @note: (2)操作失败,验证返回状态码,验证报错信息 ''' clusterapi = ClusterAPIs() LogPrint().info("Test: Delete cluster %s." % self.dm.cluster_name) r = clusterapi.delCluster(self.dm.cluster_name) # print r if r['status_code'] == self.dm.status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(self.dm.expected_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: Returned status code and messages are CORRECT.") self.flag = True else: LogPrint().error("FAIL: Returned message is INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Returned status code is wrong. ") self.flag = False self.assertTrue(self.flag)
def test_UpdateCluster_host(self): ''' @summary: 测试步骤 @note: (1) @note: (2) ''' clusterapi = ClusterAPIs() LogPrint().info( "Test: Edit cluster's name while there are hosts in cluster.") r = clusterapi.updateCluster(self.dm.cluster_name, self.dm.cluster_info_new) if r['status_code'] == self.dm.status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(self.dm.cluster_info_new) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: ITC0201040203_test_UpdateCluster_host_name SUCCESS." ) self.flag = True else: LogPrint().error( "FAIL: ITC0201040203_test_UpdateCluster_host_name. Error-info INCORRECT." ) self.flag = False else: LogPrint().error( "FAIL: ITC0201040203_test_UpdateCluster_host_name.Status_code is wrong. " ) self.flag = False self.assertTrue(self.flag)
def test_TearDown(self): dcapi = DataCenterAPIs() capi = ClusterAPIs() time.sleep(30) # Step1:将data1存储域设置为Maintenance状态 LogPrint().info("Post-Module-Test-1: 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)) # Step2:删除数据中心dc1(非强制,之后存储域变为Unattached状态) if dcapi.searchDataCenterByName(self.dm.dc_nfs_name)['result']['data_centers']: LogPrint().info("Post-Module-Test-2: 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) # Step3:删除4个Unattached状态存储域(data1/data2/iso1/export1) LogPrint().info("Post-Module-Test-3: 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) # Step4:删除主机(host1) LogPrint().info("Post-Module-Test-6: Delete host '%s'." % self.dm.host1_name) self.assertTrue(smart_del_host(self.dm.host1_name, self.dm.xml_del_host_option)) # Step5:删除集群cluster1 if capi.searchClusterByName(self.dm.cluster_nfs_name)['result']['clusters']: LogPrint().info("Post-Module-Test-5: 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)
def test_UpdateCluster_host(self): ''' @summary: 测试步骤 @note: (1)更改含有主机的集群CPU类型; @note: (2)操作成功,验证接口返回的状态码、相关信息是否正确。 ''' clusterapi = ClusterAPIs() LogPrint().info( "Test: Edit cluster's cpu type if there are hosts in this cluster." ) r = clusterapi.updateCluster(self.dm.cluster_name, self.dm.cluster_info_new) if r['status_code'] == self.dm.status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(self.dm.expected_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: ITC0201040201_test_UpdateCluster_host_cputype SUCCESS." ) self.flag = True else: LogPrint().error( "FAIL: ITC0201040201_test_UpdateCluster_host_cputype .Error-info INCORRECT." ) self.flag = False else: LogPrint().error("FAIL: Returned status code '%s' is WRONG." % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_UpdateCluster_host(self): ''' @summary: 测试步骤 @note: (1) @note: (2) ''' clusterapi = ClusterAPIs() LogPrint().info( "Test: Improve cluster's CPU level while there are hosts in cluster." ) r = clusterapi.updateCluster(self.dm.cluster_name, self.dm.cluster_info_new) if r['status_code'] == self.dm.status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(self.dm.expected_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: ITC0201040202_test_UpdateCluster_host_upcpu SUCCESS." ) self.flag = True else: LogPrint().error( "FAIL: ITC0201040202_test_UpdateCluster_host_upcpu. Error-info INCORRECT." ) self.flag = False else: LogPrint().error("FAIL: Returned tatus_code '%s' is WRONG." % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_attachNetworktoCluster(self): """ @summary: 测试用例执行步骤 @note: (1)测试将网络附加到集群 @note: (2)操作成功,验证返回状态码,验证网络是否附加到集群 """ LogPrint().info("Test: Attach Network %s to Cluster %s. " % (self.dm.nw_name, self.dm.cluster_name)) clusterapi = ClusterAPIs() r = clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info) print r if r["status_code"] == self.dm.status_code: cluster_id = r["result"]["network"]["cluster"]["@id"] cluster_name = clusterapi.getClusterNameById(cluster_id) if cluster_name == self.dm.cluster_name: LogPrint().info( "PASS: Attach Network %s to Cluster %s SUCCESS." % (self.dm.nw_name, self.dm.cluster_name) ) # return True else: LogPrint().error( "FAIL: Attach Network %s to Cluster %s FAIL." % (self.dm.nw_name, self.dm.cluster_name) ) self.flag = False else: LogPrint().error("FAIL: Returned status code is WRONG. ") self.flag = False self.assertTrue(self.flag)
def setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' # 初始化测试数据 self.dm = super(self.__class__, self).setUp() self.clusterapi = ClusterAPIs()
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)
def test_GetClusterInfo(self): ''' @summary: 测试用例执行步骤 @note: (1)获取指定集群的信息; @note: (2)验证接口返回的状态码、集群信息是否正确。 ''' # 测试1:获取集群的信息,并与期望结果进行对比 self.clusterapi = ClusterAPIs() LogPrint().info("Test: Get cluster's ('%s') info." % self.dm.cluster_name) r = self.clusterapi.getClusterInfo(self.dm.cluster_name) 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: Get Cluster '%s' info SUCCESS." % self.dm.cluster_name) self.flag = True else: LogPrint().error("FAIL: Get Cluster '%s' info INCORRECT." % self.dm.cluster_name) self.flag = False else: LogPrint().error( "FAIL: Get Cluster '%s' info FAILED. Returned status code '%s' is WRONG." % (self.dm.cluster_name, r['status_code'])) self.flag = False self.assertTrue(self.flag)
class ITC020204_detachNetworkFromCluster(BaseTestCase): ''' @summary: ITC-02集群管理-02集群网络操作-04将网络从集群分离 ''' def setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # step1:创建一个集群 LogPrint().info("Pre-Test-1: Create cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue( smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) # step2:创建一个逻辑网络 LogPrint().info("Pre-Test-2: Create network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_create_network(self.dm.nw_info, self.dm.nw_name)) # step3:附加该网络到集群上 LogPrint().info( "Pre-Test-3: Attach network '%s'to cluster '%s' for this TC." % (self.dm.nw_name, self.dm.cluster_name)) self.clusterapi = ClusterAPIs() self.clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info) def test_detachNetworkFromCluster(self): ''' @summary: 测试用例执行步骤 @note: 测试将网络从集群中分离 @note: 操作成功,验证返回状态码,验证集群中是否有该网络 ''' LogPrint().info("Test: Detach Network %s from Cluster %s. " % (self.dm.nw_name, self.dm.cluster_name)) r = self.clusterapi.detachNetworkFromCluster(self.dm.cluster_name, self.dm.nw_name) if r['status_code'] == self.dm.status_code: #检查集群中网络是否存在 if not self.clusterapi.getClusterNetworkInfo( self.dm.cluster_name, self.dm.nw_name): LogPrint().info( "PASS: Detach Network %s from Cluster %s SUCCESS. " % (self.dm.nw_name, self.dm.cluster_name)) else: LogPrint().info("FAIL: Cluster %s still has Network %s. " % (self.dm.cluster_name, self.dm.nw_name)) else: LogPrint().info("FAIL: Returned status code is WRONG.") def tearDown(self): ''' @summary: 测试结束后的资源清理(恢复初始环境) ''' LogPrint().info("Post-Test-1: Delete network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_delete_network(self.dm.nw_name, self.dm.dc_name)) LogPrint().info("Post-Test-2: Delete cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_delete_cluster(self.dm.cluster_name))
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)
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))
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))
class ITC020205_UpdateNetworkofCluster(BaseTestCase): """ @summary: ITC-02集群管理-02集群网络操作-05更新集群网络信息 """ def setUp(self): """ @summary: 测试用例执行前的环境初始化(前提) """ # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # step1:创建一个集群 LogPrint().info("Pre-Test-1: Create cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) # step2:创建一个逻辑网络 LogPrint().info("Pre-Test-2: Create network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_create_network(self.dm.nw_info, self.dm.nw_name)) # step3:附加该网络到集群上 LogPrint().info( "Pre-Test-3: Attach network '%s'to cluster '%s' for this TC." % (self.dm.nw_name, self.dm.cluster_name) ) self.clusterapi = ClusterAPIs() self.clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info) def test_UpdateNetworkofCluster(self): """ @summary: 测试用例执行步骤 @note: 更新集群网络信息 @note: 操作成功,验证返回状态码,验证更新信息是否正确 """ LogPrint().info("Test: Update Network %s of Cluster %s. " % (self.dm.nw_name, self.dm.cluster_name)) r = self.clusterapi.updateNetworkOfCluster(self.dm.cluster_name, self.dm.nw_name, self.dm.nw_info_new) if r["status_code"] == self.dm.status_code: dict_actual = self.clusterapi.getClusterNetworkInfo(self.dm.cluster_name, self.dm.nw_name) # dict_expected = {'network':xmltodict.parse(self.dm.nw_info_new)['network']} dict_expected = xmltodict.parse(self.dm.nw_info_new) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: Detach Network %s from Cluster %s SUCCESS. " % (self.dm.nw_name, self.dm.cluster_name) ) else: LogPrint().info("FAIL: Returned message is WRONG. ") else: LogPrint().info("FAIL: Returned status code is WRONG.") def tearDown(self): """ @summary: 测试结束后的资源清理(恢复初始环境) """ LogPrint().info("Post-Test-1: Delete network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_delete_network(self.dm.nw_name, self.dm.dc_name)) LogPrint().info("Post-Test-2: Delete cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_delete_cluster(self.dm.cluster_name))
class ITC020204_detachNetworkFromCluster(BaseTestCase): """ @summary: ITC-02集群管理-02集群网络操作-04将网络从集群分离 """ def setUp(self): """ @summary: 测试用例执行前的环境初始化(前提) """ # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # step1:创建一个集群 LogPrint().info("Pre-Test-1: Create cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) # step2:创建一个逻辑网络 LogPrint().info("Pre-Test-2: Create network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_create_network(self.dm.nw_info, self.dm.nw_name)) # step3:附加该网络到集群上 LogPrint().info( "Pre-Test-3: Attach network '%s'to cluster '%s' for this TC." % (self.dm.nw_name, self.dm.cluster_name) ) self.clusterapi = ClusterAPIs() self.clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info) def test_detachNetworkFromCluster(self): """ @summary: 测试用例执行步骤 @note: 测试将网络从集群中分离 @note: 操作成功,验证返回状态码,验证集群中是否有该网络 """ LogPrint().info("Test: Detach Network %s from Cluster %s. " % (self.dm.nw_name, self.dm.cluster_name)) r = self.clusterapi.detachNetworkFromCluster(self.dm.cluster_name, self.dm.nw_name) if r["status_code"] == self.dm.status_code: # 检查集群中网络是否存在 if not self.clusterapi.getClusterNetworkInfo(self.dm.cluster_name, self.dm.nw_name): LogPrint().info( "PASS: Detach Network %s from Cluster %s SUCCESS. " % (self.dm.nw_name, self.dm.cluster_name) ) else: LogPrint().info("FAIL: Cluster %s still has Network %s. " % (self.dm.cluster_name, self.dm.nw_name)) else: LogPrint().info("FAIL: Returned status code is WRONG.") def tearDown(self): """ @summary: 测试结束后的资源清理(恢复初始环境) """ LogPrint().info("Post-Test-1: Delete network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_delete_network(self.dm.nw_name, self.dm.dc_name)) LogPrint().info("Post-Test-2: Delete cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_delete_cluster(self.dm.cluster_name))
class ITC020202_GetClusterNetworkInfo(BaseTestCase): """ @summary: ITC-02集群管理-01集群操作-02获取指定集群的网络信息 """ def setUp(self): """ @summary: 测试用例执行前的环境初始化(前提) """ # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # step1:创建一个集群 LogPrint().info("Pre-Test-1: Create cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) # step2:创建一个逻辑网络 LogPrint().info("Pre-Test-2: Create network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_create_network(self.dm.nw_info, self.dm.nw_name)) # step3:附加该网络到集群上 LogPrint().info( "Pre-Test-3: Attach network '%s'to cluster '%s' for this TC." % (self.dm.nw_name, self.dm.cluster_name) ) self.clusterapi = ClusterAPIs() self.clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info) def test_GetClusterNetworkInfo(self): """ @summary: 测试用例执行步骤 @note: 操作成功,验证网络信息 """ LogPrint().info("Test: Get the cluster %s's network info. " % self.dm.cluster_name) r = self.clusterapi.getClusterNetworkInfo(self.dm.cluster_name, self.dm.nw_name) dict_actual = r dict_expected = xmltodict.parse(self.dm.nw_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Get ClusterNetwork '%s' info SUCCESS." % self.dm.nw_name) # return True else: LogPrint().error("FAIL: Returned message is WRONG. ") self.flag = False self.assertTrue(self.flag) def tearDown(self): """ @summary: 测试结束后的资源清理(恢复初始环境) """ LogPrint().info("Post-Test-1: Delete network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_delete_network(self.dm.nw_name, self.dm.dc_name)) LogPrint().info("Post-Test-2: Delete cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_delete_cluster(self.dm.cluster_name))
def test_TearDown(self): ''' @summary: 模块级测试资源清理 ''' dcapi = DataCenterAPIs() capi = ClusterAPIs() # Step2:将export和iso存储域设置为Maintenance状态,然后从数据中心分离 LogPrint().info("Post-Module-Test-2-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-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-2-3: Deactivate storage domains '%s'." % self.dm.iso1_name) self.assertTrue(smart_deactive_storage_domain(self.dm.dc_nfs_name, self.dm.iso1_name)) LogPrint().info("Post-Module-Test-2-4: Detach storage domains '%s'." % self.dm.iso1_name) self.assertTrue(smart_detach_storage_domain(self.dm.dc_nfs_name, self.dm.iso1_name)) # Step3:将data2存储域设置为Maintenance状态,然后从数据中心分离 LogPrint().info("Post-Module-Test-3-1: 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-3-2: 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)) # Step4:将data1存储域设置为Maintenance状态 LogPrint().info("Post-Module-Test-4: 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)) # LogPrint().info("Post-Module-Test-3-2: Detach data storage domains '%s'." % self.dm.data1_nfs_name) # self.assertTrue(smart_detach_storage_domain(self.dm.dc_nfs_name, self.dm.data1_nfs_name)) # Step5:删除数据中心dc1(非强制,之后存储域变为Unattached状态) if dcapi.searchDataCenterByName(self.dm.dc_nfs_name)['result']['data_centers']: LogPrint().info("Post-Module-Test-5: 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) # Step6:删除4个Unattached状态存储域(data1/data2/export1/iso) LogPrint().info("Post-Module-Test-6: Delete all unattached storage domains.") dict_sd_to_host = [self.dm.data1_nfs_name, self.dm.data2_nfs_name, self.dm.iso1_name, self.dm.export1_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) # Step7:删除主机(host1) LogPrint().info("Post-Module-Test-7: Delete host '%s'." % self.dm.host1_name) self.assertTrue(smart_del_host(self.dm.host1_name, self.dm.xml_del_host_option)) LogPrint().info("Post-Module-Test-7: Delete host '%s'." % self.dm.host2_name) self.assertTrue(smart_del_host(self.dm.host2_name, self.dm.xml_del_host_option)) # Step8:删除集群cluster1 if capi.searchClusterByName(self.dm.cluster_nfs_name)['result']['clusters']: LogPrint().info("Post-Module-Test-8: 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)
def test_GetClustersList(self): """ @summary: 测试步骤 @note: (1)获取全部集群列表; @note: (2)验证接口返回的状态码是否正确。 """ clusterapi = ClusterAPIs() LogPrint().info("Test: Get all clusters list.") r = clusterapi.getClustersList() if r["status_code"] == 200: LogPrint().info("PASS: Get Clusters list SUCCESS.") self.flag = True else: LogPrint().error('FAIL: Get Clusters list FAIL. Returned status code "%s" is WRONG.' % r["status_code"]) self.flag = False self.assertTrue(self.flag)
def test_GetClusterNetworkList(self): """ @summary: 测试用例执行步骤 @note: (1)获取集群的网络列表 @note: (2)操作成功,验证返回状态码 """ clusterapi = ClusterAPIs() LogPrint().info("Test: Get the cluster %s's network list. " % self.dm.cluster_name) r = clusterapi.getClusterNetworkList(self.dm.cluster_name) if r["status_code"] == self.dm.status_code: LogPrint().info("PASS: Get Cluster %s Network list SUCCESS." % self.dm.cluster_name) self.flag = True else: LogPrint().error("FAIL: Get Cluster %s Network list FAIL." % self.dm.cluster_name) self.flag = False self.assertTrue(self.flag)
def test_CreateClusterNoRequired(self): ''' @summary: 测试步骤 @note: (1)创建一个集群,缺少必填参数; @note: (2)操作失败,验证接口返回的状态码、提示信息是否正确。 ''' clusterapi = ClusterAPIs() self.expected_result_index = 0 # 使用数据驱动,根据测试数据文件循环创建多个数据中心 @BaseTestCase.drive_data(self, self.dm.cluster_info) def do_test(xml_info): self.flag = True r = clusterapi.createCluster(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: Returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: Returned messages are INCORRECT.") self.flag = False else: LogPrint().error( "FAIL: 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()
def test_UpdateCluster(self): ''' @summary: 测试步骤 ''' clusterapi = ClusterAPIs() self.expected_result_index = 0 # 使用数据驱动,根据测试数据文件循环创建多个数据中心 @BaseTestCase.drive_data(self, self.dm.cluster_info_new) def do_test(xml_info): self.flag = True r = clusterapi.updateCluster(self.dm.cluster_name, xml_info) if r['status_code'] == self.dm.status_code: dict_actual = r['result'] dict_expected = xmltodict.parse(xml_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: ITC02010401_UpdateCluster_nohost SUCCESS.") self.flag = True else: LogPrint().error( "FAIL: ITC02010401_UpdateCluster_nohost.Error-info INCORRECT." ) self.flag = False else: LogPrint().error( "FAIL: ITC02010401_UpdateCluster_nohost FAILED.Status-code WRONG. " ) self.flag = False self.assertTrue(self.flag) self.expected_result_index += 1 do_test()
def test_GetClusterInfo(self): """ @summary: 测试用例执行步骤 @note: (1)获取指定集群的信息; @note: (2)验证接口返回的状态码、集群信息是否正确。 """ # 测试1:获取集群的信息,并与期望结果进行对比 self.clusterapi = ClusterAPIs() LogPrint().info("Test: Get cluster's ('%s') info." % self.dm.cluster_name) r = self.clusterapi.getClusterInfo(self.dm.cluster_name) 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: Get Cluster '%s' info SUCCESS." % self.dm.cluster_name) self.flag = True else: LogPrint().error("FAIL: Get Cluster '%s' info INCORRECT." % self.dm.cluster_name) self.flag = False else: LogPrint().error( "FAIL: Get Cluster '%s' info FAILED. Returned status code '%s' is WRONG." % (self.dm.cluster_name, r["status_code"]) ) self.flag = False self.assertTrue(self.flag)
def setUp(self): """ @summary: 测试用例执行前的环境初始化(前提) """ # 初始化测试数据 self.dm = super(self.__class__, self).setUp() self.clusterapi = ClusterAPIs()
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))
def test_GetClustersList(self): ''' @summary: 测试步骤 @note: (1)获取全部集群列表; @note: (2)验证接口返回的状态码是否正确。 ''' clusterapi = ClusterAPIs() LogPrint().info("Test: Get all clusters list.") r = clusterapi.getClustersList() if r['status_code'] == 200: LogPrint().info('PASS: Get Clusters list SUCCESS.') self.flag = True else: LogPrint().error( 'FAIL: Get Clusters list FAIL. Returned status code "%s" is WRONG.' % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_TearDown(self): dcapi = DataCenterAPIs() capi = ClusterAPIs() # Step1:将ISO域和Export域设置为Maintenance状态 LogPrint().info("Post-Module-Test-1: Deactivate ISO and Export storage domains.") self.assertTrue(smart_deactive_storage_domain(self.dm.dc_name, self.dm.iso1_name)) self.assertTrue(smart_deactive_storage_domain(self.dm.dc_name, self.dm.export1_name)) # Step2:将ISO域和Export域从对应的数据中心分离(detach) LogPrint().info("Post-Module-Test-2: Deattch ISO and Export storage domains.") self.assertTrue(smart_detach_storage_domain(self.dm.dc_name, self.dm.iso1_name)) self.assertTrue(smart_detach_storage_domain(self.dm.dc_name, self.dm.export1_name)) # Step3:将Data存储域设置为Maintenance状态 LogPrint().info("Post-Module-Test-3: Deactivate all data storage domains.") self.assertTrue(smart_deactive_storage_domain(self.dm.dc_name, self.dm.data1_nfs_name)) # self.assertTrue(smart_deactive_storage_domain(self.dm.dc_name, self.dm.data1_iscsi_name)) # 删除3个数据中心(非强制,之后存储域变为Unattached状态) if dcapi.searchDataCenterByName(self.dm.dc_name): LogPrint().info("Post-Module-Test-4: Delete DataCenter '%s'." % self.dm.dc_name) self.assertTrue(dcapi.delDataCenter(self.dm.dc_name)["status_code"] == self.dm.expected_status_code_del_dc) # 删除3个Unattached状态的Data存储域和ISO/Export域(如果没有配置FC,则删除2个) LogPrint().info("Post-Module-Test-5: Delete all storage domains.") dict_sd_to_host = { self.dm.data1_nfs_name: self.dm.host1_name, self.dm.iso1_name: self.dm.host1_name, self.dm.export1_name: self.dm.host1_name, } for sd in dict_sd_to_host: smart_del_storage_domain(sd, self.dm.xml_del_sd_option, host_name=dict_sd_to_host[sd]) # 删除主机(host1和host4) LogPrint().info("Post-Module-Test-6: Delete all hosts.") for host_name in [self.dm.host1_name, self.dm.host4_name]: self.assertTrue(smart_del_host(host_name, self.dm.xml_del_host_option)) # 删除集群 if capi.searchClusterByName(self.dm.cluster_name): LogPrint().info("Post-Module-Test-7: Delete Cluster '%s'." % self.dm.cluster_name) self.assertTrue(capi.delCluster(self.dm.cluster_name)["status_code"] == self.dm.expected_status_code_del_dc)
def test_GetClusterNetworkList(self): ''' @summary: 测试用例执行步骤 @note: (1)获取集群的网络列表 @note: (2)操作成功,验证返回状态码 ''' clusterapi = ClusterAPIs() LogPrint().info("Test: Get the cluster %s's network list. " % self.dm.cluster_name) r = clusterapi.getClusterNetworkList(self.dm.cluster_name) if r['status_code'] == self.dm.status_code: LogPrint().info('PASS: Get Cluster %s Network list SUCCESS.' % self.dm.cluster_name) self.flag = True else: LogPrint().error('FAIL: Get Cluster %s Network list FAIL.' % self.dm.cluster_name) self.flag = False self.assertTrue(self.flag)
class ITC020102_GetClusterInfo(BaseTestCase): ''' @summary: ITC-02集群管理-01集群操作-02获取指定集群信息 ''' def setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # 前提1: 创建一个集群 LogPrint().info("Pre-Test: Create a cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue( smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) def test_GetClusterInfo(self): ''' @summary: 测试用例执行步骤 @note: (1)获取指定集群的信息; @note: (2)验证接口返回的状态码、集群信息是否正确。 ''' # 测试1:获取集群的信息,并与期望结果进行对比 self.clusterapi = ClusterAPIs() LogPrint().info("Test: Get cluster's ('%s') info." % self.dm.cluster_name) r = self.clusterapi.getClusterInfo(self.dm.cluster_name) 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: Get Cluster '%s' info SUCCESS." % self.dm.cluster_name) self.flag = True else: LogPrint().error("FAIL: Get Cluster '%s' info INCORRECT." % self.dm.cluster_name) self.flag = False else: LogPrint().error( "FAIL: Get Cluster '%s' info FAILED. Returned status code '%s' is WRONG." % (self.dm.cluster_name, 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))
def setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # step1:创建一个集群 LogPrint().info("Pre-Test-1: Create cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue( smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) # step2:创建一个逻辑网络 LogPrint().info("Pre-Test-2: Create network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_create_network(self.dm.nw_info, self.dm.nw_name)) # step3:附加该网络到集群上 LogPrint().info( "Pre-Test-3: Attach network '%s'to cluster '%s' for this TC." % (self.dm.nw_name, self.dm.cluster_name)) self.clusterapi = ClusterAPIs() self.clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info)
def test_DeleteCluster(self): """ @summary: 测试用例执行步骤 @note: (1)删除一个干净的集群; @note: (2)操作成功,验证接口返回的状态码是否正确,验证被删除的集群不再存在。 """ clusterapi = ClusterAPIs() # 测试1:获取集群的信息,并与期望结果进行对比 LogPrint().info("Test: Delete the clean cluster '%s'." % self.dm.cluster_name) r = clusterapi.delCluster(self.dm.cluster_name) if r["status_code"] == self.dm.status_code: # print self.clusterapi.searchClusterByName(self.dm.cluster_name)['result']['clusters'] if not clusterapi.searchClusterByName(self.dm.cluster_name)["result"]["clusters"]: LogPrint().info("PASS: Delete Cluster '%s' info SUCCESS." % self.dm.cluster_name) self.flag = True else: LogPrint().error("FAIL: The Cluster '%s' is still exist ." % 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 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)
def test_UpdateCluster_host(self): """ @summary: 测试步骤 @note: (1) @note: (2) """ clusterapi = ClusterAPIs() LogPrint().info("Test: Edit cluster's name while there are hosts in cluster.") r = clusterapi.updateCluster(self.dm.cluster_name, self.dm.cluster_info_new) if r["status_code"] == self.dm.status_code: dict_actual = r["result"] dict_expected = xmltodict.parse(self.dm.cluster_info_new) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: ITC0201040203_test_UpdateCluster_host_name SUCCESS.") self.flag = True else: LogPrint().error("FAIL: ITC0201040203_test_UpdateCluster_host_name. Error-info INCORRECT.") self.flag = False else: LogPrint().error("FAIL: ITC0201040203_test_UpdateCluster_host_name.Status_code is wrong. ") self.flag = False self.assertTrue(self.flag)
def test_UpdateCluster_host(self): """ @summary: 测试步骤 @note: (1) @note: (2) """ clusterapi = ClusterAPIs() LogPrint().info("Test: Improve cluster's CPU level while there are hosts in cluster.") r = clusterapi.updateCluster(self.dm.cluster_name, self.dm.cluster_info_new) if r["status_code"] == self.dm.status_code: dict_actual = r["result"] dict_expected = xmltodict.parse(self.dm.expected_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: ITC0201040202_test_UpdateCluster_host_upcpu SUCCESS.") self.flag = True else: LogPrint().error("FAIL: ITC0201040202_test_UpdateCluster_host_upcpu. Error-info INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Returned tatus_code '%s' is WRONG." % r["status_code"]) self.flag = False self.assertTrue(self.flag)
def test_UpdateCluster_host(self): """ @summary: 测试步骤 @note: (1)更改含有主机的集群CPU类型; @note: (2)操作成功,验证接口返回的状态码、相关信息是否正确。 """ clusterapi = ClusterAPIs() LogPrint().info("Test: Edit cluster's cpu type if there are hosts in this cluster.") r = clusterapi.updateCluster(self.dm.cluster_name, self.dm.cluster_info_new) if r["status_code"] == self.dm.status_code: dict_actual = r["result"] dict_expected = xmltodict.parse(self.dm.expected_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: ITC0201040201_test_UpdateCluster_host_cputype SUCCESS.") self.flag = True else: LogPrint().error("FAIL: ITC0201040201_test_UpdateCluster_host_cputype .Error-info INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Returned status code '%s' is WRONG." % r["status_code"]) self.flag = False self.assertTrue(self.flag)
class ITC020102_GetClusterInfo(BaseTestCase): """ @summary: ITC-02集群管理-01集群操作-02获取指定集群信息 """ def setUp(self): """ @summary: 测试用例执行前的环境初始化(前提) """ # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # 前提1: 创建一个集群 LogPrint().info("Pre-Test: Create a cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) def test_GetClusterInfo(self): """ @summary: 测试用例执行步骤 @note: (1)获取指定集群的信息; @note: (2)验证接口返回的状态码、集群信息是否正确。 """ # 测试1:获取集群的信息,并与期望结果进行对比 self.clusterapi = ClusterAPIs() LogPrint().info("Test: Get cluster's ('%s') info." % self.dm.cluster_name) r = self.clusterapi.getClusterInfo(self.dm.cluster_name) 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: Get Cluster '%s' info SUCCESS." % self.dm.cluster_name) self.flag = True else: LogPrint().error("FAIL: Get Cluster '%s' info INCORRECT." % self.dm.cluster_name) self.flag = False else: LogPrint().error( "FAIL: Get Cluster '%s' info FAILED. Returned status code '%s' is WRONG." % (self.dm.cluster_name, 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))
def test_DeleteCluster_host(self): """ @summary: 测试用例执行步骤 @note: (1)删除包含主机的集群 @note: (2)操作失败,验证返回状态码,验证报错信息 """ clusterapi = ClusterAPIs() LogPrint().info("Test: Delete cluster %s." % self.dm.cluster_name) r = clusterapi.delCluster(self.dm.cluster_name) # print r if r["status_code"] == self.dm.status_code: dict_actual = r["result"] dict_expected = xmltodict.parse(self.dm.expected_info) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info("PASS: Returned status code and messages are CORRECT.") self.flag = True else: LogPrint().error("FAIL: Returned message is INCORRECT.") self.flag = False else: LogPrint().error("FAIL: Returned status code is wrong. ") self.flag = False self.assertTrue(self.flag)
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))
def setUp(self): """ @summary: 测试用例执行前的环境初始化(前提) """ # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # step1:创建一个集群 LogPrint().info("Pre-Test-1: Create cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) # step2:创建一个逻辑网络 LogPrint().info("Pre-Test-2: Create network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_create_network(self.dm.nw_info, self.dm.nw_name)) # step3:附加该网络到集群上 LogPrint().info( "Pre-Test-3: Attach network '%s'to cluster '%s' for this TC." % (self.dm.nw_name, self.dm.cluster_name) ) self.clusterapi = ClusterAPIs() self.clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info)
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))
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 --------------------------------------------------------------------------------------------------- ''' ######################################################################## # 集群名称和两个主机id ######################################################################## cluster_name = ModuleData.cluster_nfs_name cluster_id = ClusterAPIs().getClusterIdByName(cluster_name) host1_name = ModuleData.host1_name host2_name = ModuleData.host2_name host1_id = HostAPIs().getHostIdByName(host1_name) host2_id = HostAPIs().getHostIdByName(host2_name) ######################################################################## # 主机的gluster存储目录 ######################################################################## dir_list = ['/storage/d1', '/storage/dd2', '/storage/d3', '/storage/d4'] ''' --------------------------------------------------------------------------------------------------- @note: Test-Data ---- -----------------------------------------------------------------------------------------------
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)
''' --------------------------------------------------------------------------------------------------- @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"/>
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)
from TestData.Volume import ITC10_SetUp as ModuleData 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"/>
def test_TearDown(self): dcapi = DataCenterAPIs() capi = ClusterAPIs() # Step1:将ISO域和Export域设置为Maintenance状态 LogPrint().info( "Post-Module-Test-1: Deactivate ISO and Export storage domains.") self.assertTrue( smart_deactive_storage_domain(self.dm.dc_name, self.dm.iso1_name)) self.assertTrue( smart_deactive_storage_domain(self.dm.dc_name, self.dm.export1_name)) # Step2:将ISO域和Export域从对应的数据中心分离(detach) LogPrint().info( "Post-Module-Test-2: Deattch ISO and Export storage domains.") self.assertTrue( smart_detach_storage_domain(self.dm.dc_name, self.dm.iso1_name)) self.assertTrue( smart_detach_storage_domain(self.dm.dc_name, self.dm.export1_name)) # Step3:将Data存储域设置为Maintenance状态 LogPrint().info( "Post-Module-Test-3: Deactivate all data storage domains.") self.assertTrue( smart_deactive_storage_domain(self.dm.dc_name, self.dm.data1_nfs_name)) #self.assertTrue(smart_deactive_storage_domain(self.dm.dc_name, self.dm.data1_iscsi_name)) # 删除3个数据中心(非强制,之后存储域变为Unattached状态) if dcapi.searchDataCenterByName(self.dm.dc_name): LogPrint().info("Post-Module-Test-4: Delete DataCenter '%s'." % self.dm.dc_name) self.assertTrue( dcapi.delDataCenter(self.dm.dc_name)['status_code'] == self.dm.expected_status_code_del_dc) # 删除3个Unattached状态的Data存储域和ISO/Export域(如果没有配置FC,则删除2个) LogPrint().info("Post-Module-Test-5: Delete all storage domains.") dict_sd_to_host = { self.dm.data1_nfs_name: self.dm.host1_name, self.dm.iso1_name: self.dm.host1_name, self.dm.export1_name: self.dm.host1_name } for sd in dict_sd_to_host: smart_del_storage_domain(sd, self.dm.xml_del_sd_option, host_name=dict_sd_to_host[sd]) # 删除主机(host1和host4) LogPrint().info("Post-Module-Test-6: Delete all hosts.") for host_name in [self.dm.host1_name, self.dm.host4_name]: self.assertTrue( smart_del_host(host_name, self.dm.xml_del_host_option)) # 删除集群 if capi.searchClusterByName(self.dm.cluster_name): LogPrint().info("Post-Module-Test-7: Delete Cluster '%s'." % self.dm.cluster_name) self.assertTrue( capi.delCluster(self.dm.cluster_name)['status_code'] == self.dm.expected_status_code_del_dc)
from Configs.GlobalConfig import Hosts from TestData.Host import ITC03_SetUp as ModuleData from TestAPIs.ClusterAPIs import ClusterAPIs '''----------------------------------------------------------------------------------------- @note: Pre-TestData -----------------------------------------------------------------------------------------''' host = Hosts['node1'] host_name = 'node-ITC030102' xml_host_info = ''' <host> <cluster id="%s"/> <name>%s</name> <address>%s</address> <root_password>%s</root_password> </host> ''' % (ClusterAPIs().getClusterIdByName( ModuleData.cluster_name), host_name, host['ip'], host['password']) '''----------------------------------------------------------------------------------------- @note: Post-TestData -----------------------------------------------------------------------------------------''' xml_del_option = ''' <action> <force>true</force> <async>false</async> </action> ''' '''----------------------------------------------------------------------------------------- @note: ExpectedResult -----------------------------------------------------------------------------------------''' status_code = 200
class ITC020205_UpdateNetworkofCluster(BaseTestCase): ''' @summary: ITC-02集群管理-02集群网络操作-05更新集群网络信息 ''' def setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' # 调用父类方法,获取该用例所对应的测试数据模块 self.dm = super(self.__class__, self).setUp() # step1:创建一个集群 LogPrint().info("Pre-Test-1: Create cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue( smart_create_cluster(self.dm.cluster_info, self.dm.cluster_name)) # step2:创建一个逻辑网络 LogPrint().info("Pre-Test-2: Create network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_create_network(self.dm.nw_info, self.dm.nw_name)) # step3:附加该网络到集群上 LogPrint().info( "Pre-Test-3: Attach network '%s'to cluster '%s' for this TC." % (self.dm.nw_name, self.dm.cluster_name)) self.clusterapi = ClusterAPIs() self.clusterapi.attachNetworkToCluster(self.dm.cluster_name, self.dm.nw_info) def test_UpdateNetworkofCluster(self): ''' @summary: 测试用例执行步骤 @note: 更新集群网络信息 @note: 操作成功,验证返回状态码,验证更新信息是否正确 ''' LogPrint().info("Test: Update Network %s of Cluster %s. " % (self.dm.nw_name, self.dm.cluster_name)) r = self.clusterapi.updateNetworkOfCluster(self.dm.cluster_name, self.dm.nw_name, self.dm.nw_info_new) if r['status_code'] == self.dm.status_code: dict_actual = self.clusterapi.getClusterNetworkInfo( self.dm.cluster_name, self.dm.nw_name) #dict_expected = {'network':xmltodict.parse(self.dm.nw_info_new)['network']} dict_expected = xmltodict.parse(self.dm.nw_info_new) dictCompare = DictCompare() if dictCompare.isSubsetDict(dict_expected, dict_actual): LogPrint().info( "PASS: Detach Network %s from Cluster %s SUCCESS. " % (self.dm.nw_name, self.dm.cluster_name)) else: LogPrint().info("FAIL: Returned message is WRONG. ") else: LogPrint().info("FAIL: Returned status code is WRONG.") def tearDown(self): ''' @summary: 测试结束后的资源清理(恢复初始环境) ''' LogPrint().info("Post-Test-1: Delete network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_delete_network(self.dm.nw_name, self.dm.dc_name)) LogPrint().info("Post-Test-2: Delete cluster '%s' for this TC." % self.dm.cluster_name) self.assertTrue(smart_delete_cluster(self.dm.cluster_name))