c4cfa387ea
* Adding a basic get lookup for rabbitmq. * Always return a list * If content type is JSON, make accessible via dict. * Fixed incorrect json.loads variable and missing raise * Change to document returned data * Fixed pep8 issues * Adding integration testing * Moving lookup intgration tests to new target * New rabbitmq lookup plugin (#44070). * New rabbitmq lookup plugin (#44070). * PR review feedback updates * Testing pika is installed * Minor mods to tests * Check if connection is already closed or closing * Updated tests and connection testing * PR review feedback updates * PR review include ValueError in AnsibleError output * Suggesting to use set_fact when using returned variable more than once. * Cleaned up some tests, added some notes and handling connection closure on some exceptions. * Removed finally statement and added some additional error handling. * Added some additional error handling. * PR review updates. * Additional integration tests and removing return in finally * Updated version * Changing back to running tests on ubuntu. * Additional tests * Running tests on Ubuntu only * Fixing syntax error * Fixing ingtegration tests and a string/byte issue * Removed non-required test and fixed BOTMETA * Trying to fix integration test failure on ubuntu1404 * Some issues occured when handling messages from the queue with to_native. Switching to to_text resolved the issues. * Renaming channel to queue (thanks dch). Disabling trusty tests.
138 lines
3.9 KiB
YAML
138 lines
3.9 KiB
YAML
- name: Test failure without pika installed
|
|
set_fact:
|
|
rabbit_missing_pika: "{{ lookup('rabbitmq', url='amqp://guest:guest@192.168.250.1:5672/%2F', queue='hello', count=3) }}"
|
|
ignore_errors: yes
|
|
register: rabbitmq_missing_pika_error
|
|
|
|
- assert:
|
|
that:
|
|
- "'pika python package is required' in rabbitmq_missing_pika_error.msg"
|
|
|
|
- name: Install pika and requests
|
|
pip:
|
|
name: pika,requests
|
|
state: latest
|
|
|
|
- name: Test that giving an incorrect amqp protocol in URL will error
|
|
set_fact:
|
|
rabbitmq_test_protocol: "{{ lookup('rabbitmq', url='zzzamqp://guest:guest@192.168.250.1:5672/%2F', queue='hello', count=3) }}"
|
|
ignore_errors: yes
|
|
register: rabbitmq_protocol_error
|
|
|
|
- assert:
|
|
that:
|
|
- "rabbitmq_protocol_error is failed"
|
|
- "'URL malformed' in rabbitmq_protocol_error.msg"
|
|
|
|
- name: Test that giving an incorrect IP address in URL will error
|
|
set_fact:
|
|
rabbitmq_test_protocol: "{{ lookup('rabbitmq', url='amqp://guest:guest@xxxxx192.112312368.250.1:5672/%2F', queue='hello', count=3) }}"
|
|
ignore_errors: yes
|
|
register: rabbitmq_ip_error
|
|
|
|
- assert:
|
|
that:
|
|
- "rabbitmq_ip_error is failed"
|
|
- "'Connection issue' in rabbitmq_ip_error.msg"
|
|
|
|
- name: Test missing parameters will error
|
|
set_fact:
|
|
rabbitmq_test_protocol: "{{ lookup('rabbitmq') }}"
|
|
ignore_errors: yes
|
|
register: rabbitmq_params_error
|
|
|
|
- assert:
|
|
that:
|
|
- "rabbitmq_params_error is failed"
|
|
- "'URL is required for rabbitmq lookup.' in rabbitmq_params_error.msg"
|
|
|
|
- name: Test missing queue will error
|
|
set_fact:
|
|
rabbitmq_queue_protocol: "{{ lookup('rabbitmq', url='amqp://guest:guest@192.168.250.1:5672/%2F') }}"
|
|
ignore_errors: yes
|
|
register: rabbitmq_queue_error
|
|
|
|
- assert:
|
|
that:
|
|
- "rabbitmq_queue_error is failed"
|
|
- "'Queue is required for rabbitmq lookup' in rabbitmq_queue_error.msg"
|
|
|
|
- name: Enables the rabbitmq_management plugin
|
|
rabbitmq_plugin:
|
|
names: rabbitmq_management
|
|
state: enabled
|
|
|
|
- name: Setup test queue
|
|
rabbitmq_queue:
|
|
name: hello
|
|
|
|
- name: Post test message to the exchange (string)
|
|
uri:
|
|
url: http://localhost:15672/api/exchanges/%2f/amq.default/publish
|
|
method: POST
|
|
body: '{"properties":{},"routing_key":"hello","payload":"ansible-test","payload_encoding":"string"}'
|
|
user: guest
|
|
password: guest
|
|
force_basic_auth: yes
|
|
return_content: yes
|
|
register: post_data
|
|
headers:
|
|
Content-Type: "application/json"
|
|
|
|
|
|
- name: Post test message to the exchange (json)
|
|
uri:
|
|
url: http://localhost:15672/api/exchanges/%2f/amq.default/publish
|
|
method: POST
|
|
body: '{"properties":{"content_type": "application/json"},"routing_key":"hello","payload":"{\"key\": \"value\" }","payload_encoding":"string"}'
|
|
user: guest
|
|
password: guest
|
|
force_basic_auth: yes
|
|
return_content: yes
|
|
register: post_data_json
|
|
headers:
|
|
Content-Type: "application/json"
|
|
|
|
- name: Test retrieve messages
|
|
set_fact:
|
|
rabbitmq_msg: "{{ lookup('rabbitmq', url='amqp://guest:guest@localhost:5672/%2f/hello', queue='hello') }}"
|
|
ignore_errors: yes
|
|
register: rabbitmq_msg_error
|
|
|
|
- name: Ensure two messages received
|
|
assert:
|
|
that:
|
|
- "rabbitmq_msg_error is not failed"
|
|
- rabbitmq_msg | length == 2
|
|
|
|
- name: Ensure first message is a string
|
|
assert:
|
|
that:
|
|
- rabbitmq_msg[0].msg == "ansible-test"
|
|
|
|
- name: Ensure second message is json
|
|
assert:
|
|
that:
|
|
- rabbitmq_msg[1].json.key == "value"
|
|
|
|
- name: Test missing vhost
|
|
set_fact:
|
|
rabbitmq_msg: "{{ lookup('rabbitmq', url='amqp://guest:guest@localhost:5672/missing/', queue='hello') }}"
|
|
ignore_errors: yes
|
|
register: rabbitmq_vhost_error
|
|
|
|
- assert:
|
|
that:
|
|
- "rabbitmq_vhost_error is failed"
|
|
- "'NOT_ALLOWED' in rabbitmq_vhost_error.msg"
|
|
|
|
# Tidy up
|
|
- name: Uninstall pika and requests
|
|
pip:
|
|
name: pika,requests
|
|
state: absent
|
|
|
|
- name: Disable the rabbitmq_management plugin
|
|
rabbitmq_plugin:
|
|
names: rabbitmq_management
|
|
state: disabled
|