Skip to content

Commit

Permalink
consul_session: ensure empty result is handled (ansible#58694)
Browse files Browse the repository at this point in the history
  • Loading branch information
pilou- authored and samdoran committed Jul 10, 2019
1 parent d1afcbc commit b58c64e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- consul_session - ``sessions`` returned value is a list even though no sessions were found
2 changes: 1 addition & 1 deletion lib/ansible/modules/clustering/consul_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def lookup_sessions(module):
if state == 'list':
sessions_list = consul_client.session.list(dc=datacenter)
# Ditch the index, this can be grabbed from the results
if sessions_list and sessions_list[1]:
if sessions_list and len(sessions_list) >= 2:
sessions_list = sessions_list[1]
module.exit_json(changed=True,
sessions=sessions_list)
Expand Down
24 changes: 24 additions & 0 deletions test/integration/targets/consul/tasks/consul_session.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,27 @@
- assert:
that:
- result is changed

- name: list sessions after deletion
consul_session:
state: list
register: result

- assert:
that:
- result is changed
# selectattr and equalto not available on Jinja 2.2 provided by CentOS 6
# hence the two following tasks (command/assert) are used
# - (result['sessions'] | selectattr('ID', 'equalto', session_id) | list | length) == 0

- name: search deleted session
command: echo 'session found'
loop: "{{ result['sessions'] }}"
when: "item.get('ID') == session_id and item.get('Name') == 'testsession'"
register: search_deleted

- name: ensure session was deleted
assert:
that:
- search_deleted is success
- search_deleted is not changed

0 comments on commit b58c64e

Please sign in to comment.