tox: splits test scenarios

This will allow to run backend tests independently.

Change-Id: Ie0290e4aa00cfb667053686261888218d3fad640
This commit is contained in:
Julien Danjou 2014-10-29 18:07:28 +01:00
parent 6591abf5ed
commit 3408af9429
4 changed files with 75 additions and 50 deletions

4
functions.sh Normal file
View File

@ -0,0 +1,4 @@
function check_port(){
netstat -an 2>/dev/null | grep -q "$1"
return $?
}

View File

@ -1,20 +1,9 @@
#!/bin/bash
set -e
#!/bin/bash -x -e
ZOO_CONF=/etc/zookeeper
ZOO_DIR=/usr/share/zookeeper
ZOO_BIN=$ZOO_DIR/bin
ZOO_TMP_DIR=$(mktemp -d /tmp/ZOO-TMP-XXXXX)
ZOOKEEPER_STARTED=0
mkdir $ZOO_TMP_DIR/bin
. functions.sh
function clean_exit(){
local error_code="$?"
if [ -d $ZOO_CONF ] && [ $ZOOKEEPER_STARTED -eq 1 ]; then
stop_zookeeper_server
fi
rm -rf ${ZOO_TMP_DIR}
local spawned=$(jobs -p)
if [ -n "$spawned" ]; then
kill $(jobs -p)
@ -22,44 +11,8 @@ function clean_exit(){
return $error_code
}
function start_zookeeper_server(){
#Copy zookeeper scripts in temporary directory
cp $ZOO_BIN/* $ZOO_TMP_DIR/bin
#Copy zookeeper conf and set dataDir variable to the zookeeper temporary
#directory
cp $ZOO_CONF/conf/zoo.cfg $ZOO_TMP_DIR
sed -i -r "s@(dataDir *= *).*@\1$ZOO_TMP_DIR@" $ZOO_TMP_DIR/zoo.cfg
#Replace some variables by the zookeeper temporary directory
sed -i -r "s@(ZOOCFGDIR *= *).*@\1$ZOO_TMP_DIR@" $ZOO_TMP_DIR/bin/zkEnv.sh
mkdir $ZOO_TMP_DIR/log
sed -i -r "s@(ZOO_LOG_DIR *= *).*@\1$ZOO_TMP_DIR/log@" $ZOO_TMP_DIR/bin/zkEnv.sh
$ZOO_TMP_DIR/bin/zkServer.sh start
}
function check_port(){
netstat -an 2>/dev/null | grep -q "$1"
return $?
}
function stop_zookeeper_server(){
$ZOO_TMP_DIR/bin/zkServer.sh stop
}
trap "clean_exit" EXIT
if ! check_port 2181 && [ -d $ZOO_CONF ]; then
start_zookeeper_server
if [ $? -eq 0 ]; then
ZOOKEEPER_STARTED=1
fi
fi
if ! check_port 6379; then
redis_bin=$(which redis-server || true)
if [ -n "$redis_bin" ]; then

55
setup-zookeeper-env.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash -x -e
. functions.sh
ZOO_CONF=/etc/zookeeper
ZOO_BIN=/usr/share/zookeeper/bin
ZOO_TMP_DIR=$(mktemp -d /tmp/ZOO-TMP-XXXXX)
ZOOKEEPER_STARTED=0
mkdir $ZOO_TMP_DIR/bin
function clean_exit(){
local error_code="$?"
if [ -d $ZOO_CONF ] && [ $ZOOKEEPER_STARTED -eq 1 ]; then
stop_zookeeper_server
fi
rm -rf ${ZOO_TMP_DIR}
return $error_code
}
function start_zookeeper_server(){
# Copy zookeeper scripts in temporary directory
cp $ZOO_BIN/* $ZOO_TMP_DIR/bin
# Copy zookeeper conf and set dataDir variable to the zookeeper temporary
# directory
cp $ZOO_CONF/conf/zoo.cfg $ZOO_TMP_DIR
sed -i -r "s@(dataDir *= *).*@\1$ZOO_TMP_DIR@" $ZOO_TMP_DIR/zoo.cfg
# Replace some variables by the zookeeper temporary directory
sed -i -r "s@(ZOOCFGDIR *= *).*@\1$ZOO_TMP_DIR@" $ZOO_TMP_DIR/bin/zkEnv.sh
mkdir $ZOO_TMP_DIR/log
sed -i -r "s@(ZOO_LOG_DIR *= *).*@\1$ZOO_TMP_DIR/log@" $ZOO_TMP_DIR/bin/vzkEnv.sh
$ZOO_TMP_DIR/bin/zkServer.sh start
}
function stop_zookeeper_server(){
$ZOO_TMP_DIR/bin/zkServer.sh stop
}
trap "clean_exit" EXIT
if ! check_port 2181 && [ -d $ZOO_CONF ]; then
start_zookeeper_server
if [ $? -eq 0 ]; then
ZOOKEEPER_STARTED=1
fi
fi
# Yield execution to venv command
$*

15
tox.ini
View File

@ -1,7 +1,7 @@
[tox]
minversion = 1.6
skipsdist = True
envlist = py26,py27,py33,py34,pep8
envlist = py26,py27,py33,py34,py27-zookeeper,py33-zookeeper,py34-zookeeper,pep8
[testenv]
deps = -r{toxinidir}/requirements.txt
@ -31,6 +31,19 @@ deps = -r{toxinidir}/requirements-py3.txt
deps = -r{toxinidir}/requirements-py3.txt
-r{toxinidir}/test-requirements.txt
[testenv:py27-zookeeper]
commands = {toxinidir}/setup-zookeeper-env.sh python setup.py testr --slowest --testr-args="{posargs}"
[testenv:py33-zookeeper]
deps = {[testenv:py33]deps}
basepython = python3.3
commands = {toxinidir}/setup-zookeeper-env.sh python setup.py testr --slowest --testr-args="{posargs}"
[testenv:py34-zookeeper]
deps = {[testenv:py34]deps}
basepython = python3.4
commands = {toxinidir}/setup-zookeeper-env.sh python setup.py testr --slowest --testr-args="{posargs}"
[testenv:cover]
commands =
bash -x {toxinidir}/setup-test-env.sh python setup.py testr --slowest --coverage --testr-args="{posargs}"