Blame SOURCES/network-tier1-tags.diff

48847c
diff --git a/tests/playbooks/tests_802_1x.yml b/tests/playbooks/tests_802_1x.yml
48847c
index 8151294..0c6c965 100644
48847c
--- a/tests/playbooks/tests_802_1x.yml
48847c
+++ b/tests/playbooks/tests_802_1x.yml
48847c
@@ -1,5 +1,10 @@
48847c
 # SPDX-License-Identifier: BSD-3-Clause
48847c
 ---
48847c
+- name: Save host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/save_state.yml
48847c
+
48847c
 - hosts: all
48847c
   vars:
48847c
     interface: 802-1x-test
48847c
@@ -105,3 +110,8 @@
48847c
             - include_tasks: tasks/cleanup_802_1x_server.yml
48847c
           tags:
48847c
             - "tests::cleanup"
48847c
+
48847c
+- name: Restore host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/restore_state.yml
48847c
diff --git a/tests/playbooks/tests_bridge.yml b/tests/playbooks/tests_bridge.yml
48847c
index d79d6ad..c8cf3cd 100644
48847c
--- a/tests/playbooks/tests_bridge.yml
48847c
+++ b/tests/playbooks/tests_bridge.yml
48847c
@@ -1,5 +1,10 @@
48847c
 # SPDX-License-Identifier: BSD-3-Clause
48847c
 ---
48847c
+- name: Save host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/save_state.yml
48847c
+
48847c
 - name: Test configuring bridges
48847c
   hosts: all
48847c
   vars:
48847c
@@ -14,6 +19,8 @@
48847c
 
48847c
 - name: Add test bridge
48847c
   hosts: all
48847c
+  tags:
48847c
+    - 'tests::net::bridge'
48847c
   vars:
48847c
     network_connections:
48847c
       - name: "{{ interface }}"
48847c
@@ -36,11 +43,15 @@
48847c
     task: tasks/assert_profile_present.yml
48847c
 
48847c
 - import_playbook: down_profile.yml
48847c
+  tags:
48847c
+    - 'tests::net::bridge'
48847c
   vars:
48847c
     profile: "{{ interface }}"
48847c
 # FIXME: assert profile/device down
48847c
 
48847c
 - import_playbook: remove_profile.yml
48847c
+  tags:
48847c
+    - 'tests::net::bridge'
48847c
   vars:
48847c
     profile: "{{ interface }}"
48847c
 
48847c
@@ -51,5 +62,19 @@
48847c
 
48847c
 # FIXME: Devices might still be left when profile is absent
48847c
 # - import_playbook: run_tasks.yml
48847c
-#   vars:
48847c
+#  vars:
48847c
 #     task: tasks/assert_device_absent.yml
48847c
+
48847c
+- name: Remove test bridge
48847c
+  hosts: all
48847c
+  tags:
48847c
+    - 'tests::cleanup'
48847c
+    - 'tests::net::bridge::cleanup'
48847c
+  tasks:
48847c
+    - command: 'ip link delete "{{ interface }}"'
48847c
+      ignore_errors: yes
48847c
+
48847c
+- name: Restore host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/restore_state.yml
48847c
diff --git a/tests/playbooks/tests_checkpoint_cleanup.yml b/tests/playbooks/tests_checkpoint_cleanup.yml
48847c
index 18e3fd7..3b5a41a 100644
48847c
--- a/tests/playbooks/tests_checkpoint_cleanup.yml
48847c
+++ b/tests/playbooks/tests_checkpoint_cleanup.yml
48847c
@@ -4,6 +4,11 @@
48847c
 # mark a device as unmanaged for NM and then tries to activiate it using NM.
48847c
 # This failed without removing the checkpoint.
48847c
 ---
48847c
+- name: Save host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/save_state.yml
48847c
+
48847c
 - hosts: all
48847c
   vars:
48847c
     interface: cptstbr
48847c
@@ -80,3 +85,8 @@
48847c
           ignore_errors: true
48847c
           tags:
48847c
             - "tests::cleanup"
