def writingVDBfile(x, volume): output = getoutput('mount | grep %s | awk \'{print $3}\'' %(volume['mountPoint'])) old_str = 'mountDirectory%s' %x new_str = output[0].rstrip('\n') path = 'vdbench/%s' %vdbNewFile logging.info('Replacing the std path with volume mountpoint') res = executeCmd("sed -i 's/%s/%s/' %s " %(old_str.replace('/', '\/'), new_str.replace('/', '\/'), path ))
def writingVDBfile(volume, vdbFile, vol_size): executeCmd('yes | cp -rf vdbench/templates/%s vdbench/%s' % (vdbFile, volume['name'])) logging.info('copying vdbench/templates/%s file to vdbench as "%s"', \ vdbFile, volume['name']) output = getoutput('mount | grep %s | awk \'{print $3}\'' % (volume['mountPoint'])) old_str = 'mountDirectory' new_str = output[0].rstrip('\n') old_size = getoutput("cat vdbench/%s | grep ',size=' | cut -d '=' -f 7" \ %(volume['name'])) old_size = old_size[0].strip('\n') vdb_path = 'vdbench/%s' % volume['name'] res = executeCmd("sed -i 's/%s/%s/' %s " \ %(old_str.replace('/', '\/'), new_str.replace('/', '\/'), vdb_path)) res = executeCmd("sed -i 's/%s/%s/' %s " \ %(old_size.replace('/', '\/'), vol_size.replace('/', '\/'), vdb_path)) logging.info('executing vdbench....') out = os.system('./vdbench/vdbench -f vdbench/%s -o vdbench/output &' \ %(volume['name']))
def copy_file(file_to_copy, dstntn_dir): #dstntn_dir is destination_directory logging.debug('inside copy_file method...') logging.debug('taking md5sum of %s...', file_to_copy) out = getoutput('md5sum %s' %(file_to_copy))[0] md5_of_src_file = out.split(' ')[0] logging.debug('md5sum at source of %s: %s', file_to_copy, md5_of_src_file) copy_result = executeCmd('cp %s %s/' %(file_to_copy, dstntn_dir)) if copy_result[0] == 'FAILED': logging.error('Not able to copy file at directory %s', dstntn_dir) return ['FAILED', ''] logging.debug('copied file to mounted directory successfully') out = (getoutput('md5sum %s/%s' %(dstntn_dir, file_to_copy)))[0] md5_of_dstns_file = out.split(' ')[0] logging.debug('md5sum at destination of %s: %s', file_to_copy, md5_of_dstns_file) if str(md5_of_src_file) == str(md5_of_dstns_file): logging.debug('md5sum check is passed') result = ['PASSED', md5_of_src_file] else: result = ['FAILED', 'md5sum is not same at source and destination'] logging.error('Integrity check is failed: %s', result) return result
def get_iscsi_device(): cmd = 'iscsiadm -m session -P3 | grep \'Attached scsi disk\' | awk '\ '{\'print $4\'}' logging.info('getting iSCSI loggedin device name...') logging.debug('executing command... %s', cmd) time.sleep(1) result = getoutput(cmd) if result != 'null': #logging.debug('logged iscsi device: %s', (result[0].split('\n'))[0]) result = ['PASSED', (result[-1].split('\n'))[0]] return result logging.error('Not getting iSCSI loggedin device') result = ['FAILED', ''] return result
def executeVdbenchFile(volume, vdbfile): ##volume is dictionary logging.info('.....inside excecute_vdbench method....') logging.info(' overwriting the file fileconfig with std path') executeCmd('yes | cp -rf vdbench/templates/%s vdbench/%s' %(vdbfile, volume['name'])) output = getoutput('mount | grep %s | awk \'{print $3}\'' %(volume['mountPoint'])) old_str = 'mountDirectory' new_str = output[0].rstrip('\n') path = 'vdbench/%s' %volume['name'] logging.info('Replacing the std path with volume mountpoint') res = executeCmd("sed -i 's/%s/%s/' %s " %(old_str.replace('/', '\/'), new_str.replace('/', '\/'), path )) logging.info('executing vdbench....') out = os.system('./vdbench/vdbench -f vdbench/%s -o vdbench/output &' %volume['name']) #out = os.system('./vdbench12/vdbench -f vdbench12/fileconfig &') return out
def excecute_vdbench(volume): ##volume is dictionary logging.info('.....inside excecute_vdbench method....') logging.info(' overwriting the file fileconfig with std path') executeCmd('yes | cp -rf vdbench/templates/fileconfig vdbench/fileconfig') output = getoutput('mount | grep %s | awk \'{print $3}\'' %(volume['mountPoint'])) old_str = 'mountDirectory' new_str = output[0].rstrip('\n') path = 'vdbench12/fileconfig' logging.info('Replacing the std path with volume mountpoint') res = executeCmd("sed -i 's/%s/%s/' %s " %(old_str.replace('/', '\/'),\ new_str.replace('/', '\/'), path )) logging.info('executing vdbench command') out = os.system('./vdbench/vdbench -f vdbench/fileconfig -o vdbench/output &') logging.debug('vdbench command result:%s', out)
def kill_process(process_name): logging.debug('inside kill_process...') pid = getoutput('ps -aux |grep %s |awk \'{print $2}\'' % (process_name)) logging.debug('process going to be killed...: %s', pid) processlist = [] for process in pid: p1 = process.rstrip('\n') processlist.append(p1) #print processlist logging.debug('%s process ids...: %s', process_name, processlist) cmd = 'kill -9' for proc in processlist: cmd = cmd + ' %s' % (proc) res = executeCmd(cmd) if res[0] == 'PASSED' or 'No such process' in str(res[1]): print 'process is killed' logging.debug('process are killed') else: print 'process are not killed' logging.debug('one or more process is not killed, Error: %s', \ res[1])
def iscsi_get_quota(tsm_ip, vol_iqn, vol_mntPoint): discover_lun = discover_iscsi_lun(tsm_ip, vol_iqn) if discover_lun[0] == 'FAILED': return ['FAILED', discover_lun[1]] logging.debug('IQN of discovered lun is "%s"', discover_lun[1]) lun_login = iscsi_login_logout(discover_lun[1], tsm_ip, 'login') if lun_login[0] == "FAILED": return ["FAILED", lun_login[1]] time.sleep(3) result = getDiskAllocatedToISCSI(tsm_ip, vol_mntPoint) if result[0] == 'PASSED' and vol_mntPoint in str(result[1]): logging.debug('iscsi logged device... %s', result[1][vol_mntPoint]) device = result[1][vol_mntPoint] else: return ['FAILED', 'Not able to get logged in device'] time.sleep(5) #Getting device size and converting into GB quota = getoutput('fdisk -l | grep /dev/%s: | awk {\'print $5\'}' % (device)) quota1 = int(quota[0]) / (1024 * 1024 * 1024) return ['PASSED', quota1]
def UseFileInMountPoint(volume): output = getoutput('mount | grep %s | awk \'{print $3}\'' \ %(volume['mountPoint'])) mount_point = output[0].strip('\n') exe_vdb = executeVdbenchFile(volume, VdbFile) time.sleep(20) #sleeping for 30s before trying to umount the volume on which vdbench is running logging.info('Now unmounting the mountPoint which is in use') check_vdbench = is_vdbench_alive(volume['name']) if check_vdbench: umount_output = executeCmd('umount mount/%s' %(volume['mountPoint'])) if umount_output[0] == 'FAILED': print 'expected result : %s' %(umount_output[1]) logging.debug('expected result: %s', umount_output[1]) umountFail = True return ['PASSED', umountFail] else: print 'Unexpected Result: Unmount happened when file in '\ 'mountPoint is in use' kill_process(volume['name']) return ['FAILED', 'Unmount happened when file in mountPoint is in use'] else: return ['FAILED', 'Vdbench stopped, MountPoint not in use']
config['volDatasetname%d' % (x)]) size2 = getControllerInfo(IP, password, cmd1, "backend_output0.txt") print " After copy used space of volume %s is " % ( config['volDatasetname%d' % (x)]) print size2 cmd2 = " zfs get -Hp all | grep %s | grep -w compressratio | awk \'{print $3}\'" % ( config['volDatasetname%d' % (x)]) ratio2 = getControllerInfo(IP, password, cmd2, "backend_output_ac0.txt") print " After copy compress Ratio is " print ratio2 cr2 = float(ratio2[0:-2]) print cr2 ############### Compare size ############### fs = getoutput(" du -b %s | awk '{print $1}' " % (testfile)) print "testfile size is" print fs[0] filesize = float(fs[0]) print filesize diffsize = float(size2) - float(size1) endTime = ctime() if diffsize < filesize and cr2 > cr1 and compvalue == "on": print "Compression is enabled on %s and working" % ( config['volDatasetname%d' % (x)]) resultCollection( "Compression is enabled on %s and working" % (config['volDatasetname%d' % (x)]), ("PASSED", ' '), startTime, endTime) elif diffsize >= filesize and cr2 == cr1 and compvalue == "off": print "Compression is disabled on %s and working" % (
noDiskGroups = 0 noOfSpares = 0 noOfCaches = 0 noOfLogs = 0 noOfMetaDisks = 0 noOfMetaDiskGroups = 0 noCacheDisks = 0 noSpareDisks = 0 noLogDisks = 0 noLogMirrDisks = 0 poolName = 'Pool1' #### Function(s) Declartion Ends output = [] list = getoutput('cat %s' % (file)) for st in list: s = st.split() output = output + st.split() del output[0] del output[0] output.append("last") print output pool = { "pool": "", "state": "", "noOfDataDisks": "", "noOfDataDiskGroups": "0", "dataDiskGroupType": "", "noOfLogs": "0",
endTime = ctime() if init_grp[0] == 'FAILED': #logAndresult(testcase, 'BLOCKED', init_grp[1], startTime, endTime) pass logging.debug('Iscsi Initiator group is set to "ALL" for the volume') volume = {'TSMIPAddress' : tsmIP, 'mountPoint': volname, 'name' : volname} mnt_iscsi = iscsi_mount_flow(volname, tsmIP, vol_iqn, vol_mntPoint, 'ext3') endTime = ctime() if mnt_iscsi[0] == 'FAILED': logAndresult(testcase, 'BLOCKED', mnt_iscsi[1], startTime, endTime) logging.debug('%s', mnt_iscsi[1]) device, iqn = mnt_iscsi[3], mnt_iscsi[2] mount_point = getoutput('mount | grep %s | awk \'{print $3}\'' \ %(volume['name'])) mount_point = mount_point[0].strip('\n') executeVdbenchFile(volume, 'filesystem_nfs') check_vdbench = is_vdbench_alive(volname) time.sleep(1) while True: mountDetails = mountPointDetails('-m', mount_point) Used = mountDetails[2] if int(Used) >= 1000: logging.debug('vdbench has successfully created 1 GB file of the') logging.debug('going to stop vdbench after 10 seconds...') time.sleep(10) break check_vdbench = is_vdbench_alive(volname) if check_vdbench:
if len(sys.argv) < 3: print "Argument is not correct.. Correct way as below" print " python createISCSIInitiatorGroup.py config.txt clientip" exit() ip = sys.argv[2] initname = "iqn" #iqn = sys.argv[2] #ip = sys.argv[3] ###initiator name ###get clients iqn #if iqn == "system_iqn": iqn = getoutput( 'cat /etc/iscsi/initiatorname.iscsi | grep iqn | cut -d "=" -f 2') iqn = iqn[0].strip() print iqn ###get clients ip #if ip == "system_ip": #ip = getoutput('ifconfig eth0 | grep "inet addr:" | cut -d ":" -f 2 | awk \'{ print $1}\'') #ip = ip[0].strip() print ip ### list of accounts querycommand = 'command=listAccount' resp_listAccount = sendrequest(stdurl, querycommand) filesave("logs/ListAccount.txt", "w", resp_listAccount) data = json.loads(resp_listAccount.text) #print data
delete = 1 else: print bcolors.FAIL + "Fourth element should be copy or delete or create" + bcolors.ENDC exit() else: print bcolors.FAIL + "Only five arguments are allowed, Please read the help" + bcolors.ENDC exit() # exit() #executeCmd('umount -a -t cifs -l') #executeCmd('umount -a') for x in range(1, int(config['Number_of_ISCSIVolumes'])+1): executeCmd('iscsiadm -m discovery -t st -p %s:3260' %(config['voliSCSIIPAddress%d' %(x)])) iqnname = getoutput('iscsiadm -m discovery -t st -p %s:3260 | grep %s | awk {\'print $2\'}' %(config['voliSCSIIPAddress%d' %(x)],config['voliSCSIMountpoint%d' %(x)])) print iqnname if iqnname==[]: continue output=executeCmd('iscsiadm -m node --targetname "%s" --portal "%s:3260" --logout | grep Logout' %(iqnname[0].strip(), config['voliSCSIIPAddress%d' %(x)])) ### NFS if nfsFlag == 1 or allFlag == 1: for x in range(1, int(config['Number_of_NFSVolumes'])+1): startTime = ctime() executeCmd('mkdir -p mount/%s' %(config['volMountpoint%d' %(x)])) ### Mount executeCmd('mount -t nfs %s:/%s mount/%s' %(config['volIPAddress%d' %(x)], config['volMountpoint%d' %(x)], config['volMountpoint%d' %(x)])) output=executeCmd('mount | grep %s' %(config['volMountpoint%d' %(x)]))
else: print "Argument is not correct.. Correct way as below" print " python verifyMutualChap.py config.txt" print " python verifyMutualChap.py config.txt negative" exit() #### copy iscsid.conf file under /etc/iscsi/ folder with mutualchap credentials executeCmd('cp iscsiMutualChap.conf /etc/iscsi/iscsid.conf') for x in range(1, int(config['Number_of_ISCSIVolumes']) + 1): startTime = ctime() executeCmd('mkdir -p mount/%s' % (config['voliSCSIMountpoint%d' % (x)])) ### Discovery iqnname = getoutput( 'iscsiadm -m discovery -t st -p %s:3260 | grep %s | awk {\'print $2\'}' % (config['voliSCSIIPAddress%d' % (x)], config['voliSCSIMountpoint%d' % (x)])) # for negative testcase if negativeFlag == 1: ###no iscsi volumes discovered if iqnname == []: print "Negative testcase-iscsi volume %s login failed on the client with dummy Mutualchap credentials, testcase passed" % ( config['voliSCSIDatasetname%d' % (x)]) endTime = ctime() resultCollection( "Negative testcase-iscsi volume %s login failed on the client with dummy Mutualchap credentials" % (config['voliSCSIDatasetname%d' % (x)]), ["PASSED", ""], startTime, endTime) ### some iscsi volumes discovered else: output = executeCmd(
elif sys.argv[x].lower() == "%s" % ("all"): allFlag == 1 else: print "Argument is not correct.. Correct way as below" print "python executeExpand.py config.txt NFS" print "python executeExpand.py config.txt ALL" print "python executeExpand.py config.txt NFS CIFS ISCSI" exit() executeCmd('umount -a -t cifs -l') executeCmd('umount -a') for x in range(1, int(config['Number_of_ISCSIVolumes']) + 1): executeCmd('iscsiadm -m discovery -t st -p %s:3260' % (config['voliSCSIIPAddress%d' % (x)])) iqnname = getoutput( 'iscsiadm -m discovery -t st -p %s:3260 | grep %s | awk {\'print $2\'}' % (config['voliSCSIIPAddress%d' % (x)], config['voliSCSIMountpoint%d' % (x)])) print iqnname if iqnname == []: continue output = executeCmd( 'iscsiadm -m node --targetname "%s" --portal "%s:3260" --logout | grep Logout' % (iqnname[0].strip(), config['voliSCSIIPAddress%d' % (x)])) ###NFS if nfsFlag == 1 or allFlag == 1: for x in range(1, int(config['Number_of_NFSVolumes']) + 1): startTime = ctime() executeCmd('mkdir -p mount/%s' % (config['volMountpoint%d' % (x)])) ######Mount executeCmd('mount -t nfs %s:/%s mount/%s' %
config['host'], config['apikey'], config['response']) if len(sys.argv) < 3: print "Argument is not correct.. Correct way as below" print " python createISCSIInitiatorGroup.py config.txt iqn ip initiatorGrpname" print " python createISCSIInitiatorGroup.py config.txt system_iqn system_ip initiatorGrpname" exit() iqn = sys.argv[2] ip = sys.argv[3] ###initiator name init = sys.argv[4] ###get clients iqn if iqn == "system_iqn": iqn = getoutput( 'cat /etc/iscsi/initiatorname.iscsi | grep iqn | cut -d "=" -f 2') iqn = iqn[0].strip() ###get clients ip if ip == "system_ip": ip = getoutput( 'ifconfig eth0 | grep "inet addr:" | cut -d ":" -f 2 | awk \'{ print $1}\'' ) ip = ip[0].strip() ### list of accounts querycommand = 'command=listAccount' resp_listAccount = sendrequest(stdurl, querycommand) filesave("logs/ListAccount.txt", "w", resp_listAccount) data = json.loads(resp_listAccount.text) #print data
print 'Volume \"%s\" umounted successfully' % (volume['name']) return ['PASSED', ''] else: print umountResult[1] print 'Volume \"%s\" failed to umount' % (volume['name']) return ['FAILED', umountResult[1]] else: print 'Volume \"%s\" is not mounted' % (volume['name']) return ['PASSED', 'Volume is not mounted'] ###---------------------------------------------------------------------------- startTime = ctime() infile = '/etc/default/useradd' HOME = getoutput('cat /etc/default/useradd | grep HOME | cut -d "=" -f 2') HOME = HOME[0].rstrip('\n') usr1 = 'user1' pwd = 'test123' usr2 = 'user2' list_tsm = listTSMWithIP_new(stdurl, tsm_ip) if list_tsm[0] == 'PASSED': logging.info('Tsm present with the given IP "%s"', tsm_ip) else: endTime = ctime() print 'Not able to list list_tsms due to: ' + list_tsm[1] logAndresult(testcase, 'BLOCKED', list_tsm[1], startTime, endTime) logging.info('Getting tsm_name, tsm_id, and dataset_id...') get_tsmInfo = get_tsm_info(list_tsm[1])
final_result1 = addVol_client_Mount(vol1, stdurl, tsmID, tsmName, ClientIP) # creating another volume and mounting the same vol2 = {'name': 'nfslargeVol2', 'tsmid': tsmID, 'quotasize': '25G', \ 'datasetid': datasetID, 'protocoltype': 'NFS', 'iops': 200} final_result2 = addVol_client_Mount(vol2, stdurl, tsmID, tsmName, ClientIP) # writting 20GB of data vol_size = '20G' vol_size1 = vol_size.strip('G') vol_size1 = int(vol_size1) * 1024 exe = writingVDBfile(final_result1[0], VdbFile, vol_size) check_vdbench = is_vdbench_alive(vol1['name']) mount_point1 = getoutput('mount | grep %s | awk \'{print $3}\'' \ %(final_result1[0]['mountPoint'])) mount_point1 = mount_point1[0].strip('\n') startTime = ctime() while True: mountDetails = mountPointDetails('-m', mount_point1) Used = mountDetails[2] if int(Used) >= int(vol_size1): logging.info('Vdbench has filed large file of 20G, waiting for 30s') time.sleep(30) break else: check_vdbench = is_vdbench_alive(vol1['name']) if check_vdbench: continue else:
print "python execution.py config.txt nodeIP nodePassword ALL" print "python execution.py config.txt nodeIP nodePassword NFS CIFS ISCSI" exit() IP = sys.argv[2] passwd = sys.argv[3] ########### TestCase Execution Starts.. executeCmd('umount -a -t cifs -l') executeCmd('umount -a') for x in range(1, int(config['Number_of_ISCSIVolumes']) + 1): executeCmd('iscsiadm -m discovery -t st -p %s:3260' % (config['voliSCSIIPAddress%d' % (x)])) iqnname = getoutput( 'iscsiadm -m discovery -t st -p %s:3260 | grep %s | awk {\'print $2\'}' % (config['voliSCSIIPAddress%d' % (x)], config['voliSCSIMountpoint%d' % (x)])) print iqnname if iqnname == []: continue output = executeCmd( 'iscsiadm -m node --targetname "%s" --portal "%s:3260" --logout | grep Logout' % (iqnname[0].strip(), config['voliSCSIIPAddress%d' % (x)])) ###NFS if nfsFlag == 1 or allFlag == 1: for x in range(1, int(config['Number_of_NFSVolumes']) + 1): startTime = ctime() executeCmd('mkdir -p mount/%s' % (config['volMountpoint%d' % (x)])) ######Mount executeCmd('mount -t nfs %s:/%s mount/%s' %
elif len(sys.argv) == 6: No_of_Clones = sys.argv[3] prefixName = sys.argv[4] filename = sys.argv[5] executeCmd('md5sum %s | awk \'{print $1}\' > mount/%s_md5sum' % (filename, filename)) else: print bcolors.FAIL + "Arguments are not correct. Please provide as follows..." + bcolors.ENDC print bcolors.WARNING + "python verifyDataIntegrityOfClone.py config.txt <storage_protocol(nfs/cifs/fc/iscsi/all)> Number_of_Clones Prefix_name_For_Clone(Optional) filename_for_for_check_data_Integrity(optional)" + bcolors.ENDC exit() ### Logout iscsi LUN, those are already login for x in range(1, int(config['Number_of_ISCSIVolumes']) + 1): executeCmd('iscsiadm -m discovery -t st -p %s:3260' % (config['voliSCSIIPAddress%d' % (x)])) iqnname = getoutput( 'iscsiadm -m discovery -t st -p %s:3260 | grep %s | awk {\'print $2\'}' % (config['voliSCSIIPAddress%d' % (x)], config['voliSCSIMountpoint%d' % (x)])) print iqnname if iqnname == []: continue output = executeCmd( 'iscsiadm -m node --targetname "%s" --portal "%s:3260" --logout | grep Logout' % (iqnname[0].strip(), config['voliSCSIIPAddress%d' % (x)])) ### Its comman url for all the api calls stdurl = 'https://%s/client/api?apikey=%s&response=%s&' % ( config['host'], config['apikey'], config['response']) ### command for list filesystem querycommand = 'command=listFileSystem' resp_listFileSystem = sendrequest(stdurl, querycommand) filesave("logs/ListFileSystem.txt", "w", resp_listFileSystem) data = json.loads(resp_listFileSystem.text)
addClient = addNFSclient(stdurl, volid, 'ALL') endTime = ctime() if addClient[0] == 'FAILED': logAndresult(testcase, 'BLOCKED', addClient[1], startTime, endTime) logging.debug('Added nfs client "ALL" to the volume') volume = {'TSMIPAddress' : tsmIP, 'mountPoint': vol_mntPoint,\ 'name' : volname} nfsMount = mountNFS(volume) if nfsMount[0] == 'FAILED': msg = 'failed to mount NFS share "%s"' % (volume['name']) logAndresult(testcase, 'FAILED', msg, startTime, endTime) logging.info('Mounted Nfs Share "%s" successfully', volname) mount_point = getoutput('mount | grep %s | awk \'{print $3}\'' \ %(volume['mountPoint'])) mount_point = mount_point[0].strip('\n') executeVdbenchFile(volume, 'filesystem_nfs') check_vdbench = is_vdbench_alive(volname) time.sleep(1) while True: mountDetails = mountPointDetails('-m', mount_point) Used = mountDetails[2] if int(Used) >= 1000: logging.debug('vdbench has successfully created 1 GB file of the') logging.debug('going to stop vdbench after 10 seconds...') time.sleep(10) break check_vdbench = is_vdbench_alive(volname) if check_vdbench:
print "IP = "+IP print "Password = "******"Pool = "+poolName print "File = "+file print "Command = "+command t=getControllerInfo(IP, passwd, command, file) poolType =''; poolDisks = 0; noDiskGroups = 0; noOfSpares = 0;noOfCaches = 0;noOfLogs = 0;noOfMetaDisks = 0; noOfMetaDiskGroups = 0; noCacheDisks = 0; noSpareDisks = 0 ;noLogDisks = 0;noLogMirrDisks = 0 ; #### Function(s) Declartion Ends output =[] list = getoutput('cat %s' %(file)); for st in list: output = output + st.split(); try: del output[0]; del output[0]; except: print "nofile" output.append("last"); pool = { "pool" : "", "state" : "", "noOfDataDisks" : "", "noOfDataDiskGroups" : "0", "dataDiskGroupType" : "", "noOfLogs" : "0",