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

This commit is contained in:
Zuul 2020-02-07 21:30:31 +00:00 committed by Gerrit Code Review
commit 237cc4ca3c
4 changed files with 44 additions and 2 deletions

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

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

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

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 = [
{