tripleo-ansible/tripleo_ansible/roles/tripleo_container_manage/molecule/default/converge.yml
Emilien Macchi 5040338686 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
2020-05-14 12:36:03 +00:00

372 lines
14 KiB
YAML

---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
- name: Create fedora container from /tmp/container-configs with old healthcheck
become: true
hosts: all
gather_facts: false
vars:
tripleo_container_manage_config: '/tmp/container-configs'
tripleo_container_manage_healthcheck_disabled: true
tripleo_container_manage_debug: true
tripleo_container_manage_config_patterns: 'fedora.json'
tripleo_container_manage_systemd_order: true
tasks:
- include_role:
name: tripleo_container_manage
post_tasks:
- name: Verify that Fedora container was created correctly and manually create old healthcheck for migration testing
when:
- not ansible_check_mode|bool
block:
# Reproduce what was done before to create and enable healthchecks
- name: "Enable and start systemd timers"
systemd:
state: started
name: "tripleo_fedora_healthcheck.timer"
enabled: true
daemon_reload: false
- name: "Add systemd requires for healthchecks"
command: "systemctl add-requires tripleo_fedora.service tripleo_fedora_healthcheck.timer"
# Check that migration is ready to be tested
- name: Check for fedora container
command: podman container exists fedora
- name: Check if tripleo_fedora systemd healthcheck service is active
command: systemctl is-active --quiet tripleo_fedora_healthcheck.timer
register: tripleo_fedora_healthcheck_active_result
- name: Assert that tripleo_fedora systemd healthcheck service is active
assert:
that:
- tripleo_fedora_healthcheck_active_result.rc == 0
fail_msg: 'tripleo_fedora systemd healthcheck service is not active'
success_msg: 'tripleo_fedora systemd healthcheck service is active'
- name: Create all containers from /tmp/container-configs
become: true
hosts: all
gather_facts: false
vars:
tripleo_container_manage_config: '/tmp/container-configs'
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
post_tasks:
- name: Verify that Fedora container was created correctly
when:
- not ansible_check_mode|bool
block:
- name: Check for fedora container
command: podman container exists fedora
- name: Gather facts about fedora container
podman_container_info:
name: fedora
register: fedora_infos
- name: Assert that fedora container has the right image
assert:
that:
- "'fedora:latest' in fedora_infos.containers.0.ImageName"
fail_msg: 'fedora container has wrong image'
success_msg: 'fedora container has the right image'
- name: Check if tripleo_fedora systemd service is active
command: systemctl is-active --quiet tripleo_fedora
register: tripleo_fedora_active_result
- name: Assert that tripleo_fedora systemd service is active
assert:
that:
- tripleo_fedora_active_result.rc == 0
fail_msg: 'tripleo_fedora systemd service is not active'
success_msg: 'tripleo_fedora systemd service is active'
- name: Check if tripleo_fedora healthcheck is active and healthy
assert:
that:
- "'healthy' in fedora_infos.containers.0.State.Healthcheck.Status"
fail_msg: 'fedora container healthcheck is not healthy'
success_msg: 'fedora container healthcheck is healthy'
- name: Verify that Fedora bis container was created correctly
block:
- name: Check for fedora_bis container
command: podman container exists fedora_bis
- name: Gather facts about fedora_bis container
podman_container_info:
name: fedora_bis
register: fedora_bis_infos
- name: Assert that fedora_bis container has the right image
assert:
that:
- "'fedora:latest' in fedora_bis_infos.containers.0.ImageName"
fail_msg: 'fedora_bis container has wrong image'
success_msg: 'fedora_bis container has the right image'
- name: Verify that Fedora three container was created correctly
block:
- name: Check for fedora_three container
command: podman container exists fedora_three
- name: Gather facts about fedora_three container
podman_container_info:
name: fedora_three
register: fedora_three_infos
- name: Assert that fedora_three container has the right image
assert:
that:
- "'fedora:latest' in fedora_three_infos.containers.0.ImageName"
fail_msg: 'fedora_three container has wrong image'
success_msg: 'fedora_three container has the right image'
- name: Test idempotency on fedora container
become: true
hosts: all
gather_facts: false
vars:
tripleo_container_manage_config: '/tmp/container-configs'
tripleo_container_manage_debug: true
tripleo_container_manage_config_patterns: '*.json'
tripleo_container_manage_systemd_order: true
tasks:
- name: Gather facts about fedora container before new run
podman_container_info:
name: fedora
register: fedora_infos_old
when:
- not ansible_check_mode|bool
- include_role:
name: tripleo_container_manage
- name: Gather facts about fedora container after new run
podman_container_info:
name: fedora
register: fedora_infos_new
when:
- not ansible_check_mode|bool
post_tasks:
- name: Assert that fedora container has not been re-created
assert:
that:
- fedora_infos_new == fedora_infos_old
fail_msg: 'fedora container was wrongly re-created'
success_msg: 'fedora container was not re-created'
when:
- not ansible_check_mode|bool
- name: Manage only one container
become: true
hosts: all
gather_facts: false
vars:
tripleo_container_manage_config: '/tmp/container-configs'
tripleo_container_manage_debug: true
tripleo_container_manage_config_patterns: 'fedora.json'
tripleo_container_manage_config_overrides:
fedora:
image: fedora:rawhide
tasks:
- include_role:
name: tripleo_container_manage
post_tasks:
- name: Verify that all containers still exist
when:
- not ansible_check_mode|bool
block:
- name: Check for fedora container
command: podman container exists fedora
- name: Gather facts about fedora container
podman_container_info:
name: fedora
register: fedora_infos
- name: Assert that fedora container has the right image
assert:
that:
- "'fedora:rawhide' in fedora_infos.containers.0.ImageName"
fail_msg: 'fedora container has wrong image'
success_msg: 'fedora container has the right image'
- name: Check if tripleo_fedora systemd service is active
command: systemctl is-active --quiet tripleo_fedora
register: tripleo_fedora_active_result
- name: Assert that tripleo_fedora systemd service is active
assert:
that:
- tripleo_fedora_active_result.rc == 0
fail_msg: 'tripleo_fedora systemd service is not active'
success_msg: 'tripleo_fedora systemd service is active'
- name: Check if tripleo_fedora healthcheck is active and healthy
assert:
that:
- "'healthy' in fedora_infos.containers.0.State.Healthcheck.Status"
fail_msg: 'fedora container healthcheck is not healthy'
success_msg: 'fedora container healthcheck is healthy'
- name: Check for fedora_bis container
command: podman container exists fedora_bis
- name: Check for fedora_three container
command: podman container exists fedora_three
- name: Manage a wrong container (user error)
become: true
hosts: all
gather_facts: false
vars:
tripleo_container_manage_config: '/tmp/container-configs'
tripleo_container_manage_debug: true
tripleo_container_manage_config_patterns: 'feduraaa.json'
tasks:
- include_role:
name: tripleo_container_manage
post_tasks:
- name: Verify that all containers still exist
when:
- not ansible_check_mode|bool
block:
- name: Check for fedora container
command: podman container exists fedora
- name: Gather facts about fedora container
podman_container_info:
name: fedora
register: fedora_infos
- name: Check if tripleo_fedora systemd service is active
command: systemctl is-active --quiet tripleo_fedora
register: tripleo_fedora_active_result
- name: Assert that tripleo_fedora systemd service is active
assert:
that:
- tripleo_fedora_active_result.rc == 0
fail_msg: 'tripleo_fedora systemd service is not active'
success_msg: 'tripleo_fedora systemd service is active'
- name: Check if tripleo_fedora healthcheck is active and healthy
assert:
that:
- "'healthy' in fedora_infos.containers.0.State.Healthcheck.Status"
fail_msg: 'fedora container healthcheck is not healthy'
success_msg: 'fedora container healthcheck is healthy'
- name: Check for fedora_bis container
command: podman container exists fedora_bis
- name: Check for fedora_three container
command: podman container exists fedora_three
- name: Test a container removal
become: true
hosts: all
gather_facts: false
vars:
tripleo_container_manage_config: '/tmp/container-configs'
tripleo_container_manage_debug: true
tripleo_container_manage_config_patterns: 'fedora_*.json'
tripleo_container_manage_systemd_order: true
tasks:
- name: Remove fedora container config
file:
path: '/tmp/container-configs/fedora.json'
state: absent
- include_role:
name: tripleo_container_manage
post_tasks:
- name: Verify that all containers still exist
when:
- not ansible_check_mode|bool
block:
- name: Check that fedora container was removed
command: podman container exists fedora
register: container_exist
failed_when: container_exist.rc == 0
- name: Check if tripleo_fedora systemd service is still active
command: systemctl is-active --quiet tripleo_fedora
register: tripleo_fedora_active_result
failed_when: tripleo_fedora_active_result.rc == 0
- name: Check for fedora_bis container
command: podman container exists fedora_bis
- name: Check for fedora_three container
command: podman container exists fedora_three
- name: Test a container update
become: true
hosts: all
gather_facts: false
vars:
tripleo_container_manage_config: '/tmp/container-configs'
tripleo_container_manage_debug: true
tripleo_container_manage_config_patterns: 'fedora_*.json'
tripleo_container_manage_systemd_order: true
tasks:
- name: Modify the fedora_bis container config
copy:
content: |
{
"image": "fedora:rawhide",
"net": "host",
"command": "sleep 3600"
}
dest: '/tmp/container-configs/fedora_bis.json'
- include_role:
name: tripleo_container_manage
post_tasks:
- name: Verify that Fedora bis container was re-created correctly
when:
- not ansible_check_mode|bool
block:
- name: Check for fedora_bis container
command: podman container exists fedora_bis
- name: Gather facts about fedora_bis container
podman_container_info:
name: fedora_bis
register: fedora_bis_infos
- name: Assert that fedora_bis container has the right image
assert:
that:
- "'fedora:rawhide' in fedora_bis_infos.containers.0.ImageName"
fail_msg: 'fedora_bis container has wrong image'
success_msg: 'fedora_bis container has the right image'
- name: Check for fedora_three container
command: podman container exists fedora_three
when:
- not ansible_check_mode|bool
- name: Test a container config override
become: true
hosts: all
gather_facts: false
vars:
tripleo_container_manage_config: '/tmp/container-configs'
tripleo_container_manage_debug: true
tripleo_container_manage_config_patterns: 'fedora_*.json'
tripleo_container_manage_systemd_order: true
tripleo_container_manage_config_overrides:
fedora_bis:
image: fedora:latest
tasks:
- include_role:
name: tripleo_container_manage
post_tasks:
- name: Verify that Fedora bis container was re-created correctly
when:
- not ansible_check_mode|bool
block:
- name: Check for fedora_bis container
command: podman container exists fedora_bis
- name: Gather facts about fedora_bis container
podman_container_info:
name: fedora_bis
register: fedora_bis_infos
- name: Assert that fedora_bis container has the right image
assert:
that:
- "'fedora:latest' in fedora_bis_infos.containers.0.ImageName"
fail_msg: 'fedora_bis container has wrong image'
success_msg: 'fedora_bis container has the right image'
- name: Check for fedora_three container
command: podman container exists fedora_three
when:
- not ansible_check_mode|bool