test: Add DNS, routes and network connectivity checks during cleanup

In order to guarantee each test is cleaned up properly in the end, it
is important to add a post-test check to each test checking that:

- Routes and DNS are restored.
- Network connectivity to certain hosts are preserved.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
This commit is contained in:
Wen Liang 2024-02-09 15:21:49 -05:00 committed by Richard Megginson
parent ae9f212086
commit b4f51e2691
41 changed files with 127 additions and 1 deletions

View file

@ -83,7 +83,7 @@ ibution_major_version | int < 9",
"playbooks/tests_provider.yml": {
MINIMUM_VERSION: "'1.20.0'",
"comment": "# NetworKmanager 1.20.0 added support for forgetting profiles",
EXTRA_RUN_CONDITION: "ansible_distribution != 'RedHat' or\n ansible_distr\
EXTRA_RUN_CONDITION: "ansible_distribution not in ['RedHat', 'CentOS'] or\n ansible_distr\
ibution_major_version | int < 9",
},
"playbooks/tests_eth_pci_address_match.yml": {

View file

@ -143,3 +143,5 @@
- name: Update ca trust
command: update-ca-trust
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -150,3 +150,5 @@
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -123,3 +123,5 @@
when:
- network_provider == "initscripts"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -135,3 +135,5 @@
when:
- network_provider == "initscripts"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -123,3 +123,5 @@
when:
- network_provider == "initscripts"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -89,3 +89,4 @@
lsr_cleanup:
- tasks/cleanup_bond_profile+device.yml
- tasks/remove_test_interfaces_with_dhcp.yml
- tasks/check_network_dns.yml

View file

@ -257,3 +257,5 @@
when:
- network_provider == "initscripts"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -60,3 +60,9 @@
import_playbook: run_tasks.yml
vars:
task: tasks/assert_device_absent.yml
- name: Verify that cleanup restored state to default
hosts: all
tasks:
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -60,3 +60,9 @@
import_playbook: remove_profile.yml
vars:
profile: "{{ interface }}"
- name: Verify that cleanup restored state to default
hosts: all
tasks:
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -101,3 +101,5 @@
- name: Delete the device '{{ interface }}'
command: ip link del "{{ interface }}"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -32,3 +32,4 @@
- tasks/assert_device_present.yml
lsr_cleanup:
- tasks/cleanup_profile+device.yml
- tasks/check_network_dns.yml

View file

@ -138,4 +138,6 @@
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -79,3 +79,5 @@
persistent_state: absent
state: down
failed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -74,3 +74,8 @@
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify that cleanup restored state to default
hosts: all
tasks:
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -174,3 +174,5 @@
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -224,3 +224,5 @@
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -215,3 +215,5 @@
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -79,4 +79,6 @@
include_tasks: tasks/assert_profile_absent.yml
vars:
profile: "{{ interface }}"
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -89,3 +89,5 @@
command: ip link del {{ interface }}.000a
failed_when: false
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -112,3 +112,5 @@
when:
- ansible_distribution_major_version != '6'
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -93,4 +93,6 @@
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -161,3 +161,5 @@
persistent_state: absent
state: down
failed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -185,4 +185,6 @@
include_tasks: tasks/delete_interface.yml
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -38,3 +38,4 @@
- tasks/assert_profile_present.yml
lsr_cleanup:
- tasks/cleanup_profile+device.yml
- tasks/check_network_dns.yml

View file

@ -79,3 +79,5 @@
- name: Delete the device '{{ interface }}'
command: ip link del "{{ interface }}"
changed_when: false
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -185,4 +185,6 @@
loop:
- "{{ interface0 }}"
- "{{ interface1 }}"
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -152,4 +152,6 @@
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -191,4 +191,6 @@
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -273,4 +273,6 @@
profile: "{{ interface }}"
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -145,3 +145,4 @@
condition: "{{ network_provider == 'nm' }}"
lsr_cleanup:
- tasks/cleanup_profile+device.yml
- tasks/check_network_dns.yml

View file

@ -61,3 +61,5 @@
include_tasks: tasks/delete_interface.yml
- name: Include the task 'assert_device_absent.yml'
include_tasks: tasks/assert_device_absent.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -32,3 +32,4 @@
- tasks/assert_device_present.yml
lsr_cleanup:
- tasks/cleanup_profile+device.yml
- tasks/check_network_dns.yml

View file

@ -42,4 +42,7 @@
that:
- "'NetworkManager-team' in ansible_facts.packages"
msg: "NetworkManager-team is not installed after team configuration"
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
...

View file

@ -74,3 +74,5 @@
include_tasks: tasks/manage_test_interface.yml
vars:
state: absent
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -95,3 +95,5 @@
failed_when: false
- name: Include the task 'cleanup_mock_wifi.yml'
include_tasks: tasks/cleanup_mock_wifi.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -43,3 +43,6 @@
that:
- "'NetworkManager-wifi' in ansible_facts.packages"
msg: "NetworkManager-wifi is not installed after wireless configured"
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -60,3 +60,5 @@
failed_when: false
- name: Include the task 'cleanup_mock_wifi.yml'
include_tasks: tasks/cleanup_mock_wifi.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -61,3 +61,5 @@
failed_when: false
- name: Include the task 'cleanup_mock_wifi.yml'
include_tasks: tasks/cleanup_mock_wifi.yml
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml

View file

@ -0,0 +1,39 @@
# SPDX-License-Identifier: BSD-3-Clause
---
# This is typically used after cleanup, to verify that cleanup
# worked and left networking in the default state - sort of like
# a post-condition, or pre-condition for subsequent tests
- name: Check routes and DNS
shell: |
set -euo pipefail
echo IP
ip a
echo IP ROUTE
ip route
echo IP -6 ROUTE
ip -6 route
echo RESOLV
if [ -f /etc/resolv.conf ]; then
cat /etc/resolv.conf
else
echo NO /etc/resolv.conf
ls -alrtF /etc/resolv.* || :
fi
changed_when: false
- name: Verify DNS and network connectivity
shell: |
set -euo pipefail
echo CHECK DNS AND CONNECTIVITY
for host in mirrors.fedoraproject.org mirrors.centos.org; do
if ! getent hosts "$host"; then
echo FAILED to lookup host "$host"
exit 1
fi
if ! curl -o /dev/null https://"$host"; then
echo FAILED to contact host "$host"
exit 1
fi
done
when: ansible_facts["distribution"] == "CentOS"
changed_when: false

View file

@ -176,6 +176,9 @@
state: absent
path: "{{ _rundir.path }}"
- name: Verify network state restored to default
include_tasks: tasks/check_network_dns.yml
- name: Ensure that at least one python unit test ran
fail:
msg: Tests did not run with python2 or python3