1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

rabbitmq_binding: Add support for state=absent (#48599)

* rabbitmq_binding: Add support for state=absent

* Add integration tests for rabbitmq_binding

* Update testcases

* Add changelog fragment
This commit is contained in:
Jon Bergli Heier 2018-12-04 13:42:18 +01:00 committed by John R Barker
parent 6291efd4ea
commit 9c02ade536
8 changed files with 184 additions and 9 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- "rabbitmq_binding - Delete binding when ``state`` is ``absent``."

View file

@ -27,7 +27,6 @@ options:
state:
description:
- Whether the bindings should be present or absent.
- Only present implemented at the momemt.
choices: [ "present", "absent" ]
default: present
name:
@ -159,6 +158,9 @@ class RabbitMqBinding(object):
if self.module.params['state'] == 'present':
if not self.is_present():
return True
elif self.module.params['state'] == 'absent':
if self.is_present():
return True
return False
def is_present(self):

View file

@ -0,0 +1,5 @@
destructive
shippable/posix/group1
skip/osx
skip/freebsd
skip/rhel

View file

@ -0,0 +1,2 @@
dependencies:
- setup_rabbitmq

View file

@ -0,0 +1,3 @@
---
- import_tasks: tests.yml
when: ansible_distribution == 'Ubuntu'

View file

@ -0,0 +1,132 @@
---
- name: Add test requisites
block:
- name: Add exchange
rabbitmq_exchange:
name: "{{ item }}"
type: direct
with_items:
- exchange-foo
- exchange-bar
- name: Add queue
rabbitmq_queue:
name: queue-foo
- name: Test add binding in check mode
block:
- name: Add binding
rabbitmq_binding:
source: exchange-foo
destination: queue-foo
type: queue
check_mode: true
register: add_binding
- name: Check that binding succeeds with a change
assert:
that:
- add_binding.changed == true
- name: Test add binding
block:
- name: Add binding
rabbitmq_binding:
source: exchange-foo
destination: queue-foo
type: queue
register: add_binding
- name: Check that binding succeeds with a change
assert:
that:
- add_binding.changed == true
- name: Test add binding idempotence
block:
- name: Add binding
rabbitmq_binding:
source: exchange-foo
destination: queue-foo
type: queue
register: add_binding
- name: Check that binding succeeds without a change
assert:
that:
- add_binding.changed == false
- name: Test remove binding in check mode
block:
- name: Remove binding
rabbitmq_binding:
source: exchange-foo
destination: queue-foo
type: queue
state: absent
check_mode: true
register: remove_binding
- name: Check that binding succeeds with a change
assert:
that:
- remove_binding.changed == true
- name: Test remove binding
block:
- name: Remove binding
rabbitmq_binding:
source: exchange-foo
destination: queue-foo
type: queue
state: absent
register: remove_binding
- name: Check that binding succeeds with a change
assert:
that:
- remove_binding.changed == true
- name: Test remove binding idempotence
block:
- name: Remove binding
rabbitmq_binding:
source: exchange-foo
destination: queue-foo
type: queue
state: absent
register: remove_binding
- name: Check that binding succeeds with a change
assert:
that:
- remove_binding.changed == false
- name: Test add exchange to exchange binding
block:
- name: Add binding
rabbitmq_binding:
source: exchange-foo
destination: exchange-bar
type: exchange
register: add_binding
- name: Check that binding succeeds with a change
assert:
that:
- add_binding.changed == true
- name: Test remove exchange to exchange binding
block:
- name: Remove binding
rabbitmq_binding:
source: exchange-foo
destination: exchange-bar
type: exchange
state: absent
register: remove_binding
- name: Check that binding succeeds with a change
assert:
that:
- remove_binding.changed == true

View file

@ -6,6 +6,7 @@
rabbitmq_plugin:
name: "{{ plugin_name }}"
state: enabled
new_only: True
register: result
- name: Get rabbitmq-plugins output
@ -18,13 +19,14 @@
- result is changed
- result is success
- '"{{ plugin_name }}" in result.enabled'
- result.disabled== []
- result.disabled == []
- '"[E" in cli_result.stdout'
- name: Enable plugin (idempotency)
rabbitmq_plugin:
name: "{{ plugin_name }}"
state: enabled
new_only: True
register: result
- name: Check idempotency

View file

@ -14,22 +14,49 @@
Pin-Priority: 1000
- name: Install https transport for apt
apt: name=apt-transport-https state=latest force=yes
apt:
name: apt-transport-https
state: latest
force: yes
- name: Add Erlang Solutions public GPG key
apt_key: url=https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_rabbitmq/erlang_solutions.asc state=present
apt_key:
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_rabbitmq/erlang_solutions.asc
state: present
- name: Add Erlang Solutions repository
apt_repository: repo="deb https://packages.erlang-solutions.com/ubuntu {{ ansible_distribution_release }} contrib" filename='erlang-solutions' state=present update_cache=yes
apt_repository:
repo: "deb https://packages.erlang-solutions.com/ubuntu {{ ansible_distribution_release }} contrib"
filename: 'erlang-solutions'
state: present
update_cache: yes
- name: Add RabbitMQ public GPG key
apt_key: url=https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_rabbitmq/rabbitmq-release-signing-key.asc state=present
apt_key:
url: https://s3.amazonaws.com/ansible-ci-files/test/integration/targets/setup_rabbitmq/rabbitmq-release-signing-key.asc
state: present
- name: Add RabbitMQ repository
apt_repository: repo='deb https://dl.bintray.com/rabbitmq/debian {{ ansible_distribution_release }} main' filename='rabbitmq' state=present update_cache=yes
apt_repository:
repo: 'deb https://dl.bintray.com/rabbitmq/debian {{ ansible_distribution_release }} main'
filename: 'rabbitmq'
state: present
update_cache: yes
# Required by the rabbitmq modules that uses the management API
- name: Install requests
pip:
name: requests
- name: Install RabbitMQ Server
apt: name=rabbitmq-server state=latest
apt:
name: rabbitmq-server
state: latest
- name: Start RabbitMQ service
service: name=rabbitmq-server state=started
service:
name: rabbitmq-server
state: started
- name: Enable management
command: rabbitmq-plugins enable --online rabbitmq_management