Skip to content

Commit

Permalink
[common] Update container tests
Browse files Browse the repository at this point in the history
Add an additional fail condition and make the fail_msg more verbose
Update the container tests to use elevated permissions
  • Loading branch information
elfiesmelfie committed Feb 12, 2025
1 parent 1b4cea6 commit cbb561e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion roles/common/tasks/container_test.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
---
# The containers are run by root, so need to become true
- name: Get container status
become: true
ansible.builtin.shell:
cmd: |
podman ps -a --format "{{ '{{.Names}} {{.Status}}' }}" | grep {{ container_name }}
changed_when: false
register: container_status

# NOTE: leaving the existing fail message to get the status and see if it is okay
- name: |
TEST Verify {{ container_name }} container status
{{ common_container_test_id }}
ansible.builtin.assert:
that:
- "container_status.stdout | length != 0"
- "'unhealthy' not in container_status.stdout"
success_msg: "Container '{{ container_name }}' is in 'healthy' status."
fail_msg: "Container '{{ container_name }}' is not in 'healthy' status. Current status: {{ container_status.stdout }}"
fail_msg: |
Container does not meet the required conditions:
{%- if container_status.stdout | length == 0 %}Container name did not match any existing containers;{% endif %}
{%- if "unhealthy" in container_status.stdout %}Container status is unhealthy;{% endif %}
Container '{{ container_name }}' is not in 'healthy' status. Current status: {{ container_status.stdout }}

0 comments on commit cbb561e

Please sign in to comment.