network/tests/get_coverage.yml
Noriko Hosoi 34665b916d Cleaning up ansible-lint errors except '106', '303' and '403'
That is the following errors are fixed.
'206'  # Variables should have spaces before and after: {{ var_name }}
'208'  # File permissions unset or incorrect
'301'  # Commands should not change things if nothing needs doing
'305'  # Use shell only when shell functionality is required
'502'  # All tasks should be named
'601'  # Don't compare to literal True/False
'602'  # Don't compare to empty string

RHELPLAN-73471

Signed-off-by: Noriko Hosoi <nhosoi@redhat.com>
2021-04-15 20:53:53 +02:00

87 lines
2.5 KiB
YAML

# SPDX-License-Identifier: BSD-3-Clause
---
# This expects the variable test_playbook to be set from the outside
- name: Prepare for coverage extraction
hosts: all
tasks:
# Use set_fact to set variables to make them available in all plays
# 'vars:' Would only set variables for the current play
- name: set facts
set_fact:
coverage_module: network_connections
coverage: /root/.local/bin/coverage
destdir: "remote_coverage/{{ test_playbook }}"
# This uses variables from the other set_fact task, therefore it needs to
# be its own task
- name: set more facts
set_fact:
coverage_file:
# yamllint disable-line rule:line-length
ansible-coverage-{{ coverage_module }}-{{ test_playbook|replace('.yml', '') }}
- name: debug info
debug:
msg:
# yamllint disable-line rule:line-length
Getting coverage for '{{ coverage_module }}' with '{{ test_playbook }}'
- name: combine data in case old data is left there
command: "{{ coverage }} combine"
environment:
COVERAGE_FILE: "{{ coverage_file }}"
ignore_errors: yes
changed_when: false
- name: remove old data
file:
state: absent
path: "{{ coverage_file }}"
- name: find coverage files to delete
find:
path: "{{ ansible_env.HOME }}"
patterns: ".coverage.*"
hidden: yes
register: files_to_delete
- name: remove old data
file:
path: "{{ item.path }}"
state: absent
with_items: "{{ files_to_delete.files }}"
- name: copy coveragerc
copy:
content: "[run]\ndisable_warnings = no-data-collected\n"
dest: .coveragerc
mode: "0644"
- name: install latest pip
pip:
name: coverage
extra_args: --user --upgrade
- import_playbook: "{{ test_playbook }}"
vars:
ansible_python_interpreter:
# yamllint disable-line rule:line-length
"{{ coverage }} run -p --include /*/modules/network_connections.py,/*/module_utils/network_lsr/*"
- name: Gather coverage data
hosts: all
tasks:
- name: gather coverage data
shell: "{{ coverage }} combine .coverage.*"
environment:
COVERAGE_FILE: "{{ coverage_file }}"
changed_when: false
- name: Get coverage data
hosts: all
tasks:
- name: "Fetch {{ coverage_file }}"
fetch:
src: "{{ coverage_file }}"
dest: "{{ destdir }}"
flat: no