From 8ee35e896fd89cb55bf8036d4652fc318183b989 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Evrard Date: Wed, 15 May 2019 16:31:03 +0200 Subject: [PATCH] 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 --- rabbitmq/templates/bin/_rabbitmq-test.sh.tpl | 33 ++++++++++---------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/rabbitmq/templates/bin/_rabbitmq-test.sh.tpl b/rabbitmq/templates/bin/_rabbitmq-test.sh.tpl index 84b9e7f9a..ddbb15ec3 100644 --- a/rabbitmq/templates/bin/_rabbitmq-test.sh.tpl +++ b/rabbitmq/templates/bin/_rabbitmq-test.sh.tpl @@ -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"