tripleo_container_manage: manage systemd services per step vs start_order

Instead of managing systemd services per start_order per step, we could
manage them per step.

The start_order was created to be able to create containers which runs
some command or do exec; but not really for the ones who are services
and managed by systemd.

Doing it per step will reduce the number of tasks and therefore the
deployment time.

Note: it adds dict_to_list() filter; which converts a dict of dicts to a
list of dicts. Ansible allows to do it via dict2items | list but in this
particular case we don't want key/value when later treating the data to
figure out if systemd is needed.

Change-Id: Ia38f2ec753dc3c21bcf91f057fe7ff8020d214e6
(cherry picked from commit ca80ec5c17)
This commit is contained in:
Emilien Macchi 2020-04-16 19:14:02 -04:00
parent a43242b640
commit 061fd32bf3
5 changed files with 41 additions and 6 deletions

View File

@ -44,7 +44,8 @@ class FilterModule(object):
'get_changed_containers': self.get_changed_containers,
'get_failed_containers': self.get_failed_containers,
'recursive_get_key_from_dict': self.recursive_get_key_from_dict,
'get_changed_async_task_names': self.get_changed_async_task_names
'get_changed_async_task_names': self.get_changed_async_task_names,
'dict_to_list': self.dict_to_list
}
def subsort(self, dict_to_sort, attribute, null_value=0):
@ -425,3 +426,15 @@ class FilterModule(object):
if ('changed' in i and i['changed']) or k in extra:
return_list.append(k)
return return_list
def dict_to_list(self, data):
"""Return a list of dictionaries."
This filter will take a dictionary which itself containers
multiple dictionaries; and will convert that to a list
of dictionaries.
"""
return_list = []
for k, v in data.items():
return_list.append({k: v})
return return_list

View File

@ -19,3 +19,8 @@
- tripleo_container_manage_cli == 'podman'
include: podman/start_order.yml order="{{ item.key }}" data="{{ item.value }}"
loop: "{{ all_containers_hash | subsort(attribute='start_order', null_value=0) | dict2items | list }}"
- name: "Manage container systemd services and healthchecks for {{ tripleo_container_manage_config }}"
include_tasks: podman/systemd.yml
when:
- tripleo_container_manage_cli == 'podman'

View File

@ -26,6 +26,3 @@
loop: "{{ data | batch(tripleo_container_manage_concurrency) | list }}"
loop_control:
loop_var: batched_container_data
- name: Manage container systemd services and healthchecks for start_order {{ order }}"
include_tasks: podman/systemd.yml

View File

@ -16,14 +16,14 @@
- name: Set container_config fact
set_fact:
container_config: "{{ data | list | haskey(attribute='restart', value=['always','unless-stopped'], any=True) | default([]) }}"
container_config: "{{ all_containers_hash | dict_to_list | haskey(attribute='restart', value=['always','unless-stopped'], any=True) | default([]) }}"
- name: Set container_config_healthcheck fact
set_fact:
# Using intersect to prevent a service which isn't controlled by systemd
# but has healthcheck in its configuration (by mistake)
# See https://bugs.launchpad.net/tripleo/+bug/1873249
container_config_healthcheck: "{{ data | list | haskey(attribute='healthcheck') | intersect(container_config) | default([]) }}"
container_config_healthcheck: "{{ all_containers_hash | dict_to_list | haskey(attribute='healthcheck') | intersect(container_config) | default([]) }}"
- name: "Manage systemd files"
no_log: "{{ not tripleo_container_manage_debug }}"

View File

@ -932,3 +932,23 @@ class TestHelperFilters(tests_base.TestCase):
expected_list = ['mysql', 'haproxy', 'memcached']
result = self.filters.get_changed_async_task_names(data=data, extra=['mysql'])
self.assertEqual(result, expected_list)
def test_dict_to_list(self):
dict = {
'keystone': {
'image': 'quay.io/tripleo/keystone'
},
'haproxy': {
'image': 'quay.io/tripleo/haproxy'
}
}
expected_list = [
{'keystone': {
'image': 'quay.io/tripleo/keystone',
}},
{'haproxy': {
'image': 'quay.io/tripleo/haproxy',
}}
]
result = self.filters.dict_to_list(data=dict)
self.assertEqual(result, expected_list)