Merge ~alfonsosanchezbeato/network-manager:test-ci into network-manager:snap-1.10

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Tony Espy
Approved revision: 44bb1fd711241a032021ea6780d926c7aff51f6e
Merged at revision: 068ecec4f35b4a37eb2c0abb971398fce492cee9
Proposed branch: ~alfonsosanchezbeato/network-manager:test-ci
Merge into: network-manager:snap-1.10
Diff against target: 2793 lines (+2389/-17)
50 files modified
debian/patches/series (+1/-0)
debian/patches/snap-support-ppp.patch (+134/-0)
docs/snap/configure-cellular-connections.md (+124/-0)
docs/snap/configure-wifi-connections.md (+80/-0)
docs/snap/edit-connections.md (+155/-0)
docs/snap/enable-ethernet-support.md (+38/-0)
docs/snap/explore-network-status.md (+52/-0)
docs/snap/faq.md (+18/-0)
docs/snap/index.md (+42/-0)
docs/snap/installation.md (+62/-0)
docs/snap/logging-messages.md (+43/-0)
docs/snap/metadata.yaml (+49/-0)
docs/snap/reference/available-commands.md (+19/-0)
docs/snap/reference/configuration/ethernet_support.md (+47/-0)
docs/snap/reference/dbus-api.md (+9/-0)
docs/snap/reference/snap-configuration/debug.md (+51/-0)
docs/snap/reference/snap-configuration/wifi-powersave.md (+38/-0)
docs/snap/reference/snap-configuration/wowlan.md (+126/-0)
docs/snap/release-notes.md (+35/-0)
docs/snap/report-bug.md (+36/-0)
docs/snap/routing-tables.md (+96/-0)
run-tests.sh (+88/-0)
snap-common/bin/snap-config.sh (+7/-8)
snap-patch/resolvconf.patch (+31/-0)
snap/snapcraft.yaml (+21/-9)
spread.yaml (+85/-0)
tests/full/correct-dns-setup/task.yaml (+47/-0)
tests/full/immutable-netplan-config/task.yaml (+10/-0)
tests/full/ipv6-address-assignment/task.yaml (+27/-0)
tests/full/ipv6-router-advertisements/task.yaml (+70/-0)
tests/full/no-netplan-default-config/task.yaml (+41/-0)
tests/full/system-network-is-active/task.yaml (+9/-0)
tests/full/wol-enabled-by-default/task.yaml (+60/-0)
tests/lib/prepare-all.sh (+63/-0)
tests/lib/prepare.sh (+46/-0)
tests/lib/restore-each.sh (+40/-0)
tests/lib/snap-names.sh (+7/-0)
tests/lib/utilities.sh (+166/-0)
tests/main/aliases/task.yaml (+13/-0)
tests/main/can-exec-iptables/task.yaml (+11/-0)
tests/main/debug-config-option/task.yaml (+27/-0)
tests/main/documentation-builds/task.yaml (+14/-0)
tests/main/ethernet-managed-by-networkmanager/task.yaml (+16/-0)
tests/main/installation/task.yaml (+17/-0)
tests/main/set-hostname/task.yaml (+17/-0)
tests/main/static-ip-configuration/task.yaml (+49/-0)
tests/main/wifi-connect-secured-ap/task.yaml (+14/-0)
tests/main/wifi-powersave-config-option/task.yaml (+31/-0)
tests/main/wifi-wowlan-config-option/task.yaml (+77/-0)
tests/main/wifi-wowlan-enabled-correctly/task.yaml (+30/-0)
Reviewer Review Type Date Requested Status
Tony Espy Approve
System Enablement Bot continuous-integration Approve
Review via email: mp+368284@code.launchpad.net

Commit message

* Add iptables to the snap
* Do not call nmcli while NM is not running
* Add spread tests

Description of the change

* Add iptables to the snap
* Do not call nmcli while NM is not running
* Add spread tests

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tony Espy (awe) wrote :

All looks good, however I have a question about your inclusion of resolvconf in the snap:

snap: add pppd and resolconf scripts to the snap

These files cannot be accessed from the snap anymore in UC18. Note that
the resolvconf scripts will be used only when installed in a UC16
system.

I think what you mean is that "these files" are no longer accessible from the core18 base snap.

Also instead of copying the scripts directly into the snap, a better approach would be to consume the resolvconf debian package via 'stage-packages'.

review: Needs Fixing
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

@Tony, correct, that is what I was referring to. I have changed the commit message to reflect that, and also added an explanation on why I included the resolvconf files:

<<
    snap: add pppd and resolvconf scripts to the snap

    These files cannot be accessed from the snap anymore as they are not
    included in the core18 base. Note that the resolvconf scripts will be
    used only when installed in a UC16 system.

    The resolvconf files had to be modified to use the right folders, that
    is the reason for including them instead of staging from the debian
    package.
>>

Revision history for this message
Tony Espy (awe) wrote :

> @Tony, correct, that is what I was referring to. I have changed the commit
> message to reflect that, and also added an explanation on why I included the
> resolvconf files:
>
> <<
> snap: add pppd and resolvconf scripts to the snap
>
> These files cannot be accessed from the snap anymore as they are not
> included in the core18 base. Note that the resolvconf scripts will be
> used only when installed in a UC16 system.
>
> The resolvconf files had to be modified to use the right folders, that
> is the reason for including them instead of staging from the debian
> package.
> >>

Sure, but you couldn't you do this by applying patches to the files pulled out of the stage-package? Using your approach we're flying blind wrt to resolvconf CVEs.

Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

@Tony, fair enough. Done.

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Tony Espy (awe) wrote :

Thanks for the changes, LGTM!

review: Approve
Revision history for this message
Tony Espy (awe) wrote :

One last comment, could you use different feature name branches for your future MPs? Otherwise we end up with duplicate merge commit messages like this:

