Adapt rabbitmq test for py2 and py3 support

This works well for python2, but things will become
messy when py3 will be the default.

This, at the same time, ensures the KeyErrors are
properly logged, with a way to debug them.

Change-Id: If5d8007bece9ccbff481187e757968e7d1b6f651
This commit is contained in:
Jean-Philippe Evrard 2019-05-15 16:31:03 +02:00 committed by Tin Lam
parent 5935a2c040
commit 8ee35e896f

View File

@ -48,29 +48,30 @@ function rabbit_check_node_count () {
# Check node count
rabbit_check_node_count
function rabbit_find_paritions () {
echo "Checking cluster partitions"
PARTITIONS=$(rabbitmqadmin \
function rabbit_find_partitions () {
rabbitmqadmin \
--host="${RABBIT_HOSTNAME}" \
--port="${RABBIT_PORT}" \
--username="${RABBITMQ_ADMIN_USERNAME}" \
--password="${RABBITMQ_ADMIN_PASSWORD}" \
list nodes -f raw_json | \
python -c "import json,sys;
obj=json.load(sys.stdin);
python -c "
import json, sys, traceback
print('Checking cluster partitions')
obj=json.load(sys.stdin)
for num, node in enumerate(obj):
print node['partitions'];")
for PARTITION in ${PARTITIONS}; do
if [[ $PARTITION != '[]' ]]; then
echo "Cluster partition found"
exit 1
fi
done
echo "No cluster partitions found"
try:
partition = node['partitions']
if partition:
raise Exception('cluster partition found: %s' % partition)
except KeyError:
print('Error: partition key not found for node %s' % node)
sys.exit(1)
print('No cluster partitions found')
"
}
# Check no nodes report cluster partitioning
rabbit_find_paritions
rabbit_find_partitions
function rabbit_check_users_match () {
echo "Checking users match on all nodes"