Adding rabbitmq test script and pika lib to the rabbitmq image

- This will allow the scenario tests to authenticate and test Cue clusters.

Change-Id: I3a154ed0e7359ac43815b4f41c5c418c19132e8b
This commit is contained in:
Steve Leon 2015-05-13 15:49:26 -07:00
parent 1c5046493c
commit 2c7af4a74f
1 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,64 @@
#!/bin/bash
set -eux
pip install pika
cat > /opt/rabbitmq_test.py << EOF
import argparse
import time
import pika
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-H", "--host", required=True,
help="Specify the RabbitMQ host")
parser.add_argument("-R", "--receive",
help="Specify the RabbitMQ host to receive message")
parser.add_argument("-P", "--port", required=True,
help="Specify the RabbitMQ port",
type=int)
parser.add_argument("-u", "--user", required=True,
help="Specify the RabbitMQ username")
parser.add_argument("-p", "--password", required=True,
help="Specify the RabbitMQ password")
parser.add_argument("--ssl", dest="ssl", action="store_true",
help="Specify whether to use AMQPS protocol")
args = parser.parse_args()
host = args.host
credentials = pika.PlainCredentials(args.user, args.password)
connection = pika.BlockingConnection(pika.ConnectionParameters(
credentials=credentials, host=host, port=args.port, ssl=args.ssl))
channel = connection.channel()
channel.queue_declare(queue='hello')
if args.receive:
connection_receive = pika.BlockingConnection(pika.ConnectionParameters(
credentials=credentials, host=args.receive, port=args.port,
ssl=args.ssl))
channel_receive = connection_receive.channel()
channel_receive.queue_declare(queue='hello')
else:
channel_receive = channel
for count in range(1, 10, 1):
print("Sending...")
channel.basic_publish(exchange='', routing_key='hello',
body='Hello World!' + str(count))
print(" [x] Sent 'Hello World!'" + str(count))
print("Receiving...")
method_frame, header_frame, body = channel_receive.basic_get('hello')
if method_frame:
print(method_frame, header_frame, body)
channel_receive.basic_ack(method_frame.delivery_tag)
else:
print('No message returned')
time.sleep(1)
connection.close()
EOF
chmod 777 /opt/rabbitmq_test.py