update scripts, prepare for fixing MOL-180
diff --git a/scripts/run.sh b/scripts/run.sh
index 11c90ee..368410c 100644
--- a/scripts/run.sh
+++ b/scripts/run.sh
@@ -1,85 +1,109 @@
 #!/bin/bash
 set -e
 
-type="iozone"
+# don't forget to change it in prepare.sh as well
+my_dir="$(dirname "$0")"
+source "$my_dir/config.sh"
 
-bsizes="1k 4k 64k 256k 1m"
-ops="randwrite"
-osync="s" # a
-num_times="3"
-concurrences="32"
-
-for concurrence in $concurrences; do
-	for bsize in $bsizes ; do
-		for op in $ops ; do 
-			for sync in $osync ; do 
-				for counter in $(seq 1 $num_times) ; do
-					# if [[ "$ops" == "write" && "$osync" == "s" ]] ; then
-					# 	continue
-					# fi
-
-					if [[ "$sync" == "s" ]] ; then
-						ssync="-s"
-						factor="x500"
-					else
-						if [[ "$bsize" == "1k" || "$bsize" == "4k" ]] ; then
-							continue
-						fi
-
-						ssync=
-						factor="r2"
-					fi
+BLOCK_SIZES="1k 4k 64k 256k 1m"
+OPERATIONS="randwrite write randread read"
+SYNC_TYPES="s a d"
+REPEAT_COUNT="3"
+CONCURRENCES="1 8 64"
+IODEPTHS="16"
 
 
-					io_opts="--type $type -a $op --iodepth 16 --blocksize $bsize --iosize $factor $ssync --concurrency $concurrence"
+SYNC_FACTOR="x500"
+DIRECT_FACTOR="x500"
+ASYNC_FACTOR="r2"
 
-					# aff_group=$(nova server-group-list | grep ' ceph ' | awk '{print $2}')
-					# extra_opts="user=ubuntu,keypair_name=ceph,img_name=ubuntu,flavor_name=ceph.512"
-					# extra_opts="${extra_opts},network_zone_name=net04,flt_ip_pool=net04_ext,key_file=ceph.pem"
-					# extra_opts="${extra_opts},aff_group=${aff_group},count=x1"
 
-					echo $io_opts
-					# python run_test.py --runner ssh -l -o "$io_opts" -t io-scenario $type --runner-extra-opts="$extra_opts"
+function get_file_size_opts() {
+    SYNC_TYPE="$1"
+    if [ "$SYNC_TYPE" = "s" ] ; then
+        echo "--iosize $SYNC_FACTOR -s"
+    elif [ "$SYNC_TYPE" = "d" ] ; then
+        echo "--iosize $DIRECT_FACTOR -d"
+    else
+        echo "--iosize $ASYNC_FACTOR"
+    fi
+}
 
