Skip to content
This repository was archived by the owner on Sep 26, 2019. It is now read-only.

Commit 15764fe

Browse files
Mehdi Abaakoukthomasgoirand
authored andcommitted
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
1 parent 5b15364 commit 15764fe

File tree

9 files changed

+202
-53
lines changed

9 files changed

+202
-53
lines changed

oslo_messaging/conffixture.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ def __init__(self, conf):
5656
_import_opts(self.conf,
5757
'oslo_messaging._drivers.amqp', 'amqp_opts',
5858
'oslo_messaging_qpid')
59+
_import_opts(self.conf,
60+
'oslo_messaging._drivers.impl_zmq', 'zmq_opts')
61+
_import_opts(self.conf,
62+
'oslo_messaging._drivers.matchmaker_redis',
63+
'matchmaker_redis_opts',
64+
'matchmaker_redis')
5965
_import_opts(self.conf, 'oslo_messaging.rpc.client', '_client_opts')
6066
_import_opts(self.conf, 'oslo_messaging.transport', '_transport_opts')
6167
_import_opts(self.conf,

oslo_messaging/tests/functional/gate/gate_hook.sh

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,5 @@
1212
# License for the specific language governing permissions and limitations
1313
# under the License.
1414

15-
# This script is executed inside gate_hook function in devstack gate.
1615

17-
RPC_BACKEND=$1
18-
19-
DEVSTACK_LOCAL_CONFIG=""
20-
21-
case $RPC_BACKEND in
22-
rabbit)
23-
DEVSTACK_LOCAL_CONFIG+=$'RABBIT_HOST=127.0.0.1\n'
24-
DEVSTACK_LOCAL_CONFIG+=$'RABBIT_USERID=stackrabbit\n'
25-
DEVSTACK_LOCAL_CONFIG+=$'RABBIT_PASSWORD=secretrabbit\n'
26-
;;
27-
qpid)
28-
export DEVSTACK_GATE_QPID=1
29-
DEVSTACK_LOCAL_CONFIG+=$'QPID_HOST=127.0.0.1\n'
30-
DEVSTACK_LOCAL_CONFIG+=$'QPID_USERNAME=stackqpid\n'
31-
DEVSTACK_LOCAL_CONFIG+=$'QPID_PASSWORD=secretqpid\n'
32-
;;
33-
amqp1)
34-
export DEVSTACK_GATE_QPID=1
35-
DEVSTACK_LOCAL_CONFIG+=$'QPID_HOST=127.0.0.1\n'
36-
DEVSTACK_LOCAL_CONFIG+=$'QPID_USERNAME=stackqpid\n'
37-
DEVSTACK_LOCAL_CONFIG+=$'QPID_PASSWORD=secretqpid\n'
38-
DEVSTACK_LOCAL_CONFIG+=$'RPC_MESSAGING_PROTOCOL=AMQP1\n'
39-
;;
40-
zeromq)
41-
export DEVSTACK_GATE_ZEROMQ=1
42-
DEVSTACK_LOCAL_CONFIG+=$'ZEROMQ_MATCHMAKER=redis\n'
43-
DEVSTACK_LOCAL_CONFIG+=$'MATCHMAKER_REDIS_HOST=127.0.0.1\n'
44-
;;
45-
esac
46-
47-
export DEVSTACK_LOCAL_CONFIG
48-
export DEVSTACK_GATE_INSTALL_TESTONLY=1
49-
export DEVSTACK_GATE_NO_SERVICES=1
50-
export KEEP_LOCALRC=1
51-
52-
$BASE/new/devstack-gate/devstack-vm-gate.sh
16+
# TODO(sileht): delete once the infra code have been cleanup

oslo_messaging/tests/functional/gate/post_test_hook.sh

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,54 @@
1616

1717
RPC_BACKEND=$1
1818

19+
function generate_testr_results {
20+
if [ -f .testrepository/0 ]; then
21+
sudo .tox/py27-func-${RPC_BACKEND}/bin/testr last --subunit > $WORKSPACE/testrepository.subunit
22+
sudo mv $WORKSPACE/testrepository.subunit $BASE/logs/testrepository.subunit
23+
sudo .tox/py27-func-${RPC_BACKEND}/bin/python /usr/local/jenkins/slave_scripts/subunit2html.py $BASE/logs/testrepository.subunit $BASE/logs/testr_results.html
24+
sudo gzip -9 $BASE/logs/testrepository.subunit
25+
sudo gzip -9 $BASE/logs/testr_results.html
26+
sudo chown jenkins:jenkins $BASE/logs/testrepository.subunit.gz $BASE/logs/testr_results.html.gz
27+
sudo chmod a+r $BASE/logs/testrepository.subunit.gz $BASE/logs/testr_results.html.gz
28+
fi
29+
}
30+
31+
# Allow jenkins to retrieve reports
32+
sudo chown -R jenkins:stack $BASE/new/oslo.messaging
33+
34+
set +e
35+
36+
# Install required packages
1937
case $RPC_BACKEND in
20-
amqp1|qpid)
21-
# Ensure authentification works before continuing, otherwise tests
22-
# will retries forever
23-
sudo yum install -y qpid-tools
24-
qpid-config --sasl-mechanism=PLAIN -a stackqpid/[email protected]
38+
zeromq)
39+
sudo apt-get update -y
40+
sudo apt-get install -y redis-server python-redis
41+
;;
42+
qpid)
43+
sudo apt-get update -y
44+
sudo apt-get install -y qpidd sasl2-bin
45+
;;
46+
amqp1)
47+
# qpid-tools is needed to ensure authentification works before
48+
# starting tests, otherwise tests will retries forever
49+
sudo yum install -y qpid-cpp-server qpid-proton-c-devel python-qpid-proton cyrus-sasl-lib cyrus-sasl-plain
50+
;;
51+
rabbit)
52+
sudo apt-get update -y
53+
sudo apt-get install -y rabbitmq-server
2554
;;
2655
esac
2756

