Refactor scripts

Reviewers: buda, teon.banek, florijan

Reviewed By: teon.banek

Differential Revision: https://phabricator.memgraph.io/D313
This commit is contained in:
Mislav Bradac 2017-04-26 13:48:47 +02:00
parent e78107bcea
commit 16d8a5b447
2 changed files with 77 additions and 42 deletions

25
init
View File

@ -14,7 +14,7 @@ function print_usage_and_exit {
# read arguments # read arguments
arcanist_diff_id="" arcanist_diff_id=""
clone_dependencies=true clone_dependencies=true
use_sudo=0 use_sudo=false
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case $1 in case $1 in
--no-clone-dependencies) --no-clone-dependencies)
@ -29,7 +29,7 @@ while [[ $# -gt 0 ]]; do
shift 2 shift 2
;; ;;
-s) -s)
use_sudo=1 use_sudo=true
shift shift
;; ;;
*) *)
@ -43,6 +43,7 @@ done
set -e set -e
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd ${script_dir}
required_pkgs=(git arcanist # used to clone sources required_pkgs=(git arcanist # used to clone sources
python-virtualenv python3-pip # required by 'run' script python-virtualenv python3-pip # required by 'run' script
@ -52,24 +53,32 @@ required_pkgs=(git arcanist # used to clone sources
for pkg in ${required_pkgs[@]}; do for pkg in ${required_pkgs[@]}; do
if dpkg -s $pkg 2>/dev/null >/dev/null; then if dpkg -s $pkg 2>/dev/null >/dev/null; then
echo "Found $pkg" echo "Found $pkg"
elif (( $use_sudo )); then elif [[ $use_sudo = true ]]; then
echo "Installing $pkg" echo "Installing $pkg"
if [[ ! `sudo apt-get -y install $pkg` ]]; then if [[ ! `sudo apt-get -y install $pkg` ]]; then
echo "Didn't install $pkg [required]" echo "Didn't install $pkg [required]"
required_missing=1 required_missing=true
fi fi
else else
echo "Missing $pkg [required]" echo "Missing $pkg [required]"
required_missing=1 required_missing=true
fi fi
done done
if (( $required_missing )); then if [[ $required_missing = true ]]; then
echo "Missing required packages. EXITING!" echo "Missing required packages. EXITING!"
echo "Please, install required packages and rerun $0 again." echo "Please, install required packages and rerun $0 again."
exit 2 exit 2
fi fi
# setup ve
if [ ! -d "ve3" ]; then
virtualenv -p python3 ve3
fi
source ve3/bin/activate
pip3 install --upgrade pip
pip3 install -r requirements.txt
# TODO: use pullbot and read a password from program arg or env var # TODO: use pullbot and read a password from program arg or env var
# (in order to use this script inside CI infrastructure) # (in order to use this script inside CI infrastructure)
@ -79,7 +88,7 @@ mkdir -p ${tests_folder}
# clone dressipi's tests # clone dressipi's tests
cd ${tests_folder} cd ${tests_folder}
if ${clone_dependencies}; then if [[ $clone_dependencies = true ]]; then
rm -rf ${tests_folder}/* rm -rf ${tests_folder}/*
git clone https://phabricator.memgraph.io/source/pilot_dressipi.git git clone https://phabricator.memgraph.io/source/pilot_dressipi.git
fi fi
@ -90,7 +99,7 @@ mkdir -p ${dbms_folder}
# clone memgraph & checkout right commit # clone memgraph & checkout right commit
cd ${dbms_folder} cd ${dbms_folder}
if ${clone_dependencies} ; then if [[ $clone_dependencies = true ]] ; then
rm -rf ${dbms_folder}/* rm -rf ${dbms_folder}/*
git clone https://phabricator.memgraph.io/diffusion/MG/memgraph.git git clone https://phabricator.memgraph.io/diffusion/MG/memgraph.git
fi fi

94
run
View File

@ -1,5 +1,33 @@
#!/bin/bash #!/bin/bash
function print_usage_and_exit {
echo "./run [--unstable] [--no-test-hardcoded]"
echo "Optional arguments:"
echo -e " --unstable\trun unstable scenarios"
echo -e " --no-test-hardcoded\tdon't run dressipi tests"
exit 1
}
# read arguments
unstable=false
test_hardcoded=true
while [[ $# -gt 0 ]]; do
case $1 in
--unstable)
unstable=true
shift
;;
--no-test-hardcoded)
test_hardcoded=false
shift
;;
*)
# unknown option
print_usage_and_exit
;;
esac
done
# exit if any subcommand returns a non-zero status # exit if any subcommand returns a non-zero status
set -e set -e
@ -10,55 +38,53 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
memgraph_src_dir=${script_dir}/dbms/memgraph memgraph_src_dir=${script_dir}/dbms/memgraph
memgraph_build_dir=${script_dir}/dbms/memgraph/build memgraph_build_dir=${script_dir}/dbms/memgraph/build
# setup dressipi # activate virtualenv
cd ${script_dir} source $script_dir/ve3/bin/activate
# setup ve
if [ ! -d "ve3" ]; then
virtualenv -p python3 ve3
fi
source ve3/bin/activate
pip3 install --upgrade pip
pip3 install -r requirements.txt
cd ${memgraph_build_dir}
# binary is available after the build
binary_name=$(find ${memgraph_build_dir}/ -maxdepth 1 -executable -name "memgraph*")
# get full path to memgraph config for hardcoded queries
hardcoded_queries_config_path="${memgraph_src_dir}/config/hardcoded_queries_memgraph.yaml"
# run memgraph
MEMGRAPH_CONFIG=${hardcoded_queries_config_path} ${binary_name} &
function cleanup_and_exit { function cleanup_and_exit {
pkill -9 -f "${binary_name}" pkill -9 -f "${binary_name}"
exit $1 exit $1
} }
# the script has to be careful because one process has been detached cd ${memgraph_build_dir}
# binary is available after the build
binary_name=$(find ${memgraph_build_dir}/ -maxdepth 1 -executable -name "memgraph*")
# the script has to be careful because memgraph process will be detached
set +e set +e
## run tests # run dressipi tests
if [[ $test_hardcoded = true ]]; then
# get full path to memgraph config for hardcoded queries
hardcoded_queries_config_path="${memgraph_src_dir}/config/hardcoded_queries_memgraph.yaml"
# run memgraph
MEMGRAPH_CONFIG=${hardcoded_queries_config_path} ${binary_name} 1>&2 &
# run Dressipi test # run Dressipi test
cd ${script_dir}/tests/pilot_dressipi cd ${script_dir}/tests/pilot_dressipi
python run.py python run.py
exit_code=$? exit_code=$?
if [[ ${exit_code} != 0 ]]; then if [[ ${exit_code} != 0 ]]; then
cleanup_and_exit ${exit_code} cleanup_and_exit ${exit_code}
fi
# kill memgraph for hardcoded queries
pkill -9 -f "${binary_name}"
fi fi
# kill memgraph for hardcoded queries
pkill -9 -f "${binary_name}"
# get full path to memgraph config for interpreted queries # get full path to memgraph config for interpreted queries
config_path="${memgraph_src_dir}/config/memgraph.yaml" config_path="${memgraph_src_dir}/config/memgraph.yaml"
# run memgraph # run memgraph
MEMGRAPH_CONFIG=${config_path} ${binary_name} & MEMGRAPH_CONFIG=${config_path} ${binary_name} 1>&2 &
# run custom scenarios # run custom scenarios
cd ${script_dir} cd ${script_dir}
python tck_engine/test_executor.py \ tck_flags="--root tck_engine/tests/memgraph_V1/features
--root tck_engine/tests/memgraph_V1/features \ --graphs-root tck_engine/tests/memgraph_V1/graphs
--graphs-root tck_engine/tests/memgraph_V1/graphs \ --no-side-effects
--no-side-effects \ --db memgraph"
--db memgraph if [[ $unstable = true ]]; then
tck_flags="$tck_flags --unstable"
fi
python tck_engine/test_executor.py $tck_flags
cleanup_and_exit ${exit_code} cleanup_and_exit ${exit_code}