Merge ~jocave/plainbox-provider-checkbox:wireless-nm-conn-backup into plainbox-provider-checkbox:master

Proposed by Jonathan Cave
Status: Merged
Approved by: Jonathan Cave
Approved revision: 1b78eb86ff91861c9f527762afcbdcb4bff6d98c
Merged at revision: 928732fb124a96929fbab342dd40a8c5d2ca703e
Proposed branch: ~jocave/plainbox-provider-checkbox:wireless-nm-conn-backup
Merge into: plainbox-provider-checkbox:master
Diff against target: 208 lines (+127/-0)
3 files modified
bin/wifi_nmcli_backup.py (+79/-0)
units/wireless/jobs.pxu (+28/-0)
units/wireless/test-plan.pxu (+20/-0)
Reviewer Review Type Date Requested Status
Sylvain Pineau (community) Approve
Review via email: mp+362872@code.launchpad.net

Description of the change

Bug #1765350 requested that the wireless connection jobs restore any saved NetworkManager connection information upon completion of the test process.

The jobs removed any stored configurations to prevent any unintended re-connections to an AP that is not the one specified in the test procedure.

This MR creates new templated jobs to bracket the cert test plans that copy the NetworkManager configuration files to a predictable location prior and then restore and delete them afterwards. The files are root readable only and reload the configuration also requires root privileges.

Tested on my development machine. My stored APs were still present after running wireless-cert-automated test plan and the active network was rejoined.

To post a comment you must log in.
Revision history for this message
Sylvain Pineau (sylvain-pineau) wrote :

