Browse Source

Merge "tripleo-container-manage: allow to override a container config" into stable/train

changes/40/705440/3
Zuul 1 week ago
parent
commit
237cc4ca3c
4 changed files with 44 additions and 2 deletions
  1. +7
    -1
      tripleo_ansible/ansible_plugins/filter/helpers.py
  2. +1
    -0
      tripleo_ansible/roles/tripleo-container-manage/defaults/main.yml
  3. +3
    -1
      tripleo_ansible/roles/tripleo-container-manage/tasks/main.yml
  4. +33
    -0
      tripleo_ansible/tests/plugins/filter/test_helpers.py

+ 7
- 1
tripleo_ansible/ansible_plugins/filter/helpers.py View File

@@ -65,15 +65,21 @@ class FilterModule(object):
ordered_dict[o] = v
return ordered_dict

def singledict(self, list_to_convert):
def singledict(self, list_to_convert, merge_with={}):
"""Generate a single dictionary from a list of dictionaries.

This filter will return a single dictionary from a list of
dictionaries.
If merge_with is set, the return dict will be merged with it.
"""
return_dict = {}
for i in list_to_convert:
return_dict.update(i)
for k in merge_with.keys():
if k in return_dict:
for mk, mv in merge_with[k].items():
return_dict[k][mk] = mv
break
return return_dict

def needs_delete(self, container_infos, config, config_id):

+ 1
- 0
tripleo_ansible/roles/tripleo-container-manage/defaults/main.yml View File

@@ -22,6 +22,7 @@ tripleo_container_manage_cli: podman
tripleo_container_manage_concurrency: 1
tripleo_container_manage_config: "/var/lib/tripleo-config/"
tripleo_container_manage_config_id: tripleo
tripleo_container_manage_config_overrides: {}
tripleo_container_manage_config_patterns: 'hashed-*.json'
tripleo_container_manage_debug: false
tripleo_container_manage_healthcheck_disabled: false

+ 3
- 1
tripleo_ansible/roles/tripleo-container-manage/tasks/main.yml View File

@@ -74,7 +74,9 @@
loop: "{{ container_hashes.results }}"
- name: Finalise hashes for all containers
set_fact:
all_containers_hash: "{{ container_hashes.results | map(attribute='ansible_facts.container_hash') | list | singledict() }}"
all_containers_hash: >-
{{ container_hashes.results | map(attribute='ansible_facts.container_hash') |
list | singledict(merge_with=tripleo_container_manage_config_overrides) }}

- name: "Manage systemd shutdown files"
become: true

+ 33
- 0
tripleo_ansible/tests/plugins/filter/test_helpers.py View File

@@ -125,6 +125,39 @@ class TestHelperFilters(tests_base.TestCase):
result = self.filters.singledict(list)
self.assertEqual(result, expected_dict)

def test_singledict_with_merge(self):
list = [
{
'keystone': {
'start_order': 1,
'image': 'quay.io/tripleo/keystone'
},
},
{
'mysql': {
'start_order': 0,
'image': 'quay.io/tripleo/mysql'
}
}
]
expected_dict = {
'keystone': {
'start_order': 1,
'image': 'quay.io/tripleo/keystone'
},
'mysql': {
'start_order': 0,
'image': 'quay.io/tripleo/mysql:hotfix'
}
}
override = {
'mysql': {
'image': 'quay.io/tripleo/mysql:hotfix'
}
}
result = self.filters.singledict(list, merge_with=override)
self.assertEqual(result, expected_dict)

def test_list_of_keys(self):
keys = [
{

Loading…
Cancel
Save