consul_session: ensure empty result is handled (#58694)

pull/58945/head
Pilou 5 years ago committed by Sam Doran
parent d1afcbced1
commit b58c64e3b1

@ -0,0 +1,2 @@
bugfixes:
- consul_session - ``sessions`` returned value is a list even though no sessions were found

@ -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)

@ -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

Loading…
Cancel
Save