From ab2190819de91dc09978d3db01577940aaf20af1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 25 Sep 2023 09:05:44 +0000 Subject: [PATCH 1/2] check if restart policy is 5 or less MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- tests/5_container_runtime.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/5_container_runtime.sh b/tests/5_container_runtime.sh index 7f6fa1aa..bccdf61a 100644 --- a/tests/5_container_runtime.sh +++ b/tests/5_container_runtime.sh @@ -600,27 +600,27 @@ check_5_14() { for s in $(docker service ls --format '{{.Name}}'); do if echo $container_name | grep -q "$s"; then task_id=$(docker inspect "$c" --format '{{.Name}}' | awk -F '.' '{print $NF}') - # a container name could arbitrary include a service one: it belongs to a service (created by Docker + # a container name could arbitrary include a service one: it belongs to a service (created by Docker # as part of the service), if the container task ID matches one of the task IDs of the service. if docker service ps --no-trunc "$s" --format '{{.ID}}' | grep -q "$task_id"; then - spolicy=$(docker inspect --format MaxAttempts='{{ .Spec.TaskTemplate.RestartPolicy.MaxAttempts }}' "$s") + restart_policy=$(docker inspect --format '{{ .Spec.TaskTemplate.RestartPolicy.MaxAttempts }}' "$s") break fi fi done fi - cpolicy=$(docker inspect --format MaximumRetryCount='{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c") + restart_policy=$(docker inspect --format '{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c") - if [ "$cpolicy" != "MaximumRetryCount=5" ] && [ "$spolicy" != "MaxAttempts=5" ]; then + if [ "$restart_policy" -gt "5" ]; then # If it's the first container, fail the test if [ $fail -eq 0 ]; then warn -s "$check" - warn " * MaximumRetryCount is not set to 5: $c" + warn " * MaximumRetryCount is not set to 5 or less: $c" maxretry_unset_containers="$maxretry_unset_containers $c" fail=1 continue fi - warn " * MaximumRetryCount is not set to 5: $c" + warn " * MaximumRetryCount is not set to 5 or less: $c" maxretry_unset_containers="$maxretry_unset_containers $c" fi done @@ -630,7 +630,7 @@ check_5_14() { logcheckresult "PASS" return fi - logcheckresult "WARN" "Containers with MaximumRetryCount not set to 5" "$maxretry_unset_containers" + logcheckresult "WARN" "Containers with MaximumRetryCount not set to 5 or less" "$maxretry_unset_containers" } check_5_15() { From e680ab2465be8f8381fedb0b7dac2c6eef6334a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Sj=C3=B6gren?= Date: Mon, 25 Sep 2023 15:29:45 +0000 Subject: [PATCH 2/2] update restart_policy w/o swarm MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Thomas Sjögren --- tests/5_container_runtime.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/5_container_runtime.sh b/tests/5_container_runtime.sh index bccdf61a..7e8ed076 100644 --- a/tests/5_container_runtime.sh +++ b/tests/5_container_runtime.sh @@ -609,7 +609,9 @@ check_5_14() { fi done fi - restart_policy=$(docker inspect --format '{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c") + if docker inspect --format '{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c" &>/dev/null; then + restart_policy=$(docker inspect --format '{{ .HostConfig.RestartPolicy.MaximumRetryCount }}' "$c") + fi if [ "$restart_policy" -gt "5" ]; then # If it's the first container, fail the test