Merge "tripleo-container-manage: allow to override a container config" into stable/train
This commit is contained in:
commit
237cc4ca3c
|
@ -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):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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…
Reference in New Issue