tripleo_container_manage: create a filter to get changed containers
Getting to know which containers changed is a challenge since we create the containers in async with podman_container. This patch introduces a new filter, called get_changed_containers() which knows how to use returned data from async and figure out what containers have podman actions (which mean podman rm and create); which have to trigger the systemd playbook and make sure the services are triggering changes in systemd. Change-Id: I2ecf7d942dcca1e381d329e11939fd31299551f5
This commit is contained in:
parent
d6577a1590
commit
b6ad6bf087
|
@ -41,7 +41,8 @@ class FilterModule(object):
|
|||
'get_key_from_dict': self.get_key_from_dict,
|
||||
'recursive_get_key_from_dict': self.recursive_get_key_from_dict,
|
||||
'get_role_assignments': self.get_role_assignments,
|
||||
'get_domain_id': self.get_domain_id
|
||||
'get_domain_id': self.get_domain_id,
|
||||
'get_changed_containers': self.get_changed_containers
|
||||
}
|
||||
|
||||
def subsort(self, dict_to_sort, attribute, null_value=0):
|
||||
|
@ -343,3 +344,17 @@ class FilterModule(object):
|
|||
for d in all_domains:
|
||||
if d.get('name') == domain_name:
|
||||
return d.get('id')
|
||||
|
||||
def get_changed_containers(self, async_results):
|
||||
"""Return a list of containers that changed.
|
||||
|
||||
This filter takes in input async results of a podman_container
|
||||
invocation and returns the list of containers with actions, so we
|
||||
know which containers have changed.
|
||||
"""
|
||||
changed = []
|
||||
for item in async_results:
|
||||
if item.get('podman_actions'):
|
||||
if item['container'].get('Name'):
|
||||
changed.append(item['container'].get('Name'))
|
||||
return changed
|
||||
|
|
|
@ -80,9 +80,7 @@
|
|||
# a container managed by systemd needs to be restarted
|
||||
- name: "Create a list of containers which changed"
|
||||
set_fact:
|
||||
containers_changed: >-
|
||||
{{ create_async_results.results | selectattr('changed', 'equalto', true) |
|
||||
map(attribute='container_data') | list | list_of_keys }}
|
||||
containers_changed: "{{ create_async_poll_results.results | get_changed_containers }}"
|
||||
|
||||
- name: Block for container commands
|
||||
when:
|
||||
|
|
|
@ -548,3 +548,22 @@ class TestHelperFilters(tests_base.TestCase):
|
|||
]
|
||||
result = self.filters.get_domain_id('heat_stack', openstack_domains)
|
||||
self.assertEqual(result, 'fd85b560d4554fd8bf363728e4a3863e')
|
||||
|
||||
def test_get_changed_containers(self):
|
||||
data = [
|
||||
{
|
||||
"podman_actions": [],
|
||||
"container": {
|
||||
"Name": "haproxy",
|
||||
}
|
||||
},
|
||||
{
|
||||
"podman_actions": ['podman rm mysql'],
|
||||
"container": {
|
||||
"Name": "mysql",
|
||||
}
|
||||
}
|
||||
]
|
||||
expected_list = ['mysql']
|
||||
result = self.filters.get_changed_containers(data)
|
||||
self.assertEqual(result, expected_list)
|
||||
|
|
Loading…
Reference in New Issue