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:
parent
6291efd4ea
commit
9c02ade536
8 changed files with 184 additions and 9 deletions
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "rabbitmq_binding - Delete binding when ``state`` is ``absent``."
|
|
@ -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):
|
||||
|
|
5
test/integration/targets/rabbitmq_binding/aliases
Normal file
5
test/integration/targets/rabbitmq_binding/aliases
Normal file
|
@ -0,0 +1,5 @@
|
|||
destructive
|
||||
shippable/posix/group1
|
||||
skip/osx
|
||||
skip/freebsd
|
||||
skip/rhel
|
2
test/integration/targets/rabbitmq_binding/meta/main.yml
Normal file
2
test/integration/targets/rabbitmq_binding/meta/main.yml
Normal file
|
@ -0,0 +1,2 @@
|
|||
dependencies:
|
||||
- setup_rabbitmq
|
3
test/integration/targets/rabbitmq_binding/tasks/main.yml
Normal file
3
test/integration/targets/rabbitmq_binding/tasks/main.yml
Normal file
|
@ -0,0 +1,3 @@
|
|||
---
|
||||
- import_tasks: tests.yml
|
||||
when: ansible_distribution == 'Ubuntu'
|
132
test/integration/targets/rabbitmq_binding/tasks/tests.yml
Normal file
132
test/integration/targets/rabbitmq_binding/tasks/tests.yml
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue