network/tests/tests_unit.yml
Gris Ge b0f5d6352a test: Fix EL6 repo
* As EPEL6 has been moved to archive, created `tests/tasks/enable_epel.yml`.
 * As CentOS6 has been moved to vault, created `tests/tests_00_setup.yml`.

Signed-off-by: Gris Ge <fge@redhat.com>
2020-12-22 08:14:39 +08:00

83 lines
2.3 KiB
YAML

# SPDX-License-Identifier: BSD-3-Clause
---
- hosts: all
name: Setup for test running
tasks:
- include_tasks: tasks/el_repo_setup.yml
- name: Install dependencies
package:
name: "{{ item }}"
state: present
# Ignore error because some package names might not be available
ignore_errors: true
loop:
- NetworkManager-libnm
- python2-gobject-base
- python3-gobject-base
- python-gobject-base
- python2-mock
- hosts: all
name: execute python unit tests
tasks:
- name: Copy python modules
copy:
src: "{{ item }}"
dest: /tmp/test-unit-1/
local_follow: false
loop:
- ../library/network_connections.py
- unit/test_network_connections.py
- ../module_utils/network_lsr
- name: Create helpers directory
file:
state: directory
dest: /tmp/test-unit-1/helpers
- name: Copy helpers
copy:
src: "{{ item }}"
dest: /tmp/test-unit-1/helpers
mode: 0755
with_fileglob:
- unit/helpers/*
- name: Check if python2 is available
command: python2 --version
ignore_errors: true
register: python2_available
when: true
- name: Run python2 unit tests
command: python2 /tmp/test-unit-1/test_network_connections.py --verbose
when: python2_available is succeeded and ansible_distribution != 'Fedora'
register: python2_result
- name: Check if python3 is available
command: python3 --version
ignore_errors: true
register: python3_available
when: true
- name: Run python3 unit tests
command: python3 /tmp/test-unit-1/test_network_connections.py --verbose
when: python3_available is succeeded
register: python3_result
- name: Show python2 unit test results
debug:
var: python2_result.stderr_lines
when: python2_result is succeeded
- name: Show python3 unit test results
debug:
var: python3_result.stderr_lines
when: python3_result is succeeded
- name: Ensure that at least one python unit test ran
fail:
msg: Tests did not run with python2 or python3
when: not python2_available is succeeded and
not python3_available is succeeded