forked from galaxyproject/bioblend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_bioblend_tests.sh
executable file
·133 lines (123 loc) · 5.01 KB
/
run_bioblend_tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/sh
show_help () {
echo "Usage: $0 -g GALAXY_DIR [-p PORT] [-e TOX_ENV] [-t BIOBLEND_TESTS] [-r GALAXY_REV] [-c]
Run tests for BioBlend. Useful for Continuous Integration testing.
*Please note* that this script overwrites the main.pid file and appends to the
main.log file inside the specified Galaxy directory (-g).
Options:
-g GALAXY_DIR
Path of the local Galaxy git repository.
-p PORT
Port to use for the Galaxy server. Defaults to 8080.
-e TOX_ENV
Work against specified tox environments. Defaults to py27.
-t BIOBLEND_TESTS
Subset of tests to run, e.g. 'tests/TestGalaxyObjects.py:TestHistory'.
See 'man nosetests' for more information. Defaults to all tests.
-r GALAXY_REV
Branch or commit of the local Galaxy git repository to checkout. Defaults
to the dev branch.
-c
Force removal of the temporary directory created for Galaxy, even if some
test failed."
}
get_abs_dirname () {
# $1 : relative dirname
echo $(cd "$1" && pwd)
}
e_val=py27
p_val=8080
r_val=dev
while getopts 'hcg:e:p:t:r:' option
do
case $option in
h) show_help
exit;;
c) c_val=1;;
g) g_val=$(get_abs_dirname $OPTARG);;
e) e_val=$OPTARG;;
p) p_val=$OPTARG;;
t) t_val=$OPTARG;;
r) r_val=$OPTARG;;
esac
done
if [ -z "$g_val" ]; then
echo "Error: missing -g value."
show_help
exit 1
fi
# Install BioBlend
BIOBLEND_DIR=$(get_abs_dirname $(dirname $0))
cd ${BIOBLEND_DIR}
if [ ! -d .venv ]; then
virtualenv .venv
fi
. .venv/bin/activate
python setup.py install || exit 1
pip install --upgrade "tox>=1.8.0"
# Setup Galaxy
cd ${g_val}
# Update repository (may change the sample files or the list of eggs)
git fetch
git checkout ${r_val}
if git show-ref -q --verify "refs/heads/${r_val}" 2>/dev/null; then
# ${r_val} is a branch
export GALAXY_VERSION=${r_val}
git pull --ff-only
fi
# Setup Galaxy master API key and admin user
if [ -f universe_wsgi.ini.sample ]; then
GALAXY_SAMPLE_CONFIG_FILE=universe_wsgi.ini.sample
GALAXY_CONFIG_DIR=.
else
GALAXY_SAMPLE_CONFIG_FILE=config/galaxy.ini.sample
GALAXY_CONFIG_DIR=config
fi
TEMP_DIR=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`
echo "Created temporary directory $TEMP_DIR"
export GALAXY_CONFIG_FILE=$TEMP_DIR/galaxy.ini
GALAXY_MASTER_API_KEY=`date --rfc-3339=ns | md5sum | cut -f 1 -d ' '`
GALAXY_USER_EMAIL=${USER}@localhost.localdomain
sed -e "s/^#master_api_key.*/master_api_key = $GALAXY_MASTER_API_KEY/" -e "s/^#admin_users.*/admin_users = $GALAXY_USER_EMAIL/" $GALAXY_SAMPLE_CONFIG_FILE > $GALAXY_CONFIG_FILE
sed -i -e "s|^#database_connection.*|database_connection = sqlite:///$TEMP_DIR/universe.sqlite?isolation_level=IMMEDIATE|" -e "s|^#file_path.*|file_path = $TEMP_DIR/files|" -e "s|^#new_file_path.*|new_file_path = $TEMP_DIR/tmp|" -e "s|#job_working_directory.*|job_working_directory = $TEMP_DIR/job_working_directory|" $GALAXY_CONFIG_FILE
# Change Galaxy configuration needed by many tests
sed -i -e 's/^#allow_user_dataset_purge.*/allow_user_dataset_purge = True/' $GALAXY_CONFIG_FILE
# Change Galaxy configuration needed by some library tests
sed -i -e 's/^#allow_library_path_paste.*/allow_library_path_paste = True/' $GALAXY_CONFIG_FILE
# Change Galaxy configuration needed by some tool tests
sed -i -e 's/^#conda_auto_init.*/conda_auto_init = True/' $GALAXY_CONFIG_FILE
# Change Galaxy configuration needed by some workflow tests
sed -i -e 's/^#enable_beta_workflow_modules.*/enable_beta_workflow_modules = True/' $GALAXY_CONFIG_FILE
# Change Galaxy configuration needed by some user tests
sed -i -e 's/^#allow_user_deletion.*/allow_user_deletion = True/' $GALAXY_CONFIG_FILE
if [ -f test/functional/tools/samples_tool_conf.xml ]; then
sed -i -e "s/^#tool_config_file.*/tool_config_file = $GALAXY_CONFIG_DIR\/tool_conf.xml.sample,$GALAXY_CONFIG_DIR\/shed_tool_conf.xml.sample,test\/functional\/tools\/samples_tool_conf.xml/" $GALAXY_CONFIG_FILE
fi
if [ -n "${p_val}" ]; then
# Change only the first occurence of port number
sed -i -e "0,/^#port/ s/^#port.*/port = $p_val/" $GALAXY_CONFIG_FILE
fi
# Start Galaxy and wait for successful server start
GALAXY_RUN_ALL=1 ${BIOBLEND_DIR}/run_galaxy.sh --daemon --wait || exit 1
# Use the master API key to create the admin user and get its API key
export BIOBLEND_GALAXY_URL=http://localhost:${p_val}
GALAXY_USER=$USER
GALAXY_USER_PASSWD=`date --rfc-3339=ns | md5sum | cut -f 1 -d ' '`
export BIOBLEND_GALAXY_API_KEY=`python ${BIOBLEND_DIR}/docs/examples/create_user_get_api_key.py $BIOBLEND_GALAXY_URL $GALAXY_MASTER_API_KEY $GALAXY_USER $GALAXY_USER_EMAIL $GALAXY_USER_PASSWD`
echo "Created new Galaxy user $GALAXY_USER with email $GALAXY_USER_EMAIL , password $GALAXY_USER_PASSWD and API key $BIOBLEND_GALAXY_API_KEY"
# Run the tests
cd ${BIOBLEND_DIR}
if [ -n "${t_val}" ]; then
tox -e ${e_val} -- --tests ${t_val}
else
tox -e ${e_val}
fi
exit_code=$?
deactivate
# Stop Galaxy
cd ${g_val}
GALAXY_RUN_ALL=1 ./run.sh --daemon stop
# Remove temporary directory if -c is specified or if all tests passed
if [ -n "${c_val}" ] || [ $exit_code -eq 0 ]; then
rm -rf $TEMP_DIR
fi