diff --git a/tests/playbooks/tests_802_1x.yml b/tests/playbooks/tests_802_1x.yml index 9cce1ae..76d99e9 100644 --- a/tests/playbooks/tests_802_1x.yml +++ b/tests/playbooks/tests_802_1x.yml @@ -1,5 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause --- +- name: Save host state + hosts: all + tasks: + - import_tasks: tasks/save_state.yml + - hosts: all vars: interface: 802-1x-test @@ -122,3 +127,8 @@ command: update-ca-trust tags: - "tests::cleanup" + +- name: Restore host state + hosts: all + tasks: + - import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_bond.yml b/tests/playbooks/tests_bond.yml index ab3ee43..d646a0b 100644 --- a/tests/playbooks/tests_bond.yml +++ b/tests/playbooks/tests_bond.yml @@ -1,5 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause --- +- name: Save host state + hosts: all + tasks: + - import_tasks: tasks/save_state.yml + - hosts: all vars: master_profile: bond0 @@ -94,3 +99,8 @@ - import_tasks: tasks/remove_test_interfaces_with_dhcp.yml tags: - "tests::cleanup" + +- name: Restore host state + hosts: all + tasks: + - import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_bridge.yml b/tests/playbooks/tests_bridge.yml index d79d6ad..c8cf3cd 100644 --- a/tests/playbooks/tests_bridge.yml +++ b/tests/playbooks/tests_bridge.yml @@ -1,5 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause --- +- name: Save host state + hosts: all + tasks: + - import_tasks: tasks/save_state.yml + - name: Test configuring bridges hosts: all vars: @@ -14,6 +19,8 @@ - name: Add test bridge hosts: all + tags: + - 'tests::net::bridge' vars: network_connections: - name: "{{ interface }}" @@ -36,11 +43,15 @@ task: tasks/assert_profile_present.yml - import_playbook: down_profile.yml + tags: + - 'tests::net::bridge' vars: profile: "{{ interface }}" # FIXME: assert profile/device down - import_playbook: remove_profile.yml + tags: + - 'tests::net::bridge' vars: profile: "{{ interface }}" @@ -51,5 +62,19 @@ # FIXME: Devices might still be left when profile is absent # - import_playbook: run_tasks.yml -# vars: +# vars: # task: tasks/assert_device_absent.yml + +- name: Remove test bridge + hosts: all + tags: + - 'tests::cleanup' + - 'tests::net::bridge::cleanup' + tasks: + - command: 'ip link delete "{{ interface }}"' + ignore_errors: yes + +- name: Restore host state + hosts: all + tasks: + - import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_checkpoint_cleanup.yml b/tests/playbooks/tests_checkpoint_cleanup.yml index 18e3fd7..3b5a41a 100644 --- a/tests/playbooks/tests_checkpoint_cleanup.yml +++ b/tests/playbooks/tests_checkpoint_cleanup.yml @@ -4,6 +4,11 @@ # mark a device as unmanaged for NM and then tries to activiate it using NM. # This failed without removing the checkpoint. --- +- name: Save host state + hosts: all + tasks: + - import_tasks: tasks/save_state.yml + - hosts: all vars: interface: cptstbr @@ -80,3 +85,8 @@ ignore_errors: true tags: - "tests::cleanup" + +- name: Restore host state + hosts: all + tasks: + - import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_ethernet.yml b/tests/playbooks/tests_ethernet.yml index cd02579..adcffee 100644 --- a/tests/playbooks/tests_ethernet.yml +++ b/tests/playbooks/tests_ethernet.yml @@ -1,5 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause --- +- name: Save host state + hosts: all + tasks: + - import_tasks: tasks/save_state.yml + - hosts: all tasks: - debug: @@ -9,6 +14,8 @@ - name: Test configuring ethernet devices hosts: all + tags: + - 'tests::net::veth' vars: type: veth interface: lsr27 @@ -26,6 +33,8 @@ - name: Test static interface up hosts: all + tags: + - 'tests::net::reconf' vars: network_connections: - name: "{{ interface }}" @@ -48,17 +57,29 @@ # FIXME: assert profile present # FIXME: assert profile/device up + IP address - import_playbook: down_profile.yml + tags: + - 'tests::cleanup' vars: profile: "{{ interface }}" # FIXME: assert profile/device down - import_playbook: remove_profile.yml + tags: + - 'tests::cleanup' vars: profile: "{{ interface }}" # FIXME: assert profile away - name: Remove interfaces hosts: all + tags: + - 'tests::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 + tasks: + - import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_ethtool_features.yml b/tests/playbooks/tests_ethtool_features.yml index 43fddc3..d1a87fe 100644 --- a/tests/playbooks/tests_ethtool_features.yml +++ b/tests/playbooks/tests_ethtool_features.yml @@ -1,5 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause --- +- name: Save host state + hosts: all + tasks: + - import_tasks: tasks/save_state.yml + - hosts: all vars: interface: testnic1 @@ -198,3 +203,8 @@ state: absent tags: - "tests::cleanup" + +- name: Restore host state + hosts: all + tasks: + - import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_provider.yml b/tests/playbooks/tests_provider.yml index 1db2d08..e097b4b 100644 --- a/tests/playbooks/tests_provider.yml +++ b/tests/playbooks/tests_provider.yml @@ -1,5 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause --- +- name: Save host state + hosts: all + tasks: + - import_tasks: tasks/save_state.yml + - hosts: all vars: interface: testnic1 @@ -33,3 +38,8 @@ - tasks/cleanup_profile+device.yml tags: - tests::provider:initscripts_to_nm + +- name: Restore host state + hosts: all + tasks: + - import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_reapply.yml b/tests/playbooks/tests_reapply.yml index 4b1cb09..6995607 100644 --- a/tests/playbooks/tests_reapply.yml +++ b/tests/playbooks/tests_reapply.yml @@ -4,6 +4,11 @@ # of via Ansible. Until there is better test support for this, just check the # log output for the respective log message. --- +- name: Save host state + hosts: all + tasks: + - import_tasks: tasks/save_state.yml + - hosts: all vars: interface: rpltstbr @@ -64,3 +69,8 @@ ignore_errors: true tags: - "tests::cleanup" + +- name: Restore host state + hosts: all + tasks: + - import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_states.yml b/tests/playbooks/tests_states.yml index eec27c0..a8d0ecd 100644 --- a/tests/playbooks/tests_states.yml +++ b/tests/playbooks/tests_states.yml @@ -135,3 +135,23 @@ - tasks/cleanup_profile+device.yml tags: - tests::states:remove_down_twice + + pre_tasks: + - name: Save host state + import_tasks: tasks/save_state.yml + + post_tasks: + - name: Remove test profile + tags: + - 'tests::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 + import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_vlan_mtu.yml b/tests/playbooks/tests_vlan_mtu.yml index 029b599..378d5fe 100644 --- a/tests/playbooks/tests_vlan_mtu.yml +++ b/tests/playbooks/tests_vlan_mtu.yml @@ -10,6 +10,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. @@ -38,6 +40,8 @@ ip: dhcp4: false auto6: false + tags: + - 'tests::net::reconf' - include_tasks: tasks/assert_device_present.yml vars: interface: "{{ vlan_interface }}" @@ -62,6 +66,20 @@ persistent_state: absent state: down ignore_errors: true + tags: + - 'tests::cleanup' + - 'tests::net::veth::cleanup' - include_tasks: tasks/manage_test_interface.yml vars: state: absent + tags: + - 'tests::cleanup' + - 'tests::net::veth::cleanup' + + pre_tasks: + - name: Save host state + import_tasks: tasks/save_state.yml + + post_tasks: + - name: Restore host state + import_tasks: tasks/restore_state.yml diff --git a/tests/playbooks/tests_wireless.yml b/tests/playbooks/tests_wireless.yml index 822a15e..52661bd 100644 --- a/tests/playbooks/tests_wireless.yml +++ b/tests/playbooks/tests_wireless.yml @@ -1,5 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause --- +- name: Save host state + hosts: all + tasks: + - import_tasks: tasks/save_state.yml + - hosts: all vars: interface: wlan0 @@ -86,3 +91,8 @@ - include_tasks: tasks/cleanup_mock_wifi.yml tags: - "tests::cleanup" + +- name: Restore host state + hosts: all + tasks: + - import_tasks: tasks/restore_state.yml diff --git a/tests/tasks/commonvars.yml b/tests/tasks/commonvars.yml new file mode 100644 index 0000000..50452f7 --- /dev/null +++ b/tests/tasks/commonvars.yml @@ -0,0 +1,2 @@ +restore_services: + - NetworkManager diff --git a/tests/tasks/get_services_state.yml b/tests/tasks/get_services_state.yml new file mode 100644 index 0000000..4fe5d36 --- /dev/null +++ b/tests/tasks/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/tasks/restore_services_state.yml b/tests/tasks/restore_services_state.yml new file mode 100644 index 0000000..2035dfc --- /dev/null +++ b/tests/tasks/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/tasks/restore_state.yml b/tests/tasks/restore_state.yml new file mode 100644 index 0000000..f4e3d5f --- /dev/null +++ b/tests/tasks/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/tasks/save_state.yml b/tests/tasks/save_state.yml new file mode 100644 index 0000000..5690aed --- /dev/null +++ b/tests/tasks/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_802_1x_nm.yml b/tests/tests_802_1x_nm.yml index 288cd5d..840958d 100644 --- a/tests/tests_802_1x_nm.yml +++ b/tests/tests_802_1x_nm.yml @@ -4,6 +4,8 @@ # set network provider and gather facts - hosts: all name: Run playbook 'playbooks/tests_802_1x.yml' with nm as provider + tags: + - tests::expfail tasks: - name: Set network provider to 'nm' set_fact: @@ -17,3 +19,5 @@ - import_playbook: playbooks/tests_802_1x.yml when: - ansible_distribution_major_version != '6' + tags: + - tests::expfail diff --git a/tests/tests_802_1x_updated_nm.yml b/tests/tests_802_1x_updated_nm.yml index bd335e4..4ebcaf9 100644 --- a/tests/tests_802_1x_updated_nm.yml +++ b/tests/tests_802_1x_updated_nm.yml @@ -4,6 +4,8 @@ # set network provider and gather facts - hosts: all name: Run playbook 'playbooks/tests_802_1x_updated.yml' with nm as provider + tags: + - tests::expfail tasks: - name: Set network provider to 'nm' set_fact: @@ -17,3 +19,5 @@ - import_playbook: playbooks/tests_802_1x_updated.yml when: - ansible_distribution_major_version != '6' + tags: + - tests::expfail diff --git a/tests/tests_default.yml b/tests/tests_default.yml index f6f7550..98e3c7e 100644 --- a/tests/tests_default.yml +++ b/tests/tests_default.yml @@ -10,3 +10,11 @@ that: - "'warnings' not in __network_connections_result" msg: "There are warnings" + + pre_tasks: + - name: Save host state + import_tasks: tasks/save_state.yml + + post_tasks: + - name: Restore host state + import_tasks: tasks/restore_state.yml diff --git a/tests/tests_helpers_and_asserts.yml b/tests/tests_helpers_and_asserts.yml index 5514182..d9bfa11 100644 --- a/tests/tests_helpers_and_asserts.yml +++ b/tests/tests_helpers_and_asserts.yml @@ -15,6 +15,14 @@ type: dummy interface: dummy1298 + pre_tasks: + - name: Save host state + import_tasks: tasks/save_state.yml + + post_tasks: + - name: Restore host state + import_tasks: 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