57+
# Got to the oslo.messaging dir
2858
cd $BASE/new/oslo.messaging
29-
sudo -H -u stack tox -e py27-func-$RPC_BACKEND
59+
60+
# Run tests
61+
echo "Running oslo.messaging functional test suite"
62+
# Preserve env for OS_ credentials
63+
sudo -E -H -u jenkins tox -e py27-func-$RPC_BACKEND
64+
EXIT_CODE=$?
65+
set -e
66+
67+
# Collect and parse result
68+
generate_testr_results
69+
exit $EXIT_CODE

oslo_messaging/tests/functional/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,16 @@ def setUp(self):
276276
self.url = os.environ.get('TRANSPORT_URL')
277277
if not self.url:
278278
self.skipTest("No transport url configured")
279+
279280
zmq_matchmaker = os.environ.get('ZMQ_MATCHMAKER')
280281
if zmq_matchmaker:
281-
self.conf.rpc_zmq_matchmaker = zmq_matchmaker
282+
self.config(rpc_zmq_matchmaker=zmq_matchmaker)
283+
zmq_ipc_dir = os.environ.get('ZMQ_IPC_DIR')
284+
if zmq_ipc_dir:
285+
self.config(rpc_zmq_ipc_dir=zmq_ipc_dir)
286+
zmq_redis_port = os.environ.get('ZMQ_REDIS_PORT')
287+
if zmq_redis_port:
288+
self.config(port=zmq_redis_port, group="matchmaker_redis")
282289

283290

284291
class NotificationFixture(fixtures.Fixture):

setup-test-env-qpid.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# require qpidd, qpid-tools sasl2-bin/cyrus-sasl-plain+cyrus-sasl-lib
5+
6+
. tools/functions.sh
7+
8+
DATADIR=$(mktemp -d /tmp/OSLOMSG-QPID.XXXXX)
9+
trap "clean_exit $DATADIR" EXIT
10+
11+
[ -f "/usr/lib/qpid/daemon/acl.so" ] && LIBACL="load-module=/usr/lib/qpid/daemon/acl.so"
12+
13+
cat > ${DATADIR}/qpidd.conf <<EOF
14+
port=65123
15+
acl-file=${DATADIR}/qpidd.acl
16+
sasl-config=${DATADIR}/sasl2
17+
log-to-file=${DATADIR}/log
18+
${LIBACL}
19+
mgmt-enable=yes
20+
auth=yes
21+
22+
# Used by AMQP1.0 only
23+
queue-patterns=exclusive
24+
queue-patterns=unicast
25+
topic-patterns=broadcast
26+
EOF
27+
28+
cat > ${DATADIR}/qpidd.acl <<EOF
29+
group admin stackqpid@QPID
30+
acl allow admin all
31+
acl deny all all
32+
EOF
33+
34+
mkdir -p ${DATADIR}/sasl2
35+
cat > ${DATADIR}/sasl2/qpidd.conf <<EOF
36+
pwcheck_method: auxprop
37+
auxprop_plugin: sasldb
38+
sasldb_path: ${DATADIR}/qpidd.sasldb
39+
mech_list: PLAIN
40+
EOF
41+
42+
echo secretqpid | saslpasswd2 -c -p -f ${DATADIR}/qpidd.sasldb -u QPID stackqpid
43+
44+
QPIDD=$(which qpidd 2>/dev/null)
45+
[ ! -x $QPIDD ] && /usr/sbin/qpidd
46+
47+
mkfifo ${DATADIR}/out
48+
$QPIDD --config ${DATADIR}/qpidd.conf &> ${DATADIR}/out &
49+
wait_for_line "Broker .*running" "error" ${DATADIR}/out
50+
51+
# Earlier failure if qpid-config is avialable
52+
[ -x "$(which qpid-config)" ] && qpid-config -b stackqpid/secretqpid@localhost:65123
53+
54+
$*