Merge remote-tracking branch 'abeato/test-ci' into snap-1.10

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.snap b/README-SNAP.txt
2similarity index 100%
3rename from README.snap
4rename to README-SNAP.txt
5diff --git a/debian/patches/series b/debian/patches/series
6index 0632066..3267d3c 100644
7--- a/debian/patches/series
8+++ b/debian/patches/series
9@@ -16,3 +16,4 @@ disable-libnm-glib-wifi-ap-test.patch
10 disable-libnm-glib-test-devices-array.patch
11 add-snap-support.patch
12 disable-tests-that-fail-under-launchpad-builds.patch
13+snap-support-ppp.patch
14diff --git a/debian/patches/snap-support-ppp.patch b/debian/patches/snap-support-ppp.patch
15new file mode 100644
16index 0000000..5b13a63
17--- /dev/null
18+++ b/debian/patches/snap-support-ppp.patch
19@@ -0,0 +1,134 @@
20+Index: build/src/ppp/nm-ppp-manager-call.c
21+===================================================================
22+--- build.orig/src/ppp/nm-ppp-manager-call.c
23++++ build/src/ppp/nm-ppp-manager-call.c
24+@@ -30,7 +30,7 @@
25+ #include "nm-core-utils.h"
26+ #include "nm-ppp-plugin-api.h"
27+
28+-#define PPP_PLUGIN_PATH NMPLUGINDIR "/libnm-ppp-plugin.so"
29++#define PPP_PLUGIN_PATH "libnm-ppp-plugin.so"
30+
31+ /*****************************************************************************/
32+
33+@@ -39,42 +39,45 @@ static NMPPPOps *ppp_ops = NULL;
34+ NMPPPManager *
35+ nm_ppp_manager_create (const char *iface, GError **error)
36+ {
37+- NMPPPManager *ret;
38++ NMPPPManager *ret = NULL;
39+ GModule *plugin;
40+ GError *error_local = NULL;
41+ NMPPPOps *ops;
42+ struct stat st;
43+ int errsv;
44++ char *libnm_ppp_path;
45++
46++ libnm_ppp_path = g_strdup_printf ("%s/%s", nm_utils_get_plugin_dir (), PPP_PLUGIN_PATH);
47+
48+ if (G_UNLIKELY (!ppp_ops)) {
49+- if (stat (PPP_PLUGIN_PATH, &st) != 0) {
50++ if (stat (libnm_ppp_path, &st) != 0) {
51+ errsv = errno;
52+- g_set_error_literal (error,
53+- NM_MANAGER_ERROR, NM_MANAGER_ERROR_MISSING_PLUGIN,
54+- "the PPP plugin " PPP_PLUGIN_PATH " is not installed");
55+- return NULL;
56++ g_set_error (error,
57++ NM_MANAGER_ERROR, NM_MANAGER_ERROR_MISSING_PLUGIN,
58++ "the PPP plugin %s is not installed", libnm_ppp_path);
59++ goto end;
60+ }
61+
62+- if (!nm_utils_validate_plugin (PPP_PLUGIN_PATH, &st, &error_local)) {
63++ if (!nm_utils_validate_plugin (libnm_ppp_path, &st, &error_local)) {
64+ g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_MISSING_PLUGIN,
65+- "could not load the PPP plugin " PPP_PLUGIN_PATH ": %s",
66+- error_local->message);
67++ "could not load the PPP plugin %s: %s",
68++ libnm_ppp_path, error_local->message);
69+ g_clear_error (&error_local);
70+- return NULL;
71++ goto end;
72+ }
73+
74+- plugin = g_module_open (PPP_PLUGIN_PATH, G_MODULE_BIND_LOCAL);
75++ plugin = g_module_open (libnm_ppp_path, G_MODULE_BIND_LOCAL);
76+ if (!plugin) {
77+ g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_MISSING_PLUGIN,
78+- "could not load the PPP plugin " PPP_PLUGIN_PATH ": %s",
79+- g_module_error ());
80+- return NULL;
81++ "could not load the PPP plugin %s: %s",
82++ libnm_ppp_path, g_module_error ());
83++ goto end;
84+ }
85+
86+ if (!g_module_symbol (plugin, "ppp_ops", (gpointer) &ops)) {
87+ g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_MISSING_PLUGIN,
88+ "error loading the PPP plugin: %s", g_module_error ());
89+- return NULL;
90++ goto end;
91+ }
92+
93+ /* after loading glib types from the plugin, we cannot unload the library anymore.
94+@@ -90,11 +93,14 @@ nm_ppp_manager_create (const char *iface
95+
96+ ppp_ops = ops;
97+
98+- nm_log_info (LOGD_CORE | LOGD_PPP, "loaded PPP plugin " PPP_PLUGIN_PATH);
99++ nm_log_info (LOGD_CORE | LOGD_PPP, "loaded PPP plugin %s", libnm_ppp_path);
100+ }
101+
102+ ret = ppp_ops->create (iface);
103+ g_return_val_if_fail (ret, NULL);
104++
105++end:
106++ g_free (libnm_ppp_path);
107+ return ret;
108+ }
109+
110+Index: build/src/nm-core-utils.c
111+===================================================================
112+--- build.orig/src/nm-core-utils.c
113++++ build/src/nm-core-utils.c
114+@@ -1171,10 +1171,38 @@ const char *const NM_PATHS_DEFAULT[] = {
115+ NULL,
116+ };
117+
118++const char *const *
119++utils_get_search_paths(void)
120++{
121++ static char **paths;
122++
123++ const char *snap_path;
124++
125++ if (paths)
126++ return (const char *const *) paths;
127++
128++ snap_path = getenv("SNAP");
129++ if (snap_path) {
130++ unsigned np, i;
131++
132++ np = g_strv_length((char **) NM_PATHS_DEFAULT);
133++ paths = malloc(sizeof(char *)*(np*2 + 1));
134++ for (i = 0; i < np; ++i) {
135++ paths[i] = g_strdup_printf("%s%s", snap_path, NM_PATHS_DEFAULT[i]);
136++ paths[np + i] = g_strdup(NM_PATHS_DEFAULT[i]);
137++ }
138++ paths[2*np] = NULL;
139++ } else {
140++ paths = g_strdupv((char **) NM_PATHS_DEFAULT);;
141++ }
142++
143++ return (const char *const *) paths;
144++}
145++
146+ const char *
147+ nm_utils_find_helper(const char *progname, const char *try_first, GError **error)
148+ {
149+- return nm_utils_file_search_in_paths (progname, try_first, NM_PATHS_DEFAULT, G_FILE_TEST_IS_EXECUTABLE, NULL, NULL, error);
150++ return nm_utils_file_search_in_paths (progname, try_first, utils_get_search_paths (), G_FILE_TEST_IS_EXECUTABLE, NULL, NULL, error);
151+ }
152+
153+ /*****************************************************************************/
154diff --git a/docs/snap/configure-cellular-connections.md b/docs/snap/configure-cellular-connections.md
155new file mode 100644
156index 0000000..215f2dc
157--- /dev/null
158+++ b/docs/snap/configure-cellular-connections.md
159@@ -0,0 +1,124 @@
160+---
161+title: "Configure Cellular Connections"
162+table_of_contents: False
163+---
164+
165+# Configure Cellular Connections
166+
167+Check whether a modem was properly detected via:
168+
169+```
170+$ sudo modem-manager.mmcli -L
171+Found 1 modems:
172+ /org/freedesktop/ModemManager1/Modem/0 [description]
173+```
174+
175+In this case we have just one modem, with index 0 (the number at the end of the DBus object path).
176+
177+Show detailed information about the modem:
178+
179+```
180+$ sudo modem-manager.mmcli -m 0
181+/org/freedesktop/ModemManager1/Modem/0 (device id '871faa978a12ccb25b9fa30d15667571ab38ed88')
182+ -------------------------
183+ Hardware | manufacturer: 'ZTE INCORPORATED'
184+ | model: 'MF626'
185+ | revision: 'MF626V1.0.0B06'
186+ | supported: 'gsm-umts'
187+ | current: 'gsm-umts'
188+ | equipment id: '357037039840195'
189+ -------------------------
190+ System | device: '/sys/devices/pci0000:00/0000:00:01.2/usb1/1-1'
191+ | drivers: 'option1'
192+ | plugin: 'ZTE'
193+ | primary port: 'ttyUSB3'
194+ | ports: 'ttyUSB0 (qcdm), ttyUSB1 (at), ttyUSB3 (at)'
195+ -------------------------
196+ Numbers | own : 'unknown'
197+ -------------------------
198+ Status | lock: 'sim-pin'
199+ | unlock retries: 'sim-pin (3), sim-puk (10)'
200+ | state: 'locked'
201+ | power state: 'on'
202+ | access tech: 'unknown'
203+ | signal quality: '0' (cached)
204+ -------------------------
205+ Modes | supported: 'allowed: any; preferred: none'
206+ | current: 'allowed: any; preferred: none'
207+ -------------------------
208+ Bands | supported: 'unknown'
209+ | current: 'unknown'
210+ -------------------------
211+ IP | supported: 'none'
212+ -------------------------
213+ SIM | path: '/org/freedesktop/ModemManager1/SIM/0'
214+
215+ -------------------------
216+ Bearers | paths: 'none'
217+```
218+
219+In this case we can see that the SIM has PIN locking enabled and its state is
220+‘locked’. To enter the PIN, we need to know the SIM index, which in this
221+case is 0 (it is the number at the end of /org/freedesktop/ModemManager1/SIM/0).
222+Once the index is known, we can enter the SIM PIN with:
223+
224+```
225+$ sudo modem-manager.mmcli -i 0 --pin=<PIN>
226+successfully sent PIN code to the SIM
227+```
228+
229+Some more commands for handling SIM PINs include:
230+
231+```
232+$ sudo modem-manager.mmcli -i 0 --pin=<PIN> --enable-pin
233+$ sudo modem-manager.mmcli -i 0 --pin=<PIN> --disable-pin
234+$ sudo modem-manager.mmcli -i 0 --pin=<PIN> --change-pin=<NEW_PIN>
235+$ sudo modem-manager.mmcli -i 0 --puk=<PUK>
236+```
237+
238+Which respectively enables PIN locking, disables PIN locking, changes the PIN code,
239+and unlocks a [PUK](https://en.wikipedia.org/wiki/Personal_unblocking_code)-locked SIM.
240+
241+After that we can add a cellular connection with:
242+
243+```
244+$ nmcli c add type gsm ifname <interface> con-name <name> apn <operator_apn>
245+$ nmcli r wwan on
246+```
247+
248+where &lt;interface&gt; is the string listed as “primary port” in the output from 'sudo mmcli -m &lt;N&gt;'
249+(as previously described),
250+&lt;name&gt; is an arbitrary name used to identify the connection, and &lt;operator_apn&gt; is
251+the APN name for your cellular data plan. Note that &lt;interface&gt; is usually a serial
252+port with pattern /dev/tty*, not a networking interface. The reason for ModemManager
253+to use that instead of the networking interface is that this last one can appear/disappear
254+dynamically while the ports do not if the hardware configuration remains unchanged.
255+For instance, the networking interface can be ppp0, ppp1, etc., and it might be
256+different each time it is possible to have other ppp connections with, say, VPNs.
257+
258+After executing these commands, NetworkManager will automatically try to bring up
259+the cellular connection whenever ModemManager reports that the modem has
260+registered (the state of the modem can be checked with the previously introduced
261+command “sudo modem-manager.mmcli -m &lt;N&gt;”). When done successfully, NetworkManager
262+will create routes for the new network interface, with less priority than
263+Ethernet or WiFi interfaces. To disable the connection, we can do:
264+
265+```
266+$ nmcli r wwan off
267+```
268+
269+or change the autoconnect property and turn the connection off if we need more
270+fine-grained control:
271+
272+```
273+$ nmcli c modify <name> connection.autoconnect [yes|no]
274+$ nmcli c down <name>
275+```
276+
277+Finally, note that we can provide the PIN (so it is entered automatically) or more
278+needed APN provisioning information when creating/modifying the WWAN connection.
279+For instance:
280+
281+```
282+$ nmcli c add type gsm ifname <interface> con-name <name> apn <operator_apn> username <user> password <password> pin <PIN>
283+```
284diff --git a/docs/snap/configure-wifi-connections.md b/docs/snap/configure-wifi-connections.md
285new file mode 100644
286index 0000000..4602dfd
287--- /dev/null
288+++ b/docs/snap/configure-wifi-connections.md
289@@ -0,0 +1,80 @@
290+---
291+title: "Configure WiFi Connections"
292+table_of_contents: True
293+---
294+
295+# Configure WiFi Connections
296+
297+This section explains how to establish a WiFi connection. It covers creating and
298+modyfying connections as well as directly connecting.
299+
300+## Establish a Wireless Connection
301+
302+This section will show how to establish a wifi connection to the wireles
303+network. Note that directly connecting will implicitly create a connection (that
304+can be seen with "nmcli c"). The naming of such will follow "SSID N" pattern,
305+where N is a number.
306+
307+First, determine the name of the WiFi interface:
308+
309+```
310+$ nmcli d
311+DEVICE TYPE STATE CONNECTION
312+...
313+wlan0 wifi disconnected --
314+```
315+
316+Make sure the WiFi radio is on (which is its default state):
317+
318+```
319+$ nmcli r wifi on
320+```
321+
322+Then, list the available WiFi networks:
323+
324+```
325+$ nmcli d wifi list
326+* SSID MODE CHAN RATE SIGNAL BARS SECURITY
327+ ...
328+ my_wifi Infra 5 54 Mbit/s 89 ▂▄▆█ WPA2
329+```
330+
331+As an example, to connect to the access point 'my_wifi', you would use the
332+following command:
333+
334+```
335+$ nmcli d wifi connect my_wifi password <password>
336+```
337+
338+&lt;password&gt; is the password for the connection which needs to have 8-63
339+characters or 64 hexadecimal characters to specify a full 256-bit key.
340+
341+## Connect to a Hidden Network
342+
343+A hidden network is a normal wireless network that simply does not broadcast
344+it's SSID unless solicited. This means that its name cannot be searched and
345+must be known from some other source.
346+
347+Issue the following command to create a connection associated with a hidden
348+network &lt;ssid&gt;:
349+
350+```
351+$ nmcli c add type wifi con-name <name> ifname wlan0 ssid <ssid>
352+$ nmcli c modify <name> wifi-sec.key-mgmt wpa-psk wifi-sec.psk <password>
353+```
354+
355+Now you can establish a connection by typing:
356+
357+```
358+$ nmcli c up <name>
359+```
360+
361+&lt;name&gt; is an arbitrary name given to the connection and &lt;password&gt;
362+is the password to the network. It needs to have between 8-63 characters or 64
363+hexadecimal characters in order to specify a full 256-bit key.
364+
365+## Further Information
366+
367+You will find further information and more detailed examples on following pages:
368+
369+* <https://developer.gnome.org/NetworkManager/unstable/nmcli.html>
370diff --git a/docs/snap/edit-connections.md b/docs/snap/edit-connections.md
371new file mode 100644
372index 0000000..0c9d087
373--- /dev/null
374+++ b/docs/snap/edit-connections.md
375@@ -0,0 +1,155 @@
376+---
377+title: "Edit Connections"
378+table_of_contents: True
379+---
380+
381+# Edit Connections
382+
383+This part will show you how to use a network-manager built-in editor to modify
384+the connections as well as provide a reference for setting some of the
385+settings.
386+
387+## Using nmcli Console
388+
389+Aside from offering the possibility to manage and modify the network connections
390+using the command-line, network-manager offers a built-in, interactive
391+console to achieve the same. In order to use it type:
392+
393+```
394+$ nmcli connection edit
395+```
396+
397+It will bring up an interactive console. In the first step you will be prompted
398+to enter the connection type. The list of valid connection types will be
399+displayed on the screen. Once you select one you will be taken to the nmcli
400+console where you have the possibility to modify its parameters.
401+
402+Alternatively, if you know the valid connection types, you could jump straight
403+to the nmcli console by providing the type as a parameter:
404+
405+```
406+$ nmcli connection edit type <type>
407+```
408+
409+where &lt;type&gt; must be a valid connection type such as 'wifi'.
410+
411+An attempt to edit the wifi connection type would look like:
412+
413+```
414+$ nmcli c edit
415+
416+Valid connection types: generic, 802-3-ethernet (ethernet), pppoe,
417+802-11-wireless (wifi), wimax, gsm, cdma, infiniband, adsl, bluetooth, vpn,
418+802-11-olpc-mesh (olpc-mesh), vlan, bond, team, bridge, bond-slave, team-slave,
419+bridge-slave, no-slave, tun, ip-tunnel, macvlan, vxlan
420+Enter connection type: wifi
421+
422+===| nmcli interactive connection editor |===
423+
424+Adding a new '802-11-wireless' connection
425+
426+Type 'help' or '?' for available commands.
427+Type 'describe [<setting>.<prop>]' for detailed property description.
428+
429+You may edit the following settings: connection, 802-11-wireless (wifi),
430+802-11-wireless-security (wifi-sec), 802-1x, ipv4, ipv6
431+nmcli>
432+```
433+
434+From now on it is possible to edit the wifi connection settings. The list of
435+settings is provided as in the example above. The nmcli console offers a set of
436+commands that can be used to navigate between settings. To get the list of
437+available commands type 'help' or '?'
438+
439+```
440+nmcli> ?
441+------------------------------------------------------------------------------
442+---[ Main menu ]---
443+goto [<setting> | <prop>] :: go to a setting or property
444+remove <setting>[.<prop>] | <prop> :: remove setting or reset property value
445+set [<setting>.<prop> <value>] :: set property value
446+describe [<setting>.<prop>] :: describe property
447+print [all | <setting>[.<prop>]] :: print the connection
448+verify [all | fix] :: verify the connection
449+save [persistent|temporary] :: save the connection
450+activate [<ifname>] [/<ap>|<nsp>] :: activate the connection
451+back :: go one level up (back)
452+help/? [<command>] :: print this help
453+nmcli <conf-option> <value> :: nmcli configuration
454+quit :: exit nmcli
455+------------------------------------------------------------------------------
456+nmcli>
457+```
458+
459+## Change Connection Details
460+
461+This section will show how to change some of the connection details including
462+IPv4 and IPv6 settings.
463+
464+It is important to understand that every option can be modified using either the
465+command-line or the editor. The advantage of the editor is that it shows which
466+options are availabe for modification in contrast to the command-line which does
467+not.
468+
469+It is possible however to learn about the available settings from the
470+command-line by printing the connection details. Type:
471+
472+```
473+$ nmcli c show <name>
474+```
475+
476+where &lt;name&gt; is the connection name.
477+
478+The above will bring a fairly long list of text on the terminal, therefore it is
479+best to either use a pager or grep to make the results manageable.
480+
481+### IPv4 and IPv6 Options
482+
483+For example for IPv4 settings one would do:
484+
485+```
486+$ nmcli c show <name> | grep ipv4
487+ipv4.method: auto
488+ipv4.dns:
489+ipv4.dns-search:
490+ipv4.dns-options: (default)
491+ipv4.addresses:
492+ipv4.gateway: --
493+ipv4.routes:
494+ipv4.route-metric: -1
495+ipv4.ignore-auto-routes: no
496+ipv4.ignore-auto-dns: no
497+ipv4.dhcp-client-id: --
498+ipv4.dhcp-timeout: 0
499+ipv4.dhcp-send-hostname: yes
500+ipv4.dhcp-hostname: --
501+ipv4.dhcp-fqdn: --
502+ipv4.never-default: no
503+ipv4.may-fail: yes
504+ipv4.dad-timeout: -1 (default)
505+```
506+
507+For example setting up the DNS server would require typing:
508+
509+```
510+$ nmcli c modify <name> ipv4.dns "8.8.8.8"
511+```
512+
513+The rest of the settings can be modified in the same fashion.
514+
515+### WiFi Powersave Option
516+
517+The WiFi powersave option can have one of the following values:
518+
519+| Value | Meaning |
520+|-------|---------------------------------------------------|
521+| 0 | Default |
522+| 1 | Ignore, do not touch currently configured setting |
523+| 2 | Disable |
524+| 3 | Enable |
525+
526+Changing it is as simple as:
527+
528+```
529+$ nmcli c modify <name> 802-11-wireless.powersave 2
530+```
531diff --git a/docs/snap/enable-ethernet-support.md b/docs/snap/enable-ethernet-support.md
532new file mode 100644
533index 0000000..1aebf45
534--- /dev/null
535+++ b/docs/snap/enable-ethernet-support.md
536@@ -0,0 +1,38 @@
537+---
538+title: "Enable Ethernet Support"
539+table_of_contents: False
540+---
541+
542+# Enable Ethernet Support
543+
544+The default netplan configuration files in Ubuntu Core leave management of
545+Ethernet devices to networkd. Therefore, to avoid conflicts, the
546+network-manager snap does not manage Ethernet devices by default. The user has
547+to take care to enable it after installation if desired.
548+
549+## Configure System for Ethernet Support
550+
551+Before following the instructions below, backup the contents of /etc/netplan to
552+be able to restore it at a later point.
553+
554+Also, note that this change might lead to a system without properly configured
555+network connections, which would lead to problems accessing the device, so be
556+careful when doing this.
557+
558+To enable ethernet support, you have to set the `ethernet.enable` property to
559+`true`. See how to do this [here](reference/configuration/ethernet_support.md).
560+When this is done, configuration files for netplan are created so
561+network-manager is the default netplan renderer. When set to `false` (the
562+default), the NM snap explicitly disables the management of ethernet devices to
563+avoid conflicts with networkd.
564+
565+Rebooting the system will be needed for the changes to take effect.
566+
567+After the reboot, NetworkManager should automatically set up attached Ethernet
568+ports or use existing netplan configuration files to setup connections.
569+
570+Once logged into the system you may check the current connection status by
571+
572+```
573+$ nmcli c show
574+```
575diff --git a/docs/snap/explore-network-status.md b/docs/snap/explore-network-status.md
576new file mode 100644
577index 0000000..7b43950
578--- /dev/null
579+++ b/docs/snap/explore-network-status.md
580@@ -0,0 +1,52 @@
581+---
582+title: "Explore Network Status"
583+table_of_contents: False
584+---
585+
586+# Exploring Network Status
587+
588+This section shows how to use the nmcli command-line tool to examine the status
589+of NetworkManager’s connections and devices.
590+
591+Show the status of devices known to NetworkManager:
592+
593+```
594+$ nmcli d
595+```
596+
597+Show more information for this option:
598+
599+```
600+$ nmcli d --help
601+```
602+
603+Show the current status of each of NetworkManager’s connections:
604+
605+```
606+$ nmcli c
607+```
608+
609+Command “c” is for connections but is a abbreviated form of the real command
610+"connections". As for the devices command, “--help” shows more information for
611+this option. Finally, we can see the state of radio interfaces, including WiFi
612+and WWAN (cellular) with:
613+
614+```
615+$ nmcli r
616+WIFI-HW WIFI WWAN-HW WWAN
617+enabled enabled enabled enabled
618+```
619+
620+It is important to make sure that WiFi/WWAN radios are enabled so the respective
621+connection types can establish a connection (we will specify how to this in
622+following sections). As with the other commands, “--help” shows usage information.
623+
624+Observe NetworkManage activity (changes in connectivity state, devices or
625+connection properties):
626+
627+```
628+$ nmcli monitor
629+```
630+
631+See nmcli connection monitor and nmcli device monitor to watch for changes in
632+certain connections or devices.
633diff --git a/docs/snap/faq.md b/docs/snap/faq.md
634new file mode 100644
635index 0000000..ede5b21
636--- /dev/null
637+++ b/docs/snap/faq.md
638@@ -0,0 +1,18 @@
639+---
640+title: "FAQ"
641+table_of_contents: False
642+---
643+
644+# FAQ
645+
646+This section covers some of the most commonly encountered problems and attempts
647+to provide solutions for them.
648+
649+## Ethernet devices are not used
650+
651+### Possible cause: Ethernet support is disabled for NetworkManager
652+
653+By default the network-manager snap disables Ethernet support to avoid conflicts
654+with networkd/netplan which are used by default on Ubuntu Core 16. See
655+*[Enable Ethernet Support](enable-ethernet-support.md)* for details on how to
656+enable it.
657diff --git a/docs/snap/index.md b/docs/snap/index.md
658new file mode 100644
659index 0000000..81dcc30
660--- /dev/null
661+++ b/docs/snap/index.md
662@@ -0,0 +1,42 @@
663+---
664+title: "NetworkManager"
665+table_of_contents: False
666+---
667+
668+# About NetworkManager
669+
670+NetworkManager is a system network service that manages your network
671+devices and connections, attempts to keep network connectivity active
672+when available. It manages Ethernet, WiFi, mobile broadband (WWAN) and
673+PPPoE devices while also providing VPN integration with a variety of
674+different VPN serivces.
675+
676+By default network management on [Ubuntu Core](https://www.ubuntu.com/core) is
677+handled by systemd's
678+[networkd](https://www.freedesktop.org/software/systemd/man/systemd-networkd.service.html)
679+and [netplan](https://launchpad.net/netplan). While NetworkManager has some
680+support to handle netplan configuration files, Ethernet support is disabled by
681+default and has to be turned on explicitly to avoid conflicts with existing
682+network configuration.
683+
684+## What NetworkManager Offers
685+
686+The upstream NetworkManager project offers a wide range of features which are
687+partially available in the snap version. However,
688+as the snap should be always delivered in high quality we don't have yet all
689+upstream features enabled.
690+
691+Currently we provide support for the following high level features:
692+
693+ * WiFi connectivity
694+ * WWAN connectivity (together with ModemManager)
695+ * Ethernet connectivity
696+
697+ Currently we do not support the following features:
698+
699+ * VPN
700+
701+## Upstream documentation
702+
703+Existing documentation from the upstream project can be found
704+[here](https://wiki.gnome.org/Projects/NetworkManager).
705diff --git a/docs/snap/installation.md b/docs/snap/installation.md
706new file mode 100644
707index 0000000..b031d79
708--- /dev/null
709+++ b/docs/snap/installation.md
710@@ -0,0 +1,62 @@
711+---
712+title: "Install NetworkManager"
713+table_of_contents: True
714+---
715+
716+# Install NetworkManager
717+
718+The NetworkManager snap is currently available from the Ubuntu Store. It can
719+be installed on any system that supports snaps but is only recommended on
720+[Ubuntu Core](https://www.ubuntu.com/core) at the moment.
721+
722+You can install the snap with the following command:
723+
724+```
725+ $ snap install network-manager
726+ network-manager 1.2.2-10 from 'canonical' installed
727+```
728+
729+Although the network-manager snap is available from other channels (candidate, beta, edge),
730+only the stable version should be used for production devices. Their meaning is internal
731+to the development team of the network-manager snap.
732+
733+All necessary plugs and slots will be automatically connected within the
734+installation process. You can verify this with:
735+
736+```
737+$ snap interfaces network-manager
738+Slot Plug
739+:network-setup-observe network-manager
740+:ppp network-manager
741+network-manager:service network-manager:nmcli
742+- network-manager:modem-manager
743+```
744+
745+**NOTE:** The _network-manager:modem-manager_ plug only gets connected when the
746+_modem-manager_ snap is installed too. Otherwise it stays disconnected.
747+
748+Once the installation has successfully finished the
749+NetworkManager service is running in the background. You can check its current
750+status with
751+
752+```
753+ $ systemctl status snap.networkmanager
754+ ● snap.networkmanager.service - Service for snap application networkmanager
755+ Loaded: loaded (/etc/systemd/system/snap.networkmanager.service; enabled; vendor preset: enabled)
756+ Active: active (running) since Thu 2017-02-16 09:59:39 UTC; 16s ago
757+ Main PID: 1389 (networkmanager)
758+ [...]
759+```
760+
761+Now you have NetworkManager successfully installed.
762+
763+## Next Steps
764+
765+ * [Enable Ethernet Support](enable-ethernet-support.md)
766+ * [Explore Network Status](explore-network-status.md)
767+ * [Configure WiFi Connections](configure-wifi-connections.md)
768+ * [Configure Cellular Connections](configure-cellular-connections.md)
769+ * [Edit Network Connections](edit-connections.md)
770+ * [Routing Tables](routing-tables.md)
771+ * [Logging Messages](logging-messages.md)
772+ * [Enable Debug Support](reference/snap-configuration/debug.md)
773diff --git a/docs/snap/logging-messages.md b/docs/snap/logging-messages.md
774new file mode 100644
775index 0000000..d242808
776--- /dev/null
777+++ b/docs/snap/logging-messages.md
778@@ -0,0 +1,43 @@
779+---
780+title: "Logging Messages"
781+table_of_contents: False
782+---
783+
784+# Logging Messages
785+
786+This section will show how to modify the logging levels by NetworkManager.
787+
788+NetworkManager supports on the fly changing of the logging levels and allows for
789+a fine control over what is logged.
790+
791+First check what is the current logging setup, type:
792+
793+```
794+$ nmcli general logging
795+```
796+
797+As a result you will be presented with the information about the current
798+configuration:
799+
800+```
801+LEVEL DOMAINS
802+INFO PLATFORM,RFKILL,ETHER,WIFI,BT,MB,DHCP4,DHCP6,PPP,IP4,IP6,AUTOIP4,DNS,VPN,SHARING,SUPPLICANT,AGENTS,SETTINGS,SUSPEND,CORE,DEVICE,OLPC,INFINIBAND,FIREWALL,ADSL,BOND,VLAN,BRIDGE,TEAM,CONCHECK,DCB,DISPATCH,AUDIT,SYSTEMD
803+```
804+
805+It is possible to change the level either globally or for each domain
806+separately. The command to achieve this is:
807+
808+```
809+$ nmcli general logging [level <level> [domain <domain>]]
810+```
811+
812+The &lt;level&gt; is the desired log level. You can choose from the following:
813+
814+* **ERR:** will log only critical errors
815+* **WARN:** will log warnin messages
816+* **INFO:** will log various informational messages
817+* **DEBUG:** enables verbose logging for debugging purposes
818+
819+&lt;domain&gt; is the category of messages that shall be logged with given
820+severity. **WIFI** will include only WiFi related messages, **IP4** will include
821+only IPv4 related messages and so on..
822diff --git a/docs/snap/metadata.yaml b/docs/snap/metadata.yaml
823new file mode 100644
824index 0000000..82bf35f
825--- /dev/null
826+++ b/docs/snap/metadata.yaml
827@@ -0,0 +1,49 @@
828+site_title: NetworkManager documentation
829+site_logo_url: https://assets.ubuntu.com/v1/c5cb0f8e-picto-ubuntu.svg
830+navigation:
831+ - title: Introduction
832+ children:
833+ - title: About NetworkManager
834+ location: index.md
835+ - title: Install & Configure
836+ children:
837+ - title: Install NetworkManager
838+ location: installation.md
839+ - title: Explore Network Status
840+ location: explore-network-status.md
841+ - title: Configure WiFi Connections
842+ location: configure-wifi-connections.md
843+ - title: Configure Cellular Connections
844+ location: configure-cellular-connections.md
845+ - title: Enable Ethernet Support
846+ location: enable-ethernet-support.md
847+ - title: Edit Connections
848+ location: edit-connections.md
849+ - title: Routing Tables
850+ location: routing-tables.md
851+ - title: Logging Messages
852+ location: logging-messages.md
853+ - title: Reference
854+ children:
855+ - title: Snap Configuration
856+ children:
857+ - title: Ethernet Support
858+ location: reference/configuration/ethernet_support.md
859+ - title: Debug
860+ location: reference/snap-configuration/debug.md
861+ - title: Wake on WLAN
862+ location: reference/snap-configuration/wowlan.md
863+ - title: WiFi Powersave
864+ location: reference/snap-configuration/wifi-powersave.md
865+ - title: Available Commands
866+ location: reference/available-commands.md
867+ - title: DBUS API
868+ location: reference/dbus-api.md
869+ - title: Troubleshoot
870+ children:
871+ - title: FAQ
872+ location: faq.md
873+ - title: Release Notes
874+ location: release-notes.md
875+ - title: Report a Bug
876+ location: report-bug.md
877diff --git a/docs/snap/reference/available-commands.md b/docs/snap/reference/available-commands.md
878new file mode 100644
879index 0000000..18b3cec
880--- /dev/null
881+++ b/docs/snap/reference/available-commands.md
882@@ -0,0 +1,19 @@
883+---
884+title: Available Commands
885+table_of_contents: true
886+---
887+
888+# Available Commands
889+
890+The NetworkManager upstream project comes with a few commands which can be used
891+to control and manage the NetworkManager service. This page gives a short overview
892+of those commands which are available as part of the snap and what they are used for.
893+Further details about their usage is given on linked pages.
894+
895+## nmcli
896+
897+The nmcli command offers a command-line based way to control and manage the
898+NetworkManager service.
899+
900+An explanatory description of the command and available options are available
901+[here](https://developer.gnome.org/NetworkManager/1.2/nmcli.html)
902diff --git a/docs/snap/reference/configuration/ethernet_support.md b/docs/snap/reference/configuration/ethernet_support.md
903new file mode 100644
904index 0000000..fbc5929
905--- /dev/null
906+++ b/docs/snap/reference/configuration/ethernet_support.md
907@@ -0,0 +1,47 @@
908+---
909+title: Ethernet Support
910+table_of_contents: true
911+---
912+
913+# Ethernet Support
914+
915+*Available since:* 1.2.2-12
916+
917+The NetworkManager snap provides a configuration option to adjust
918+if it should manage ethernet network connections.
919+
920+By default the NetworkManager snap **does not** manage ethernet network
921+devices as it would conflict with the default network management in
922+Ubuntu Core which is handled by [netplan](https://launchpad.net/netplan) and
923+[networkd](https://www.freedesktop.org/software/systemd/man/systemd-networkd.service.html).
924+
925+## Enable Ethernet Support
926+
927+To enable management of ethernet network devices the snap provides the
928+*ethernet.enable* configuration option.
929+
930+This configuration option accepts the following values
931+
932+ * **false (default):** Ethernet support is disabled. All network
933+ devices matching the expression 'en*' or 'eth*' will be ignored.
934+ * **true:** All ethernet devices available on the system will be
935+ managed by NetworkManager. networkd will not manage any of these
936+ anymore.
937+
938+Changing the *ethernet* configuration option needs a reboot of the
939+device it's running on.
940+
941+After the device has rebooted ethernet support is enabled NetworkManager will
942+take over management of all available ethernet network devices on the device.
943+
944+NetworkManager will reuse existing configurations files from */etc/netplan*
945+when ethernet support is enabled. Those will marked as immutable inside
946+NetworkManager and any changes need to be written manually into the relevant
947+files in */etc/netplan*.
948+
949+Example:
950+
951+```
952+ $ snap set network-manager ethernet.enable=true
953+ $ sudo reboot
954+```
955diff --git a/docs/snap/reference/dbus-api.md b/docs/snap/reference/dbus-api.md
956new file mode 100644
957index 0000000..7cece10
958--- /dev/null
959+++ b/docs/snap/reference/dbus-api.md
960@@ -0,0 +1,9 @@
961+---
962+title: "DBUS API"
963+table_of_contents: False
964+---
965+
966+# DBUS API
967+
968+Documentation of the DBus API is provided by the NetworkManager upstream project
969+[here](https://developer.gnome.org/NetworkManager/1.2/spec.html).
970diff --git a/docs/snap/reference/snap-configuration/debug.md b/docs/snap/reference/snap-configuration/debug.md
971new file mode 100644
972index 0000000..e16d17c
973--- /dev/null
974+++ b/docs/snap/reference/snap-configuration/debug.md
975@@ -0,0 +1,51 @@
976+---
977+title: Debug
978+table_of_contents: True
979+---
980+
981+# Debug
982+
983+Debug is a feature that controls the amount of logs produced by the network-manager
984+snap. It is useful for collecting information required to either report a bug or
985+investigate a network-manager failure (if happens).
986+
987+It is disabled by default and has to be explicitely turned on for usage.
988+
989+Note that the debug logs may contain sensitive information.
990+
991+## Enable Debug
992+
993+The network-manager snap provides a single configuration option which can be used to
994+turn the debug feature either on or off:
995+
996+ * **debug.enable**
997+
998+The option takes a boolean value. The meaning of the possible values are:
999+
1000+ * **true:** Enable logging debug information
1001+ * **false (default):** Disable logging debug information
1002+
1003+Changing the **debug** configuration option has immediate effect and also
1004+affects future executions of the NM daemon.
1005+
1006+**Example:** Enable debug feature
1007+
1008+```
1009+$ snap set network-manager debug.enable=true
1010+```
1011+
1012+<br/>
1013+**Example:** Disable debug feature.
1014+
1015+```
1016+$ snap set network-manager debug.enable=false
1017+```
1018+
1019+## Viewing logs
1020+
1021+The debug information, when enabled, will be available in the journal and can
1022+be viewed with:
1023+
1024+```
1025+$ journalctl --no-pager -u snap.network-manager.networkmanager.service
1026+```
1027diff --git a/docs/snap/reference/snap-configuration/wifi-powersave.md b/docs/snap/reference/snap-configuration/wifi-powersave.md
1028new file mode 100644
1029index 0000000..8b9e68f
1030--- /dev/null
1031+++ b/docs/snap/reference/snap-configuration/wifi-powersave.md
1032@@ -0,0 +1,38 @@
1033+---
1034+title: WiFi Powersave
1035+table_of_contents: True
1036+---
1037+
1038+# WiFi Powersave
1039+
1040+WiFi Powersave is a feature that allows a device to suspend its radio activity
1041+after a fixed period of inactivity. The device remains idle for a fixed time,
1042+usualy about 100ms, and once it is reached it wakes up to check if the
1043+infrastructure has any packets queued up for it.
1044+
1045+The NetworkManager snap allows to configure this option by either enabling or
1046+disabling the powersave feature.
1047+
1048+You can read more about the WiFi Powersave feature on the following sites:
1049+
1050+*
1051+<https://wireless.wiki.kernel.org/en/developers/documentation/ieee80211/power-savings>
1052+
1053+### Enable WiFi Powersave
1054+
1055+To allow users to enable or disable WiFi Powersave, the snap provides a single
1056+configuration option:
1057+
1058+* wifi.powersave
1059+
1060+Option can be set via the configuration API snaps provide. See
1061+<https://docs.ubuntu.com/core/en/guides/build-device/config-hooks> for more
1062+details.
1063+
1064+#### wifi.powersave
1065+
1066+This configuration option accepts the following values:
1067+
1068+* **disabled (default):** WiFi powersaving is disabled
1069+* **enabled:** WiFi powersaving is enabled
1070+
1071diff --git a/docs/snap/reference/snap-configuration/wowlan.md b/docs/snap/reference/snap-configuration/wowlan.md
1072new file mode 100644
1073index 0000000..2ae0791
1074--- /dev/null
1075+++ b/docs/snap/reference/snap-configuration/wowlan.md
1076@@ -0,0 +1,126 @@
1077+---
1078+title: Wake on WLAN
1079+table_of_contents: True
1080+---
1081+
1082+# Wake on WLAN
1083+
1084+*Available since:* 1.2.2-11
1085+
1086+Wake on WLAN (called WoWLAN in the following) is a feature which allows a device
1087+to be woken up from standby power states to faciliate device management. It is based
1088+on the well well-established standard for Wake on LAN. The functionality is not entirely
1089+equivalent to Wake on LAN and there are some limitations.
1090+
1091+The NetworkManager snap allows its users to configure one or more triggers to allow
1092+the device it operates on to be woken up remotely.
1093+
1094+An important precondition for WoWLAN to work is that your device's kernel WiFi driver
1095+has support for it. If it is has support for WoWLAN it may only support a subset
1096+of possible triggers.
1097+
1098+You can read more about the kernel side implementation on the following sites:
1099+
1100+ * <https://wireless.wiki.kernel.org/en/users/documentation/wowlan>
1101+
1102+### Enable Wake on WLAN Globally
1103+
1104+To allow users to enable or disable WoWLAN, the snap provides two configuration
1105+options:
1106+
1107+ * **wifi.wake-on-wlan**
1108+ * **wifi.wake-on-wlan-password**
1109+
1110+Both options can be set via the configuration API snaps provide. See
1111+<https://docs.ubuntu.com/core/en/guides/build-device/config-hooks> for more
1112+details.
1113+
1114+Both configuration options will affect all wireless network devices. If you
1115+want to change it just for a single wireless connection please have a look at
1116+the chapter [Per Connection Configuration](#per-connection-configuration) below.
1117+
1118+
1119+#### wifi.wake-on-wlan
1120+
1121+This configuration option accepts the following values:
1122+
1123+ * **disabled (default):** Wake on WLAN is disabled for all wireless network devices.
1124+ * **any:** Wake on WLAN is enabled and any possible trigger will cause the system to wake up.
1125+ * **disconnect:** If a connection to a station gets disconnected the device will be woken up.
1126+ * **magic:** Wake on WLAN is enabled and only a received magic packet will cause the
1127+ system to wake up. The magic packet has the same structure as the one
1128+ used for Wake on LAN. For more details see <https://en.wikipedia.org/wiki/Wake-on-LAN#Magic_packet>
1129+ The content of the magic packet can be extended with the
1130+ wifi.wake-on-wlan-password option to require the client to send a
1131+ specific byte sequence functioning as a password so that not anyone
1132+ unpriviledged can wake up the system.
1133+ * **gtk-rekey-failure:** A failure of a GTK rekey operation will cause the device to wake up.
1134+ * **4way-handshake:** Reiteration of the 4way handshake will cause the device to wake up.
1135+ * **rfkill-release:** Release of a rfkill will cause the device to wake up.
1136+ * **tcp:** Any incoming TCP packet will cause the device to wake up.
1137+
1138+Example:
1139+
1140+```
1141+ $ snap set network-manager wifi.wake-on-wlan=magic
1142+```
1143+
1144+#### wifi.wake-on-wlan-password
1145+
1146+This configuration option accepts a textual value. If specified, the value will
1147+be used in addition to the wireless device MAC address to function as a password
1148+that disallows unpriviledged actors to wake up the device.
1149+
1150+Example:
1151+
1152+```
1153+ $ snap set network-manager wifi.wake-on-wlan-password=MyPassword
1154+```
1155+</br>
1156+### Per Connection Configuration
1157+
1158+To configure WoWLAN per connection you have to use the *nmcli* utility which comes
1159+with the NetworkManager snap. It allows you to configure the same two options
1160+as the snap accepts. However, the *wifi.wake-on-wlan* option takes a numeric value
1161+instead of a textual one.
1162+
1163+The *wifi.wake-on-wlan* option accepts the following values (see above for a detailed
1164+description of each value)
1165+
1166+ * **0:** disabled
1167+ * **1:** Use global default configuration
1168+ * **2:** any
1169+ * **4:** disconnect
1170+ * **8:** magic
1171+ * **16:** gtk-rekey-failure
1172+ * **32:** 4way-handshake
1173+ * **128:** rfkill-release
1174+ * **256:** tcp
1175+
1176+The *wifi.wake-on-wlan-password* option accepts the same values as the snap
1177+configuration option.
1178+
1179+Example:
1180+
1181+```
1182+ $ nmcli c modify my-connection wifi.wake-on-wlan 2
1183+ $ nmcli c modify my-connection wifi.wake-on-wlan-password Test1234
1184+```
1185+</br>
1186+### Verify WoWLAN Configuration
1187+
1188+NetworkManager will use the kernel to configure WoWLAN on the hardware level.
1189+The *iw* utility provides a simple way to verify the right option is configured.
1190+
1191+If you don't have the *iw* utility on your system you can install it with the
1192+*wireless-tools* snap.
1193+
1194+```
1195+ $ snap install --devmode wireless-tools
1196+ $ sudo wireless-tools.iw phy phy0 wowlan show
1197+ WoWLAN is enabled:
1198+ * wake up on magic packet
1199+```
1200+
1201+See the help output of the *iw* command for more documentation and available
1202+options.
1203diff --git a/docs/snap/release-notes.md b/docs/snap/release-notes.md
1204new file mode 100644
1205index 0000000..8a96cee
1206--- /dev/null
1207+++ b/docs/snap/release-notes.md
1208@@ -0,0 +1,35 @@
1209+---
1210+title: "Release Notes"
1211+table_of_contents: False
1212+---
1213+
1214+# Release Notes
1215+
1216+The version numbers mentioned on this page correspond to those released in the
1217+Ubuntu snap store.
1218+
1219+You can check with the following command which version you have currently
1220+installed:
1221+
1222+```
1223+$ snap info network-manager
1224+name: network-manager
1225+summary: "Network management based on NeworkManager"
1226+publisher: canonical
1227+description: |
1228+ Network management of wired Ethernet, WiFi and mobile data connection based on
1229+ NetworkManager and ModemManager
1230+commands:
1231+ - nmcli
1232+tracking: stable
1233+installed: 1.2.2-10 (73) 5MB -
1234+[...]
1235+```
1236+</br>
1237+## 1.2.2-11
1238+
1239+ * Wake-on-WLAN can be configured via snap/nmcli
1240+ * Automatic reconfiguration of network devices when device comes back from a
1241+ low power state
1242+ * Snap alias available for nmcli
1243+ * WiFi powersave is configurable via snap configuration
1244diff --git a/docs/snap/report-bug.md b/docs/snap/report-bug.md
1245new file mode 100644
1246index 0000000..ba02a2e
1247--- /dev/null
1248+++ b/docs/snap/report-bug.md
1249@@ -0,0 +1,36 @@
1250+---
1251+title: "Report a Bug"
1252+table_of_contents: False
1253+---
1254+
1255+# Report a Bug
1256+
1257+Bugs can be reported [here](https://bugs.launchpad.net/snappy-hwe-snaps/+filebug).
1258+
1259+When submitting a bug report, please attach system log coming from the journal:
1260+
1261+ * $ journalctl --no-pager > system-log
1262+
1263+And the output of the following two commands:
1264+
1265+```
1266+$ nmcli d
1267+$ nmcli c
1268+```
1269+
1270+It is a good idea to set the log level to DEBUG so that the verbose information
1271+is provided. To do this for NetworkManager please see the [Logging Messages](logging-messages.md)
1272+page.
1273+
1274+If there is a modem and the modem-manager snap is installed, also add the output
1275+of
1276+
1277+```
1278+$ sudo modem-manager.mmcli -m <N>
1279+```
1280+
1281+With being <N> the modem number as reported by
1282+
1283+```
1284+$ sudo modem-manager.mmcli -L
1285+```
1286diff --git a/docs/snap/routing-tables.md b/docs/snap/routing-tables.md
1287new file mode 100644
1288index 0000000..85b4ff8
1289--- /dev/null
1290+++ b/docs/snap/routing-tables.md
1291@@ -0,0 +1,96 @@
1292+---
1293+title: "Routing Tables"
1294+table_of_contents: True
1295+---
1296+
1297+# Routing Tables
1298+
1299+This section describes the way to setup routing table as well as it explains the
1300+logic used to prioritize interfaces.
1301+
1302+The routing table is stored in the kernel which merely acts upon it. The route
1303+itself is set by the user-space tools. There is no preference as any tool
1304+created for this reason will do. It can be either a DHCP client, ip command or
1305+route command.
1306+
1307+It is important to understand that NetworkManager changes the routing table
1308+whenever it creates a new connection.
1309+
1310+Routing table acts as a junction and is there to show where the different
1311+network subnets will be routed to. An example of a routing table is shown below.
1312+
1313+```
1314+$ ip route
1315+default via 10.0.0.1 dev wlp3s0 proto static metric 600
1316+10.0.0.0/24 dev wlp3s0 proto kernel scope link src 10.0.0.73 metric 600
1317+10.0.1.0/24 dev lxcbr0 proto kernel scope link src 10.0.1.1
1318+169.254.0.0/16 dev docker0 scope link metric 1000 linkdown
1319+172.17.0.0/16 dev docker0 proto kernel scope link src 172.17.0.1 linkdown
1320+192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown
1321+```
1322+
1323+The first column is the &lt;Destination&gt; subnet with the "default" being a
1324+wildcard for everything else. The "via" fragment points to the &lt;Gateway&gt;
1325+however when it is missing it indicates that that network is connected directly
1326+and instead it describes a source address.
1327+
1328+The &lt;Metric&gt; column translates to the number of hops required to reach the
1329+destination and is used to determine which route shall be preferred when there
1330+are more than one route available for a specific destination. Since it
1331+reassembles the concept of distance the lower it's value is the better.
1332+
1333+The &lt;Metric&gt; value can be set manually however when NetworkManager creates
1334+a connection the following defaults are applied:
1335+
1336+* Ethernet is preferred over WiFi
1337+* WiFi is preferred over WWAN
1338+
1339+# Editing the Routing Tables
1340+
1341+The routing table can be added or modified using the standard *ip* command which
1342+is available on Ubuntu Core.
1343+
1344+You can find more information on it on the following page:
1345+
1346+* <https://linux.die.net/man/8/ip?>
1347+
1348+Separately it is possible to modify routing information per single connection
1349+using the nmcli tool. The parameters such as: gateway, routes and metrics can be
1350+modified.
1351+
1352+The following options are responsible:
1353+
1354+```
1355+ipv4.gateway:
1356+ipv4.routes:
1357+ipv4.route-metric:
1358+
1359+ipv6.gateway:
1360+ipv6.routes:
1361+ipv6.route-metric:
1362+```
1363+
1364+These options can be modified in a following way:
1365+
1366+```
1367+$ nmcli connection modify <name> +ipv4.routes <destination> ipv4.gateway <gateway>
1368+$ nmcli connection modify <name> ipv4.route-metric <metric>
1369+```
1370+
1371+Where &lt;name&gt; is the connection name. You can obtain it by listing
1372+available connections on the system:
1373+
1374+```
1375+$ nmcli c show
1376+```
1377+
1378+&lt;destination&gt; is the destination network provided as a static IP address,
1379+subnet or "default". &lt;gateway&gt; is the new gateway information.
1380+&lt;metric&gt; is the new metric information.
1381+
1382+Note that this kind of changes can be made separately for each connection thus
1383+it is possible to provide a fine grained control over how the packets directed
1384+to different networks are routed.
1385+
1386+It is also important to understand that bringing up and down connections with
1387+different values set for these options is in fact changing the routing table.
1388diff --git a/run-tests.sh b/run-tests.sh
1389new file mode 100755
1390index 0000000..7ce726e
1391--- /dev/null
1392+++ b/run-tests.sh
1393@@ -0,0 +1,88 @@
1394+#!/bin/bash
1395+#
1396+# Copyright (C) 2016 Canonical Ltd
1397+#
1398+# This program is free software: you can redistribute it and/or modify
1399+# it under the terms of the GNU General Public License version 3 as
1400+# published by the Free Software Foundation.
1401+#
1402+# This program is distributed in the hope that it will be useful,
1403+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1404+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1405+# GNU General Public License for more details.
1406+#
1407+# You should have received a copy of the GNU General Public License
1408+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1409+
1410+set -ex
1411+
1412+TESTS_EXTRAS_URL="https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/tests-extras"
1413+TESTS_EXTRAS_PATH="tests-extras"
1414+
1415+show_help() {
1416+ exec cat <<'EOF'
1417+Usage: run-tests.sh [OPTIONS]
1418+
1419+This is fetch & forget script and what it does is to fetch the
1420+tests-extras repository and execute the run-tests.sh script from
1421+there passing arguments as-is.
1422+
1423+When you see this message you don't have the tests-extras repository
1424+successfully populated in your workspace yet. Please rerun without
1425+specifying --help to proceed with the initial clone of the git repository.
1426+EOF
1427+}
1428+
1429+# Clone the tests-extras repository
1430+clone_tests_extras() {
1431+ echo "INFO: Fetching tests-extras scripts into $TESTS_EXTRAS_PATH ..."
1432+ if ! git clone -b master $TESTS_EXTRAS_URL $TESTS_EXTRAS_PATH >/dev/null 2>&1; then
1433+ echo "ERROR: Failed to fetch the $TESTS_EXTRAS_URL repo, exiting.."
1434+ exit 1
1435+ fi
1436+}
1437+
1438+# Make sure the already cloned tests-extras repository is in a known and update
1439+# state before it is going to be used.
1440+restore_and_update_tests_extras() {
1441+ echo "INFO: Restoring and updating $TESTS_EXTRAS_PATH"
1442+ cd $TESTS_EXTRAS_PATH && git reset --hard && git clean -dfx && git pull
1443+ cd -
1444+}
1445+
1446+# ==============================================================================
1447+# This is fetch & forget script and what it does is to fetch the tests-extras
1448+# repo and execute the run-tests.sh script from there passing arguments as-is.
1449+#
1450+# The tests-extras repository ends up checked out in the snap tree but as a
1451+# hidden directory which is re-used since then.
1452+
1453+# Find snap to use in the tests
1454+snaps=$(find . -maxdepth 1 -type f -name \
1455+ "network-manager_*_$(dpkg-architecture -q DEB_HOST_ARCH).snap")
1456+while read -r snap_file; do
1457+ if [ -n "$snap" ]; then
1458+ printf "More than one snap revision in the folder\n"
1459+ exit 1
1460+ fi
1461+ snap=$PWD/${snap_file#*/}
1462+done < <(printf "%s\n" "$snaps")
1463+
1464+[ ! -d "$TESTS_EXTRAS_PATH" ] && [ "$1" = "--help" ] && show_help
1465+
1466+if [ -d "$TESTS_EXTRAS_PATH" ]; then
1467+ restore_and_update_tests_extras
1468+else
1469+ clone_tests_extras
1470+fi
1471+
1472+# Any project-specific options for test-runner should be specified in
1473+# .tests_config under EXTRA_ARGS
1474+if [ -f ".tests_config" ]; then
1475+ # shellcheck disable=SC1091
1476+ . .tests_config
1477+fi
1478+
1479+echo "INFO: Executing tests runner"
1480+# shellcheck disable=SC2086
1481+cd $TESTS_EXTRAS_PATH && ./tests-runner.sh "$@" --snap="$snap" $EXTRA_ARGS
1482diff --git a/snap-common/bin/snap-config.sh b/snap-common/bin/snap-config.sh
1483index 1c61ddc..7107a2c 100644
1484--- a/snap-common/bin/snap-config.sh
1485+++ b/snap-common/bin/snap-config.sh
1486@@ -119,15 +119,9 @@ _switch_debug_enable() {
1487 # We create/remove the file for future executions and also change
1488 # the logging level of the running daemon.
1489 if [ "$1" = "true" ]; then
1490- if [ ! -f "$DEBUG_FILE" ]; then
1491- touch "$DEBUG_FILE"
1492- "$SNAP"/bin/nmcli-internal g log level DEBUG
1493- fi
1494+ touch "$DEBUG_FILE"
1495 else
1496- if [ -f "$DEBUG_FILE" ]; then
1497- rm -f "$DEBUG_FILE"
1498- "$SNAP"/bin/nmcli-internal g log level INFO
1499- fi
1500+ rm -f "$DEBUG_FILE"
1501 fi
1502 }
1503
1504@@ -157,6 +151,11 @@ _switch_connectivity_check() {
1505 # $1: true/false
1506 _switch_defaultrenderer() {
1507 path=/etc/netplan/00-default-nm-renderer.yaml
1508+
1509+ # Remove related configuration file from older NM snap versions.
1510+ # We let netplan do whatever is needed.
1511+ rm -f "$SNAP_DATA"/conf.d/disable-ethernet.conf
1512+
1513 if [ "$1" = true ] || [ "$1" = yes ]; then
1514 if [ ! -f "$path" ]; then
1515 printf "network:\n renderer: NetworkManager\n" > "$path"
1516diff --git a/snap-patch/resolvconf.patch b/snap-patch/resolvconf.patch
1517new file mode 100644
1518index 0000000..2538bb9
1519--- /dev/null
1520+++ b/snap-patch/resolvconf.patch
1521@@ -0,0 +1,31 @@
1522+--- a/etc/resolvconf/update.d/libc 2017-11-29 19:26:46.000000000 +0100
1523++++ b/etc/resolvconf/update.d/libc 2019-06-07 08:55:49.486028633 +0200
1524+@@ -18,7 +18,7 @@
1525+ set -e
1526+ PATH=/sbin:/bin
1527+
1528+-[ -x /lib/resolvconf/list-records ] || exit 1
1529++[ -x "$SNAP"/lib/resolvconf/list-records ] || exit 1
1530+
1531+ # Default override
1532+ [ -r /etc/default/resolvconf ] && . /etc/default/resolvconf
1533+@@ -107,7 +107,7 @@
1534+ done
1535+ }
1536+
1537+-RSLVCNFFILES="$(/lib/resolvconf/list-records)"
1538++RSLVCNFFILES="$($SNAP/lib/resolvconf/list-records)"
1539+
1540+ [ -f "$BASEFILE" ] && RSLVCNFFILES="$RSLVCNFFILES
1541+ $BASEFILE"
1542+--- a/sbin/resolvconf 2019-05-06 10:39:40.000000000 +0200
1543++++ b/sbin/resolvconf 2019-06-07 08:55:49.514029312 +0200
1544+@@ -63,7 +63,7 @@
1545+ update_and_exit()
1546+ {
1547+ rm -f "$POSTPONED_UPDATE_FLAGFILE"
1548+- exec run-parts ${1:+--arg="$1"} ${2:+--arg="$2"} /etc/resolvconf/update.d
1549++ exec run-parts ${1:+--arg="$1"} ${2:+--arg="$2"} "$SNAP"/etc/resolvconf/update.d
1550+ }
1551+
1552+ # Handle commands that don't require normalized_stdin()
1553diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml
1554index 290ab83..d07b5ed 100644
1555--- a/snap/snapcraft.yaml
1556+++ b/snap/snapcraft.yaml
1557@@ -123,15 +123,14 @@ parts:
1558 - --with-dhcpcd=no
1559 - --with-dhclient=no
1560 - --with-dnsmasq=no
1561+ - --with-iptables=/snap/$SNAPCRAFT_PROJECT_NAME/current/sbin/iptables
1562 - --with-systemd-journal=yes
1563- # from 1.10 deb:
1564- - --libexecdir=/usr/lib/NetworkManager
1565- - --with-pppd=/usr/sbin/pppd
1566- - --with-resolvconf=no
1567+ - --libexecdir=/snap/$SNAPCRAFT_PROJECT_NAME/current/usr/lib/NetworkManager
1568+ - --with-pppd=/snap/$SNAPCRAFT_PROJECT_NAME/current/usr/sbin/pppd
1569+ - --with-resolvconf=/snap/$SNAPCRAFT_PROJECT_NAME/current/sbin/resolvconf
1570 #
1571- # TODO: iptables & dnsmasq are used for AP mode; not
1572+ # TODO: dnsmasq is used for AP mode; not
1573 # currently supported by the snap:
1574- # - --with-iptables=/sbin/iptables
1575 # - --with-dnsmasq=/usr/sbin/dnsmasq
1576 - --with-dnssec-trigger=/usr/lib/dnssec-trigger/dnssec-trigger-script
1577 - --with-systemdsystemunitdir=/lib/systemd/system
1578@@ -175,6 +174,7 @@ parts:
1579 # Run all tests NetworkManager ships by default
1580 make check
1581 stage-packages:
1582+ - iptables
1583 - iputils-arping
1584 - libasn1-8-heimdal
1585 - libdbus-glib-1-2
1586@@ -223,6 +223,12 @@ parts:
1587 - libslang2
1588 - libtasn1-6
1589 - libwind0-heimdal
1590+ - ppp
1591+ - resolvconf
1592+
1593+ override-stage: |
1594+ snapcraftctl stage
1595+ patch -p1 < "$SNAPCRAFT_PART_SRC"/snap-patch/resolvconf.patch
1596
1597 # Filter files pulled in by stage-packages so they aren't
1598 # included in the final snap. We only need them to build
1599@@ -231,21 +237,26 @@ parts:
1600 # here are the results of the network manager build.
1601 filesets:
1602 binaries:
1603+ - sbin/*tables*
1604+ - sbin/resolvconf
1605 - usr/bin/arping
1606 - usr/bin/nmcli
1607 - usr/bin/nmtui
1608 - usr/bin/nmtui-connect
1609 - usr/bin/nmtui-edit
1610 - usr/bin/nmtui-hostname
1611+ - usr/sbin/pppd
1612 - usr/lib/*/NetworkManager
1613 - usr/lib/pppd/2.4.5/nm-pppd-plugin.so
1614 - usr/lib/NetworkManager
1615 - usr/sbin/NetworkManager
1616 configs:
1617 - etc/NetworkManager/*
1618+ - etc/resolvconf/update.d/libc
1619 docs:
1620 - usr/share/doc/*/copyright
1621 libs:
1622+ - lib/resolvconf/list-records
1623 - lib/*/libnewt*
1624 - lib/*/libslang*
1625 - usr/lib/libnm*
1626@@ -258,6 +269,8 @@ parts:
1627 - usr/lib/*/libheimbase*
1628 - usr/lib/*/libheimntlm*
1629 - usr/lib/*/libhx509*
1630+ - usr/lib/*/libip4tc*
1631+ - usr/lib/*/libip6tc*
1632 # required for teamdctl
1633 - usr/lib/*/libjansson*
1634 - usr/lib/*/libkrb5*26*
1635@@ -267,12 +280,14 @@ parts:
1636 - usr/lib/*/libmm-glib*
1637 - usr/lib/*/libndp*
1638 - usr/lib/*/libnghttp2*
1639+ - usr/lib/*/libpcap*
1640 - usr/lib/*/libpsl*
1641 - usr/lib/*/libroken*
1642 - usr/lib/*/librtmp*
1643 - usr/lib/*/libsasl2*
1644 - usr/lib/*/libteamdctl*
1645 - usr/lib/*/libwind*
1646+ - usr/lib/*/libxtables*
1647 unwanted:
1648 # We don't use dhclient so we don't need this helper
1649 - -usr/lib/NetworkManager/nm-dhcp-helper
1650@@ -288,6 +303,3 @@ parts:
1651 - $docs
1652 - $libs
1653 - $unwanted
1654-
1655-
1656-
1657diff --git a/spread.yaml b/spread.yaml
1658new file mode 100644
1659index 0000000..83abb24
1660--- /dev/null
1661+++ b/spread.yaml
1662@@ -0,0 +1,85 @@
1663+#
1664+# Copyright (C) 2015, 2016 Canonical Ltd
1665+#
1666+# This program is free software: you can redistribute it and/or modify
1667+# it under the terms of the GNU General Public License version 3 as
1668+# published by the Free Software Foundation.
1669+#
1670+# This program is distributed in the hope that it will be useful,
1671+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1672+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1673+# GNU General Public License for more details.
1674+#
1675+# You should have received a copy of the GNU General Public License
1676+# along with this program. If not, see <http://www.gnu.org/licenses/>.
1677+
1678+
1679+project: network-manager
1680+
1681+environment:
1682+ PROJECT_PATH: /home/network-manager
1683+ TESTSLIB: $PROJECT_PATH/tests/lib
1684+ SNAP_NAME: network-manager
1685+ # Allow the host to pass the channel to use for the test run
1686+ SNAP_CHANNEL: $(HOST:echo $SNAP_CHANNEL)
1687+
1688+backends:
1689+ qemu:
1690+ systems:
1691+ - ubuntu-core-16:
1692+ username: test
1693+ password: test
1694+
1695+# Put this somewhere where we have read-write access
1696+path: /home/network-manager
1697+
1698+exclude:
1699+ - .git
1700+
1701+prepare: |
1702+ . $TESTSLIB/prepare-all.sh
1703+
1704+prepare-each: |
1705+ # Cleanup logs so we can just dump what has happened in the debug-each
1706+ # step below after a test case ran.
1707+ journalctl --rotate
1708+ sleep .1
1709+ journalctl --vacuum-time=1ms
1710+ dmesg -c > /dev/null
1711+
1712+debug-each: |
1713+ journalctl
1714+ dmesg | grep DENIED || true
1715+
1716+# Default is 15 min but we use a higher one here as we build the entire
1717+# network-manager snap inside the global prepare step so we need quite
1718+# some time. Once we can reuse artifacts from other builds we can change
1719+# this back to the default.
1720+kill-timeout: 30m
1721+
1722+suites:
1723+ tests/main/:
1724+ summary: Full-system tests for NetworkManager without ethernet support
1725+ systems:
1726+ - ubuntu-core-16
1727+ prepare: |
1728+ . $TESTSLIB/prepare.sh
1729+ restore-each: |
1730+ . $TESTSLIB/restore-each.sh
1731+ tests/full/:
1732+ summary: Full-system tests for NetworkManager being the only network management service
1733+ systems:
1734+ - ubuntu-core-16
1735+ prepare: |
1736+ . $TESTSLIB/utilities.sh
1737+ stop_after_first_reboot
1738+ switch_netplan_to_network_manager
1739+ . $TESTSLIB/prepare.sh
1740+ REBOOT
1741+ restore-each: |
1742+ . $TESTSLIB/restore-each.sh
1743+ restore: |
1744+ . $TESTSLIB/utilities.sh
1745+ stop_after_first_reboot
1746+ switch_netplan_to_networkd
1747+ REBOOT
1748diff --git a/tests/full/correct-dns-setup/task.yaml b/tests/full/correct-dns-setup/task.yaml
1749new file mode 100644
1750index 0000000..9b6dfe0
1751--- /dev/null
1752+++ b/tests/full/correct-dns-setup/task.yaml
1753@@ -0,0 +1,47 @@
1754+summary: Verify correct DNS setup
1755+
1756+execute: |
1757+ . $TESTSLIB/utilities.sh
1758+ case $SPREAD_REBOOT in
1759+ 0)
1760+ # For correct timing if the device has just booted
1761+ wait_for_network_manager
1762+
1763+ # Precondition is a existing network connection
1764+ /snap/bin/network-manager.nmcli d | grep 'eth0.*connected'
1765+
1766+ # We get a default nameserver from the gateway
1767+ if [ "$SPREAD_BACKEND" = "qemu" ] ; then
1768+ cat /etc/resolv.conf | grep 'nameserver 10.0.2.3'
1769+ fi
1770+
1771+ # Ensure we can resolve a hostname correctly; must give a
1772+ # valid IP address
1773+ address=`python3 -c 'import socket; print(socket.gethostbyname("ubuntu.com"))' 2> /dev/null || echo "invalid"`
1774+ [ "$address" != "invalid" ] && [[ $address =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
1775+
1776+ # Now lets switch to a system where we have a configuration
1777+ # for ethernet we can change
1778+ rm /etc/netplan/00-snapd-config.yaml
1779+ REBOOT
1780+ ;;
1781+ 1)
1782+ /snap/bin/network-manager.nmcli d | grep 'eth0.*connected'
1783+ /snap/bin/network-manager.nmcli d | grep -v netplan
1784+
1785+ connection=$(/snap/bin/network-manager.nmcli -m multiline -f UUID c show --active | awk '{print$2;exit}')
1786+ /snap/bin/network-manager.nmcli c modify $connection ipv4.dns 8.8.8.8
1787+ # We need to bring up the connection again here to get the DNS
1788+ # server really applied to the system.
1789+ /snap/bin/network-manager.nmcli c up $connection
1790+
1791+ # Give system a moment to settle
1792+ sleep 1
1793+
1794+ grep 'nameserver 8.8.8.8' /etc/resolv.conf
1795+ address=`python3 -c 'import socket; print(socket.gethostbyname("ubuntu.com"))' 2> /dev/null || echo "invalid"`
1796+ [ "$address" != "invalid" ] && [[ $address =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]
1797+ ;;
1798+ *)
1799+ ;;
1800+ esac
1801diff --git a/tests/full/immutable-netplan-config/task.yaml b/tests/full/immutable-netplan-config/task.yaml
1802new file mode 100644
1803index 0000000..c218478
1804--- /dev/null
1805+++ b/tests/full/immutable-netplan-config/task.yaml
1806@@ -0,0 +1,10 @@
1807+summary: Verify that netplan configuration files are immutable
1808+
1809+execute: |
1810+ # Ensure we're using a configuration generated from netplan
1811+ test -e /etc/netplan/00-snapd-config.yaml
1812+ test -e /run/NetworkManager/system-connections/netplan-eth0
1813+
1814+ /snap/bin/network-manager.nmcli c | MATCH 'netplan.eth0.*eth0'
1815+ # Try to change the DNS server used on this connection
1816+ test ! `/snap/bin/network-manager.nmcli c modify netplan-eth0 ipv4.dns 8.8.8.8`
1817diff --git a/tests/full/ipv6-address-assignment/task.yaml b/tests/full/ipv6-address-assignment/task.yaml
1818new file mode 100644
1819index 0000000..e36ef00
1820--- /dev/null
1821+++ b/tests/full/ipv6-address-assignment/task.yaml
1822@@ -0,0 +1,27 @@
1823+summary: Verify NetworkManager can assign a static IPv6 address to an interface
1824+
1825+restore: |
1826+ # Ensure that the created virtual network interfaces are removed
1827+ # in any case when we're done
1828+ if [ -e /sys/class/net/veth0 ] ; then
1829+ ip link delete veth0
1830+ fi
1831+
1832+execute: |
1833+ . $TESTSLIB/utilities.sh
1834+
1835+ # Ensure that we have IPv6 support enabled in the kernel
1836+ test -e /proc/net/if_inet6
1837+
1838+ ip link add dev veth0 type veth peer name veth1
1839+
1840+ wait_for_network_manager
1841+
1842+ connection=veth-ipv6
1843+ /snap/bin/network-manager.nmcli c add con-name $connection ifname veth0 type ethernet \
1844+ ip6 abbe::cafe
1845+ /snap/bin/network-manager.nmcli c up $connection
1846+
1847+ # Verify that NetworkManager assigned the correct IPv6 address
1848+ # to the interface
1849+ ifconfig veth0 | grep 'abbe::cafe/128'
1850diff --git a/tests/full/ipv6-router-advertisements/task.yaml b/tests/full/ipv6-router-advertisements/task.yaml
1851new file mode 100644
1852index 0000000..4af402b
1853--- /dev/null
1854+++ b/tests/full/ipv6-router-advertisements/task.yaml
1855@@ -0,0 +1,70 @@
1856+summary: Test IPv6 address assignment via router advertisements
1857+
1858+restore: |
1859+ # Ensure that the created virtual network interfaces are removed
1860+ # in any case when we're done
1861+ if [ -e /sys/class/net/veth0 ] ; then
1862+ ip link delete veth0
1863+ fi
1864+
1865+execute: |
1866+ . $TESTSLIB/utilities.sh
1867+
1868+ # Ensure that we have IPv6 support enabled in the kernel
1869+ test -e /proc/net/if_inet6
1870+
1871+ snap install --devmode se-test-tools
1872+ snap connect se-test-tools:home core
1873+ snap connect se-test-tools:network-control core
1874+
1875+ # Create virtual ethernet interface pair
1876+ sudo ip link add dev veth0 type veth peer name veth1
1877+
1878+ # As the virtual ethernet devices don't get IPv6 setup
1879+ # correctly by default we have to do this
1880+ sudo sysctl -w net.ipv6.conf.veth0.disable_ipv6=0
1881+ sudo sysctl -w net.ipv6.conf.veth1.disable_ipv6=0
1882+ veth0_lla=$(mac_to_ipv6 `cat /sys/class/net/veth0/address`)
1883+ veth1_lla=$(mac_to_ipv6 `cat /sys/class/net/veth1/address`)
1884+
1885+ # The radvd daemon will send out router advertisements on veth1
1886+ # so that we can receive them on veth0 end
1887+ cat <<-EOF > /home/test/radvd.conf
1888+ interface veth1 {
1889+ AdvSendAdvert on;
1890+ prefix 2001:db8:1:2::/64 {};
1891+ };
1892+ EOF
1893+
1894+ # To ensure that nobody touches veth1 we tell NetworkManager
1895+ # explicitly to do that.
1896+ /snap/bin/network-manager.nmcli d set veth1 managed no
1897+
1898+ # Assign our link-local addresses
1899+ if ! ip addr show dev veth0 | grep 'inet6.*scope link.*' ; then
1900+ sudo ip addr add dev veth0 scope link $veth0_lla
1901+ fi
1902+ if ! ip addr show dev veth1 | grep 'inet6.*scope link.*' ; then
1903+ sudo ip addr add dev veth1 scope link $veth1_lla
1904+ fi
1905+
1906+ # This will get our router advertisement daemon started and we
1907+ # now configure NetworkManager
1908+ sudo se-test-tools.radvd -C /home/test/radvd.conf -n -d 5 -m stderr -p /home/test/radvd.pid &
1909+
1910+ # Give things a bit more time to settle
1911+ sleep 10
1912+ ip addr show dev veth0
1913+
1914+ # At this point veth0 should have now a global IPv6 address
1915+ # assigned via router advertisements
1916+ ip addr show dev veth0 | grep 'inet6 2001:db8:1:2:.*/64 scope global'
1917+ # but veth1 should not have any
1918+ ip addr show dev veth1 | grep -v 'inet6.*scope global'
1919+
1920+ # NetworkManager should report the same addresses for IPv6
1921+ /snap/bin/network-manager.nmcli d show veth0 | grep 'GENERAL.STATE.*connected'
1922+ /snap/bin/network-manager.nmcli d show veth0 | grep 'IP6.ADDRESS.*2001:db8:1:2.*/64'
1923+
1924+ # Stop the radvd daemon
1925+ kill -TERM `cat /home/test/radvd.pid`
1926diff --git a/tests/full/no-netplan-default-config/task.yaml b/tests/full/no-netplan-default-config/task.yaml
1927new file mode 100644
1928index 0000000..66a75c6
1929--- /dev/null
1930+++ b/tests/full/no-netplan-default-config/task.yaml
1931@@ -0,0 +1,41 @@
1932+summary: Verify ethernet is auto-connected when no default netplan configuration exists
1933+
1934+prepare: |
1935+ cp /etc/netplan/00-snapd-config.yaml /etc/netplan/00-snapd-config.yaml.orig
1936+
1937+restore: |
1938+ mv /etc/netplan/00-snapd-config.yaml.orig /etc/netplan/00-snapd-config.yaml
1939+
1940+execute: |
1941+ . $TESTSLIB/utilities.sh
1942+ case "$SPREAD_REBOOT" in
1943+ 0)
1944+ # Remove all configuration files from netplan to get a system
1945+ # without generated configuration files from netplan
1946+ if [ -e /usr/lib/snapd/generate-network-conf ] ; then
1947+ echo "" > /etc/netplan/00-snapd-config.yaml
1948+ else
1949+ rm /etc/netplan/00-snapd-config.yaml
1950+ fi
1951+ REBOOT
1952+ ;;
1953+ 1)
1954+ # We should be automatically connected now and not via a configuration
1955+ # generated from netplan
1956+ wait_for_network_manager
1957+ /snap/bin/network-manager.nmcli d | grep 'eth0.*connected'
1958+ networkctl status eth0 | grep unmanaged
1959+ /snap/bin/network-manager.nmcli c show --active | grep eth0 | grep -v netplan
1960+
1961+ # We should only have a single active configuration
1962+ test `/snap/bin/network-manager.nmcli -m multiline -f UUID c show --active | wc -l` -eq 1
1963+
1964+ # Verify that we can modify the automatically created connection
1965+ connection=$(/snap/bin/network-manager.nmcli -m multiline -f UUID c show --active | awk '{print$2;exit}')
1966+ /snap/bin/network-manager.nmcli c modify $connection 802-3-ethernet.wake-on-lan magic
1967+ wol_value=$(/snap/bin/network-manager.nmcli -f 802-3-ethernet.wake-on-lan c show $connection | xargs | cut -d':' -f 2)
1968+ test "$wol_value" = " magic"
1969+ ;;
1970+ *)
1971+ ;;
1972+ esac
1973diff --git a/tests/full/system-network-is-active/task.yaml b/tests/full/system-network-is-active/task.yaml
1974new file mode 100644
1975index 0000000..22d7830
1976--- /dev/null
1977+++ b/tests/full/system-network-is-active/task.yaml
1978@@ -0,0 +1,9 @@
1979+summary: Ethernet network should be managed by NetworkManager
1980+
1981+execute: |
1982+ . $TESTSLIB/utilities.sh
1983+ # Verify NetworManager handles ethernet and marks it as connected
1984+ test -e /etc/netplan/00-default-nm-renderer.yaml
1985+ wait_for_network_manager
1986+ /snap/bin/network-manager.nmcli d | grep 'eth0.*connected'
1987+ networkctl status eth0 | grep unmanaged
1988diff --git a/tests/full/wol-enabled-by-default/task.yaml b/tests/full/wol-enabled-by-default/task.yaml
1989new file mode 100644
1990index 0000000..9d7d034
1991--- /dev/null
1992+++ b/tests/full/wol-enabled-by-default/task.yaml
1993@@ -0,0 +1,60 @@
1994+summary: Verify that wake-on-lan is enabled by default for all ethernet connections
1995+
1996+execute: |
1997+ . $TESTSLIB/utilities.sh
1998+ nmcli=/snap/bin/network-manager.nmcli
1999+ case "$SPREAD_REBOOT" in
2000+ 0)
2001+ # For correct timing if the device has just booted
2002+ wait_for_network_manager
2003+
2004+ # The config file needs to be present and have the correct default set
2005+ test -e /var/snap/network-manager/current/conf.d/enable-wol.conf
2006+ cat /var/snap/network-manager/current/conf.d/enable-wol.conf | grep '802-3-ethernet.wake-on-lan=64'
2007+
2008+ # Precondition is a existing network connection
2009+ $nmcli d | grep 'eth0.*connected'
2010+
2011+ # The netplan configuration file has WoL disabled by default as
2012+ # the default one the core snap provides does not explicitly
2013+ # enable WoL.
2014+ connection=$($nmcli -m multiline -f UUID c show --active | awk '{print$2;exit}')
2015+ $nmcli -m multiline -f connection.id c show $connection | grep 'netplan-eth0'
2016+ $nmcli -m multiline -f connection.type c show $connection | grep '802-3-ethernet'
2017+ $nmcli -m multiline -f 802-3-ethernet.wake-on-lan c show $connection |
2018+ grep '^802-3-ethernet.wake-on-lan: *--$'
2019+
2020+ # Now prepare for the next boot where we will run without a netplan
2021+ # config to get eth0 correctly configured.
2022+ rm /etc/netplan/00-snapd-config.yaml
2023+ REBOOT
2024+ ;;
2025+ 1)
2026+ # For correct timing if the device has just booted
2027+ wait_for_network_manager
2028+
2029+ # Precondition is a existing network connection
2030+ $nmcli d | grep 'eth0.*connected'
2031+
2032+ # Connection should have the default wake-on-lan setting
2033+ connection=$($nmcli -m multiline -f UUID c show | awk '{print$2;exit}')
2034+ $nmcli -m multiline -f connection.type c show $connection | grep '802-3-ethernet'
2035+ # wake-on-lan should be set to respect the global defaults here
2036+ $nmcli -m multiline -f 802-3-ethernet.wake-on-lan c show $connection | grep 'default'
2037+
2038+ # We can sadly only verify that the value was correctly applied when
2039+ # we're running the tests on a real device. QEMU doesn't support setting
2040+ # the WoL value of the ethernet network device.
2041+ if [ -z "`cat /proc/cpuinfo | grep QEMU`" ] ; then
2042+ # Get the tools snap to have the ethtool tool available
2043+ snap install --devmode --edge se-test-tools
2044+ snap connect se-test-tools:network core
2045+ snap connect se-test-tools:network-bind core
2046+ snap connect se-test-tools:network-control core
2047+
2048+ # See `man ethtool` for details; 'g' means 'wakeup when magic packet comes in'
2049+ # and is the default behavior we want.
2050+ /snap/bin/se-test-tools.ethtool eth0 | grep 'Wake-up: g'
2051+ fi
2052+ ;;
2053+ esac
2054diff --git a/tests/lib/prepare-all.sh b/tests/lib/prepare-all.sh
2055new file mode 100644
2056index 0000000..fa8fb6b
2057--- /dev/null
2058+++ b/tests/lib/prepare-all.sh
2059@@ -0,0 +1,63 @@
2060+#!/bin/bash -x
2061+
2062+# Create a service to get the mac80211_hwsim driver loaded on system
2063+# startup so that we don't need to load it again in our tests as
2064+# load/unload multiple times in a running system can lead to kernel
2065+# crashes.
2066+cat << EOF > /etc/systemd/system/load-mac80211-hwsim.service
2067+[Unit]
2068+Description=Load mac8022_hwsim driver
2069+[Service]
2070+ExecStart=/sbin/modprobe mac80211_hwsim radios=2
2071+[Install]
2072+WantedBy=multi-user.target
2073+EOF
2074+
2075+systemctl enable load-mac80211-hwsim
2076+systemctl start load-mac80211-hwsim
2077+
2078+# We don't have to build a snap when we should use one from a
2079+# channel
2080+if [ -n "$SNAP_CHANNEL" ] ; then
2081+ exit 0
2082+fi
2083+
2084+# If there is a network-manager snap prebuilt for us, lets take
2085+# that one to speed things up.
2086+if [ -f /writable/system-data/network-manager_*_amd64.snap ]; then
2087+ mv /writable/system-data/network-manager_*_amd64.snap /home/network-manager/
2088+fi
2089+if [ -f /home/network-manager/network-manager_*_amd64.snap ] ; then
2090+ exit 0
2091+fi
2092+
2093+# Setup classic snap and build the network-manager snap in there
2094+snap install --devmode --beta classic
2095+cat <<-EOF > /home/test/build-snap.sh
2096+#!/bin/sh
2097+set -ex
2098+
2099+export DEBIAN_FRONTEND=noninteractive
2100+
2101+# FIXME: Enable propose for now until problems with conflicting systemd
2102+# packages between the Ubuntu Core image ppa and the archive are fixed.
2103+echo "deb http://archive.ubuntu.com/ubuntu/ xenial-proposed restricted main universe" > /etc/apt/sources.list.d/ubuntu-proposed.list
2104+echo "deb http://ppa.launchpad.net/snappy-dev/image/ubuntu xenial main" > /etc/apt/sources.list.d/ubuntu-image-ppa.list
2105+
2106+
2107+# Ensure we have the latest updates installed as the core snap
2108+# may be a bit out of date.
2109+apt update
2110+apt -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' full-upgrade -y --force-yes
2111+
2112+apt install -y --force-yes snapcraft
2113+cd /home/network-manager
2114+snapcraft clean
2115+snapcraft
2116+EOF
2117+chmod +x /home/test/build-snap.sh
2118+sudo classic /home/test/build-snap.sh
2119+snap remove classic
2120+
2121+# Make sure we have a snap build
2122+test -e /home/network-manager/network-manager_*_amd64.snap
2123diff --git a/tests/lib/prepare.sh b/tests/lib/prepare.sh
2124new file mode 100644
2125index 0000000..6565405
2126--- /dev/null
2127+++ b/tests/lib/prepare.sh
2128@@ -0,0 +1,46 @@
2129+#!/bin/bash
2130+. $TESTSLIB/utilities.sh
2131+
2132+echo "Wait for firstboot change to be ready"
2133+while ! snap changes | grep -q "Done"; do
2134+ snap changes || true
2135+ snap change 1 || true
2136+ sleep 1
2137+done
2138+
2139+echo "Ensure fundamental snaps are still present"
2140+. $TESTSLIB/snap-names.sh
2141+for name in $gadget_name $kernel_name $core_name; do
2142+ if ! snap list | grep -q $name ; then
2143+ echo "Not all fundamental snaps are available, all-snap image not valid"
2144+ echo "Currently installed snaps:"
2145+ snap list
2146+ exit 1
2147+ fi
2148+done
2149+
2150+# Remove any existing state archive from other test suites
2151+rm -f /home/network-manager/snapd-state.tar.gz
2152+rm -f /home/network-manager/nm-state.tar.gz
2153+
2154+# TODO install from stable once NM 1.10 is released there
2155+snap_install network-manager --channel=1.10/beta
2156+
2157+# Snapshot of the current snapd state for a later restore
2158+systemctl stop snapd.service snapd.socket
2159+tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd /etc/netplan
2160+systemctl start snapd.socket
2161+
2162+# Make sure the original netplan configuration is applied and active
2163+# (we do this before re-starting NM to avoid race conditions in some tests)
2164+netplan generate
2165+netplan apply
2166+
2167+# And also snapshot NetworkManager's state
2168+systemctl stop snap.network-manager.networkmanager
2169+tar czf $SPREAD_PATH/nm-state.tar.gz /var/snap/network-manager
2170+systemctl start snap.network-manager.networkmanager
2171+
2172+# For debugging dump all snaps and connected slots/plugs
2173+snap list
2174+snap interfaces
2175diff --git a/tests/lib/restore-each.sh b/tests/lib/restore-each.sh
2176new file mode 100644
2177index 0000000..b8cdac1
2178--- /dev/null
2179+++ b/tests/lib/restore-each.sh
2180@@ -0,0 +1,40 @@
2181+#!/bin/bash
2182+
2183+. $TESTSLIB/snap-names.sh
2184+. $TESTSLIB/utilities.sh
2185+
2186+# Remove all snaps not being the core, gadget, kernel or snap we're testing
2187+for snap in /snap/*; do
2188+ snap="${snap:6}"
2189+ case "$snap" in
2190+ "bin" | "$gadget_name" | "$kernel_name" | core* | "$SNAP_NAME" )
2191+ ;;
2192+ *)
2193+ snap remove "$snap"
2194+ ;;
2195+ esac
2196+done
2197+
2198+# Drop any generated or modified netplan configuration files. The original
2199+# ones will be restored below.
2200+rm -f /etc/netplan/*
2201+
2202+# Ensure we have the same state for snapd as we had before
2203+systemctl stop snapd.service snapd.socket
2204+rm -rf /var/lib/snapd/*
2205+tar xzf $SPREAD_PATH/snapd-state.tar.gz -C /
2206+rm -rf /root/.snap
2207+systemctl start snapd.service snapd.socket
2208+wait_for_systemd_service snapd.service
2209+wait_for_systemd_service snapd.socket
2210+
2211+# Make sure the original netplan configuration is applied and active
2212+# (we do this before re-starting NM to avoid race conditions in some tests)
2213+netplan generate
2214+netplan apply
2215+
2216+systemctl stop snap.network-manager.networkmanager
2217+rm -rf /var/snap/network-manager/*
2218+tar xzf $SPREAD_PATH/nm-state.tar.gz -C /
2219+systemctl start snap.network-manager.networkmanager
2220+wait_for_network_manager
2221diff --git a/tests/lib/snap-names.sh b/tests/lib/snap-names.sh
2222new file mode 100644
2223index 0000000..f15b09a
2224--- /dev/null
2225+++ b/tests/lib/snap-names.sh
2226@@ -0,0 +1,7 @@
2227+#!/bin/bash
2228+gadget_name=$(snap list | sed -n 's/^\(pc\|pi[23]\|dragonboard\) .*/\1/p')
2229+kernel_name=$gadget_name-kernel
2230+core_name=$(snap list | awk '/^(ubuntu-)?core / {print $1; exit}')
2231+if [ "$kernel_name" = "pi3-kernel" ] ; then
2232+ kernel_name=pi2-kernel
2233+fi
2234diff --git a/tests/lib/utilities.sh b/tests/lib/utilities.sh
2235new file mode 100644
2236index 0000000..6144a89
2237--- /dev/null
2238+++ b/tests/lib/utilities.sh
2239@@ -0,0 +1,166 @@
2240+#!/bin/sh
2241+
2242+snap_install() {
2243+ name=$1
2244+ if [ -n "$SNAP_CHANNEL" ] ; then
2245+ # Don't reinstall if we have it installed already
2246+ if ! snap list | grep $name ; then
2247+ snap install --$SNAP_CHANNEL $name
2248+ fi
2249+ else
2250+ # Need first install from store to get all necessary assertions into
2251+ # place. Second local install will then bring in our locally built
2252+ # snap.
2253+ snap install $name $2
2254+ snap install --dangerous $PROJECT_PATH/$name*_amd64.snap
2255+ fi
2256+}
2257+
2258+switch_netplan_to_network_manager() {
2259+ if [ -e /etc/netplan/00-default-nm-renderer.yaml ] ; then
2260+ return 0
2261+ fi
2262+
2263+ # set 'defaultrenderer' in case the snap is already installed
2264+ if snap list | grep -q network-manager ; then
2265+ snap set network-manager defaultrenderer=true
2266+ # Leave some time for NM wrapper to write netplan config
2267+ repeat_until_done "test -e /etc/netplan/00-default-nm-renderer.yaml"
2268+ else
2269+ cat << EOF > /etc/netplan/00-default-nm-renderer.yaml
2270+network:
2271+ renderer: NetworkManager
2272+EOF
2273+ fi
2274+}
2275+
2276+switch_netplan_to_networkd() {
2277+ if [ ! -e /etc/netplan/00-default-nm-renderer.yaml ] ; then
2278+ return 0
2279+ fi
2280+
2281+ # unset 'defaultrenderer' in case the snap is already installed
2282+ if snap list | grep -q network-manager ; then
2283+ snap set network-manager defaultrenderer=false
2284+ # Leave some time for NM wrapper to remove netplan config
2285+ repeat_until_done "test ! -e /etc/netplan/00-default-nm-renderer.yaml"
2286+ else
2287+ rm /etc/netplan/00-default-nm-renderer.yaml
2288+ fi
2289+}
2290+
2291+# waits for a service to be active. Besides that, waits enough
2292+# time after detecting it to be active to prevent restarting
2293+# same service too quickly several times.
2294+# $1 service name
2295+# $2 start limit interval in seconds (default set to 10. Exec `systemctl show THE_SERVICE -p StartLimitInterval` to verify)
2296+# $3 start limit burst. Times allowed to start the service in start_limit_interval time (default set to 5. Exec `systemctl show THE_SERVICE -p StartLimitBurst` to verify)
2297+wait_for_systemd_service() {
2298+ while ! systemctl status $1 ; do
2299+ sleep 1
2300+ done
2301+ # As debian services default limit is to allow 5 restarts in a 10sec period
2302+ # (StartLimitInterval=10000000 and StartLimitBurst=5), having enough wait time we
2303+ # prevent "service: Start request repeated too quickly" error.
2304+ #
2305+ # You can check those values for certain service by typing:
2306+ # $systemctl show THE_SERVICE -p StartLimitInterval,StartLimitBurst
2307+ #
2308+ if [ $# -ge 2 ]; then
2309+ start_limit_interval = $2
2310+ else
2311+ start_limit_interval=$(systemctl show $1 -p StartLimitInterval | sed 's/StartLimitInterval=//')
2312+ # original limit interval is provided in microseconds.
2313+ start_limit_interval=$((start_limit_interval / 1000000))
2314+ fi
2315+
2316+ if [ $# -eq 3 ]; then
2317+ start_limit_burst = $3
2318+ else
2319+ start_limit_burst=$(systemctl show $1 -p StartLimitBurst | sed 's/StartLimitBurst=//')
2320+ fi
2321+
2322+ # adding 1 to be sure we exceed the limit
2323+ sleep_time=$((1 + $start_limit_interval / $start_limit_burst))
2324+ sleep $sleep_time
2325+}
2326+
2327+wait_for_network_manager() {
2328+ wait_for_systemd_service snap.network-manager.networkmanager
2329+}
2330+
2331+stop_after_first_reboot() {
2332+ if [ $SPREAD_REBOOT -gt 0 ] ; then
2333+ exit 0
2334+ fi
2335+}
2336+
2337+mac_to_ipv6() {
2338+ mac=$1
2339+ ipv6_address=fe80::$(printf %02x $((0x${mac%%:*} ^ 2)))
2340+ mac=${mac#*:}
2341+ ipv6_address=$ipv6_address${mac%:*:*:*}ff:fe
2342+ mac=${mac#*:*:}
2343+ ipv6_address=$ipv6_address${mac%:*}${mac##*:}
2344+ echo $ipv6_address
2345+}
2346+
2347+# Creates an AP using wifi-ap
2348+# $1: SSID name
2349+# $2: Passphrase. If present, AP will use WPA2, otherwise it will be open.
2350+create_ap() {
2351+ if [ $# -lt 1 ]; then
2352+ echo "Not enough arguments for $0"
2353+ return 1
2354+ fi
2355+
2356+ snap install wifi-ap
2357+ # wifi-ap needs a bit of time to settle down
2358+ repeat_until_done 'wifi-ap.status | MATCH "ap.active: true"' 0.5
2359+
2360+ /snap/bin/wifi-ap.config set wifi.interface=wlan0
2361+ /snap/bin/wifi-ap.config set wifi.ssid="$1"
2362+ if [ $# -ge 2 ]; then
2363+ /snap/bin/wifi-ap.config set wifi.security=wpa2
2364+ /snap/bin/wifi-ap.config set wifi.security-passphrase="$2"
2365+ else
2366+ /snap/bin/wifi-ap.config set wifi.security=open
2367+ fi
2368+
2369+ # NM some times still detects the wifi as WPA2 instead of open, so we need
2370+ # to re-start to force it to refresh. See LP: #1704085. Before that, we have
2371+ # to wait to make sure the AP sends the beacon frames so wpa_supplicant
2372+ # detects the AP changes and reports the right environment to the new NM
2373+ # instance.
2374+ sleep 30
2375+
2376+ systemctl restart snap.network-manager.networkmanager.service
2377+ repeat_until_done "busctl status org.freedesktop.NetworkManager &> /dev/null" 0.5
2378+
2379+ repeat_until_done "network-manager.nmcli d wifi | MATCH $1" 5
2380+}
2381+
2382+# $1 instruction to execute repeatedly until complete or max times
2383+# $2 sleep time between retries. Default 1sec
2384+# $3 max_iterations. Default 20
2385+repeat_until_done() {
2386+ timeout=1
2387+ if [ $# -ge 2 ]; then
2388+ timeout=$2
2389+ fi
2390+
2391+ max_iterations=20
2392+ if [ $# -ge 3 ]; then
2393+ max_iterations=$3
2394+ fi
2395+
2396+ i=0
2397+ while [ $i -lt $max_iterations ] ; do
2398+ if $(eval $1) ; then
2399+ break
2400+ fi
2401+ sleep $timeout
2402+ let i=i+1
2403+ done
2404+ test $i -lt $max_iterations
2405+}
2406diff --git a/tests/main/aliases/task.yaml b/tests/main/aliases/task.yaml
2407new file mode 100644
2408index 0000000..1ae0e05
2409--- /dev/null
2410+++ b/tests/main/aliases/task.yaml
2411@@ -0,0 +1,13 @@
2412+summary: Verify aliases provided by the snap are correctly enabled
2413+
2414+execute: |
2415+ # FIXME: Aliases should be not in place automatically unless we
2416+ # have them approved from the store in our snap-declaration assertion.
2417+ test ! -e /snap/bin/nmcli
2418+
2419+ snap alias $SNAP_NAME.nmcli nmcli
2420+
2421+ test -e /snap/bin/nmcli
2422+
2423+ # Verify the alias works without any problems
2424+ /snap/bin/nmcli g
2425diff --git a/tests/main/can-exec-iptables/task.yaml b/tests/main/can-exec-iptables/task.yaml
2426new file mode 100644
2427index 0000000..eeffe75
2428--- /dev/null
2429+++ b/tests/main/can-exec-iptables/task.yaml
2430@@ -0,0 +1,11 @@
2431+summary: Verify the NetworkManager snap is allowed to modify the iptables firewall configuration
2432+
2433+execute: |
2434+ # Running a simple command in the runtime environment of our service
2435+ # binary will tell us if we're allowed to execute the iptables binary
2436+ # from the core snap or not.
2437+ snap run --shell network-manager.networkmanager <<EOF
2438+ set -ex
2439+ export LD_LIBRARY_PATH=/snap/network-manager/current/lib:/snap/network-manager/current/usr/lib:/snap/network-manager/current/lib/$(arch)-linux-gnu:/snap/network-manager/current/usr/lib/$(arch)-linux-gnu:/snap/network-manager/current/usr/lib/NetworkManager
2440+ /snap/network-manager/current/sbin/iptables -L
2441+ EOF
2442diff --git a/tests/main/debug-config-option/task.yaml b/tests/main/debug-config-option/task.yaml
2443new file mode 100644
2444index 0000000..3ffa20e
2445--- /dev/null
2446+++ b/tests/main/debug-config-option/task.yaml
2447@@ -0,0 +1,27 @@
2448+summary: Test network-manager snap debug configuration
2449+
2450+execute: |
2451+ . $TESTSLIB/utilities.sh
2452+
2453+ test "$(snap get network-manager debug.enable)" = "false"
2454+ if journalctl --no-pager -u snap.network-manager.networkmanager.service |
2455+ MATCH "<debug>"; then
2456+ echo "Debug traces found with disabled debug option"
2457+ exit 1
2458+ fi
2459+
2460+ snap set network-manager debug.enable=true
2461+ test "$(snap get network-manager debug.enable)" = "true"
2462+ # NM will create the file after being re-started by the hook, wait a bit
2463+ wait_for_network_manager
2464+ sleep 5
2465+ test -f /var/snap/network-manager/current/.debug_enabled
2466+ network-manager.nmcli g log | MATCH "^DEBUG"
2467+
2468+ snap set network-manager debug.enable=false
2469+ test "$(snap get network-manager debug.enable)" = "false"
2470+ # NM will create the file after being re-started by the hook, wait a bit
2471+ wait_for_network_manager
2472+ sleep 5
2473+ test ! -f /var/snap/network-manager/current/.debug_enabled
2474+ network-manager.nmcli g log | MATCH "^INFO"
2475diff --git a/tests/main/documentation-builds/task.yaml b/tests/main/documentation-builds/task.yaml
2476new file mode 100644
2477index 0000000..fd2a358
2478--- /dev/null
2479+++ b/tests/main/documentation-builds/task.yaml
2480@@ -0,0 +1,14 @@
2481+summary: Verify the project documentation is building without errors
2482+
2483+execute: |
2484+ # Need to install in devmode as otherwise the snap can't access our project
2485+ # home which is outside of the home directory of our current user.
2486+ snap install --devmode documentation-builder
2487+
2488+ outdir=$PROJECT_PATH/docs/snap/build
2489+
2490+ cd $PROJECT_PATH/docs/snap
2491+ /snap/bin/documentation-builder --output-path $outdir
2492+
2493+ # Ensure we have some files in the output directory
2494+ test `find $outdir -type f | wc -l` -gt 0
2495diff --git a/tests/main/ethernet-managed-by-networkmanager/task.yaml b/tests/main/ethernet-managed-by-networkmanager/task.yaml
2496new file mode 100644
2497index 0000000..a3c1b13
2498--- /dev/null
2499+++ b/tests/main/ethernet-managed-by-networkmanager/task.yaml
2500@@ -0,0 +1,16 @@
2501+summary: When defaultrender is set NM manages ethernet
2502+
2503+execute: |
2504+ . $TESTSLIB/utilities.sh
2505+ snap set network-manager defaultrenderer=true
2506+ netplan apply
2507+ # Whenever we can call netplan from the NM snap, the following line won't
2508+ # be needed
2509+ systemctl restart systemd-networkd
2510+ sleep 5
2511+ networkctl | grep 'eth0.*unmanaged'
2512+ wait_for_network_manager
2513+ /snap/bin/network-manager.nmcli d | grep 'eth0.*connected'
2514+ snap set network-manager defaultrenderer=false
2515+ netplan apply
2516+ systemctl restart systemd-networkd
2517diff --git a/tests/main/installation/task.yaml b/tests/main/installation/task.yaml
2518new file mode 100644
2519index 0000000..bdaf48d
2520--- /dev/null
2521+++ b/tests/main/installation/task.yaml
2522@@ -0,0 +1,17 @@
2523+summary: Test network-manager snap installation was successful
2524+
2525+execute: |
2526+ . $TESTSLIB/utilities.sh
2527+
2528+ # Service should be up an running
2529+ wait_for_network_manager
2530+
2531+ # .. and nmcli should be able to reach NetworkManager
2532+ /snap/bin/network-manager.nmcli g
2533+
2534+ # Ensure all necessary plugs/slots are connected
2535+ snap interfaces | grep -Pzq ":network-setup-observe +[a-z,-]*network-manager"
2536+ snap interfaces | grep -Pzq ":ppp +[a-z,-]*network-manager"
2537+ snap interfaces | grep -Pzq ":firewall-control +[a-z,-]*network-manager"
2538+ snap interfaces | grep -Pzq ":network-setup-observe +[a-z,-]*network-manager"
2539+ snap interfaces | grep -Pzq "network-manager:service +network-manager:nmcli"
2540diff --git a/tests/main/set-hostname/task.yaml b/tests/main/set-hostname/task.yaml
2541new file mode 100644
2542index 0000000..69b27c8
2543--- /dev/null
2544+++ b/tests/main/set-hostname/task.yaml
2545@@ -0,0 +1,17 @@
2546+summary: Verify we can modify the hostname of the system
2547+
2548+execute: |
2549+ . "$TESTSLIB/utilities.sh"
2550+
2551+ wait_for_network_manager
2552+
2553+ # Print out current hostname for nm and hostnamed to have a reference
2554+ # for debugging later.
2555+ /snap/bin/network-manager.nmcli general hostname
2556+ hostnamectl
2557+
2558+ expected_hostname=foobar
2559+ /snap/bin/network-manager.nmcli general hostname $expected_hostname
2560+ test "`/snap/bin/network-manager.nmcli general hostname`" = "$expected_hostname"
2561+ test "`hostnamectl status | grep Static`" = " Static hostname: $expected_hostname"
2562+ test "`hostname`" = "$expected_hostname"
2563diff --git a/tests/main/static-ip-configuration/task.yaml b/tests/main/static-ip-configuration/task.yaml
2564new file mode 100644
2565index 0000000..6c86dda
2566--- /dev/null
2567+++ b/tests/main/static-ip-configuration/task.yaml
2568@@ -0,0 +1,49 @@
2569+summary: Test static IP configuration
2570+
2571+restore: |
2572+ # Ensure that the created virtual network interfaces are removed
2573+ # in any case when we're done
2574+ if [ -e /sys/class/net/veth0 ] ; then
2575+ ip link delete veth0
2576+ fi
2577+
2578+execute: |
2579+ . $TESTSLIB/utilities.sh
2580+
2581+ ip link add dev veth0 type veth peer name veth1
2582+
2583+ wait_for_network_manager
2584+ # NetworkManager should ignore the other side of our pipe so
2585+ # that we can configure it statically.
2586+ /snap/bin/network-manager.nmcli d set veth1 managed no
2587+ ip addr add 10.0.1.1/24 dev veth1
2588+
2589+ connection=veth0-static
2590+ /snap/bin/network-manager.nmcli c add con-name $connection type ethernet ifname veth0 \
2591+ ip4 10.0.1.2/24
2592+ /snap/bin/network-manager.nmcli c up $connection
2593+ /snap/bin/network-manager.nmcli d | grep 'veth0.*connected'
2594+
2595+ # Address should be correctly applied now
2596+ expected_veth0_address="10.0.1.2/24"
2597+ /snap/bin/network-manager.nmcli -m multiline -f IP4.ADDRESS c show veth0-static | grep $expected_veth0_address
2598+ ip addr show dev veth0 | grep 'UP'
2599+ ip addr show dev veth0 | grep $expected_veth0_address
2600+
2601+ # Routing needs to be in place as well
2602+ expected_veth0_route="10.0.1.0/24 dev veth0 proto kernel scope link src 10.0.1.2 metric 101"
2603+ ip route | grep "$expected_veth0_route"
2604+
2605+ # Disable connection and ensure IP configuration is removed
2606+ /snap/bin/network-manager.nmcli c down $connection
2607+ ip addr show dev veth0 | grep -v $expected_veth0_address
2608+ ip route | grep -v "$expected_veth0_route"
2609+
2610+ # Enabling network connection again and removing it should remove
2611+ # the IP configuration too
2612+ /snap/bin/network-manager.nmcli c up $connection
2613+ ip addr show dev veth0 | grep $expected_veth0_address
2614+ ip route | grep "$expected_veth0_route"
2615+ /snap/bin/network-manager.nmcli c delete $connection
2616+ ip addr show dev veth0 | grep -v $expected_veth0_address
2617+ ip route | grep -v "$expected_veth0_route"
2618diff --git a/tests/main/wifi-connect-secured-ap/task.yaml b/tests/main/wifi-connect-secured-ap/task.yaml
2619new file mode 100644
2620index 0000000..46c2ba6
2621--- /dev/null
2622+++ b/tests/main/wifi-connect-secured-ap/task.yaml
2623@@ -0,0 +1,14 @@
2624+summary: Test connection to a secured WiFi AP
2625+
2626+environment:
2627+ WIFI_SSID: Ubuntu
2628+ WIFI_PASSPHRASE: Test1234
2629+
2630+execute: |
2631+ . $TESTSLIB/utilities.sh
2632+
2633+ create_ap "$WIFI_SSID" "$WIFI_PASSPHRASE"
2634+
2635+ # Connect to the AP and ensure the connection was established
2636+ /snap/bin/network-manager.nmcli d wifi connect $WIFI_SSID password $WIFI_PASSPHRASE
2637+ /snap/bin/network-manager.nmcli d | grep 'wlan1.*connected'
2638diff --git a/tests/main/wifi-powersave-config-option/task.yaml b/tests/main/wifi-powersave-config-option/task.yaml
2639new file mode 100644
2640index 0000000..621256e
2641--- /dev/null
2642+++ b/tests/main/wifi-powersave-config-option/task.yaml
2643@@ -0,0 +1,31 @@
2644+summary: Verify WiFi powersave can be enabled via a snap config option
2645+
2646+environment:
2647+ WIFI_POWERSAVE_CONF_PATH: /var/snap/network-manager/current/conf.d/wifi-powersave.conf
2648+
2649+execute: |
2650+ . $TESTSLIB/utilities.sh
2651+
2652+ # The mac80211_hwsim driver does not support the powersave mode
2653+ # so we can't check this reliable.
2654+
2655+ test "`snap get network-manager wifi.powersave`" = "disabled"
2656+ grep "wifi.powersave = 2" $WIFI_POWERSAVE_CONF_PATH
2657+
2658+ # Try to enable and disable again
2659+ snap set network-manager wifi.powersave=enabled
2660+ wait_for_network_manager
2661+ test "`snap get network-manager wifi.powersave`" = "enabled"
2662+ grep "wifi.powersave = 3" $WIFI_POWERSAVE_CONF_PATH
2663+
2664+ snap set network-manager wifi.powersave=disabled
2665+ wait_for_network_manager
2666+ test "`snap get network-manager wifi.powersave`" = "disabled"
2667+ grep "wifi.powersave = 2" $WIFI_POWERSAVE_CONF_PATH
2668+
2669+ # Specifying no value means the snap should use the default
2670+ # which is 'disable'
2671+ snap set network-manager wifi.powersave=
2672+ wait_for_network_manager
2673+ test "`snap get network-manager wifi.powersave`" = "disabled"
2674+ grep "wifi.powersave = 2" $WIFI_POWERSAVE_CONF_PATH
2675diff --git a/tests/main/wifi-wowlan-config-option/task.yaml b/tests/main/wifi-wowlan-config-option/task.yaml
2676new file mode 100644
2677index 0000000..a0e1e0b
2678--- /dev/null
2679+++ b/tests/main/wifi-wowlan-config-option/task.yaml
2680@@ -0,0 +1,77 @@
2681+summary: Verify WiFi WoWLAN can be enabled via a snap config option
2682+
2683+environment:
2684+ WIFI_WOWL_CONF_PATH: /var/snap/network-manager/current/conf.d/wifi-wowlan.conf
2685+
2686+execute: |
2687+ . $TESTSLIB/utilities.sh
2688+
2689+ # The mac80211_hwsim driver does not support WoWLAN so we can't
2690+ # check this reliable on the hardware level and will only check
2691+ # in the following that the correct configuration for
2692+ # NetworkManager itself is written out.
2693+
2694+ test `snap get network-manager wifi.wake-on-wlan` = disabled
2695+ grep "^wifi.wake-on-wlan=0$" $WIFI_WOWL_CONF_PATH
2696+
2697+ test "`snap get network-manager wifi.wake-on-wlan-password`" = ""
2698+ grep -v "^wifi.wake-on-wlan-password=.*$" $WIFI_WOWL_CONF_PATH
2699+
2700+ snap set network-manager wifi.wake-on-wlan-password=Test1234
2701+ wait_for_network_manager
2702+ grep "^wifi.wake-on-wlan-password=Test1234$" $WIFI_WOWL_CONF_PATH
2703+ # Setting the password alone should keep the actual WoWLAN value
2704+ # still unset so that NetworkManager uses its default.
2705+ grep -v "^wifi.wake-on-wlan=.*$" $WIFI_WOWL_CONF_PATH
2706+
2707+ snap set network-manager wifi.wake-on-wlan=magic
2708+ wait_for_network_manager
2709+ grep "^wifi.wake-on-wlan=8$" $WIFI_WOWL_CONF_PATH
2710+ grep "^wifi.wake-on-wlan-password=Test1234$" $WIFI_WOWL_CONF_PATH
2711+
2712+ # Test all other possible keys for the wifi.wake-on-wlan option
2713+ snap set network-manager wifi.wake-on-wlan=disabled
2714+ wait_for_network_manager
2715+ grep "^wifi.wake-on-wlan=0$" $WIFI_WOWL_CONF_PATH
2716+
2717+ snap set network-manager wifi.wake-on-wlan=any
2718+ wait_for_network_manager
2719+ grep "^wifi.wake-on-wlan=2$" $WIFI_WOWL_CONF_PATH
2720+
2721+ snap set network-manager wifi.wake-on-wlan=disconnect
2722+ wait_for_network_manager
2723+ grep "^wifi.wake-on-wlan=4$" $WIFI_WOWL_CONF_PATH
2724+
2725+ snap set network-manager wifi.wake-on-wlan=magic
2726+ wait_for_network_manager
2727+ grep "^wifi.wake-on-wlan=8$" $WIFI_WOWL_CONF_PATH
2728+
2729+ snap set network-manager wifi.wake-on-wlan=gtk-rekey-failure
2730+ wait_for_network_manager
2731+ grep "^wifi.wake-on-wlan=16$" $WIFI_WOWL_CONF_PATH
2732+
2733+ snap set network-manager wifi.wake-on-wlan=eap-identity-request
2734+ wait_for_network_manager
2735+ grep "^wifi.wake-on-wlan=32$" $WIFI_WOWL_CONF_PATH
2736+
2737+ snap set network-manager wifi.wake-on-wlan=4way-handshake
2738+ wait_for_network_manager
2739+ grep "^wifi.wake-on-wlan=64$" $WIFI_WOWL_CONF_PATH
2740+
2741+ snap set network-manager wifi.wake-on-wlan=rfkill-release
2742+ wait_for_network_manager
2743+ grep "^wifi.wake-on-wlan=128$" $WIFI_WOWL_CONF_PATH
2744+
2745+ snap set network-manager wifi.wake-on-wlan=tcp
2746+ wait_for_network_manager
2747+ grep "^wifi.wake-on-wlan=256$" $WIFI_WOWL_CONF_PATH
2748+
2749+ # Not setting any concrete value should remove the configuration
2750+ snap set network-manager wifi.wake-on-wlan-password=
2751+ wait_for_network_manager
2752+ grep -v "^wifi.wake-on-wlan-password=.*$" $WIFI_WOWL_CONF_PATH
2753+
2754+ snap set network-manager wifi.wake-on-wlan=
2755+ wait_for_network_manager
2756+ grep -v "^wifi.wake-on-wlan=.*$" $WIFI_WOWL_CONF_PATH
2757+ grep -v "^wifi.wake-on-wlan-password=.*$" $WIFI_WOWL_CONF_PATH
2758diff --git a/tests/main/wifi-wowlan-enabled-correctly/task.yaml b/tests/main/wifi-wowlan-enabled-correctly/task.yaml
2759new file mode 100644
2760index 0000000..8fcaecc
2761--- /dev/null
2762+++ b/tests/main/wifi-wowlan-enabled-correctly/task.yaml
2763@@ -0,0 +1,30 @@
2764+summary: Verify WiFi WoWLAN can be enabled in NetworkManager globally via a snap config option
2765+
2766+execute: |
2767+ . $TESTSLIB/utilities.sh
2768+
2769+ # Enable WoWLAN globally for all new WiFi connections
2770+ snap set network-manager wifi.wake-on-wlan=any
2771+ wait_for_network_manager
2772+
2773+ # Get us an AP via the wifi-ap we can use to create a connection to
2774+ create_ap Ubuntu
2775+
2776+ # Connect to the AP and ensure the connection was established
2777+ /snap/bin/network-manager.nmcli d wifi | grep Ubuntu
2778+ /snap/bin/network-manager.nmcli d wifi connect Ubuntu
2779+ /snap/bin/network-manager.nmcli d | grep 'wlan1.*connected'
2780+
2781+ # Now that we're connected a new connection exists which we can look at
2782+ # to verify that the WoWLAN key is correctly set.
2783+ /snap/bin/network-manager.nmcli c show Ubuntu | grep '802-11-wireless.wake-on-wlan:.*0x1 (default)'
2784+
2785+ if [ "$SPREAD_SYSTEM" = "hw-ubuntu-core-16" ]; then
2786+ if ! iw phy phy0 info | grep -q "WoWLAN support:" ; then
2787+ echo "INFO: Hardware does not support WoWLAN so we're not testing application"
2788+ echo " of the configuration option on the hardware."
2789+ exit 0
2790+ fi
2791+ iw phy phy0 wowlan show | grep "WoWLAN is enabled"
2792+ iw phy phy0 wowlan show | grep "wake up on special any trigger"
2793+ fi

Subscribers

People subscribed via source and target branches