552 lines
14 KiB
Diff
552 lines
14 KiB
Diff
diff --git a/tests/commonvars.yml b/tests/commonvars.yml
|
|
new file mode 100644
|
|
index 0000000..50452f7
|
|
--- /dev/null
|
|
+++ b/tests/commonvars.yml
|
|
@@ -0,0 +1,2 @@
|
|
+restore_services:
|
|
+ - NetworkManager
|
|
diff --git a/tests/get_services_state.yml b/tests/get_services_state.yml
|
|
new file mode 100644
|
|
index 0000000..4fe5d36
|
|
--- /dev/null
|
|
+++ b/tests/get_services_state.yml
|
|
@@ -0,0 +1,4 @@
|
|
+- name: Get initial state of services
|
|
+ tags: tests::cleanup
|
|
+ service_facts:
|
|
+ register: initial_state
|
|
diff --git a/tests/playbooks/tests_states.yml b/tests/playbooks/tests_states.yml
|
|
index 7a1e207..3c1f65d 100644
|
|
--- a/tests/playbooks/tests_states.yml
|
|
+++ b/tests/playbooks/tests_states.yml
|
|
@@ -1,6 +1,8 @@
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
---
|
|
- hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
vars:
|
|
interface: statebr
|
|
profile: "{{ interface }}"
|
|
@@ -22,6 +24,8 @@
|
|
ip:
|
|
dhcp4: false
|
|
auto6: false
|
|
+ tags:
|
|
+ - 'tests::net::bridge'
|
|
- include_tasks: tasks/assert-device_present.yml
|
|
- include_tasks: tasks/assert-profile_present.yml
|
|
|
|
@@ -47,3 +51,28 @@
|
|
state: down
|
|
- include_tasks: tasks/assert-device_absent.yml
|
|
- include_tasks: tasks/assert-profile_absent.yml
|
|
+
|
|
+ pre_tasks:
|
|
+ - name: Save host state
|
|
+ tags:
|
|
+ - 'tests::tier1::cleanup'
|
|
+ import_tasks: "../save_state.yml"
|
|
+
|
|
+ post_tasks:
|
|
+ - name: Remove test profile
|
|
+ tags:
|
|
+ - 'tests::cleanup'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ - 'tests::net::bridge::cleanup'
|
|
+ import_role:
|
|
+ name: linux-system-roles.network
|
|
+ vars:
|
|
+ network_connections:
|
|
+ - name: statebr
|
|
+ state: down
|
|
+ persistent_state: absent
|
|
+
|
|
+ - name: Restore host state
|
|
+ tags:
|
|
+ - 'tests::tier1::cleanup'
|
|
+ import_tasks: "../restore_state.yml"
|
|
diff --git a/tests/playbooks/tests_vlan_mtu.yml b/tests/playbooks/tests_vlan_mtu.yml
|
|
index ae0322e..bf6e518 100644
|
|
--- a/tests/playbooks/tests_vlan_mtu.yml
|
|
+++ b/tests/playbooks/tests_vlan_mtu.yml
|
|
@@ -1,6 +1,8 @@
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
---
|
|
- hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
vars:
|
|
type: veth
|
|
interface: lsr101
|
|
@@ -10,6 +12,8 @@
|
|
- include_tasks: tasks/manage-test-interface.yml
|
|
vars:
|
|
state: present
|
|
+ tags:
|
|
+ - 'tests::net::veth'
|
|
- include_tasks: tasks/assert-device_present.yml
|
|
- name: "TEST: I can configure the MTU for a vlan interface without autoconnect."
|
|
debug:
|
|
@@ -37,6 +41,8 @@
|
|
ip:
|
|
dhcp4: false
|
|
auto6: false
|
|
+ tags:
|
|
+ - 'tests::net::reconf'
|
|
- include_tasks: tasks/assert-device_present.yml
|
|
vars:
|
|
interface: "{{ vlan_interface }}"
|
|
@@ -61,6 +67,26 @@
|
|
persistent_state: absent
|
|
state: down
|
|
ignore_errors: true
|
|
+ tags:
|
|
+ - 'tests::cleanup'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ - 'tests::net::veth::cleanup'
|
|
- include_tasks: tasks/manage-test-interface.yml
|
|
vars:
|
|
state: absent
|
|
+ tags:
|
|
+ - 'tests::cleanup'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ - 'tests::net::veth::cleanup'
|
|
+
|
|
+ pre_tasks:
|
|
+ - name: Save host state
|
|
+ tags:
|
|
+ - 'tests::tier1::cleanup'
|
|
+ import_tasks: "../save_state.yml"
|
|
+
|
|
+ post_tasks:
|
|
+ - name: Restore host state
|
|
+ tags:
|
|
+ - 'tests::tier1::cleanup'
|
|
+ import_tasks: "../restore_state.yml"
|
|
diff --git a/tests/restore_services_state.yml b/tests/restore_services_state.yml
|
|
new file mode 100644
|
|
index 0000000..2035dfc
|
|
--- /dev/null
|
|
+++ b/tests/restore_services_state.yml
|
|
@@ -0,0 +1,22 @@
|
|
+- block:
|
|
+ - name: load common vars
|
|
+ include_vars:
|
|
+ file: commonvars.yml
|
|
+
|
|
+ - name: Get final state of services
|
|
+ service_facts:
|
|
+ register: final_state
|
|
+
|
|
+ - name: Restore state of services
|
|
+ service:
|
|
+ name: "{{ item }}"
|
|
+ state: "{{ 'started' if
|
|
+ initial_state.ansible_facts.services[sname]['state']
|
|
+ == 'running' else 'stopped' }}"
|
|
+ when:
|
|
+ - sname in final_state.ansible_facts.services
|
|
+ - sname in initial_state.ansible_facts.services
|
|
+ vars:
|
|
+ sname: "{{ item + '.service' }}"
|
|
+ with_items: "{{ restore_services }}"
|
|
+ tags: tests::cleanup
|
|
diff --git a/tests/restore_state.yml b/tests/restore_state.yml
|
|
new file mode 100644
|
|
index 0000000..f4e3d5f
|
|
--- /dev/null
|
|
+++ b/tests/restore_state.yml
|
|
@@ -0,0 +1,24 @@
|
|
+---
|
|
+- name: Remove /etc/sysconfig/network if there was no one
|
|
+ tags:
|
|
+ - 'tests::cleanup'
|
|
+ file:
|
|
+ path: /etc/sysconfig/network
|
|
+ state: absent
|
|
+ when:
|
|
+ - etc_sysconfig_network_stat is defined
|
|
+ - not etc_sysconfig_network_stat.stat.exists
|
|
+
|
|
+- name: Restore services
|
|
+ import_tasks: restore_services_state.yml
|
|
+
|
|
+- name: reload NetworkManager
|
|
+ tags:
|
|
+ - 'tests::cleanup'
|
|
+ command: nmcli connection reload
|
|
+ when:
|
|
+ - sname in final_state.ansible_facts.services
|
|
+ - sname in initial_state.ansible_facts.services
|
|
+ - final_state.ansible_facts.services[sname]['state'] == 'running'
|
|
+ vars:
|
|
+ sname: NetworkManager.service
|
|
diff --git a/tests/save_state.yml b/tests/save_state.yml
|
|
new file mode 100644
|
|
index 0000000..5690aed
|
|
--- /dev/null
|
|
+++ b/tests/save_state.yml
|
|
@@ -0,0 +1,11 @@
|
|
+---
|
|
+- name: Get services state
|
|
+ import_tasks: get_services_state.yml
|
|
+
|
|
+- name: Investigate /etc/sysconfig/network presence
|
|
+ tags:
|
|
+ - 'tests::cleanup'
|
|
+ stat:
|
|
+ path: /etc/sysconfig/network
|
|
+ register: etc_sysconfig_network_stat
|
|
+ ignore_errors: yes
|
|
diff --git a/tests/tests_bridge.yml b/tests/tests_bridge.yml
|
|
index 9ead308..394d392 100644
|
|
--- a/tests/tests_bridge.yml
|
|
+++ b/tests/tests_bridge.yml
|
|
@@ -1,7 +1,17 @@
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
---
|
|
+- name: Save host state
|
|
+ hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ tasks:
|
|
+ - import_tasks: save_state.yml
|
|
+
|
|
- name: Test configuring bridges
|
|
hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
vars:
|
|
interface: LSR-TST-br31
|
|
|
|
@@ -14,6 +24,9 @@
|
|
|
|
- name: Add test bridge
|
|
hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::net::bridge'
|
|
vars:
|
|
network_connections:
|
|
- name: "{{ interface }}"
|
|
@@ -27,24 +40,40 @@
|
|
- linux-system-roles.network
|
|
|
|
- import_playbook: run-tasks.yml
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
vars:
|
|
task: tasks/assert-device_present.yml
|
|
|
|
- import_playbook: run-tasks.yml
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
task: tasks/assert-profile_present.yml
|
|
|
|
- import_playbook: down-profile.yml
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::cleanup'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ - 'tests::net::bridge::cleanup'
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
# FIXME: assert profile/device down
|
|
|
|
- import_playbook: remove-profile.yml
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::cleanup'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ - 'tests::net::bridge::cleanup'
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
|
|
- import_playbook: run-tasks.yml
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
task: tasks/assert-profile_absent.yml
|
|
@@ -53,3 +82,22 @@
|
|
#- import_playbook: run-tasks.yml
|
|
# vars:
|
|
# task: tasks/assert-device_absent.yml
|
|
+
|
|
+- name: Remove test bridge
|
|
+ hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::cleanup'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ - 'tests::net::bridge::cleanup'
|
|
+ tasks:
|
|
+ - command: 'ip link delete "{{ interface }}"'
|
|
+ ignore_errors: yes
|
|
+
|
|
+- name: Restore host state
|
|
+ hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ tasks:
|
|
+ - import_tasks: restore_state.yml
|
|
diff --git a/tests/tests_bridge_other_provider.yml b/tests/tests_bridge_other_provider.yml
|
|
index e5a4ad7..4d1d2dd 100644
|
|
--- a/tests/tests_bridge_other_provider.yml
|
|
+++ b/tests/tests_bridge_other_provider.yml
|
|
@@ -1,6 +1,8 @@
|
|
---
|
|
- hosts: all
|
|
name: Run playbook 'tests_bridge.yml' with non-default provider
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- name: Get service facts
|
|
service_facts: null
|
|
diff --git a/tests/tests_default.yml b/tests/tests_default.yml
|
|
index fda6ed5..0ce3ab9 100644
|
|
--- a/tests/tests_default.yml
|
|
+++ b/tests/tests_default.yml
|
|
@@ -2,5 +2,19 @@
|
|
---
|
|
- name: Test executing the role with default parameters
|
|
hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
roles:
|
|
- linux-system-roles.network
|
|
+
|
|
+ pre_tasks:
|
|
+ - name: Save host state
|
|
+ tags:
|
|
+ - 'tests::tier1::cleanup'
|
|
+ import_tasks: save_state.yml
|
|
+
|
|
+ post_tasks:
|
|
+ - name: Restore host state
|
|
+ tags:
|
|
+ - 'tests::tier1::cleanup'
|
|
+ import_tasks: restore_state.yml
|
|
diff --git a/tests/tests_default_other_provider.yml b/tests/tests_default_other_provider.yml
|
|
index 697bc57..0c70dac 100644
|
|
--- a/tests/tests_default_other_provider.yml
|
|
+++ b/tests/tests_default_other_provider.yml
|
|
@@ -1,6 +1,8 @@
|
|
---
|
|
- hosts: all
|
|
name: Run playbook 'tests_default.yml' with non-default provider
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- name: Get service facts
|
|
service_facts: null
|
|
diff --git a/tests/tests_ethernet.yml b/tests/tests_ethernet.yml
|
|
index 25f117d..c85f853 100644
|
|
--- a/tests/tests_ethernet.yml
|
|
+++ b/tests/tests_ethernet.yml
|
|
@@ -1,6 +1,16 @@
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
---
|
|
+- name: Save host state
|
|
+ hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ tasks:
|
|
+ - import_tasks: save_state.yml
|
|
+
|
|
- hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- debug:
|
|
msg: Inside ethernet tests
|
|
@@ -9,6 +19,9 @@
|
|
|
|
- name: Test configuring ethernet devices
|
|
hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::net::veth'
|
|
vars:
|
|
type: veth
|
|
interface: lsr27
|
|
@@ -18,6 +31,7 @@
|
|
set_fact:
|
|
type: "{{ type }}"
|
|
interface: "{{ interface }}"
|
|
+# cacheable: yes
|
|
- include_tasks: tasks/show-interfaces.yml
|
|
- include_tasks: tasks/manage-test-interface.yml
|
|
vars:
|
|
@@ -26,6 +40,9 @@
|
|
|
|
- name: Test static interface up
|
|
hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::net::reconf'
|
|
vars:
|
|
network_connections:
|
|
- name: "{{ interface }}"
|
|
@@ -39,6 +56,8 @@
|
|
- linux-system-roles.network
|
|
|
|
- hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- debug:
|
|
var: network_provider
|
|
@@ -46,17 +65,38 @@
|
|
# FIXME: assert profile present
|
|
# FIXME: assert profile/device up + IP address
|
|
- import_playbook: down-profile.yml
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::cleanup'
|
|
+ - 'tests::tier1::cleanup'
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
# FIXME: assert profile/device down
|
|
- import_playbook: remove-profile.yml
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::cleanup'
|
|
+ - 'tests::tier1::cleanup'
|
|
vars:
|
|
profile: "{{ interface }}"
|
|
# FIXME: assert profile away
|
|
- name: Remove interfaces
|
|
hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::cleanup'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ - 'tests::net::veth::cleanup'
|
|
tasks:
|
|
- include_tasks: tasks/manage-test-interface.yml
|
|
vars:
|
|
state: absent
|
|
- include_tasks: tasks/assert-device_absent.yml
|
|
+
|
|
+- name: Restore host state
|
|
+ hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
+ - 'tests::tier1::cleanup'
|
|
+ tasks:
|
|
+ - import_tasks: restore_state.yml
|
|
diff --git a/tests/tests_ethernet_other_provider.yml b/tests/tests_ethernet_other_provider.yml
|
|
index 456b052..5a5dbb0 100644
|
|
--- a/tests/tests_ethernet_other_provider.yml
|
|
+++ b/tests/tests_ethernet_other_provider.yml
|
|
@@ -1,6 +1,8 @@
|
|
---
|
|
- hosts: all
|
|
name: Run playbook 'tests_ethernet.yml' with non-default provider
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- name: Get service facts
|
|
service_facts: null
|
|
diff --git a/tests/tests_helpers-and-asserts.yml b/tests/tests_helpers-and-asserts.yml
|
|
index 36f02c2..b44599a 100644
|
|
--- a/tests/tests_helpers-and-asserts.yml
|
|
+++ b/tests/tests_helpers-and-asserts.yml
|
|
@@ -2,6 +2,8 @@
|
|
---
|
|
- name: Check that creating and removing test devices and assertions work
|
|
hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- name: test veth interface management
|
|
include_tasks: tasks/create-and-remove-interface.yml
|
|
@@ -15,6 +17,18 @@
|
|
type: dummy
|
|
interface: dummy1298
|
|
|
|
+ pre_tasks:
|
|
+ - name: Save host state
|
|
+ tags:
|
|
+ - 'tests::tier1::cleanup'
|
|
+ import_tasks: save_state.yml
|
|
+
|
|
+ post_tasks:
|
|
+ - name: Restore host state
|
|
+ tags:
|
|
+ - 'tests::tier1::cleanup'
|
|
+ import_tasks: restore_state.yml
|
|
+
|
|
# 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
|
|
diff --git a/tests/tests_states.yml b/tests/tests_states.yml
|
|
index eff3436..46cfe87 100644
|
|
--- a/tests/tests_states.yml
|
|
+++ b/tests/tests_states.yml
|
|
@@ -1,6 +1,8 @@
|
|
---
|
|
# empty playbook to gather facts for import_playbook when clause
|
|
- hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
|
|
# workaround for: https://github.com/ansible/ansible/issues/27973
|
|
# There is no way in Ansible to abort a playbook hosts with specific OS
|
|
diff --git a/tests/tests_unit.yml b/tests/tests_unit.yml
|
|
index c6ea4ef..8d56cf4 100644
|
|
--- a/tests/tests_unit.yml
|
|
+++ b/tests/tests_unit.yml
|
|
@@ -2,6 +2,8 @@
|
|
---
|
|
- hosts: all
|
|
name: Setup for test running
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- name: Install EPEL on enterprise Linux for python2-mock
|
|
command: yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-{{ ansible_distribution_major_version }}.noarch.rpm
|
|
@@ -27,6 +29,8 @@
|
|
|
|
- hosts: all
|
|
name: execute python unit tests
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- name: Copy python modules
|
|
copy:
|
|
diff --git a/tests/tests_vlan_mtu_initscripts.yml b/tests/tests_vlan_mtu_initscripts.yml
|
|
index a57db4b..d3a48c7 100644
|
|
--- a/tests/tests_vlan_mtu_initscripts.yml
|
|
+++ b/tests/tests_vlan_mtu_initscripts.yml
|
|
@@ -1,6 +1,8 @@
|
|
---
|
|
# set network provider and gather facts
|
|
- hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- name: Set network provider to 'initscripts'
|
|
set_fact:
|
|
diff --git a/tests/tests_vlan_mtu_nm.yml b/tests/tests_vlan_mtu_nm.yml
|
|
index d830817..68b61b5 100644
|
|
--- a/tests/tests_vlan_mtu_nm.yml
|
|
+++ b/tests/tests_vlan_mtu_nm.yml
|
|
@@ -1,6 +1,8 @@
|
|
---
|
|
# set network provider and gather facts
|
|
- hosts: all
|
|
+ tags:
|
|
+ - 'tests::tier1'
|
|
tasks:
|
|
- name: Set network provider to 'nm'
|
|
set_fact:
|