LGTM, +1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/bin/wifi_nmcli_backup.py b/bin/wifi_nmcli_backup.py
0new file mode 1007550new file mode 100755
index 0000000..7ec9c89
--- /dev/null
+++ b/bin/wifi_nmcli_backup.py
@@ -0,0 +1,79 @@
1#!/usr/bin/env python3
2# Copyright 2019 Canonical Ltd.
3# All rights reserved.
4#
5# Written by:
6# Jonathan Cave <jonathan.cave@canonical.com>
7#
8# Save/Restore NetworkManager wifi connections
9
10import os
11import shutil
12import subprocess as sp
13import sys
14
15NM_CON_DIR = '/etc/NetworkManager/system-connections'
16SAVE_DIR = os.path.join(os.path.expandvars(
17 '$PLAINBOX_SESSION_SHARE'), 'stored-system-connections')
18
19
20def get_nm_connections():
21 c = []
22 cmd = 'nmcli -t -f TYPE,NAME c'
23 output = sp.check_output(cmd, shell=True)
24 for line in output.decode(sys.stdout.encoding).splitlines():
25 con_type, name = line.strip().split(':')
26 if con_type == '802-11-wireless':
27 c.append(name)
28 return c
29
30
31def reload_nm_connections():
32 cmd = 'nmcli c reload'
33 sp.check_call(cmd, shell=True)
34
35
36def save_connections(con_list):
37 if len(con_list) == 0:
38 print('No stored 802.11 connections to save')
39 return
40 if not os.path.exists(SAVE_DIR):
41 os.makedirs(SAVE_DIR)
42 for c in con_list:
43 print('Save connection {}'.format(c))
44 c_loc = os.path.join(NM_CON_DIR, c)
45 if not os.path.exists(c_loc):
46 print(' No stored connection fount at {}'.format(c_loc))
47 continue
48 print(' Found file {}'.format(c_loc))
49 save_f = shutil.copy(c_loc, SAVE_DIR)
50 print(' Saved copy at {}'.format(save_f))
51
52
53def restore_connections():
54 saved_list = [f for f in os.listdir(
55 SAVE_DIR) if os.path.isfile(os.path.join(SAVE_DIR, f))]
56 if len(saved_list) == 0:
57 print('No stored 802.11 connections found')
58 return
59 for f in saved_list:
60 save_f = os.path.join(SAVE_DIR, f)
61 print('Restore connection {}'.format(save_f))
62 restore_f = shutil.copy(save_f, NM_CON_DIR)
63 print(' Restored file at {}'.format(restore_f))
64 os.remove(save_f)
65 print(' Removed copy from {}'.format(save_f))
66
67
68if __name__ == '__main__':
69 if len(sys.argv) != 2:
70 raise SystemExit('ERROR: please specify save or restore')
71 action = sys.argv[1]
72
73 if action == 'save':
74 save_connections(get_nm_connections())
75 elif action == 'restore':
76 restore_connections()
77 reload_nm_connections()
78 else:
79 raise SystemExit('ERROR: unrecognised action')
diff --git a/units/wireless/jobs.pxu b/units/wireless/jobs.pxu
index 52b2b01..9c25c71 100644
--- a/units/wireless/jobs.pxu
+++ b/units/wireless/jobs.pxu
@@ -442,3 +442,31 @@ command:
442estimated_duration: 330.0442estimated_duration: 330.0
443_description:443_description:
444 Tests the performance of a system's wireless connection through the iperf tool, using UDP packets.444 Tests the performance of a system's wireless connection through the iperf tool, using UDP packets.
445
446
447unit: template
448template-resource: device
449template-filter: device.category == 'WIRELESS' and device.interface != 'UNKNOWN'
450id: wireless/nm_connection_save_{category}
451category_id: com.canonical.plainbox::wireless
452_summary: Save any NetworkManager 802.11 configurations prior to testing
453plugin: shell
454user: root
455command:
456 wifi_nmcli_backup.py save
457estimated_duration: 2.0
458flags: preserve-locale also-after-suspend also-after-suspend-manual
459
460unit: template
461template-resource: device
462template-filter: device.category == 'WIRELESS' and device.interface != 'UNKNOWN'
463id: wireless/nm_connection_restore_{category}
464category_id: com.canonical.plainbox::wireless
465_summary: Restore any NetworkManager 802.11 configurations after testing
466plugin: shell
467user: root
468command:
469 wifi_nmcli_backup.py restore
470estimated_duration: 2.0
471depends: wireless/nm_connection_save_{category}
472flags: preserve-locale also-after-suspend also-after-suspend-manual
445\ No newline at end of file473\ No newline at end of file
diff --git a/units/wireless/test-plan.pxu b/units/wireless/test-plan.pxu
index 74bf271..8b4aafe 100644
--- a/units/wireless/test-plan.pxu
+++ b/units/wireless/test-plan.pxu
@@ -30,7 +30,10 @@ id: wireless-cert-automated
30unit: test plan30unit: test plan
31_name: Wireless tests31_name: Wireless tests
32_description: Wireless connection tests32_description: Wireless connection tests
33bootstrap_include:
34 device
33include:35include:
36 wireless/nm_connection_save_.*
34 wireless/wireless_scanning_.* certification-status=blocker37 wireless/wireless_scanning_.* certification-status=blocker
35 wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker38 wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker
36 wireless/wireless_connection_open_bg_nm_.* certification-status=blocker39 wireless/wireless_connection_open_bg_nm_.* certification-status=blocker
@@ -38,36 +41,48 @@ include:
38 wireless/wireless_connection_open_n_nm_.* certification-status=blocker41 wireless/wireless_connection_open_n_nm_.* certification-status=blocker
39 wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker42 wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker
40 wireless/wireless_connection_open_ac_nm_.* certification-status=blocker43 wireless/wireless_connection_open_ac_nm_.* certification-status=blocker
44 wireless/nm_connection_restore_.*
4145
42id: after-suspend-wireless-cert-automated46id: after-suspend-wireless-cert-automated
43unit: test plan47unit: test plan
44_name: Wireless tests (after suspend, automated)48_name: Wireless tests (after suspend, automated)
45_description: Wireless connection tests (after suspend, automated)49_description: Wireless connection tests (after suspend, automated)
50bootstrap_include:
51 device
46include:52include:
53 after-suspend-wireless/nm_connection_save_.*
47 after-suspend-wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker54 after-suspend-wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker
48 after-suspend-wireless/wireless_connection_open_bg_nm_.* certification-status=blocker55 after-suspend-wireless/wireless_connection_open_bg_nm_.* certification-status=blocker
49 after-suspend-wireless/wireless_connection_wpa_n_nm_.* certification-status=blocker56 after-suspend-wireless/wireless_connection_wpa_n_nm_.* certification-status=blocker
50 after-suspend-wireless/wireless_connection_open_n_nm_.* certification-status=blocker57 after-suspend-wireless/wireless_connection_open_n_nm_.* certification-status=blocker
51 after-suspend-wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker58 after-suspend-wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker
52 after-suspend-wireless/wireless_connection_open_ac_nm_.* certification-status=blocker59 after-suspend-wireless/wireless_connection_open_ac_nm_.* certification-status=blocker
60 after-suspend-wireless/nm_connection_restore_.*
5361
54id: after-suspend-manual-wireless-cert-automated62id: after-suspend-manual-wireless-cert-automated
55unit: test plan63unit: test plan
56_name: Wireless tests (after manual suspend, automated)64_name: Wireless tests (after manual suspend, automated)
57_description: Wireless connection tests (after manual suspend, automated)65_description: Wireless connection tests (after manual suspend, automated)
66bootstrap_include:
67 device
58include:68include:
69 after-suspend-manual-wireless/nm_connection_save_.*
59 after-suspend-manual-wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker70 after-suspend-manual-wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker
60 after-suspend-manual-wireless/wireless_connection_open_bg_nm_.* certification-status=blocker71 after-suspend-manual-wireless/wireless_connection_open_bg_nm_.* certification-status=blocker
61 after-suspend-manual-wireless/wireless_connection_wpa_n_nm_.* certification-status=blocker72 after-suspend-manual-wireless/wireless_connection_wpa_n_nm_.* certification-status=blocker
62 after-suspend-manual-wireless/wireless_connection_open_n_nm_.* certification-status=blocker73 after-suspend-manual-wireless/wireless_connection_open_n_nm_.* certification-status=blocker
63 after-suspend-manual-wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker74 after-suspend-manual-wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker
64 after-suspend-manual-wireless/wireless_connection_open_ac_nm_.* certification-status=blocker75 after-suspend-manual-wireless/wireless_connection_open_ac_nm_.* certification-status=blocker
76 after-suspend-manual-wireless/nm_connection_restore_.*
6577
66id: wireless-cert-blockers78id: wireless-cert-blockers
67unit: test plan79unit: test plan
68_name: Wireless tests (certification blockers only)80_name: Wireless tests (certification blockers only)
69_description: Wireless connection tests (certification blockers only)81_description: Wireless connection tests (certification blockers only)
82bootstrap_include:
83 device
70include:84include:
85 wireless/nm_connection_save_.*
71 wireless/wireless_scanning_.* certification-status=blocker86 wireless/wireless_scanning_.* certification-status=blocker
72 wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker87 wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker
73 wireless/wireless_connection_open_bg_nm_.* certification-status=blocker88 wireless/wireless_connection_open_bg_nm_.* certification-status=blocker
@@ -75,16 +90,21 @@ include:
75 wireless/wireless_connection_open_n_nm_.* certification-status=blocker90 wireless/wireless_connection_open_n_nm_.* certification-status=blocker
76 wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker91 wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker
77 wireless/wireless_connection_open_ac_nm_.* certification-status=blocker92 wireless/wireless_connection_open_ac_nm_.* certification-status=blocker
93 wireless/nm_connection_restore_.*
7894
79id: after-suspend-wireless-cert-blockers95id: after-suspend-wireless-cert-blockers
80unit: test plan96unit: test plan
81_name: Wireless tests (after manual suspend, certification blockers only)97_name: Wireless tests (after manual suspend, certification blockers only)
82_description:98_description:
83 Wireless connection tests (after manual suspend, certification blockers only)99 Wireless connection tests (after manual suspend, certification blockers only)
100bootstrap_include:
101 device
84include:102include:
103 after-suspend-manual-wireless/nm_connection_save_.*
85 after-suspend-manual-wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker104 after-suspend-manual-wireless/wireless_connection_wpa_bg_nm_.* certification-status=blocker
86 after-suspend-manual-wireless/wireless_connection_open_bg_nm_.* certification-status=blocker105 after-suspend-manual-wireless/wireless_connection_open_bg_nm_.* certification-status=blocker
87 after-suspend-manual-wireless/wireless_connection_wpa_n_nm_.* certification-status=blocker106 after-suspend-manual-wireless/wireless_connection_wpa_n_nm_.* certification-status=blocker
88 after-suspend-manual-wireless/wireless_connection_open_n_nm_.* certification-status=blocker107 after-suspend-manual-wireless/wireless_connection_open_n_nm_.* certification-status=blocker
89 after-suspend-manual-wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker108 after-suspend-manual-wireless/wireless_connection_wpa_ac_nm_.* certification-status=blocker
90 after-suspend-manual-wireless/wireless_connection_open_ac_nm_.* certification-status=blocker109 after-suspend-manual-wireless/wireless_connection_open_ac_nm_.* certification-status=blocker
110 after-suspend-manual-wireless/nm_connection_restore_.*

Subscribers

People subscribed via source and target branches