summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKaushal M <kaushal@redhat.com>2012-09-14 11:45:34 +0530
committerAnand Avati <avati@redhat.com>2012-12-04 14:44:36 -0800
commit7b5a21707edbbee1940f7cd3d05043bec998e51a (patch)
tree0e5fdbc08d6461ec30d8f5cf829d61e187a58c27 /tests
parent6a1b89c0c4221b13c21e66a048e08e4eb95de7bd (diff)
glusterd, cli: Task id's for async tasks
This patch introduces task-id's for async tasks like rebalance, remove-brick and replace-brick. An id is generated for each task when it is started and displayed to the user in cli output. The status of running tasks is also included in the output of "volume status" along with its id, so that a user can easily track the progress of an async task. Also, * added tests for this feature into the regression test suite. * added a python script for creating files, 'create-files.py', courtesy Vijaykumar Koppad (vkoppad@redhat.com) into the test suite. Change-Id: Ib0c0d12e0d6c8f72ace48d303d7ff3102157e876 BUG: 857330 Signed-off-by: Kaushal M <kaushal@redhat.com> Reviewed-on: http://review.gluster.org/3942 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Anand Avati <avati@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/bugs/bug-857330/common.rc70
-rwxr-xr-xtests/bugs/bug-857330/normal.t78
-rwxr-xr-xtests/bugs/bug-857330/xml.t101
-rwxr-xr-xtests/utils/create-files.py207
4 files changed, 456 insertions, 0 deletions
diff --git a/tests/bugs/bug-857330/common.rc b/tests/bugs/bug-857330/common.rc
new file mode 100644
index 00000000..f2327a86
--- /dev/null
+++ b/tests/bugs/bug-857330/common.rc
@@ -0,0 +1,70 @@
+. $(dirname $0)/../../include.rc
+
+UUID_REGEX='[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}'
+
+TASK_ID=""
+COMMAND=""
+PATTERN=""
+
+function check-and-store-task-id()
+{
+ TASK_ID=""
+
+ local task_id=$($CLI $COMMAND | grep $PATTERN | grep -o -E "$UUID_REGEX")
+
+ if [ -z "$task_id" ] && [ "${task_id+asdf}" = "asdf" ]; then
+ return 1
+ fi
+
+ TASK_ID=$task_id
+ return 0;
+}
+
+function check-with-stored-task-id()
+{
+ local task_id=$($CLI $COMMAND | grep $PATTERN | grep -o -E "$UUID_REGEX")
+
+ if [ -z "$task_id" ] && [ "${task_id+asdf}" = "asdf" ]; then
+ return 1
+ fi
+
+ if [ "$TASK_ID" != "$task_id" ]; then
+ return 1
+ fi
+
+ return 0
+}
+
+function check-and-store-task-id-xml()
+{
+ TASK_ID=""
+
+ local task_id=$($CLI $COMMAND --xml | xmllint --format - | grep $PATTERN | grep -o -E "$UUID_REGEX")
+
+ if [ -z "$task_id" ] && [ "${task_id+asdf}" = "asdf" ]; then
+ return 1
+ fi
+
+ TASK_ID=$task_id
+ return 0;
+}
+
+function check-with-stored-task-id-xml()
+{
+ local task_id=$($CLI $COMMAND --xml | xmllint --format - | grep $PATTERN | grep -o -E "$UUID_REGEX")
+
+ if [ -z "$task_id" ] && [ "${task_id+asdf}" = "asdf" ]; then
+ return 1
+ fi
+
+ if [ "$TASK_ID" != "$task_id" ]; then
+ return 1
+ fi
+
+ return 0
+}
+
+function get-task-status()
+{
+ $CLI $COMMAND | grep -o $PATTERN
+}
diff --git a/tests/bugs/bug-857330/normal.t b/tests/bugs/bug-857330/normal.t
new file mode 100755
index 00000000..abf8e2ac
--- /dev/null
+++ b/tests/bugs/bug-857330/normal.t
@@ -0,0 +1,78 @@
+#!/bin/bash
+
+. $(dirname $0)/common.rc
+
+cleanup;
+
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume info;
+
+TEST $CLI volume create $V0 $H0:$B0/${V0}1;
+TEST $CLI volume info $V0;
+TEST $CLI volume start $V0;
+
+TEST glusterfs -s $H0 --volfile-id=$V0 $M0;
+
+TEST python2 $(dirname $0)/../../utils/create-files.py --multi -b 10 -d 10 -n 10 $M0;
+
+TEST umount $M0;
+
+###############
+## Rebalance ##
+###############
+TEST $CLI volume add-brick $V0 $H0:$B0/${V0}2;
+
+COMMAND="volume rebalance $V0 start"
+PATTERN="ID:"
+TEST check-and-store-task-id
+
+COMMAND="volume status $V0"
+PATTERN="Rebalance"
+TEST check-with-stored-task-id
+
+COMMAND="volume rebalance $V0 status"
+PATTERN="completed"
+EXPECT_WITHIN 300 $PATTERN get-task-status
+
+###################
+## Replace-brick ##
+###################
+REP_BRICK_PAIR="$H0:$B0/${V0}2 $H0:$B0/${V0}3"
+
+COMMAND="volume replace-brick $V0 $REP_BRICK_PAIR start"
+PATTERN="ID:"
+TEST check-and-store-task-id
+
+COMMAND="volume status $V0"
+PATTERN="Replace"
+TEST check-with-stored-task-id
+
+COMMAND="volume replace-brick $V0 $REP_BRICK_PAIR status"
+PATTERN="complete"
+EXPECT_WITHIN 300 $PATTERN get-task-status
+
+TEST $CLI volume replace-brick $V0 $REP_BRICK_PAIR commit;
+
+##################
+## Remove-brick ##
+##################
+COMMAND="volume remove-brick $V0 $H0:$B0/${V0}3 start"
+PATTERN="ID:"
+TEST check-and-store-task-id
+
+COMMAND="volume status $V0"
+PATTERN="Remove"
+TEST check-with-stored-task-id
+
+COMMAND="volume remove-brick $V0 $H0:$B0/${V0}3 status"
+PATTERN="completed"
+EXPECT_WITHIN 300 $PATTERN get-task-status
+
+TEST $CLI volume remove-brick $V0 $H0:$B0/${V0}3 commit
+
+TEST $CLI volume stop $V0;
+TEST $CLI volume delete $V0;
+TEST ! $CLI volume info $V0;
+
+cleanup;
diff --git a/tests/bugs/bug-857330/xml.t b/tests/bugs/bug-857330/xml.t
new file mode 100755
index 00000000..a6e0b34c
--- /dev/null
+++ b/tests/bugs/bug-857330/xml.t
@@ -0,0 +1,101 @@
+#!/bin/bash
+
+. $(dirname $0)/common.rc
+
+cleanup;
+
+TEST glusterd
+TEST pidof glusterd
+TEST $CLI volume info;
+
+TEST $CLI volume create $V0 $H0:$B0/${V0}1;
+TEST $CLI volume info $V0;
+TEST $CLI volume start $V0;
+
+TEST glusterfs -s $H0 --volfile-id=$V0 $M0;
+
+TEST python2 $(dirname $0)/../../utils/create-files.py --multi -b 10 -d 10 -n 10 $M0;
+
+TEST umount $M0;
+
+
+###############
+## Rebalance ##
+###############
+TEST $CLI volume add-brick $V0 $H0:$B0/${V0}2;
+
+COMMAND="volume rebalance $V0 start"
+PATTERN="task-id"
+TEST check-and-store-task-id-xml
+
+COMMAND="volume status $V0"
+PATTERN="id"
+TEST check-with-stored-task-id-xml
+
+COMMAND="volume rebalance $V0 status"
+PATTERN="task-id"
+TEST check-with-stored-task-id-xml
+
+## TODO: Add tests for rebalance stop
+
+COMMAND="volume rebalance $V0 status"
+PATTERN="completed"
+EXPECT_WITHIN 300 $PATTERN get-task-status
+
+###################
+## Replace-brick ##
+###################
+REP_BRICK_PAIR="$H0:$B0/${V0}2 $H0:$B0/${V0}3"
+
+COMMAND="volume replace-brick $V0 $REP_BRICK_PAIR start"
+PATTERN="task-id"
+TEST check-and-store-task-id-xml
+
+COMMAND="volume status $V0"
+PATTERN="id"
+TEST check-with-stored-task-id-xml
+
+COMMAND="volume replace-brick $V0 $REP_BRICK_PAIR status"
+PATTERN="task-id"
+TEST check-with-stored-task-id-xml
+
+## TODO: Add more tests for replace-brick pause|abort
+
+COMMAND="volume replace-brick $V0 $REP_BRICK_PAIR status"
+PATTERN="complete"
+EXPECT_WITHIN 300 $PATTERN get-task-status
+
+COMMAND="volume replace-brick $V0 $REP_BRICK_PAIR commit"
+PATTERN="task-id"
+TEST check-with-stored-task-id-xml
+
+##################
+## Remove-brick ##
+##################
+COMMAND="volume remove-brick $V0 $H0:$B0/${V0}3 start"
+PATTERN="task-id"
+TEST check-and-store-task-id-xml
+
+COMMAND="volume status $V0"
+PATTERN="id"
+TEST check-with-stored-task-id-xml
+
+COMMAND="volume remove-brick $V0 $H0:$B0/${V0}3 status"
+PATTERN="task-id"
+TEST check-with-stored-task-id-xml
+
+COMMAND="volume remove-brick $V0 $H0:$B0/${V0}3 status"
+PATTERN="completed"
+EXPECT_WITHIN 300 $PATTERN get-task-status
+
+## TODO: Add tests for remove-brick stop
+
+COMMAND="volume remove-brick $V0 $H0:$B0/${V0}3 commit"
+PATTERN="task-id"
+TEST check-with-stored-task-id-xml
+
+TEST $CLI volume stop $V0;
+TEST $CLI volume delete $V0;
+TEST ! $CLI volume info $V0;
+
+cleanup;
diff --git a/tests/utils/create-files.py b/tests/utils/create-files.py
new file mode 100755
index 00000000..0d937eff
--- /dev/null
+++ b/tests/utils/create-files.py
@@ -0,0 +1,207 @@
+#!/usr/bin/python
+
+# This script was developed by Vijaykumar Koppad (vkoppad@redhat.com)
+# The latest version of this script can found at
+# http://github.com/vijaykumar-koppad/crefi
+
+from __future__ import with_statement
+import sys
+import os
+import re
+import random
+from optparse import OptionParser
+import time
+import string
+import errno
+
+def os_rd(src, size):
+ fd = os.open(src,os.O_RDONLY)
+ data = os.read(fd, size)
+ os.close(fd)
+ return data
+
+def os_wr(dest, data):
+ fd = os.open(dest,os.O_WRONLY|os.O_CREAT|os.O_EXCL, 0644)
+ os.write(fd, data)
+ os.close(fd)
+ return
+
+def create_sparse_file(fil):
+ if option.size:
+ option.random = False
+ size = option.size
+ else:
+ size = random.randint(option.min, option.max)
+ data = os_rd("/dev/zero", size)
+ os_wr(fil, data)
+ return
+
+def create_binary_file(fil):
+ if option.size:
+ option.random = False
+ size = option.size
+ else:
+ size = random.randint(option.min, option.max)
+ data = os_rd("/dev/urandom", size)
+ os_wr(fil, data)
+ return
+
+def create_txt_file(fil):
+ if option.size:
+ option.random = False
+ size = option.size
+ else:
+ size = random.randint(option.min, option.max)
+ if size < 500*1024:
+ data = os_rd("/etc/services", size)
+ os_wr(fil, data)
+ else:
+ data = os_rd("/etc/services", 500*1024)
+ file_size = 0
+ fd = os.open(fil,os.O_WRONLY|os.O_CREAT|os.O_EXCL, 0644)
+ while file_size < size:
+ os.write(fd, data)
+ file_size += 500*1024
+ os.close(fd)
+ return
+
+def get_filename():
+ size = option.flen
+ char = string.uppercase+string.digits
+ st = ''.join(random.choice(char) for i in range(size))
+ ti = str((hex(int(str(time.time()).split('.')[0])))[2:])
+ return ti+"~~"+st
+
+def text_files(files, file_count):
+ for k in range(files):
+ if not file_count%option.inter:
+ print file_count
+ fil = get_filename()
+ create_txt_file(fil)
+ file_count += 1
+ return file_count
+
+def sparse_files(files, file_count):
+ for k in range(files):
+ if not file_count%option.inter:
+ print file_count
+ fil = get_filename()
+ create_sparse_file(fil)
+ file_count += 1
+ return file_count
+
+def binary_files(files, file_count):
+ for k in range(files):
+ if not file_count%option.inter:
+ print file_count
+ fil = get_filename()
+ create_binary_file(fil)
+ file_count += 1
+ return file_count
+
+def human2bytes(size):
+ size_short = {
+ 1024 : ['K','KB','KiB','k','kB','kiB'],
+ 1024*1024 : ['M','MB','MiB'],
+ 1024*1024*1024 : ['G','GB','GiB']
+}
+ num = re.search('(\d+)',size).group()
+ ext = size[len(num):]
+ num = int(num)
+ if ext == '':
+ return num
+ for value, keys in size_short.items():
+ if ext in keys:
+ size = num*value
+ return size
+
+def multipledir(mnt_pnt,brdth,depth,files):
+ files_count = 1
+ for i in range(brdth):
+ breadth = mnt_pnt+"/"+str(i)
+ try:
+ os.makedirs(breadth)
+ except OSError as ex:
+ if not ex.errno is errno.EEXIST:
+ raise
+ os.chdir(breadth)
+ dir_depth = breadth
+ print breadth
+ for j in range(depth):
+ dir_depth = dir_depth+"/"+str(j)
+ try:
+ os.makedirs(dir_depth)
+ except OSError as ex:
+ if not ex.errno is errno.EEXIST:
+ raise
+ os.chdir(dir_depth)
+ if option.file_type == "text":
+ files_count = text_files(files, files_count)
+ elif option.file_type == "sparse":
+ files_count = sparse_files(files, files_count)
+ elif option.file_type == "binary":
+ files_count = binary_files(files, files_count)
+ else:
+ print "Not a valid file type"
+ sys.exit(1)
+
+def singledir(mnt_pnt, files):
+ files_count = 1
+ os.chdir(mnt_pnt)
+ if option.file_type == "text":
+ files_count = text_files(files, files_count)
+ elif option.file_type == "sparse":
+ files_count = sparse_files(files, files_count)
+ elif option.file_type == "binary":
+ files_count = binary_files(files, files_count)
+ else:
+ print "Not a valid file type"
+ sys.exit(1)
+
+if __name__ == '__main__':
+ usage = "usage: %prog [option] <MNT_PT>"
+ parser = OptionParser(usage=usage)
+ parser.add_option("-n", dest="files",type="int" ,default=100,
+ help="number of files in each level [default: %default]")
+ parser.add_option("--size", action = "store",type="string",
+ help="size of the files to be used")
+ parser.add_option("--random", action="store_true", default=True,
+ help="random size of the file between --min and --max "
+ "[default: %default]")
+ parser.add_option("--max", action = "store",type="string", default="500K",
+ help="maximum size of the files, if random is True "
+ "[default: %default]")
+ parser.add_option("--min", action = "store",type="string", default="10K",
+ help="minimum size of the files, if random is True "
+ "[default: %default]" )
+ parser.add_option("--single", action="store_true", dest="dir",default=True,
+ help="create files in single directory [default: %default]" )
+ parser.add_option("--multi", action="store_false", dest="dir",
+ help="create files in multiple directories")
+ parser.add_option("-b", dest="brdth",type="int",default=5,
+ help="number of directories in one level(works with --multi)[default: %default]")
+ parser.add_option("-d", dest="depth",type="int",default=5,
+ help="number of levels of directories(works with --multi)[default: %default]")
+ parser.add_option("-l", dest="flen",type="int" ,default=10,
+ help="number of bytes for filename "
+ "[default: %default]")
+ parser.add_option("-t","--type", action="store", type="string" , dest="file_type",default="text",
+ help="type of the file to be created (text, sparse, binary) [default: %default]" )
+ parser.add_option("-I", dest="inter", type="int", default=100,
+ help="print number files created of interval [defailt: %dafault]")
+ (option,args) = parser.parse_args()
+ if not args:
+ print "usage: <script> [option] <MNT_PT>"
+ print ""
+ sys.exit(1)
+ args[0] = os.path.abspath(args[0])
+ if option.size:
+ option.size = human2bytes(option.size)
+ else:
+ option.max = human2bytes(option.max)
+ option.min = human2bytes(option.min)
+ if option.dir:
+ singledir(args[0], option.files)
+ else:
+ multipledir(args[0], option.brdth, option.depth, option.files)
+ print "creation of files completed.\n"