Skip to content

Commit

Permalink
ALL_QMGRS option for queue_manager module (#105)
Browse files Browse the repository at this point in the history
* ALL_QMGRS option for queue_manager module

* Update Documentation

---------

Co-authored-by: James Page <James.Page@ibm.com>
  • Loading branch information
JamRamPage and James Page committed May 2, 2024
1 parent 1ae6ab6 commit 6aafd00
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 1 deletion.
11 changes: 11 additions & 0 deletions docs/QUEUE_MANAGER.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ Module to create, start, delete a queue manager and run MQSC files.
mqsc_file: 'commfile.in'
```

#### Use of ALL_QMGRS value

This may be used to refer to all queue managers currently defined to a system, e.g to start/stop both QM1 and QM2 defined in mq-setup.yml.

```
- name: Run MQSC command file
queue_manager:
qmname: 'ALL_QMGRS'
state: running
```

## Example of unit testing of a module

Note: Exeption classes `AnsibleExitJson` and `AnsibleFailJson` should be set. See [`test_queue_manager.py`](ansible_collections/ibm/ibmmq/tests/unit/test_queue_manager.py) for reference.
Expand Down
4 changes: 4 additions & 0 deletions plugins/modules/queue_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ def main():
argument_spec=qmgr_attributes
)

if module.params['qmname'][0] == "ALL_QMGRS":
module.params['qmname'] = re.findall("(?<=QMNAME\()([^\)]*)", module.run_command(['dspmq'])[1])
result['qmlists'] = re.findall("(?<=QMNAME\()([^\)]*)", module.run_command(['dspmq'])[1])

ops = {
"present": state_present,
"running": state_running,
Expand Down
34 changes: 34 additions & 0 deletions tests/playbooks/cleanup_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,37 @@
state: absent
register: testout_3
failed_when: false

- name: Stop qmgr if running
queue_manager:
qmname: qm1_all
state: stopped
register: testout_2
failed_when: false

- name: Delete qmgr
until: testout_3.state == 'absent'
retries: 3
delay: 1
queue_manager:
qmname: qm1_all
state: absent
register: testout_3
failed_when: false

- name: Stop qmgr if running
queue_manager:
qmname: qm2_all
state: stopped
register: testout_2
failed_when: false

- name: Delete qmgr
until: testout_3.state == 'absent'
retries: 3
delay: 1
queue_manager:
qmname: qm2_all
state: absent
register: testout_3
failed_when: false
79 changes: 79 additions & 0 deletions tests/playbooks/test_all_qmgrs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
- name: ALL_QMGRS Tests (5)
hosts: all
become: true
become_user: mqm
environment:
PATH: /opt/mqm/bin:{{ ansible_env.PATH }}

tasks:
- name: (SETUP) create QMGRs
queue_manager:
qmname:
- qm1_all
- qm2_all
state: present
register: testout

- name: Dump create output
debug:
msg: "{{ testout }}"

- name: Start ALL_QMGRs
queue_manager:
qmname: ALL_QMGRS
state: running
register: testout_1

- name: Dump start output
debug:
msg: "{{ testout_1 }}"

- name: Test start output
assert:
that:
- testout_1.state == 'running'
- testout_1.rc == 0
- testout_1.msg == "IBM MQ queue manager 'qm2_all' running."
fail_msg: '<<FAILED>> {{testout_1.msg}}'
success_msg: '<<SUCCESS>> {{testout_1.msg}}'

- name: Can stop when present
queue_manager:
qmname: ALL_QMGRS
state: stopped
register: testout_2
failed_when: false

- name: Dump stop output
debug:
msg: "{{ testout_2 }}"

- name: Test stop output
assert:
that:
- testout_2.state == 'stopped'
- testout_2.rc == 0
- testout_2.msg == "Quiesce request accepted. The queue manager will stop when all outstanding work\nis complete.\n"
fail_msg: '<<FAILED>> {{testout_2.msg}}'
success_msg: '<<SUCCESS>> {{testout_2.msg}}'

- name: Can delete when present
queue_manager:
qmname: ALL_QMGRS
state: absent
register: testout_3
failed_when: false

- name: Dump delete output
debug:
msg: "{{ testout_3 }}"

- name: Test delete output
assert:
that:
- testout_3.state == 'absent'
- testout_3.rc == 0
- testout_3.msg == "IBM MQ queue manager 'qm2_all' deleted."
fail_msg: '<<FAILED>> {{testout_3.msg}}'
success_msg: '<<SUCCESS>> {{testout_3.msg}}'
5 changes: 4 additions & 1 deletion tests/playbooks/tests_unix_based.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@
import_playbook: test_web_console.yml

- name: Clean up after testing
import_playbook: cleanup_test.yml
import_playbook: cleanup_test.yml

- name: Test ALL_QMGRS
import_playbook: test_all_qmgrs.yml

0 comments on commit 6aafd00

Please sign in to comment.