48847c
+
48847c
+- name: Restore host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/restore_state.yml
48847c
diff --git a/tests/playbooks/tests_ethernet.yml b/tests/playbooks/tests_ethernet.yml
48847c
index cd02579..adcffee 100644
48847c
--- a/tests/playbooks/tests_ethernet.yml
48847c
+++ b/tests/playbooks/tests_ethernet.yml
48847c
@@ -1,5 +1,10 @@
48847c
 # SPDX-License-Identifier: BSD-3-Clause
48847c
 ---
48847c
+- name: Save host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/save_state.yml
48847c
+
48847c
 - hosts: all
48847c
   tasks:
48847c
     - debug:
48847c
@@ -9,6 +14,8 @@
48847c
 
48847c
 - name: Test configuring ethernet devices
48847c
   hosts: all
48847c
+  tags:
48847c
+    - 'tests::net::veth'
48847c
   vars:
48847c
     type: veth
48847c
     interface: lsr27
48847c
@@ -26,6 +33,8 @@
48847c
 
48847c
 - name: Test static interface up
48847c
   hosts: all
48847c
+  tags:
48847c
+    - 'tests::net::reconf'
48847c
   vars:
48847c
     network_connections:
48847c
       - name: "{{ interface }}"
48847c
@@ -48,17 +57,29 @@
48847c
 # FIXME: assert profile present
48847c
 # FIXME: assert profile/device up + IP address
48847c
 - import_playbook: down_profile.yml
48847c
+  tags:
48847c
+    - 'tests::cleanup'
48847c
   vars:
48847c
     profile: "{{ interface }}"
48847c
 # FIXME: assert profile/device down
48847c
 - import_playbook: remove_profile.yml
48847c
+  tags:
48847c
+    - 'tests::cleanup'
48847c
   vars:
48847c
     profile: "{{ interface }}"
48847c
 # FIXME: assert profile away
48847c
 - name: Remove interfaces
48847c
   hosts: all
48847c
+  tags:
48847c
+    - 'tests::cleanup'
48847c
+    - 'tests::net::veth::cleanup'
48847c
   tasks:
48847c
     - include_tasks: tasks/manage_test_interface.yml
48847c
       vars:
48847c
         state: absent
48847c
     - include_tasks: tasks/assert_device_absent.yml
48847c
+
48847c
+- name: Restore host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/restore_state.yml
48847c
diff --git a/tests/playbooks/tests_reapply.yml b/tests/playbooks/tests_reapply.yml
48847c
index 4b1cb09..6995607 100644
48847c
--- a/tests/playbooks/tests_reapply.yml
48847c
+++ b/tests/playbooks/tests_reapply.yml
48847c
@@ -4,6 +4,11 @@
48847c
 # of via Ansible. Until there is better test support for this, just check the
48847c
 # log output for the respective log message.
48847c
 ---
48847c
+- name: Save host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/save_state.yml
48847c
+
48847c
 - hosts: all
48847c
   vars:
48847c
     interface: rpltstbr
48847c
@@ -64,3 +69,8 @@
48847c
           ignore_errors: true
48847c
           tags:
48847c
             - "tests::cleanup"
48847c
+
48847c
+- name: Restore host state
48847c
+  hosts: all
48847c
+  tasks:
48847c
+    - import_tasks: tasks/restore_state.yml
48847c
diff --git a/tests/playbooks/tests_states.yml b/tests/playbooks/tests_states.yml
48847c
index 8edbf8f..ef59063 100644
48847c
--- a/tests/playbooks/tests_states.yml
48847c
+++ b/tests/playbooks/tests_states.yml
48847c
@@ -22,6 +22,8 @@
48847c
             ip:
48847c
               dhcp4: false
48847c
               auto6: false
48847c
+      tags:
48847c
+        - 'tests::net::bridge'
48847c
     - include_tasks: tasks/assert_device_present.yml
48847c
     - include_tasks: tasks/assert_profile_present.yml
48847c
 
48847c
@@ -75,3 +77,18 @@
48847c
         - assert:
48847c
             that: __network_test_failed
48847c
             fail_msg: "The role did not fail when it should have"
