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
arcanist_diff_id=""
clone_dependencies=true
use_sudo=0
use_sudo=false
while [[ $# -gt 0 ]]; do
case $1 in
--no-clone-dependencies)
@ -29,7 +29,7 @@ while [[ $# -gt 0 ]]; do
shift 2
;;
-s)
use_sudo=1
use_sudo=true
shift
;;
*)
@ -43,6 +43,7 @@ done
set -e
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd ${script_dir}
required_pkgs=(git arcanist # used to clone sources
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
if dpkg -s $pkg 2>/dev/null >/dev/null; then
echo "Found $pkg"
elif (( $use_sudo )); then
elif [[ $use_sudo = true ]]; then
echo "Installing $pkg"
if [[ ! `sudo apt-get -y install $pkg` ]]; then
echo "Didn't install $pkg [required]"
required_missing=1
required_missing=true
fi
else
echo "Missing $pkg [required]"
required_missing=1
required_missing=true
fi
done
if (( $required_missing )); then
if [[ $required_missing = true ]]; then
echo "Missing required packages. EXITING!"
echo "Please, install required packages and rerun $0 again."
exit 2
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
# (in order to use this script inside CI infrastructure)
@ -79,7 +88,7 @@ mkdir -p ${tests_folder}
# clone dressipi's tests
cd ${tests_folder}
if ${clone_dependencies}; then
if [[ $clone_dependencies = true ]]; then
rm -rf ${tests_folder}/*
git clone https://phabricator.memgraph.io/source/pilot_dressipi.git
fi
@ -90,7 +99,7 @@ mkdir -p ${dbms_folder}
# clone memgraph & checkout right commit
cd ${dbms_folder}
if ${clone_dependencies} ; then
if [[ $clone_dependencies = true ]] ; then
rm -rf ${dbms_folder}/*
git clone https://phabricator.memgraph.io/diffusion/MG/memgraph.git
fi

94
run
View File

@ -1,5 +1,33 @@
#!/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
set -e
@ -10,55 +38,53 @@ script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
memgraph_src_dir=${script_dir}/dbms/memgraph
memgraph_build_dir=${script_dir}/dbms/memgraph/build
# setup dressipi
cd ${script_dir}
# 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} &
# activate virtualenv
source $script_dir/ve3/bin/activate
function cleanup_and_exit {
pkill -9 -f "${binary_name}"
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
## 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
cd ${script_dir}/tests/pilot_dressipi
python run.py
exit_code=$?
if [[ ${exit_code} != 0 ]]; then
cleanup_and_exit ${exit_code}
# run Dressipi test
cd ${script_dir}/tests/pilot_dressipi
python run.py
exit_code=$?
if [[ ${exit_code} != 0 ]]; then
cleanup_and_exit ${exit_code}
fi
# kill memgraph for hardcoded queries
pkill -9 -f "${binary_name}"
fi
# kill memgraph for hardcoded queries
pkill -9 -f "${binary_name}"
# get full path to memgraph config for interpreted queries
config_path="${memgraph_src_dir}/config/memgraph.yaml"
# run memgraph
MEMGRAPH_CONFIG=${config_path} ${binary_name} &
MEMGRAPH_CONFIG=${config_path} ${binary_name} 1>&2 &
# run custom scenarios
cd ${script_dir}
python tck_engine/test_executor.py \
--root tck_engine/tests/memgraph_V1/features \
--graphs-root tck_engine/tests/memgraph_V1/graphs \
--no-side-effects \
--db memgraph
tck_flags="--root tck_engine/tests/memgraph_V1/features
--graphs-root tck_engine/tests/memgraph_V1/graphs
--no-side-effects
--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}