def test_1009_Dettach_Volume(cinderUrl, auth_id, host_name, vol_start_index, vol_name_prefix, server_name_prefix, novaUrl, con_dettach): volumesDict = {} try: _, volumesDict = cinderUtils.listVolumeDetails(cinderUrl, auth_id) except HttpError as e: print(('HTTP Error: {0}'.format(e.body))) exit(1) if volumesDict: volumeList = volumesDict['volumes'] volumes_to_dettach = [] dettach_number = 0 for volume in volumeList: if volume['name'].startswith(vol_name_prefix): # Find the corresponding server vol_metadata = {} if volume['attachments']: vm_id = volume['attachments'][0]['server_id'] vol_id = volume['attachments'][0]['id'] # Now fire the dettach command. vol_metadata['vm_id'] = vm_id vol_metadata['vol_id'] = vol_id volumes_to_dettach.append(vol_metadata) dettach_number += conn_dettach_vols(auth_id, novaUrl, volumes_to_dettach, con_dettach) return dettach_number
def test_1021_unmanagevolumes(self): options_missing = False for option in self.required_options: if not self.config.has_option(self.config_section, option): print 'option=', option, 'not found in configuration file' options_missing = True if options_missing: print 'Provide missing options to the configuration file.' os._exit(1) volume_list = [] volumestoragelist = [] novaUrl = self.getServiceUrl('compute') token = self.authent_id cinderUrl = self.getServiceUrl('volume') print cinderUrl ressto = cinderUtils.showAllStorageProvidersDetail(cinderUrl, token) print ressto[1]['storage_providers'] #storageName = self.config_get('svc_display_name_list') volume_name_prefix = self.config_get('volume_name_prefix') vol_unmanage_count = int(self.config_get('vol_unmanage_count')) unmanagecount = 0; for s in range(len(volume_name_prefix)): #storagedisplayname = storageName[s] volume_name = volume_name_prefix[s] argumNo = str(s) print "Validating for " + argumNo + " argument" #print "Storage name in powervc =>", storagedisplayname # Check if svc display name matches in pvc print "Check volume existence:", volume_name # Get list of all volumes from that storgae _, volumesDict = cinderUtils.listVolumeDetails(cinderUrl, token) #print "volumesdict", volumesDict if volumesDict: volumeList = volumesDict['volumes'] #print "volume list is", volumeList if volumeList: for volume in volumeList: print 'name=', volume['name'], 'volume id in pvc=', volume['id'], 'status=', volume['status'], 'storage_hostname=', volume['backend_host'] #print "volume name from config file is", volume_name if volume_name in volume['name']: print "Volume found in powervc" if volume['status'] == 'available': if vol_unmanage_count > unmanagecount: print "Volume is available for unmanage" #volume_list.append(volume['id']) volumeid = volume['id'] host_name = volume['backend_host'] try: configUtils.unmanage_vol(cinderUrl, token, volumeid, host_name) unmanagecount += 1 except HttpError, e: print 'HTTP Error: {0}'.format(e.body) else: print "User input threshold is reached. No need to unmanage additional volumes" os._exit(0)
def test_1009_Attach_Volume(cinderUrl, auth_id, host_name, vol_start_index, vol_name_prefix, server_name_prefix,volume_count, novaUrl, con_attach): try: _, volumesDict = cinderUtils.listVolumeDetails(cinderUrl, auth_id) except HttpError, e: print 'HTTP Error: {0}'.format(e.body) exit(1)
def test_1008_list_delete_volumes(self): authTokenId = self.authent_id cinderUrl = self.getServiceUrl('volume') _, volumeType = cinderUtils.listVolumeTypes(cinderUrl, self.authent_id) if volumeType: volumeTypeList = volumeType['volume_types'] if volumeTypeList: for type in volumeTypeList: print 'name=', type['name'] print 'id=', type['id'] print 'Obtaining the volume List...to be deleted' try: _, volumesDict = cinderUtils.listVolumeDetails( cinderUrl, self.authent_id) to_be_deleted = [] notto_be_deleted = [] volume_id_list = [] volume_dnd = [] if volumesDict: volumeList = volumesDict['volumes'] print 'Printing the volumeList =', volumeList #print "harsha_____________________________" if volumeList: for volume in volumeList: volume_name = volume['name'] if (fnmatch.fnmatch(volume_name.upper(), '*DND*')): notto_be_deleted.append(volume) print 'not to be deleted since start with dnd' else: to_be_deleted.append(volume) if to_be_deleted: for vol in to_be_deleted: print 'name=', vol['name'], 'id=', vol['id'] volume_id_list.append({'id': vol['id']}) get_deleted_volume_list(cinderUrl, authTokenId, volume_id_list) print 'The number of volumes in the volume list is %d' % len( volume_id_list) except HttpError, e: print 'HTTP Error: {0}'.format(e.body) os._exit(1)
def test_1009_Attach_Volume(cinderUrl, auth_id, host_name, vol_start_index, vol_name_prefix, server_name_prefix, novaUrl, con_attach): try: _, volumesDict = cinderUtils.listVolumeDetails(cinderUrl, auth_id) except HttpError as e: print('HTTP Error: {0}'.format(e.body)) exit(1) vm_list = Utils.get_server_list_host(auth_id, novaUrl, host_name) to_be_attached = [] server_list = [] count = 0 vol_idx = vol_start_index to_attach_list = [] eligible_vols = [] vol_name = vol_name_prefix if volumesDict: volumeList = volumesDict['volumes'] for volume in volumeList: if volume['status'] == 'available' and \ volume['name'].startswith(vol_name): eligible_vols.append(volume) no_of_used_vols = 0 attach_number = 0 for vm in vm_list: if vm['name'].startswith(server_name_prefix): if vm['OS-EXT-STS:vm_state'] == 'active' and\ vm['health_status']['health_value'] == 'OK': vol_name = vol_name_prefix + str(vol_idx) vol_id = 'not set' if eligible_vols: if len(eligible_vols) > no_of_used_vols: volume = eligible_vols[no_of_used_vols] vol_metadata = {} vol_id = volume['id'] no_of_used_vols = no_of_used_vols + 1 volumeProps = { "volumeId": vol_id, } #call attach volume function vol_metadata['vol_props'] = volumeProps vol_metadata['vm_id'] = vm['id'] to_attach_list.append(vol_metadata) attach_number += conn_attach_vols(auth_id, novaUrl, to_attach_list, con_attach) return attach_number
def test_1009_Attach_Volume(cinderUrl, auth_id, host_name, vol_start_index, vol_name_prefix, server_name_prefix, volume_count, novaUrl, con_attach): try: _, volumesDict = cinderUtils.listVolumeDetails(cinderUrl, auth_id) except HttpError as e: print('HTTP Error: {0}'.format(e.body)) exit(1) print(" inside test_1009_Attach_Volume() ") vm_list = Utils.get_server_list_host(auth_id, novaUrl, host_name) print("length of vm list=") print(len(vm_list)) to_be_attached = [] server_list = [] count = 0 vol_idx = vol_start_index to_attach_list = [] eligible_vols = [] vol_name = vol_name_prefix if volumesDict: volumeList = volumesDict['volumes'] for volume in volumeList: print(volume['name'], volume['status']) #if volume['status'] == 'available' and \ if volume['status'] == 'available' and volume['name'] is not None and \ volume['name'].startswith(vol_name): eligible_vols.append(volume) print("length of eligibile volumes=") print(len(eligible_vols)) print("eligible volumes") print(eligible_vols) no_of_used_vols = 0 attach_number = 0 no_of_vol = 0 elgible_vol_count = len(eligible_vols) if volume_count > elgible_vol_count: print("There are no enough volumes available for bulk volume attach") print("Number of volumes needed for attach=", volume_count) print("Number of volumes available=", elgible_vol_count) os._exit(1) for vm in vm_list: #print "chocolate -vm name",vm['name'] if vm['name'].startswith(server_name_prefix): """ if vm['OS-EXT-STS:vm_state'] == 'active' and\ vm['health_status']['health_value'] == 'OK': """ if vm['OS-EXT-STS:vm_state'] == 'active': vol_name = vol_name_prefix + str(vol_idx) vol_id = 'not set' if eligible_vols: if len(eligible_vols) > no_of_used_vols: if elgible_vol_count >= volume_count: #print " yes am in " volumeproperties = [] for x in range(volume_count): volume = eligible_vols[no_of_used_vols] vol_id = volume['id'] #create attach volume properties volumeProps = { "volumeId": vol_id, } volumeproperties.append(volumeProps) no_of_used_vols = no_of_used_vols + 1 elgible_vol_count = elgible_vol_count - 1 #call attach volume function vol_metadata = {} vol_metadata['vol_props'] = volumeproperties vol_metadata['vm_id'] = vm['id'] to_attach_list.append(vol_metadata) attach_number += conn_attach_vols(auth_id, novaUrl, to_attach_list, con_attach) sleep(300) return attach_number