mirror of
https://github.com/linux-system-roles/network.git
synced 2026-01-23 10:25:28 +00:00
Add helper tasks for integration tests
This commit is contained in:
parent
14e65ec6c5
commit
ff2f35cb8a
9 changed files with 128 additions and 0 deletions
6
tests/run-tasks.yml
Normal file
6
tests/run-tasks.yml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Run the tasklist {{ task }}
|
||||
hosts: all
|
||||
tasks:
|
||||
- include_tasks: "{{ task }}"
|
||||
7
tests/tasks/assert-device_absent.yml
Normal file
7
tests/tasks/assert-device_absent.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- setup:
|
||||
- assert:
|
||||
name: "assert that {{ interface }} is absent"
|
||||
that: "{{ not interface in ansible_interfaces }}"
|
||||
msg: "{{ interface }} is in ansible_interfaces: {{ ansible_interfaces }}"
|
||||
8
tests/tasks/assert-device_present.yml
Normal file
8
tests/tasks/assert-device_present.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
# need to run setup again when this is just a task to make sure ansible_interfaces is correct
|
||||
- setup:
|
||||
- assert:
|
||||
name: "assert that {{ interface }} is present"
|
||||
that: "{{ interface in ansible_interfaces }}"
|
||||
msg: "{{ interface }} is not in ansible_interfaces: {{ ansible_interfaces }}"
|
||||
20
tests/tasks/create-and-remove-interface.yml
Normal file
20
tests/tasks/create-and-remove-interface.yml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: manage-test-interface.yml
|
||||
vars:
|
||||
state: absent
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: assert-device_absent.yml
|
||||
|
||||
- include_tasks: manage-test-interface.yml
|
||||
vars:
|
||||
state: present
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: assert-device_present.yml
|
||||
|
||||
- include_tasks: manage-test-interface.yml
|
||||
vars:
|
||||
state: absent
|
||||
- include_tasks: show-interfaces.yml
|
||||
- include_tasks: assert-device_absent.yml
|
||||
10
tests/tasks/make-profile-absent.yml
Normal file
10
tests/tasks/make-profile-absent.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Remove {{ profile }}
|
||||
hosts: all
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ profile }}"
|
||||
state: absent
|
||||
roles:
|
||||
- linux-system-roles.network
|
||||
10
tests/tasks/make-profile-down.yml
Normal file
10
tests/tasks/make-profile-down.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Set {{ profile }} down
|
||||
hosts: all
|
||||
vars:
|
||||
network_connections:
|
||||
- name: "{{ profile }}"
|
||||
state: down
|
||||
roles:
|
||||
- linux-system-roles.network
|
||||
39
tests/tasks/manage-test-interface.yml
Normal file
39
tests/tasks/manage-test-interface.yml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- fail:
|
||||
msg: "state needs to be present or absent, not '{{ state }}'"
|
||||
when: state not in ["present", "absent"]
|
||||
|
||||
- fail:
|
||||
msg: "type needs to be dummy, tap or veth, not '{{ type }}'"
|
||||
when: type not in ["dummy", "tap", "veth"]
|
||||
|
||||
# run setup again to make sure ansible_interfaces is accurate
|
||||
- setup:
|
||||
|
||||
# veth
|
||||
- name: Create veth interface {{ interface }}
|
||||
shell: ip link add {{ interface }} type veth peer name peer{{ interface }}
|
||||
when: "type == 'veth' and state == 'present' and interface not in ansible_interfaces"
|
||||
|
||||
- name: Delete veth interface {{ interface }}
|
||||
shell: ip link del {{ interface }} type veth
|
||||
when: "type == 'veth' and state == 'absent' and interface in ansible_interfaces"
|
||||
|
||||
# dummy
|
||||
- name: Create dummy interface {{ interface }}
|
||||
shell: ip link add "{{ interface }}" type dummy
|
||||
when: "type == 'dummy' and state == 'present' and interface not in ansible_interfaces"
|
||||
|
||||
- name: Delete dummy interface {{ interface }}
|
||||
shell: ip link del "{{ interface }}" type dummy
|
||||
when: "type == 'dummy' and state == 'absent' and interface in ansible_interfaces"
|
||||
|
||||
# tap
|
||||
- name: Create tap interface {{ interface }}
|
||||
shell: ip tuntap add dev {{ interface }} mode tap
|
||||
when: "type == 'tap' and state == 'present' and interface not in ansible_interfaces"
|
||||
|
||||
- name: Delete tap interface {{ interface }}
|
||||
shell: ip tuntap del dev {{ interface }} mode tap
|
||||
when: "type == 'tap' and state == 'absent' and interface in ansible_interfaces"
|
||||
4
tests/tasks/show-interfaces.yml
Normal file
4
tests/tasks/show-interfaces.yml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- debug:
|
||||
msg: "ansible_interfaces: {{ ansible_interfaces }}"
|
||||
24
tests/tests_helpers-and-asserts.yml
Normal file
24
tests/tests_helpers-and-asserts.yml
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
---
|
||||
- name: Check that creating and removing test devices and assertions work
|
||||
hosts: all
|
||||
tasks:
|
||||
- name: test veth interface management
|
||||
include_tasks: tasks/create-and-remove-interface.yml
|
||||
vars:
|
||||
type: veth
|
||||
interface: veth1298
|
||||
|
||||
- name: test veth interface management
|
||||
include_tasks: tasks/create-and-remove-interface.yml
|
||||
vars:
|
||||
type: dummy
|
||||
interface: dummy1298
|
||||
|
||||
# FIXME: when: does not seem to work with include_tasks, therefore this cannot be safely tested for now
|
||||
# - name: test tap interfaces
|
||||
# include_tasks: tasks/create-and-remove-interface.yml type=tap interface=tap1298
|
||||
# when: ansible_distribution_major_version > 6
|
||||
# # ip tuntap does not exist on RHEL6
|
||||
# # FIXME: Maybe use some other tool to manage devices, openvpn can do this,
|
||||
# # but it is in EPEL
|
||||
Loading…
Add table
Add a link
Reference in a new issue