48847c
+
48847c
+  pre_tasks:
48847c
+    - name: Save host state
48847c
+      import_tasks: tasks/save_state.yml
48847c
+
48847c
+  post_tasks:
48847c
+    - name: Remove test bridge in case it is still lingering
48847c
+      command: 'ip link delete "{{ interface }}"'
48847c
+      tags:
48847c
+        - 'tests::cleanup'
48847c
+        - 'tests::net::bridge::cleanup'
48847c
+      ignore_errors: yes
48847c
+
48847c
+    - name: Restore host state
48847c
+      import_tasks: tasks/restore_state.yml
48847c
diff --git a/tests/playbooks/tests_vlan_mtu.yml b/tests/playbooks/tests_vlan_mtu.yml
48847c
index 029b599..378d5fe 100644
48847c
--- a/tests/playbooks/tests_vlan_mtu.yml
48847c
+++ b/tests/playbooks/tests_vlan_mtu.yml
48847c
@@ -10,6 +10,8 @@
48847c
     - include_tasks: tasks/manage_test_interface.yml
48847c
       vars:
48847c
         state: present
48847c
+      tags:
48847c
+        - 'tests::net::veth'
48847c
     - include_tasks: tasks/assert_device_present.yml
48847c
     - name: >-
48847c
         TEST: I can configure the MTU for a vlan interface without autoconnect.
48847c
@@ -38,6 +40,8 @@
48847c
             ip:
48847c
               dhcp4: false
48847c
               auto6: false
48847c
+      tags:
48847c
+        - 'tests::net::reconf'
48847c
     - include_tasks: tasks/assert_device_present.yml
48847c
       vars:
48847c
         interface: "{{ vlan_interface }}"
48847c
@@ -62,6 +66,20 @@
48847c
             persistent_state: absent
48847c
             state: down
48847c
       ignore_errors: true
48847c
+      tags:
48847c
+        - 'tests::cleanup'
48847c
+        - 'tests::net::veth::cleanup'
48847c
     - include_tasks: tasks/manage_test_interface.yml
48847c
       vars:
48847c
         state: absent