setup-test-env-rabbit.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -e
3+
4+
. tools/functions.sh
5+
6+
DATADIR=$(mktemp -d /tmp/OSLOMSG-RABBIT.XXXXX)
7+
trap "clean_exit $DATADIR" EXIT
8+
9+
export RABBITMQ_NODE_IP_ADDRESS=127.0.0.1
10+
export RABBITMQ_NODE_PORT=65123
11+
export RABBITMQ_NODENAME=oslomsg-test@localhost
12+
export RABBITMQ_LOG_BASE=$DATADIR
13+
export RABBITMQ_MNESIA_BASE=$DATADIR
14+
export RABBITMQ_PID_FILE=$DATADIR/pid
15+
export HOME=$DATADIR
16+
17+
# NOTE(sileht): We directly use the rabbitmq scripts
18+
# to avoid distribution check, like running as root/rabbitmq
19+
# enforcing.
20+
export PATH=/usr/lib/rabbitmq/bin/:$PATH
21+
22+
23+
mkfifo ${DATADIR}/out
24+
rabbitmq-server &> ${DATADIR}/out &
25+
wait_for_line "Starting broker... completed" "ERROR:" ${DATADIR}/out
26+
27+
rabbitmqctl add_user oslomsg oslosecret
28+
rabbitmqctl set_permissions "oslomsg" ".*" ".*" ".*"
29+
30+
31+
export TRANSPORT_URL=rabbit://oslomsg:[email protected]:65123//
32+
$*

setup-test-env-zmq.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash
2+
set -e
3+
4+
. tools/functions.sh
5+
6+
DATADIR=$(mktemp -d /tmp/OSLOMSG-ZEROMQ.XXXXX)
7+
trap "clean_exit $DATADIR" EXIT
8+
9+
export TRANSPORT_URL=zmq://
10+
export ZMQ_MATCHMAKER=redis
11+
export ZMQ_REDIS_PORT=65123
12+
export ZMQ_IPC_DIR=${DATADIR}
13+
14+
cat > ${DATADIR}/zmq.conf <<EOF
15+
[DEFAULT]
16+
transport_url=${TRANSPORT_URL}
17+
rpc_zmq_matchmaker=${ZMQ_MATCHMAKER}
18+
rpc_zmq_ipc_dir=${ZMQ_IPC_DIR}
19+
[matchmaker_redis]
20+
port=${ZMQ_REDIS_PORT}
21+
EOF
22+
23+
redis-server --port $ZMQ_REDIS_PORT &
24+
25+
oslo-messaging-zmq-receiver --config-file ${DATADIR}/zmq.conf > ${DATADIR}/receiver.log 2>&1 &
26+
27+
# FIXME(sileht): This does the same kind of setup that devstack does
28+
# But this doesn't work yet, a zeromq maintener should take a look on that
29+
30+
$*

tools/functions.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
wait_for_line () {
3+
while read line
4+
do
5+
echo "$line" | grep -q "$1" && break
6+
echo "$line" | grep "$2" && exit 1
7+
done < "$3"
8+
# Read the fifo for ever otherwise process would block
9+
cat "$3" >/dev/null &
10+
}
11+
12+
function clean_exit(){
13+
local error_code="$?"
14+
kill -9 $(jobs -p)
15+
rm -rf "$1"
16+
return $error_code
17+
}
18+
19+

tox.ini

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,22 @@ deps = -r{toxinidir}/requirements-py3.txt
2828
-r{toxinidir}/test-requirements-py3.txt
2929

3030
[testenv:py27-func-qpid]
31-
setenv = TRANSPORT_URL=qpid://stackqpid:[email protected]//
32-
commands = python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
31+
setenv = TRANSPORT_URL=qpid://stackqpid:[email protected]:65123//
32+
commands = {toxinidir}/setup-test-env-qpid.sh python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
3333

3434
[testenv:py27-func-rabbit]
35-
setenv = TRANSPORT_URL=rabbit://stackrabbit:[email protected]//
36-
commands = python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
35+
commands = {toxinidir}/setup-test-env-rabbit.sh python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
3736

3837
[testenv:py27-func-amqp1]
39-
setenv = TRANSPORT_URL=amqp://stackqpid:[email protected]//
38+
setenv = TRANSPORT_URL=amqp://stackqpid:[email protected]:65123//
4039
deps = -r{toxinidir}/amqp1-requirements.txt
4140
{[testenv]deps}
4241
# NOTE(sileht): This gate job run in fedora21 because proton libs are not
4342
# available on ubuntu yet,
44-
commands = python setup.py testr --slowest --testr-args='oslo_messaging.tests.(functional|test_amqp_driver)'
43+
commands = {toxinidir}/setup-test-env-qpid.sh python setup.py testr --slowest --testr-args='oslo_messaging.tests.(functional|test_amqp_driver)'
4544

4645
[testenv:py27-func-zeromq]
47-
setenv = TRANSPORT_URL=zmq://
48-
ZMQ_MATCHMAKER=oslo_messaging._drivers.matchmaker_redis.MatchMakerRedis
49-
commands = python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
46+
commands = {toxinidir}/setup-test-env-zmq.sh python setup.py testr --slowest --testr-args='oslo_messaging.tests.functional'
5047

5148
[flake8]
5249
show-source = True

0 commit comments

Comments
 (0)