Don't use devstack to setup our functional env

This adds a setup script for each tox functional target to start a
rabbitmq-server, qpidd or redis daemon dedicated for the functional
testing.

This script is responsible to spawn a preconfigured daemon needed for
the functional tests.

This also changes the gate script to just install the required packages
instead of setup a devstack.

This also fixes the zmq config options loading in tests

Closes-bug: #1442612

Change-Id: I27eb2c1d3d0ca67aa361c83e41372138e03d9bdd
This commit is contained in:
Mehdi Abaakouk 2015-06-10 10:00:09 +00:00
parent 2e5ba4538e
commit 80ece65a54
9 changed files with 202 additions and 53 deletions

View File

@ -56,6 +56,12 @@ class ConfFixture(fixtures.Fixture):
_import_opts(self.conf,
'oslo_messaging._drivers.amqp', 'amqp_opts',
'oslo_messaging_qpid')
_import_opts(self.conf,
'oslo_messaging._drivers.impl_zmq', 'zmq_opts')
_import_opts(self.conf,
'oslo_messaging._drivers.matchmaker_redis',
'matchmaker_redis_opts',
'matchmaker_redis')
_import_opts(self.conf, 'oslo_messaging.rpc.client', '_client_opts')
_import_opts(self.conf, 'oslo_messaging.transport', '_transport_opts')
_import_opts(self.conf,

View File

@ -12,41 +12,5 @@
# License for the specific language governing permissions and limitations
# under the License.
# This script is executed inside gate_hook function in devstack gate.
RPC_BACKEND=$1
DEVSTACK_LOCAL_CONFIG=""
case $RPC_BACKEND in
rabbit)
DEVSTACK_LOCAL_CONFIG+=$'RABBIT_HOST=127.0.0.1\n'
DEVSTACK_LOCAL_CONFIG+=$'RABBIT_USERID=stackrabbit\n'
DEVSTACK_LOCAL_CONFIG+=$'RABBIT_PASSWORD=secretrabbit\n'
;;
qpid)
export DEVSTACK_GATE_QPID=1
DEVSTACK_LOCAL_CONFIG+=$'QPID_HOST=127.0.0.1\n'
DEVSTACK_LOCAL_CONFIG+=$'QPID_USERNAME=stackqpid\n'
DEVSTACK_LOCAL_CONFIG+=$'QPID_PASSWORD=secretqpid\n'
;;
amqp1)
export DEVSTACK_GATE_QPID=1
DEVSTACK_LOCAL_CONFIG+=$'QPID_HOST=127.0.0.1\n'
DEVSTACK_LOCAL_CONFIG+=$'QPID_USERNAME=stackqpid\n'
DEVSTACK_LOCAL_CONFIG+=$'QPID_PASSWORD=secretqpid\n'
DEVSTACK_LOCAL_CONFIG+=$'RPC_MESSAGING_PROTOCOL=AMQP1\n'
;;
zeromq)
export DEVSTACK_GATE_ZEROMQ=1
DEVSTACK_LOCAL_CONFIG+=$'ZEROMQ_MATCHMAKER=redis\n'
DEVSTACK_LOCAL_CONFIG+=$'MATCHMAKER_REDIS_HOST=127.0.0.1\n'
;;
esac
export DEVSTACK_LOCAL_CONFIG
export DEVSTACK_GATE_INSTALL_TESTONLY=1
export DEVSTACK_GATE_NO_SERVICES=1
export KEEP_LOCALRC=1
$BASE/new/devstack-gate/devstack-vm-gate.sh
# TODO(sileht): delete once the infra code have been cleanup

View File

