container_manage: catch more containers with wrong return code
- helpers/haskey: add excluded_keys argument. It allows to return the
config that has an attribute but also where some attributed are
excluded. The use case here is that we have some container configs
which have both "command" and "action". We want to use that filter to
build a list of containers where the return code has to be checked;
which is the not the case for the containers with "action" in their
configs; since they are used for "podman exec" configs (and there is
nothing to check in return from podman inspect).
- check_exit_code: change the list of containers to check the exit code
to include all the containers with a "command" but not "action".
It should cover all the containers which are used to run some
non-services things like db_sync etc.
- molecule: change the fedora_bis and fedora_three containers to run
short sleep so we can actually test that change against these
containers and also on the first deployment of fedora_bis and
fedora_three, we'll check their return code.
Change-Id: I466a57bd788e02c32b1efb0ac0223684f0d39393
Closes-Bug: #1878074
(cherry picked from commit 5040338686
)
This commit is contained in:
parent
f321a32794
commit
8150aba8a1
|
@ -191,7 +191,8 @@ class FilterModule(object):
|
|||
|
||||
return to_delete
|
||||
|
||||
def haskey(self, data, attribute, value=None, reverse=False, any=False):
|
||||
def haskey(self, data, attribute, value=None, reverse=False, any=False,
|
||||
excluded_keys=[]):
|
||||
"""Return dict data with a specific key.
|
||||
|
||||
This filter will take a list of dictionaries (data)
|
||||
|
@ -201,10 +202,21 @@ class FilterModule(object):
|
|||
which have the attribute.
|
||||
If any is set to True, the returned list will match any value in
|
||||
the list of values for "value" parameter which has to be a list.
|
||||
If we want to exclude items which have certain key(s); these keys
|
||||
should be added to the excluded_keys list. If excluded_keys is used
|
||||
with reverse, we'll just exclude the items which had a key from
|
||||
excluded_keys in the reversed list.
|
||||
"""
|
||||
return_list = []
|
||||
for i in data:
|
||||
to_skip = False
|
||||
for k, v in json.loads(json.dumps(i)).items():
|
||||
for e in excluded_keys:
|
||||
if e in v:
|
||||
to_skip = True
|
||||
break
|
||||
if to_skip:
|
||||
break
|
||||
if attribute in v and not reverse:
|
||||
if value is None:
|
||||
return_list.append(i)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
tripleo_container_manage_debug: true
|
||||
tripleo_container_manage_config_patterns: '*.json'
|
||||
tripleo_container_manage_systemd_order: true
|
||||
tripleo_container_manage_valid_exit_code: [0]
|
||||
tasks:
|
||||
- include_role:
|
||||
name: tripleo-container-manage
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
"image": "fedora:latest",
|
||||
"net": "host",
|
||||
"command": "sleep 3600",
|
||||
"command": "sleep 5",
|
||||
"healthcheck": { "test": "echo test" }
|
||||
}
|
||||
dest: '/tmp/container-configs/fedora_bis.json'
|
||||
|
@ -53,6 +54,6 @@
|
|||
{
|
||||
"image": "fedora:latest",
|
||||
"net": "host",
|
||||
"command": "sleep 3600"
|
||||
"command": "sleep 5"
|
||||
}
|
||||
dest: '/tmp/container-configs/fedora_three.json'
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
- name: "Wait for containers to be exit"
|
||||
podman_container_info:
|
||||
name: "{{ batched_container_data | haskey(attribute='action', reverse=True) | list_of_keys }}"
|
||||
name: "{{ containers_with_exit_code }}"
|
||||
register: podman_containers_infos
|
||||
until: ( podman_containers_infos.containers | selectattr('State.Running', 'equalto', True) |list|length ) == 0
|
||||
# Retry 30 times every 10 seconds so we wait 5 min in total
|
||||
|
|
|
@ -92,10 +92,11 @@
|
|||
when:
|
||||
- not ansible_check_mode|bool
|
||||
|
||||
- name: "Create facts for containers which changed or failed"
|
||||
- name: "Create facts for containers which changed or failed or which require rc check"
|
||||
set_fact:
|
||||
containers_changed: "{{ create_async_poll_results.results | get_changed_containers }}"
|
||||
containers_failed: "{{ create_async_poll_results.results | get_failed_containers }}"
|
||||
containers_to_check: "{{ batched_container_data | haskey(attribute='command', excluded_keys=['action', 'restart']) | list_of_keys | default([]) }}"
|
||||
|
||||
- name: Print the containers that failed to start
|
||||
fail:
|
||||
|
@ -115,6 +116,9 @@
|
|||
|
||||
- name: "Block for container exit codes"
|
||||
when:
|
||||
- tripleo_container_manage_valid_exit_code|length != 0
|
||||
- not ansible_check_mode|bool
|
||||
- tripleo_container_manage_valid_exit_code|length != 0
|
||||
- containers_to_check|length != 0
|
||||
include_tasks: podman/check_exit_code.yml
|
||||
vars:
|
||||
containers_with_exit_code: "{{ containers_to_check }}"
|
||||
|
|
|
@ -200,6 +200,90 @@ class TestHelperFilters(tests_base.TestCase):
|
|||
attribute='restart', value='always')
|
||||
self.assertEqual(result, expected_list)
|
||||
|
||||
def test_haskey_exclude(self):
|
||||
data = [
|
||||
{
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'command': 'sleep 10',
|
||||
'restart': 'always'
|
||||
},
|
||||
},
|
||||
{
|
||||
'nova': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/nova',
|
||||
'command': 'sleep 10',
|
||||
'action': 'exec'
|
||||
},
|
||||
},
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'command': 'sleep 10',
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
},
|
||||
{
|
||||
'haproxy': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/haproxy'
|
||||
}
|
||||
}
|
||||
]
|
||||
expected_list = [
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'command': 'sleep 10',
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
},
|
||||
}
|
||||
]
|
||||
result = self.filters.haskey(data=data,
|
||||
attribute='command',
|
||||
excluded_keys=['action', 'restart'])
|
||||
self.assertEqual(result, expected_list)
|
||||
|
||||
def test_haskey_reverse_exclude(self):
|
||||
data = [
|
||||
{
|
||||
'keystone': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/keystone',
|
||||
'restart': 'always'
|
||||
},
|
||||
},
|
||||
{
|
||||
'nova': {
|
||||
'start_order': 1,
|
||||
'image': 'quay.io/tripleo/nova',
|
||||
'action': 'exec'
|
||||
},
|
||||
},
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
}
|
||||
}
|
||||
]
|
||||
expected_list = [
|
||||
{
|
||||
'mysql': {
|
||||
'start_order': 0,
|
||||
'image': 'quay.io/tripleo/mysql'
|
||||
},
|
||||
}
|
||||
]
|
||||
result = self.filters.haskey(data=data,
|
||||
attribute='restart',
|
||||
value='always',
|
||||
reverse=True,
|
||||
excluded_keys=['action'])
|
||||
self.assertEqual(result, expected_list)
|
||||
|
||||
def test_haskey_reverse(self):
|
||||
data = [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue