From 9b766087574650a36b4359868219f8d514d98280 Mon Sep 17 00:00:00 2001 From: Wen Liang Date: Fri, 26 Jan 2024 15:24:16 -0500 Subject: [PATCH] test: Clean up mock wifi at the end of each wireless test Baseos CI runs different wireless tests in a sequence, the mock wifi needs to be cleaned up properly at the end of each wireless test, otherwise, it will cause the failure during the setup of mock wifi for the next wireless test. Signed-off-by: Wen Liang --- tests/playbooks/tests_wireless_wpa3_owe.yml | 37 +++++++--- tests/playbooks/tests_wireless_wpa3_sae.yml | 82 +++++++++++++-------- 2 files changed, 76 insertions(+), 43 deletions(-) diff --git a/tests/playbooks/tests_wireless_wpa3_owe.yml b/tests/playbooks/tests_wireless_wpa3_owe.yml index 366c953..41344a1 100644 --- a/tests/playbooks/tests_wireless_wpa3_owe.yml +++ b/tests/playbooks/tests_wireless_wpa3_owe.yml @@ -33,15 +33,30 @@ ssid: "hostapd-owe" key_mgmt: "owe" - - name: "Verify connection profile" - shell: - nmcli c show {{ interface }} | grep 802-11-wireless-security.key-mgmt - register: key_mgmt - ignore_errors: true - changed_when: false + - name: "Verify connection profile" + shell: nmcli c show {{ interface }} | grep 802-11-wireless-security.key-mgmt + register: key_mgmt + ignore_errors: true + changed_when: false - - name: "Assert that OWE is configured correctly" - assert: - that: - - "'owe' in key_mgmt.stdout" - msg: "OWE is configured incorrectly" + - name: "Assert that OWE is configured correctly" + assert: + that: + - "'owe' in key_mgmt.stdout" + msg: "OWE is configured incorrectly" + always: + - name: Clean up the test device and the connection profile + tags: + - "tests::cleanup" + block: + - name: Import network role + import_role: + name: linux-system-roles.network + vars: + network_connections: + - name: "{{ interface }}" + persistent_state: absent + state: down + failed_when: false + - name: Include the task 'cleanup_mock_wifi.yml' + include_tasks: tasks/cleanup_mock_wifi.yml diff --git a/tests/playbooks/tests_wireless_wpa3_sae.yml b/tests/playbooks/tests_wireless_wpa3_sae.yml index 90b8482..d2b5549 100644 --- a/tests/playbooks/tests_wireless_wpa3_sae.yml +++ b/tests/playbooks/tests_wireless_wpa3_sae.yml @@ -9,37 +9,55 @@ include_tasks: tasks/setup_mock_wifi_wpa3_sae.yml when: ansible_distribution in ['CentOS', 'Fedora'] - - name: "TEST: wireless connection with WPA3 Personal" - import_role: - name: linux-system-roles.network - vars: - network_allow_restart: true - network_connections: - - name: "{{ interface }}" - # set `state: down` on RHEL 8 since we failed in setting up mock - # wifi on RHEL 8 - state: "{{ 'down' if ansible_distribution == 'RedHat' else 'up' }}" - type: wireless - ip: - address: - - 203.0.113.2/24 - dhcp4: "no" - auto6: "no" - wireless: - ssid: "hostapd-sae" - key_mgmt: "sae" - password: "p@55w0rD" + - name: Test wireless connection with WPA3 Personal + block: + - name: "TEST: wireless connection with WPA3 Personal" + import_role: + name: linux-system-roles.network + vars: + network_allow_restart: true + network_connections: + - name: "{{ interface }}" + # set `state: down` on RHEL 8 since we failed in setting up mock + # wifi on RHEL 8 + state: "{{ 'down' if ansible_distribution == 'RedHat' else 'up' }}" + type: wireless + ip: + address: + - 203.0.113.2/24 + dhcp4: "no" + auto6: "no" + wireless: + ssid: "hostapd-sae" + key_mgmt: "sae" + password: "p@55w0rD" - - name: Verify wireless profile KEY_MGMT entry - shell: | - set -euxo pipefail - nmcli c show {{ interface }} | grep 802-11-wireless-security.key-mgmt - register: key_mgmt - ignore_errors: true - changed_when: false + - name: Verify wireless profile KEY_MGMT entry + shell: | + set -euxo pipefail + nmcli c show {{ interface }} | grep 802-11-wireless-security.key-mgmt + register: key_mgmt + ignore_errors: true + changed_when: false - - name: "Assert that WPA3 Personal is configured correctly" - assert: - that: - - "'sae' in key_mgmt.stdout" - msg: "WPA3 Personal is configured incorrectly" + - name: "Assert that WPA3 Personal is configured correctly" + assert: + that: + - "'sae' in key_mgmt.stdout" + msg: "WPA3 Personal is configured incorrectly" + always: + - name: Clean up the test device and the connection profile + tags: + - "tests::cleanup" + block: + - name: Import network role + import_role: + name: linux-system-roles.network + vars: + network_connections: + - name: "{{ interface }}" + persistent_state: absent + state: down + failed_when: false + - name: Include the task 'cleanup_mock_wifi.yml' + include_tasks: tasks/cleanup_mock_wifi.yml