-					# io_opts="--type $type -a $op --iodepth 16 --blocksize $bsize --iosize $factor $ssync"
-					# python run_test.py --runner rally -l -o "$io_opts" -t io-scenario $type --runner-extra-opts="--deployment $1"
-				done
-			done
-		done
-	done
-done
+function echo_combinations() {
+    for IODEPTH in $IODEPTHS ; do
+        for CONCURRENCE in $CONCURRENCES ; do
+            for BSIZE in $BLOCK_SIZES ; do
+                for OPERATION in $OPERATIONS ; do 
+                    for SYNC_TYPE in $SYNC_TYPES ; do
 
-# bsizes="4k 64k 256k 1m"
-# ops="randread read"
+                        # filter out too slow options
+                        if [ "$BLOCKSIZE" = "1k" -o "$BLOCK_SIZE" = "4k" ] ; then
+                            if [ "$SYNC_TYPE" = "a" ] ; then
+                                continue
+                            fi
+                        fi 
 
-# for bsize in $bsizes ; do
-# 	for op in $ops ; do 
-# 		for xxx in $three_times ; do
-# 			io_opts="--type $type -a $op --iodepth 16 --blocksize $bsize --iosize r2"
-# 			python run_rally_test.py -l -o "$io_opts" -t io-scenario $type --rally-extra-opts="--deployment $1"
-# 		done
-# 	done
-# done
+                        # filter out sync reads
+                        if [ "$OPERATION" = "read" -o "$OPERATION" = "randread" ] ; then
+                            if [ "$SYNC_TYPE" = "s" ] ; then
+                                continue
+                            fi
+                        fi 
 
-# bsizes="1k 4k"
-# ops="randwrite write"
-# three_times="1 2 3"
+                        FILE_SIZE_AND_SYNC=$(get_file_size_opts "$SYNC_TYPE")
 
-# for bsize in $bsizes ; do
-# 	for op in $ops ; do 
-# 		for xxx in $three_times ; do
-# 			factor="r2"
-# 			io_opts="--type $type -a $op --iodepth 16 --blocksize $bsize --iosize $factor"
-# 			python run_rally_test.py -l -o "$io_opts" -t io-scenario $type --rally-extra-opts="--deployment $1"
-# 		done
-# 	done
-# done
 
-# ops="randread read"
+                        IO_OPTS="--type $TESTER_TYPE "
+                        IO_OPTS="$IO_OPTS -a $OPERATION "
+                        IO_OPTS="$IO_OPTS --iodepth $IODEPTH "
+                        IO_OPTS="$IO_OPTS --blocksize $BSIZE "
+                        IO_OPTS="$IO_OPTS $FILE_SIZE_AND_SYNC "
+                        IO_OPTS="$IO_OPTS --concurrency $CONCURRENCE"
 
-# for op in $ops ; do 
-# 	for xxx in $three_times ; do
-# 		io_opts="--type $type -a $op --iodepth 16 --blocksize 1k --iosize r2"
-# 		python run_rally_test.py -l -o "$io_opts" -t io-scenario $type --rally-extra-opts="--deployment $1"
-# 	done
-# done
+                        for COUNTER in $(seq 1 $REPEAT_COUNT) ; do
+                            echo $IO_OPTS
+                        done
+                    done
+                done
+            done
+        done
+    done
+}
+
+
+function run_test() {
+    OPTION_FILE="$1"
+
+    if [ ! -f "$OPTION_FILE" ] ; then
+        echo "Path to file with io.py options list should be passed"
+        exit 1
+    fi
+
+    if [ "$RUNNER" = "ssh" ] ; then
+        GROUP_ID=$(nova server-group-list | grep " $SERV_GROUP " | awk '{print $2}' )
+        EXTRA_OPTS="user=$IMAGE_USER"
+        EXTRA_OPTS="${EXTRA_OPTS},keypair_name=$KEYPAIR_NAME"
+        EXTRA_OPTS="${EXTRA_OPTS},img_name=$IMAGE_NAME"
+        EXTRA_OPTS="${EXTRA_OPTS},flavor_name=$FLAVOR_NAME"
+        EXTRA_OPTS="${EXTRA_OPTS},network_zone_name=$NETWORK_ZONE_NAME"
+        EXTRA_OPTS="${EXTRA_OPTS},flt_ip_pool=$FL_NETWORK_ZONE_NAME"
+        EXTRA_OPTS="${EXTRA_OPTS},key_file=$KEY_FILE_NAME"
+        EXTRA_OPTS="${EXTRA_OPTS},aff_group=$GROUP_ID"
+        EXTRA_OPTS="${EXTRA_OPTS},count=$VM_COUNT"
+    else
+        echo "Unsupported runner $RUNNER"
+        exit 1
+    fi
+
+    RUN_TEST_OPTS="-t io-scenario -l --runner $RUNNER"
+    set -x
+    python run_test.py $RUN_TEST_OPTS --runner-extra-opts="$EXTRA_OPTS" -f "$OPTION_FILE" $TESTER_TYPE
+    set +x
+}
+
+if [ "$1" = '--prepare-opts' ] ; then
+    echo_combinations
+else
+    run_test $1
+fi
+