Skip to content

Commit 8da0a85

Browse files
committed
test: refactor wireless tests into single setup and cleanup
The wireless test setup/cleanup had a lot of duplicated code scattered among a few task files. This unifies the setup and cleanup code and gets rid of redundant files. This also enables all of the wireless tests on CentOS 7 and later, and RHEL 8 and later. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent 3c4717c commit 8da0a85

18 files changed

Lines changed: 272 additions & 378 deletions

tests/ensure_provider_tests.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,10 @@
107107
EXTRA_RUN_CONDITION = "extra_run_condition"
108108
NM_ONLY_TESTS = {
109109
"playbooks/tests_802_1x_updated.yml": {
110-
EXTRA_RUN_CONDITION: (
111-
"(not __network_is_rhel and\n"
112-
" __network_distro_major_version | int > 7) or\n"
113-
" __network_distro_major_version | int == 8"
114-
),
110+
EXTRA_RUN_CONDITION: "not __network_is_rhel or __network_distro_major_version | int > 7",
115111
},
116112
"playbooks/tests_802_1x.yml": {
117-
EXTRA_RUN_CONDITION: (
118-
"(not __network_is_rhel and\n"
119-
" __network_distro_major_version | int > 7) or\n"
120-
" __network_distro_major_version | int == 8"
121-
),
113+
EXTRA_RUN_CONDITION: "not __network_is_rhel or __network_distro_major_version | int > 7",
122114
},
123115
"playbooks/tests_ignore_auto_dns.yml": {},
124116
"playbooks/tests_bond_options.yml": {},
@@ -164,25 +156,21 @@
164156
"playbooks/tests_team_plugin_installation.yml": {
165157
EXTRA_RUN_CONDITION: "not __is_rh_distro or\n __network_distro_major_version | int < 10",
166158
},
167-
# mac80211_hwsim (used for tests_wireless) only seems to be available
168-
# and working on RHEL/CentOS 7
159+
# hostapd is not available on RHEL7, so tests_wireless cannot be run on RHEL7
169160
"playbooks/tests_wireless.yml": {
170-
EXTRA_RUN_CONDITION: "__network_distro_major_version == '7'",
161+
EXTRA_RUN_CONDITION: "not __network_is_rhel or __network_distro_major_version | int > 7",
171162
},
172163
"playbooks/tests_wireless_and_network_restart.yml": {},
173164
"playbooks/tests_wireless_plugin_installation.yml": {},
174165
"playbooks/tests_wireless_wpa3_owe.yml": {
175166
"comment": "# OWE has not been supported by NetworkManager 1.18.8 on \
176167
RHEL 7(dist-tag). Failed in setting up mock wifi on RHEL 8",
177-
EXTRA_RUN_CONDITION: "__network_distro_major_version | int > 7 and \
178-
__network_is_centos or\n __network_distro_major_version | int > 32 \
179-
and __network_is_fedora",
168+
EXTRA_RUN_CONDITION: "not __network_is_rhel or __network_distro_major_version | int > 7",
180169
},
181170
"playbooks/tests_wireless_wpa3_sae.yml": {
182171
"comment": "# SAE has not been supported by NetworkManager 1.18.8 on \
183172
RHEL 7. Failed in setting up mock wifi on RHEL 8",
184-
EXTRA_RUN_CONDITION: "__network_distro_major_version != '7' and \
185-
not __network_is_rhel",
173+
EXTRA_RUN_CONDITION: "not __network_is_rhel or __network_distro_major_version | int > 7",
186174
},
187175
}
188176
# NM_CONDITIONAL_TESTS is used to store the test playbooks which are demanding for NM

tests/playbooks/tests_802_1x.yml

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
- name: "INIT: 802.1x tests"
99
debug:
1010
msg: "##################################################"
11-
- name: Include the task 'setup_802.1x.yml'
12-
include_tasks: tasks/setup_802.1x.yml
11+
- name: Include the task 'setup_mock_wifi.yml'
12+
include_tasks: tasks/setup_mock_wifi.yml
13+
vars:
14+
__mock_wifi_mode: 802_1x
1315
- name: Test configuring 802.1x authentication
1416
block:
1517
- name: "TEST: 802.1x profile with private key password and ca cert"
@@ -127,17 +129,8 @@
127129
persistent_state: absent
128130
state: down
129131
__sr_failed_when: false
130-
- name: Include the task 'cleanup_802_1x_server.yml'
131-
include_tasks: tasks/cleanup_802_1x_server.yml
132-
- name: Remove test certificates
133-
file:
134-
state: absent
135-
path: "/etc/pki/tls/{{ item }}"
136-
with_items:
137-
- client.key
138-
- client.key.nocrypt
139-
- client.pem
140-
- cacert.pem
132+
- name: Include the task 'cleanup_mock_wifi.yml'
133+
include_tasks: tasks/cleanup_mock_wifi.yml
141134
- name: Remove test CA
142135
file:
143136
state: absent

