Fix get_failed_containers() to correctly fetch container_data

To avoid this error:
The error was: KeyError: 'container_data'

We need to fetch container_data from async_result_item in the async
results; that's where the key is. Updating unit tests as well, and the
task which creates the facts so there is no confusion in the logs.

Change-Id: I2a5533335151c4b292e85aea310adfdc44ab1e02
This commit is contained in:
Emilien Macchi 2020-03-25 21:59:05 -04:00
parent 967da6836e
commit d6204498d7
3 changed files with 18 additions and 13 deletions

View File

@ -399,6 +399,7 @@ class FilterModule(object):
failed = []
for item in async_results:
if item['failed'] or not item['finished']:
for k, v in item['container_data'].items():
async_result_item = item['create_async_result_item']
for k, v in async_result_item['container_data'].items():
failed.append(k)
return failed

View File

@ -91,9 +91,7 @@
when:
- not ansible_check_mode|bool
# This fact will be used in systemd playbook to figure out if whether or not
# a container managed by systemd needs to be restarted
- name: "Create a list of containers which changed"
- name: "Create facts for containers which changed or failed"
set_fact:
containers_changed: "{{ create_async_poll_results.results | get_changed_containers }}"
containers_failed: "{{ create_async_poll_results.results | get_failed_containers }}"

View File

@ -827,9 +827,11 @@ class TestHelperFilters(tests_base.TestCase):
"ansible_job_id": "948704694230.17597",
"ansible_loop_var": "container_data",
"changed": True,
"container_data": {
"haproxy": {
"image": "haproxy:latest",
"create_async_result_item": {
"container_data": {
"haproxy": {
"image": "haproxy:latest",
}
}
},
"failed": False,
@ -841,9 +843,11 @@ class TestHelperFilters(tests_base.TestCase):
"ansible_job_id": "948704694230.17597",
"ansible_loop_var": "container_data",
"changed": True,
"container_data": {
"memcached": {
"image": "memcached:latest",
"create_async_result_item": {
"container_data": {
"memcached": {
"image": "memcached:latest",
}
}
},
"failed": True,
@ -855,9 +859,11 @@ class TestHelperFilters(tests_base.TestCase):
"ansible_job_id": "316140143697.17616",
"ansible_loop_var": "container_data",
"changed": True,
"container_data": {
"mysql": {
"image": "mysql:latest",
"create_async_result_item": {
"container_data": {
"mysql": {
"image": "mysql:latest",
}
}
},
"failed": False,