@ -16,14 +16,54 @@
RPC_BACKEND=$1
function generate_testr_results {
if [ -f .testrepository/0 ]; then
sudo .tox/py27-func-${RPC_BACKEND}/bin/testr last --subunit > $WORKSPACE/testrepository.subunit
sudo mv $WORKSPACE/testrepository.subunit $BASE/logs/testrepository.subunit
sudo .tox/py27-func-${RPC_BACKEND}/bin/python /usr/local/jenkins/slave_scripts/subunit2html.py $BASE/logs/testrepository.subunit $BASE/logs/testr_results.html
sudo gzip -9 $BASE/logs/testrepository.subunit
sudo gzip -9 $BASE/logs/testr_results.html
sudo chown jenkins:jenkins $BASE/logs/testrepository.subunit.gz $BASE/logs/testr_results.html.gz
sudo chmod a+r $BASE/logs/testrepository.subunit.gz $BASE/logs/testr_results.html.gz
fi
}
# Allow jenkins to retrieve reports
sudo chown -R jenkins:stack $BASE/new/oslo.messaging
set +e
# Install required packages
case $RPC_BACKEND in
amqp1|qpid)
# Ensure authentification works before continuing, otherwise tests
# will retries forever
sudo yum install -y qpid-tools
qpid-config --sasl-mechanism=PLAIN -a stackqpid/secretqpid@127.0.0.1
zeromq)
sudo apt-get update -y
sudo apt-get install -y redis-server python-redis
;;
qpid)
sudo apt-get update -y
sudo apt-get install -y qpidd sasl2-bin
;;
amqp1)
# qpid-tools is needed to ensure authentification works before
# starting tests, otherwise tests will retries forever
sudo yum install -y qpid-cpp-server qpid-proton-c-devel python-qpid-proton cyrus-sasl-lib cyrus-sasl-plain
;;
rabbit)
sudo apt-get update -y
sudo apt-get install -y rabbitmq-server
;;
esac
# Got to the oslo.messaging dir
cd $BASE/new/oslo.messaging
sudo -H -u stack tox -e py27-func-$RPC_BACKEND
# Run tests
echo "Running oslo.messaging functional test suite"
# Preserve env for OS_ credentials
sudo -E -H -u jenkins tox -e py27-func-$RPC_BACKEND
EXIT_CODE=$?
set -e
# Collect and parse result
generate_testr_results
exit $EXIT_CODE

View File

@ -276,9 +276,16 @@ class SkipIfNoTransportURL(test_utils.BaseTestCase):
self.url = os.environ.get('TRANSPORT_URL')
if not self.url:
self.skipTest("No transport url configured")
zmq_matchmaker = os.environ.get('ZMQ_MATCHMAKER')
if zmq_matchmaker:
self.conf.rpc_zmq_matchmaker = zmq_matchmaker
self.config(rpc_zmq_matchmaker=zmq_matchmaker)
zmq_ipc_dir = os.environ.get('ZMQ_IPC_DIR')
if zmq_ipc_dir:
self.config(rpc_zmq_ipc_dir=zmq_ipc_dir)
zmq_redis_port = os.environ.get('ZMQ_REDIS_PORT')
if zmq_redis_port:
self.config(port=zmq_redis_port, group="matchmaker_redis")
class NotificationFixture(fixtures.Fixture):

54
setup-test-env-qpid.sh Executable file
View File

@ -0,0 +1,54 @@
#!/bin/bash
set -e
# require qpidd, qpid-tools sasl2-bin/cyrus-sasl-plain+cyrus-sasl-lib
. tools/functions.sh
DATADIR=$(mktemp -d /tmp/OSLOMSG-QPID.XXXXX)
trap "clean_exit $DATADIR" EXIT
[ -f "/usr/lib/qpid/daemon/acl.so" ] && LIBACL="load-module=/usr/lib/qpid/daemon/acl.so"
cat > ${DATADIR}/qpidd.conf <<EOF
port=65123
acl-file=${DATADIR}/qpidd.acl
sasl-config=${DATADIR}/sasl2
log-to-file=${DATADIR}/log
${LIBACL}
mgmt-enable=yes
auth=yes
# Used by AMQP1.0 only
queue-patterns=exclusive
queue-patterns=unicast
topic-patterns=broadcast
EOF
cat > ${DATADIR}/qpidd.acl <<EOF
group admin stackqpid@QPID
acl allow admin all
acl deny all all
EOF
mkdir -p ${DATADIR}/sasl2
cat > ${DATADIR}/sasl2/qpidd.conf <<EOF
pwcheck_method: auxprop
auxprop_plugin: sasldb
sasldb_path: ${DATADIR}/qpidd.sasldb
mech_list: PLAIN
EOF
echo secretqpid | saslpasswd2 -c -p -f ${DATADIR}/qpidd.sasldb -u QPID stackqpid
QPIDD=$(which qpidd 2>/dev/null)
[ ! -x $QPIDD ] && /usr/sbin/qpidd
mkfifo ${DATADIR}/out
$QPIDD --config ${DATADIR}/qpidd.conf &> ${DATADIR}/out &
wait_for_line "Broker .*running" "error" ${DATADIR}/out
# Earlier failure if qpid-config is avialable
[ -x "$(which qpid-config)" ] && qpid-config -b stackqpid/secretqpid@localhost:65123
$*

32
setup-test-env-rabbit.sh Executable file
View File

