summaryrefslogtreecommitdiffstats
path: root/glustolibs-io
diff options
context:
space:
mode:
authorkshithijiyer <kshithij.ki@gmail.com>2019-08-16 14:38:21 +0530
committerBala Konda Reddy M <bmekala@redhat.com>2019-08-27 13:25:25 +0000
commitde8bd253642e821cb8e15b74387ead06c00a55fc (patch)
treea1081a0f1558c3504c3b87ff3ffbc439a4fb2d74 /glustolibs-io
parent7cfff7f9d8d482289b08a28e1537f9f08b5122a1 (diff)
Adding library to run_crefi() to glustolibs-IO.
What is crefi? Crefi is a Python command-line tool to create multi threaded workload on a filesystem and do file operations on created data. It provides basic operations to create files of different sizes, different types, in different directory structures, along with creating symlinks, hardlinks to files, and also rename, truncate, chmod, chown, chgrp and setxattr on the created files. Typical use involves creating large number of files of different sizes, over different layout, and do different operations on the created files. Which components need this tool? - Geo-rep - AFR Changes needed in infrastructure: https://github.com/gluster/centosci/commit/1fe330d34a62b56438f6eb86538286962b1abd90 Change-Id: I1e579f6f1f2c6ef0d018c055234abbf0f147e621 Signed-off-by: kshithijiyer <kshithij.ki@gmail.com>
Diffstat (limited to 'glustolibs-io')
-rwxr-xr-xglustolibs-io/glustolibs/io/utils.py128
1 files changed, 128 insertions, 0 deletions
diff --git a/glustolibs-io/glustolibs/io/utils.py b/glustolibs-io/glustolibs/io/utils.py
index 52c2c7df0..ba73b1711 100755
--- a/glustolibs-io/glustolibs/io/utils.py
+++ b/glustolibs-io/glustolibs/io/utils.py
@@ -800,3 +800,131 @@ def check_arequal_bricks_replicated(mnode, volname):
g.log.info('Arequals for subvol and %s are equal', brick)
g.log.info('All arequals are equal for volume %s', volname)
return True
+
+
+def run_crefi(client, mountpoint, number, breadth, depth, thread=5,
+ random_size=False, fop='create', filetype='text',
+ minfs=10, maxfs=500, single=False, multi=False, size=100,
+ interval=100, nameBytes=10, random_filename=True):
+ """
+ A function to run crefi on a given mount point and generate I/O.
+
+ Args:
+ client(str): Client on which I/O has to be performed.
+ mountpoint(str): Mount point where the client is mounted.
+ number(int): Number of files to be created.
+ breadth(int): Number of directories in one level.
+ depth(int): Number of levels of directories.
+
+ Kwargs:
+ thread(int): Number of threads used to generate fop.
+ random_size(bool): Random size of the file between min and max.
+ fop(str): fop can be [create|rename|chmod|chown|chgrp|symlink|hardlink|
+ truncate|setxattr] this specifies the type of fop to be
+ executed by default it is create.
+ filetype(str): filetype can be [text|sparse|binary|tar] this specifies
+ the type of file by default it is text.
+ minfs(int): If random is set to true then this value has to be altered
+ to change minimum file size. (Value is in KB)
+ maxfs(int): If random is set to true then this value has to be altered
+ to change maximum file size. (Value is in KB)
+ single(bool): Create files in a single directory.
+ multi(bool): Create files in sub-dir and sub-sub dir.
+ size(int): Size of the files to be created. (Value is in KB)
+ interval(int): Print number files created of interval.
+ nameBytes(int): Number of bytes for filename. (Value is in Bytes)
+ random_filename(bool): It creates files with random names, if set to
+ False it creates files with file name file1,
+ file2 and so on.
+
+ Returns:
+ bool: True if I/O was sucessfully otherwise False.
+
+ NOTE:
+ To use this function it is a prerequisite to have crefi installed
+ on all the clients. Please use the below command to install it:
+ $ pip install crefi
+ $ pip install pyxattr
+ """
+
+ # Checking value of fop.
+ list_of_fops = ["create", "rename", "chmod", "chown", "chgrp", "symlink",
+ "hardlink", "truncate", "setxattr"]
+ if fop not in list_of_fops:
+ g.log.error("fop value is not valid.")
+ return False
+
+ # Checking value of filetype.
+ list_of_filetypes = ["text", "sparse", "binary", "tar"]
+ if filetype not in list_of_filetypes:
+ g.log.error("filetype is not a valid file type.")
+ return False
+
+ # Checking if single and multi both are set to true.
+ if single and multi:
+ g.log.error("single and mutli both can't be true.")
+ return False
+
+ # Checking if file size and random size arguments are given together.
+ if (size > 100 or size < 100) and random_size:
+ g.log.error("Size and Random size can't be used together.")
+ return False
+
+ # Checking if minfs is greater than or equal to maxfs.
+ if random_size and (minfs >= maxfs):
+ g.log.error("minfs shouldn't be greater than or equal to maxfs.")
+ return False
+
+ # Creating basic command.
+ command = ("crefi %s -n %s -b %s -d %s "
+ % (mountpoint, number, breadth, depth))
+
+ # Checking thread value and adding it, If it is greater or smaller than 5.
+ if thread > 5 or thread < 5:
+ command = command + ("-T %s " % thread)
+
+ # Checking if random size is true or false.
+ if random_size:
+ command = command + "--random "
+ if minfs > 10 or minfs < 10:
+ command = command + ("--min %s " % minfs)
+ if maxfs > 500 or maxfs < 500:
+ command = command + ("--max %s " % maxfs)
+
+ # Checking fop and adding it if not create.
+ if fop != "create":
+ command = command + ("--fop %s " % fop)
+
+ # Checking if size if greater than or less than 100.
+ if size > 100 or size < 100:
+ command = command + ("--size %s " % size)
+
+ # Checking if single or mutli is true.
+ if single:
+ command = command + "--single "
+ if multi:
+ command = command + "--multi "
+
+ # Checking if random_filename is false.
+ if not random_filename:
+ command = command + "-R "
+
+ # Checking if print interval is greater than or less than 100.
+ if interval > 100 or interval < 100:
+ command = command + ("-I %s " % interval)
+
+ # Checking if name Bytes is greater than or less than 10.
+ if nameBytes > 10 or nameBytes < 10:
+ command = command + ("-l %s " % nameBytes)
+
+ # Checking filetype and setting it if not
+ # text.
+ if filetype != "text":
+ command = command + ("-t %s " % filetype)
+
+ # Running the command on the client node.
+ ret, _, _ = g.run(client, command)
+ if ret:
+ g.log.error("Failed to run crefi on %s." % client)
+ return False
+ return True