def test_Create_DC(self): ''' @summary: 创建一个数据中心 ''' dcapi = DataCenterAPIs() LogPrint().info("Pre-Module-Test: Create DataCenter '%s'." % self.dm.dc_name) dcapi.createDataCenter(self.dm.dc_info)
def test_GetTemplateDiskList(self): ''' @summary: 获取模板的磁盘列表 @note: 操作成功,验证返回状态码和返回信息 ''' self.flag = True tempdisk_api = TemplateDisksAPIs() LogPrint().info("Test: Get disk list of template %s." % self.dm.temp_name) r = tempdisk_api.getTemplateDiskList(self.dm.temp_name) if r['status_code'] == self.dm.expected_status_code: LogPrint().info("PASS: Get disk list of template %s SUCCESS." % self.dm.temp_name) else: LogPrint().error("FAIL: The status_code is WRONG") self.flag = False self.assertTrue(self.flag)
def smart_start_volume(cluster_name, volume_name, status_code=200): r = volumeapi.startGlusterVolume(cluster_name, volume_name) if r['status_code'] == status_code: def is_volume_up(): return volumeapi.getClusterVolumeStatus(cluster_name, volume_name) == "up" if wait_until(is_volume_up, 600, 5): LogPrint().info("Start volume success.") return True else: LogPrint().error("Start volume failed.Status is not UP.") return False else: LogPrint().error("Status_code is WRONG.") return False
def setUp(self): self.dm = super(self.__class__, self).setUp() self.diskapi = DiskAPIs() #创建一个虚拟机 LogPrint().info("Pre-Test-1: Create vm %s for TC."% self.dm.vm_name) self.assertTrue(smart_create_vm(self.dm.vm_name, self.dm.vm_info)) #创建一块磁盘 ''' @note: 创建磁盘时,磁盘的sharable属性必须为false,因为共享磁盘不作为模板的一部份 ''' LogPrint().info("Pre-Test-2: Create a disk for TC.") r= smart_create_disk(self.dm.disk_info, self.dm.disk_name) self.assertTrue(r[0]) self.disk_id = r[1] #将该磁盘附加到虚拟机 LogPrint().info("Pre-Test-3: Attach disk %s to vm %s for TC."% (self.dm.disk_name ,self.dm.vm_name)) self.vmdiskapi = VmDiskAPIs() r=self.vmdiskapi.attachDiskToVm(self.dm.vm_name, self.disk_id) if r['status_code'] == 200: LogPrint().info("Attach Disk to vm success.") else: LogPrint().error("Attach Disk to vm fail.Status-code is wrong.") self.assertTrue(False) #启动虚拟机 LogPrint().info("Pre-Test-4: Start vm for TC.") self.assertTrue(smart_start_vm(self.dm.vm_name)) #激活磁盘 LogPrint().info("Pre-Test-5: Active vmdisk for TC.") self.assertTrue(smart_active_vmdisk(self.dm.vm_name,self.disk_id))
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_DeleteProfile(self): ''' @summary: 删除配置集 @note: 操作成功,验证返回状态码,验证配置集是否存在 ''' self.flag = True LogPrint().info("Test: Delete profile %s."%self.dm.profile_name) r = self.proapi.delProfile(self.dm.profile_name, self.nw_id) if r['status_code'] == self.dm.expected_status_code: if not self.proapi.isExist(self.dm.profile_name, self.nw_id): LogPrint().info("PASS: Delete profile %s SUCCESS."%self.dm.profile_name) else: LogPrint().error("FAIL: Profile %s is still exist."%self.dm.profile_name) self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s', INCORRECT. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def setUp(self): self.dm = super(self.__class__, self).setUp() self.nwapi = NetworkAPIs() ''' @note: 如果该数据中心内不存在网络,就创建一个网络 ''' LogPrint().info("Pre-Test: Create network %s."%self.dm.nw_name) if not self.nwapi.searchNetworkByName(self.dm.nw_name)['result']['networks']: self.nwapi.createNetwork(self.dm.nw_info)
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))
def tearDown(self): ''' @summary: 资源清理 @note: (1)删除创建的游离存储 ''' for sd_name in self.dm.data1_name: LogPrint().info("Post-Test: Delete storage domain '%s'." % sd_name) self.assertTrue( smart_del_storage_domain(sd_name, self.dm.xml_del_sd_option))
def test_DeleteNetwork(self): ''' @summary: 删除网络 @note: 操作成功,检查返回状态码,检查网络是否存在 ''' LogPrint().info("Test: Delete network %s."%self.dm.nw_name) r = self.nwapi.delNetwork(self.dm.nw_name, self.dm.dc_name) if r['status_code'] == self.dm.expected_status_code: if not self.nwapi.isNetworkExist(self.dm.nw_name, self.dm.dc_name): LogPrint().info("PASS: Delete network %s success."%self.dm.nw_name) self.flag = True else: LogPrint().error("FAIL: Delete network fail.The network %s is still exist."%self.dm.nw_name) self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s', INCORRECT. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def create_clusters(xml_cluster_info): LogPrint().info( "Pre-Module-Test-2: Create Cluster '%s' in DataCenter '%s'." % (xmltodict.parse(xml_cluster_info)['cluster']['name'], xmltodict.parse(xml_cluster_info)['cluster']['data_center'] ['name'])) self.assertTrue( capi.createCluster(xml_cluster_info)['status_code'] == self.dm.expected_status_code_create_cluster)
def setUp(self): self.dm = super(self.__class__, self).setUp() LogPrint().info("Pre-Test-1: Create a template %s for TC." % self.dm.temp_name) self.assertTrue( smart_create_template(self.dm.temp_name, self.dm.temp_info)) #为所在数据中心的ovirtmgmt网络创建一个配置集 LogPrint().info("Pre-Test-2: Create a profile %s for ovirtmgmt." % self.dm.profile_name) self.nw_id = NetworkAPIs().getNetworkIdByName('ovirtmgmt', self.dm.dc_name) print self.nw_id r = ProfilesAPIs().createProfiles(self.dm.profile_info, self.nw_id) if r['status_code'] == 201: self.proid = r['result']['vnic_profile']['@id'] LogPrint().info("Create Profile SUCCESS.") else: LogPrint().error("Create Profile fail.The status_code is WRONG.")
def setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' self.dm = super(self.__class__, self).setUp() self.nwapi = NetworkAPIs() #首先新建一个网络并获取其id LogPrint().info("Pre-Test: Create a network %s for TC."%self.dm.nw_name) self.nw_id = self.nwapi.createNetwork(self.dm.nw_info)['result']['network']['@id']
def tearDown(self): ''' @summary: 资源清理 @note: (1)删除创建的磁盘; ''' LogPrint().info("Post-Test: Delete disk '%s' from data storage '%s'." % (self.dm.disk_name, self.dm.data1_name)) self.assertTrue( smart_delete_disk(self.disk_id, self.dm.xml_del_disk_option))
def setUp(self): ''' @summary: 初始化测试数据、测试环境。 ''' self.dm = super(self.__class__, self).setUp() self.nwapi = NetworkAPIs() #首先新建一个网络并获取其id LogPrint().info("Pre-Test-1: Create a new network '%s'." % self.dm.nw_name) self.nw_id = self.nwapi.createNetwork(self.dm.nw_info)['result']['network']['@id'] #为该网络创建多个配置集 LogPrint().info("Pre-Test-2: Create multi-profiles for network '%s'." % self.dm.nw_name) self.proapi = ProfilesAPIs() @BaseTestCase.drive_data(self, self.dm.profile_info) def do_test(xml_info): self.proapi.createProfiles(xml_info,self.nw_id) do_test()
def tearDown(self): ''' @summary: 资源清理 ''' LogPrint().info("Post-Test: Delete storage domain '%s'." % self.dm.data_name) self.assertTrue( smart_del_storage_domain(self.dm.data_name, self.dm.xml_del_sd_option))
def test_CreateProfile_DupName(self): ''' @note: 操作失败,检查返回状态码和提示信息 ''' self.flag = True LogPrint().info("Test: Create a dupname profile for network %s."% self.dm.nw_name) r = self.proapi.createProfiles(self.dm.profile_info, self.nw_id) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(r['result'], xmltodict.parse(self.dm.expected_info)): LogPrint().info("PASS: The returned status code and messages are CORRECT when create dup profile.") else: LogPrint().error("FAIL: The returned messages are INCORRECCT when create dup profile.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s', INCORRECT. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_Scene(self): ''' @summary: 测试场景描述 ''' #step1:创建一个distributed类型的卷 volumeapi = GlusterVolumeAPIs() LogPrint().info("Create volume dis") r = volumeapi.createGlusterVolume(self.dm.cluster_name, self.dm.xml_volume_dis) print r if r['status_code'] == self.dm.expected_status_code_create_volume: LogPrint().info("PASS:Create volume dis success.") self.flag = True else: LogPrint().error("FAIL:Status_code is WRONG.") self.flag = False self.assertTrue(self.flag) #step2:添加两个brick volume_id = GlusterVolumeAPIs().getVolumeIdByName( self.dm.cluster_name, 'dis') r = volumeapi.addbrick(self.dm.cluster_id, volume_id, self.dm.xml_brick_info) if r['status_code'] == self.expected_status_code_add_brick: LogPrint().info("PASS:ADD brick to volume dis success.") self.flag = True else: LogPrint().error("FAIL:Status_code is WRONG.") self.flag = False self.assertTrue(self.flag) #step3:启动卷 LogPrint().info("Start volume dis") r = volumeapi.startGlusterVolume(self.dm.cluster_name, "dis") if r['status_code'] == self.dm.expected_status_code_start_volume: def is_volume_up(): return volumeapi.getClusterVolumeStatus( self.dm.cluster_name, "dis") == "up" if wait_until(is_volume_up, 600, 5): LogPrint().info("PASS:Start volume dis success.") self.flag = True else: LogPrint().error("FAIL:Start volume failed.Status is not UP.") self.flag = False else: LogPrint().error("FAIL:Status_code is WRONG.") self.flag = False self.assertTrue(self.flag)
def test_DeleteDisk_AttachtoDownVm(self): ''' @summary: 删除附加到运行虚拟机的磁盘 @note: 操作成功,验证返回状态码,验证磁盘是否存在 ''' diskapi = DiskAPIs() self.flag = True LogPrint().info("Test: Delete disk %s attached to down vm %s."% (self.dm.disk_name, self.dm.vm_name)) r = diskapi.deleteDisk(self.disk_id) if r['status_code'] == self.dm.expected_status_code: if not diskapi.isExist(self.disk_id): LogPrint().info("PASS: Delete Disk attached to down vm SUCCESS." ) else: LogPrint().error("FAIL: Disk is still exist. " ) self.flag = False else: LogPrint().error("FAIL: Returned status code is %s. "% r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_DeleteDisk_AttachtoRunVm(self): ''' @summary: 删除附加到运行虚拟机的磁盘 @note: 操作失败,验证返回状态码和报错信息 ''' self.flag = True LogPrint().info("Test: Delete disk %s attached to running vm %s."% (self.dm.disk_name, self.dm.vm_name)) r = self.diskapi.deleteDisk(self.disk_id) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(xmltodict.parse(self.dm.expected_info), r['result']): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: The returned messages are INCORRECT.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s' while it should be '%s'." % (r['status_code'], self.dm.expected_status_code)) self.flag = False self.assertTrue(self.flag)
def test_DeleteDisk_AttachtoTemp(self): ''' @summary: 删除附加到模板的磁盘 @note: 操作失败,验证返回验证码及报错信息 ''' self.flag = True LogPrint().info("Test: Delete disk attached to template.") r = DiskAPIs().deleteDisk(self.disk_id_temp) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(xmltodict.parse(self.dm.expected_info), r['result']): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: The returned messages are INCORRECT.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s' while it should be '%s'." % (r['status_code'], self.dm.expected_status_code)) self.flag = False self.assertTrue(self.flag)
def setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' self.dm = super(self.__class__, self).setUp() #首先新建一个磁盘并获取id LogPrint().info("Pre-Test-1: Create Disk %s for TC."% self.dm.disk_name) r = smart_create_disk(self.dm.disk_info,self.dm.disk_name) self.disk_id = r[1] self.assertTrue(r[0])
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 setUp(self): ''' @summary: 测试用例执行前的环境初始化(前提) ''' # 初始化测试数据 self.dm = super(self.__class__, self).setUp() self.nwapi = NetworkAPIs() # 准备1:创建一个网络 LogPrint().info("Pre-Test: Create a network '%s' for this TC." % self.dm.nw_name) self.assertTrue(smart_create_network(self.dm.nw_info,self.dm.nw_name))
def test_UpdateNetwork(self): ''' @summary: 编辑配置集,更改所属网络 @note: 操作失败,验证返回状态码,验证报错信息 ''' self.flag = True LogPrint().info("Test: Update profile %s.Change its network."%self.dm.profile_name) r = self.proapi.updateProfile(self.dm.profile_name, self.nw_id, self.dm.update_info) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(r['result'], xmltodict.parse(self.dm.expected_info)): LogPrint().info("PASS: The returned status code and messages are CORRECT when update dup network.") else: LogPrint().error("FAIL: The returned messages are INCORRECCT when update dup network.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s', INCORRECT. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_CreateNetwork_DupVlan(self): ''' @summary: 创建网络,vlan id重复 @note: 操作失败,检查返回状态码和报错信息 ''' LogPrint().info("Test: Create network %s.Set its vlan id 2."%self.dm.nw_name2) r = self.nwapi.createNetwork(self.dm.nw_info2) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(r['result'], xmltodict.parse(self.dm.expected_info)): LogPrint().info("PASS: Returned status code and messages are CORRECT when create dup_vlan network.") self.flag = True else: LogPrint().error("FAIL: Returned messages are INCORRECCT when create dup_vlan network.") self.flag = False else: LogPrint().error("FAIL: Returned status code is '%s', INCORRECT. " % r['status_code']) self.flag = False self.assertTrue(self.flag)
def test_CreateDisk_VerifyName(self): ''' @summary: 验证名称合法性:包含非法字符 @note: 操作失败,验证返回状态码及报错信息 ''' diskapi = DiskAPIs() LogPrint().info("Test: Create disk and verify name.") r = diskapi.createDisk(self.dm.disk_info) if r['status_code'] == self.dm.expected_status_code: dictCompare = DictCompare() if dictCompare.isSubsetDict(xmltodict.parse(self.dm.expected_info), r['result']): LogPrint().info("PASS: The returned status code and messages are CORRECT.") else: LogPrint().error("FAIL: The returned messages are INCORRECT.") self.flag = False else: LogPrint().error("FAIL: The returned status code is '%s' while it should be '%s'." % (r['status_code'], self.dm.expected_status_code)) self.flag = False self.assertTrue(self.flag)
def smart_delete_cluster(cluster_name,status_code=200): ''' @summary: 删除集群 @param cluster_name:待删除的集群名称 @param status_code:删除集群返回的状态码,成功为200 @return: True/False ''' cluster_api = ClusterAPIs() try: cluster_api.getClusterInfo(cluster_name) r = cluster_api.delCluster(cluster_name) if r ['status_code'] == status_code: LogPrint().info("Post-Test:Delete Cluster '%s'success."%cluster_name) return True else: LogPrint().error("Post-Test:Delete Cluster '%s' fail."%cluster_name) return False except: LogPrint().info("Post-Test:Cluster '%s' is not exist"%cluster_name) return True
def smart_delete_tempnic(temp_name, nic_name): ''' @summary: 删除模板的网络接口 @param temp_name: 模板名称 @param nic_name:网络接口名称 @return: True or False ''' tempnic_api = TemplateNicsAPIs() try: tempnic_api.getTemplateNicInfo(temp_name, nic_name) r = tempnic_api.deleteTemplateNic(temp_name, nic_name) if r['status_code'] == 200: LogPrint().info("Post-Test:Delete template's nic success.") return True else: LogPrint().error("Post-Test:Delete template's nic failed") return False except: LogPrint().warning("WARN: Template_nic is not exist.") return True
def test_GetDisksFromDataStorage(self): ''' @summary: 测试步骤 @note: (1)调用相应接口,获取Data存储域中的disk列表; @note: (2)操作成功,验证接口返回的状态码、disk列表是否正确。 ''' data_storage_api = DataStorageAPIs() LogPrint().info("Test: Get disks list of Data Storage '%s'." % self.dm.data1_name) r = data_storage_api.getDisksListFromDataStorage(self.dm.data1_name) if r['status_code'] == self.dm.expected_status_code_get_disk_list_in_data_storage: LogPrint().info( "PASS: Get the disks list from Data Storage '%s' SUCCESS." % self.dm.data1_name) self.flag = True else: LogPrint().error("FAIL: Returned status code '%s' INCORRECT." % r['status_code']) self.flag = False self.assertTrue(self.flag)