tests/playbooks/tests_wireless.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@
1010
msg: "##################################################"
1111
- name: Include the task 'setup_mock_wifi.yml'
1212
include_tasks: tasks/setup_mock_wifi.yml
13-
- name: Copy client certs
14-
copy:
15-
src: "{{ item }}"
16-
dest: "/etc/pki/tls/{{ item }}"
17-
mode: "0644"
18-
with_items:
19-
- client.key
20-
- client.pem
21-
- cacert.pem
2213
- name: Test wireless connection with WPA-PSK
2314
block:
2415
- name: "TEST: wireless connection with WPA-PSK"

tests/playbooks/tests_wireless_wpa3_owe.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
- name: "INIT: wireless tests"
99
debug:
1010
msg: "##################################################"
11-
- name: Include the task 'setup_mock_wifi_wpa3_owe.yml'
12-
include_tasks: tasks/setup_mock_wifi_wpa3_owe.yml
11+
- name: Include the task 'setup_mock_wifi.yml'
12+
include_tasks: tasks/setup_mock_wifi.yml
13+
vars:
14+
__mock_wifi_mode: owe
1315
- name: Test wireless connection with OWE
1416
block:
1517
- name: "TEST: wireless connection with OWE"

tests/playbooks/tests_wireless_wpa3_sae.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
interface: wlan0
77
tasks:
88
- name: "INIT: wireless tests"
9-
include_tasks: tasks/setup_mock_wifi_wpa3_sae.yml
10-
when: ansible_facts['distribution'] in ['CentOS', 'Fedora']
9+
debug:
10+
msg: "##################################################"
11+
- name: Include the task 'setup_mock_wifi.yml'
12+
include_tasks: tasks/setup_mock_wifi.yml
13+
vars:
14+
__mock_wifi_mode: sae
1115

1216
- name: Test wireless connection with WPA3 Personal
1317
block:
@@ -17,9 +21,7 @@
1721
network_allow_restart: true
1822
network_connections:
1923
- name: "{{ interface }}"
20-
# set `state: down` on RHEL 8 since we failed in setting up mock
21-
# wifi on RHEL 8
22-
state: "{{ 'down' if ansible_facts['distribution'] == 'RedHat' else 'up' }}"
24+
state: up
2325
type: wireless
2426
ip:
2527
address:

tests/tasks/cleanup_802_1x_server.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

tests/tasks/cleanup_mock_wifi.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,49 @@
11
# SPDX-License-Identifier: BSD-3-Clause
22
---
3+
- name: Remove wired 802.1x test interfaces
4+
shell: |
5+
set -uxo pipefail
6+
exec 1>&2
7+
ip netns delete ns1
8+
ip link delete veth1-br
9+
ip link delete veth2-br
10+
ip link delete br1
11+
changed_when: false
12+
failed_when: false
13+
314
- name: Unload mac80211_hwsim module
415
command: modprobe -r mac80211_hwsim
516
changed_when: false
17+
failed_when: false
618

719
- name: Kill hostapd process
820
command: pkill hostapd
921
changed_when: false
22+
failed_when: false
23+
24+
- name: Remove hostapd config files
25+
file:
26+
state: absent
27+
path: "{{ item }}"
28+
with_items:
29+
- /etc/hostapd/wireless.conf
30+
- /etc/hostapd/wired.conf
31+
- /etc/hostapd/hostapd.eap_user
32+
33+
- name: Remove server certificate directory for wired 802.1x tests
34+
file:
35+
state: absent
36+
path: /etc/pki/tls/hostapd_test
37+
38+
- name: Remove test certificates
39+
file:
40+
state: absent
41+
path: "/etc/pki/tls/{{ item }}"
42+
with_items:
43+
- server.key
44+
- dh.pem
45+
- server.pem
46+
- cacert.pem
47+
- client.key
48+
- client.key.nocrypt
49+
- client.pem

tests/tasks/setup_802.1x.yml

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/tasks/setup_802_1x_server.yml

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)