network/tests/tasks/run_test.yml
Rich Megginson db10fc2035 add support for ansible-core 2.11 ansible-lint, ansible-test
Add support for using latest ansible-lint and ansible-test with
ansible-core 2.11.  There are a few new warnings that need to
be addressed or suppressed.

One of the changes is to add `# noqa ignore-errors` to the places in
the role where `ignore_errors: true` is used.  In general, it is not
a good idea to use `ignore_errors: true` - instead, it is better to
capture the result of the command using a `register`, then use
`failed_when`.  Or, if that is not possible, use a `block`/`rescue`
for more complex error handling.  However, in the case where the network
role is using `ignore_errors: true` in test code, it is acceptable.
see https://ansible-lint.readthedocs.io/en/latest/default_rules.html#ignore-errors

Another change is to have all tasks have a valid `name:`.  This
is explained at https://ansible-lint.readthedocs.io/en/latest/default_rules.html#unnamed-task

Signed-off-by: Rich Megginson <rmeggins@redhat.com>
2021-10-11 12:03:00 -06:00

71 lines
1.6 KiB
YAML

# SPDX-License-Identifier: BSD-3-Clause
---
- name: Run test
block:
- name: "TEST: {{ lsr_description }}"
debug:
msg: "########## {{ lsr_description }} ##########"
- name: Show item
debug:
var: "{{ item }}"
loop:
- lsr_description
- lsr_setup
- lsr_test
- lsr_assert
- lsr_assert_when
- lsr_fail_debug
- lsr_cleanup
- include_tasks: tasks/show_interfaces.yml
- name: setup
include_tasks: "{{ item }}"
loop: "{{ lsr_setup }}"
tags:
- "tests::setup"
- name: test
include_tasks: "{{ item }}"
loop: "{{ lsr_test }}"
tags:
- "tests::test"
- name: asserts
include_tasks: "{{ item }}"
loop: "{{ lsr_assert }}"
tags:
- "tests::assert"
- name: conditional asserts
include_tasks: "{{ item['what'] }}"
when:
- "{{ item['when'] }}"
loop: "{{ lsr_assert_when|default([]) }}"
- name: "Success in test '{{ lsr_description }}'"
debug:
msg: "+++++ Success in test '{{ lsr_description }}' +++++"
rescue:
- name: "Failure in test '{{ lsr_description }}'"
debug:
msg: "!!!!! Failure in test '{{ lsr_description }}' !!!!!"
- name: Show item that failed
debug:
var: "{{ item }}"
loop: "{{ lsr_fail_debug | default([]) }}"
- name: Issue failed message
fail:
msg: "!!!!! Failure in test '{{ lsr_description }}' !!!!!"
always:
- name: cleanup
include_tasks: "{{ item }}"
loop: "{{ lsr_cleanup }}"
tags:
- "tests::cleanup"
...