mirror of
https://github.com/linux-system-roles/network.git
synced 2026-07-20 17:59:00 +00:00
Add playbooks to automate integration testing
The main playbook executes integration/test_ethernet.py with pytest, adapting the installation for different distributions. Signed-off-by: Elvira García Ruiz <elviragr@riseup.net>
This commit is contained in:
parent
c29a2bf708
commit
5320e96a0e
2 changed files with 106 additions and 0 deletions
97
tests/playbooks/integration_pytest_python3.yml
Normal file
97
tests/playbooks/integration_pytest_python3.yml
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Install dependencies for integration tests
|
||||
hosts: all
|
||||
vars:
|
||||
- rpmdependencies:
|
||||
- git
|
||||
- python3-pip
|
||||
- rsync
|
||||
|
||||
tasks:
|
||||
- name: Install EPEL for RHEL and CentOS
|
||||
# yamllint disable-line rule:line-length
|
||||
command: "yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm"
|
||||
when: ansible_distribution in ["CentOS", "RedHat"]
|
||||
|
||||
- name: Install rpm dependencies
|
||||
package:
|
||||
state: present
|
||||
name: "{{ rpmdependencies }}"
|
||||
|
||||
- name: Install Pytest
|
||||
command: "pip3 install pytest"
|
||||
|
||||
|
||||
# Import needed in order to install initscripts dependencies on the remote
|
||||
# system.
|
||||
- import_playbook: "../tests_default_initscripts.yml"
|
||||
|
||||
# Import needed in order to install Network Manager dependencies on the remote
|
||||
# system.
|
||||
- import_playbook: "../tests_default_nm.yml"
|
||||
|
||||
|
||||
- name: Run Pytest tests
|
||||
hosts: all
|
||||
vars:
|
||||
- rundir: /run/system-roles-test
|
||||
tasks:
|
||||
- file:
|
||||
state: directory
|
||||
path: "{{ rundir }}"
|
||||
recurse: true
|
||||
|
||||
- command: git rev-parse --show-toplevel
|
||||
register: git_top_directory
|
||||
delegate_to: localhost
|
||||
|
||||
- debug:
|
||||
var: git_top_directory
|
||||
|
||||
- synchronize:
|
||||
src: "{{ git_top_directory.stdout }}/"
|
||||
dest: "{{ rundir }}/"
|
||||
recursive: yes
|
||||
delete: yes
|
||||
rsync_opts:
|
||||
- "--exclude=.pyc"
|
||||
- "--exclude=__pycache__"
|
||||
when: False
|
||||
|
||||
# TODO: using tar and copying the file is a workaround for the synchronize
|
||||
# module that does not work in test-harness. Related issue:
|
||||
# https://github.com/linux-system-roles/test-harness/issues/102
|
||||
#
|
||||
- name: Create Tar file
|
||||
shell: 'tar -cvf {{ git_top_directory.stdout }}/testrepo.tar
|
||||
--exclude "*.pyc" --exclude "__pycache__" --exclude testrepo.tar
|
||||
-C {{ git_top_directory.stdout }} .'
|
||||
delegate_to: localhost
|
||||
|
||||
- name: Copy testrepo.tar to the remote system
|
||||
copy:
|
||||
src: "{{ git_top_directory.stdout }}/testrepo.tar"
|
||||
dest: "{{ rundir }}"
|
||||
|
||||
- name: Untar testrepo.tar
|
||||
command: tar xf testrepo.tar
|
||||
args:
|
||||
chdir: "{{ rundir }}"
|
||||
|
||||
- block:
|
||||
- name: Run pytest with nm
|
||||
command: "pytest {{ rundir }}/tests/integration/ --provider=nm"
|
||||
register: playbook_run
|
||||
always:
|
||||
- debug:
|
||||
var: playbook_run.stdout_lines
|
||||
|
||||
- block:
|
||||
- name: Run pytest with initscripts
|
||||
command: >
|
||||
pytest '{{ rundir }}/tests/integration/' --provider=initscripts
|
||||
register: playbook_run
|
||||
always:
|
||||
- debug:
|
||||
var: playbook_run.stdout_lines
|
||||
9
tests/tests_integration_pytest.yml
Normal file
9
tests/tests_integration_pytest.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Empty play to gather facts
|
||||
hosts: all
|
||||
|
||||
- import_playbook: playbooks/integration_pytest_python3.yml
|
||||
when: (ansible_distribution in ["CentOS", "RedHat"] and
|
||||
ansible_distribution_major_version == "8") or
|
||||
ansible_distribution == "Fedora"
|
||||
Loading…
Add table
Add a link
Reference in a new issue