48847c
+      tags:
48847c
+        - 'tests::cleanup'
48847c
+        - 'tests::net::veth::cleanup'
48847c
+
48847c
+  pre_tasks:
48847c
+    - name: Save host state
48847c
+      import_tasks: tasks/save_state.yml
48847c
+
48847c
+  post_tasks:
48847c
+    - name: Restore host state
48847c
+      import_tasks: tasks/restore_state.yml
48847c
diff --git a/tests/tasks/commonvars.yml b/tests/tasks/commonvars.yml
48847c
new file mode 100644
48847c
index 0000000..50452f7
48847c
--- /dev/null
48847c
+++ b/tests/tasks/commonvars.yml
48847c
@@ -0,0 +1,2 @@
48847c
+restore_services:
48847c
+  - NetworkManager
48847c
diff --git a/tests/tasks/get_services_state.yml b/tests/tasks/get_services_state.yml
48847c
new file mode 100644
48847c
index 0000000..4fe5d36
48847c
--- /dev/null
48847c
+++ b/tests/tasks/get_services_state.yml
48847c
@@ -0,0 +1,4 @@
48847c
+- name: Get initial state of services
48847c
+  tags: tests::cleanup
48847c
+  service_facts:
48847c
+  register: initial_state
48847c
diff --git a/tests/tasks/restore_services_state.yml b/tests/tasks/restore_services_state.yml
48847c
new file mode 100644
48847c
index 0000000..2035dfc
48847c
--- /dev/null
48847c
+++ b/tests/tasks/restore_services_state.yml
48847c
@@ -0,0 +1,22 @@
48847c
+- block:
48847c
+    - name: load common vars
48847c
+      include_vars:
48847c
+        file: commonvars.yml
48847c
+
48847c
+    - name: Get final state of services
48847c
+      service_facts:
48847c
+      register: final_state
48847c
+
48847c
+    - name: Restore state of services
48847c
+      service:
48847c
+        name: "{{ item }}"
48847c
+        state: "{{ 'started' if
48847c
+                   initial_state.ansible_facts.services[sname]['state']
48847c
+                   == 'running' else 'stopped' }}"
48847c
+      when:
48847c
+         - sname in final_state.ansible_facts.services
48847c
+         - sname in initial_state.ansible_facts.services
48847c
+      vars:
48847c
+        sname: "{{ item + '.service' }}"
48847c
+      with_items: "{{ restore_services }}"
48847c
+  tags: tests::cleanup
48847c
diff --git a/tests/tasks/restore_state.yml b/tests/tasks/restore_state.yml
48847c
new file mode 100644
48847c
index 0000000..f4e3d5f
48847c
--- /dev/null
48847c
+++ b/tests/tasks/restore_state.yml
48847c
@@ -0,0 +1,24 @@
48847c
+---
48847c
+- name: Remove /etc/sysconfig/network if there was no one
48847c
+  tags:
48847c
+    - 'tests::cleanup'
48847c
+  file:
48847c
+    path: /etc/sysconfig/network
48847c
+    state: absent
48847c
+  when:
48847c
+    - etc_sysconfig_network_stat is defined
48847c
+    - not etc_sysconfig_network_stat.stat.exists
48847c
+
48847c
+- name: Restore services
48847c
+  import_tasks: restore_services_state.yml
48847c
+
48847c
+- name: reload NetworkManager
48847c
+  tags:
48847c
+    - 'tests::cleanup'
48847c
+  command: nmcli connection reload
48847c
+  when:
48847c
+    - sname in final_state.ansible_facts.services
48847c
+    - sname in initial_state.ansible_facts.services
48847c
+    - final_state.ansible_facts.services[sname]['state'] == 'running'
48847c
+  vars:
48847c
+    sname: NetworkManager.service
48847c
diff --git a/tests/tasks/save_state.yml b/tests/tasks/save_state.yml
48847c
new file mode 100644
48847c
index 0000000..5690aed
48847c
--- /dev/null
48847c
+++ b/tests/tasks/save_state.yml
48847c
@@ -0,0 +1,11 @@
48847c
+---
48847c
+- name: Get services state
48847c
+  import_tasks: get_services_state.yml
48847c
+
48847c
+- name: Investigate /etc/sysconfig/network presence
48847c
+  tags:
48847c
+    - 'tests::cleanup'
48847c
+  stat:
48847c
+    path: /etc/sysconfig/network
48847c
+  register: etc_sysconfig_network_stat
48847c
+  ignore_errors: yes
48847c
diff --git a/tests/tests_default.yml b/tests/tests_default.yml
48847c
index f6f7550..98e3c7e 100644
48847c
--- a/tests/tests_default.yml
48847c
+++ b/tests/tests_default.yml
48847c
@@ -10,3 +10,11 @@
48847c
         that:
48847c
           - "'warnings' not in __network_connections_result"
48847c
         msg: "There are warnings"
48847c
+
48847c
+  pre_tasks:
48847c
+    - name: Save host state
48847c
+      import_tasks: tasks/save_state.yml
48847c
+
48847c
+  post_tasks:
48847c
+    - name: Restore host state
48847c
+      import_tasks: tasks/restore_state.yml
48847c
diff --git a/tests/tests_helpers_and_asserts.yml b/tests/tests_helpers_and_asserts.yml
48847c
index 5514182..d9bfa11 100644
48847c
--- a/tests/tests_helpers_and_asserts.yml
48847c
+++ b/tests/tests_helpers_and_asserts.yml
48847c
@@ -15,6 +15,14 @@
48847c
         type: dummy
48847c
         interface: dummy1298
48847c
 
48847c
+  pre_tasks:
48847c
+    - name: Save host state
48847c
+      import_tasks: tasks/save_state.yml
48847c
+
48847c
+  post_tasks:
48847c
+    - name: Restore host state
48847c
+      import_tasks: tasks/restore_state.yml
48847c
+
48847c
 # FIXME: when: does not seem to work with include_tasks, therefore this cannot
48847c
 # be safely tested for now
48847c
 #    - name: test tap interfaces