@ -0,0 +1,32 @@
#!/bin/bash
set -e
. tools/functions.sh
DATADIR=$(mktemp -d /tmp/OSLOMSG-RABBIT.XXXXX)
trap "clean_exit $DATADIR" EXIT
export RABBITMQ_NODE_IP_ADDRESS=127.0.0.1
export RABBITMQ_NODE_PORT=65123
export RABBITMQ_NODENAME=oslomsg-test@localhost
export RABBITMQ_LOG_BASE=$DATADIR
export RABBITMQ_MNESIA_BASE=$DATADIR
export RABBITMQ_PID_FILE=$DATADIR/pid
export HOME=$DATADIR
# NOTE(sileht): We directly use the rabbitmq scripts
# to avoid distribution check, like running as root/rabbitmq
# enforcing.
export PATH=/usr/lib/rabbitmq/bin/:$PATH
mkfifo ${DATADIR}/out
rabbitmq-server &> ${DATADIR}/out &
wait_for_line "Starting broker... completed" "ERROR:" ${DATADIR}/out
rabbitmqctl add_user oslomsg oslosecret
rabbitmqctl set_permissions "oslomsg" ".*" ".*" ".*"
export TRANSPORT_URL=rabbit://oslomsg:oslosecret@127.0.0.1:65123//
$*

30
setup-test-env-zmq.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/bash
set -e
. tools/functions.sh
DATADIR=$(mktemp -d /tmp/OSLOMSG-ZEROMQ.XXXXX)
trap "clean_exit $DATADIR" EXIT
export TRANSPORT_URL=zmq://
export ZMQ_MATCHMAKER=redis
export ZMQ_REDIS_PORT=65123
export ZMQ_IPC_DIR=${DATADIR}
cat > ${DATADIR}/zmq.conf <<EOF
[DEFAULT]
transport_url=${TRANSPORT_URL}
rpc_zmq_matchmaker=${ZMQ_MATCHMAKER}
rpc_zmq_ipc_dir=${ZMQ_IPC_DIR}
[matchmaker_redis]
port=${ZMQ_REDIS_PORT}
EOF
redis-server --port $ZMQ_REDIS_PORT &
oslo-messaging-zmq-receiver --config-file ${DATADIR}/zmq.conf > ${DATADIR}/receiver.log 2>&1 &
# FIXME(sileht): This does the same kind of setup that devstack does
# But this doesn't work yet, a zeromq maintener should take a look on that
$*

19
tools/functions.sh Normal file
View File

@ -0,0 +1,19 @@
wait_for_line () {
while read line
do
echo "$line" | grep -q "$1" && break
echo "$line" | grep "$2" && exit 1
done < "$3"
# Read the fifo for ever otherwise process would block
cat "$3" >/dev/null &
}
function clean_exit(){
local error_code="$?"
kill -9 $(jobs -p)
rm -rf "$1"
return $error_code
}

15
tox.ini
View File

@ -28,25 +28,22 @@ deps = -r{toxinidir}/requirements-py3.txt
-r{toxinidir}/test-requirements-py3.txt
[testenv:py27-func-qpid]
setenv = TRANSPORT_URL=qpid://stackqpid:secretqpid@127.0.0.1//
commands = python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
setenv = TRANSPORT_URL=qpid://stackqpid:secretqpid@127.0.0.1:65123//
commands = {toxinidir}/setup-test-env-qpid.sh python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
[testenv:py27-func-rabbit]
setenv = TRANSPORT_URL=rabbit://stackrabbit:secretrabbit@127.0.0.1//
commands = python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
commands = {toxinidir}/setup-test-env-rabbit.sh python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
[testenv:py27-func-amqp1]
setenv = TRANSPORT_URL=amqp://stackqpid:secretqpid@127.0.0.1//
setenv = TRANSPORT_URL=amqp://stackqpid:secretqpid@127.0.0.1:65123//
deps = -r{toxinidir}/amqp1-requirements.txt
{[testenv]deps}
# NOTE(sileht): This gate job run in fedora21 because proton libs are not
# available on ubuntu yet,
commands = python setup.py testr --slowest --testr-args='oslo_messaging.tests.(functional|test_amqp_driver)'
commands = {toxinidir}/setup-test-env-qpid.sh python setup.py testr --slowest --testr-args='oslo_messaging.tests.(functional|test_amqp_driver)'
[testenv:py27-func-zeromq]
setenv = TRANSPORT_URL=zmq://
ZMQ_MATCHMAKER=oslo_messaging._drivers.matchmaker_redis.MatchMakerRedis
commands = python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
commands = {toxinidir}/setup-test-env-zmq.sh python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
[flake8]
show-source = True