Merge ~morphis/snappy-hwe-snaps/+git/network-manager:powersave-configuration into ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:master

Proposed by Simon Fels
Status: Merged
Approved by: Simon Fels
Approved revision: 639d7ce78b40bea7ac3db467a76fb95578346b6e
Merged at revision: 0be7e8ba7b2d2243c45c3fe119ad3f7e18419685
Proposed branch: ~morphis/snappy-hwe-snaps/+git/network-manager:powersave-configuration
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:master
Diff against target: 277 lines (+124/-37)
9 files modified
README.md (+15/-0)
hooks/configure (+33/-0)
spread.yaml (+0/-7)
tests/full/wol-enabled-by-default/task.yaml (+1/-1)
tests/lib/prepare-all.sh (+6/-0)
tests/lib/prepare.sh (+18/-19)
tests/lib/restore-each.sh (+7/-10)
tests/lib/utilities.sh (+16/-0)
tests/main/wifi-powersave-config-option/task.yaml (+28/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Jim Hodapp (community) Approve
Alfonso Sanchez-Beato Approve
Tony Espy Pending
Review via email: mp+312898@code.launchpad.net

Description of the change

Implement configure hook to accept wifi.powersave option.

This will default to "disable" to keep powersave mode off.

The hook itself isn't enabled in the default snap build yet because snapcraft doesn't support hooks yet. In the spread test we're copying the hook manually in place to be able to test it properly.

To post a comment you must log in.
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Some comments below. Two additional points:

1. Please rebase and force-push to reduce the number of commits so history is cleaner.

2. As hooks are not currently supported by snapcraft, there are additional steps for building the snap. Please comment on how to do this in README.md, or better, provide a script/makefile that makes the build.

review: Needs Fixing
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
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
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

LGTM

review: Approve
Revision history for this message
Jim Hodapp (jhodapp) wrote :

One minor typo to fix, see inline below.

review: Needs Fixing (code)
Revision history for this message
Simon Fels (morphis) wrote :

@Jim: Fixed.

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
Jim Hodapp (jhodapp) wrote :

LGTM

review: Approve
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
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)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/README.md b/README.md
2index a8fec2f..8b92863 100644
3--- a/README.md
4+++ b/README.md
5@@ -2,6 +2,21 @@
6
7 This is the snap to package the NetworkManager management service.
8
9+## Hook support
10+
11+All implemented hooks are stored inside the hooks directory.
12+
13+As snapcraft has no support as of today (09/12/2016) to include
14+hooks in a snap this always needs to be done manually. For this
15+
16+$ snapcraft
17+$ cp -r hooks prime/meta/
18+$ snapcraft snap prime
19+
20+does the job. Please note that none of the snaps available from the
21+store will have these hooks included until snapcraft receives
22+support for hooks.
23+
24 ## Running tests
25
26 We have a set of spread (https://github.com/snapcore/spread) tests which
27diff --git a/hooks/configure b/hooks/configure
28new file mode 100755
29index 0000000..1d3399e
30--- /dev/null
31+++ b/hooks/configure
32@@ -0,0 +1,33 @@
33+#!/bin/bash
34+wifi_powersave_default="disable"
35+wifi_powersave_conf_path=$SNAP_DATA/conf.d/wifi-powersave.conf
36+
37+switch_wifi_powersave() {
38+ # See https://developer.gnome.org/libnm/stable/NMSettingWireless.html#NMSettingWirelessPowersave
39+ # for the meaning of the different values for the wifi.powersave option.
40+ case $1 in
41+ enable)
42+ cat << EOF > $wifi_powersave_conf_path
43+[connection]
44+wifi.powersave = 3
45+EOF
46+ ;;
47+ disable)
48+ cat << EOF > $wifi_powersave_conf_path
49+[connection]
50+wifi.powersave = 2
51+EOF
52+ ;;
53+ *)
54+ echo "WARNING: invalid value '$1' supplied for wifi.powersave configuration option"
55+ ;;
56+ esac
57+}
58+
59+wifi_powersave="`snapctl get wifi.powersave`"
60+if [ -n "$wifi_powersave" ]; then
61+ switch_wifi_powersave $wifi_powersave
62+else
63+ snapctl set wifi.powersave=$wifi_powersave_default
64+ switch_wifi_powersave $wifi_powersave_default
65+fi
66diff --git a/spread.yaml b/spread.yaml
67index d718813..0ae35a2 100644
68--- a/spread.yaml
69+++ b/spread.yaml
70@@ -55,9 +55,6 @@ suites:
71 prepare: |
72 . $TESTSLIB/utilities.sh
73 stop_after_first_reboot
74- # Force snapd state to be regenerated so that it also preserves
75- # the netplan renderer switch configuration file.
76- rm -f /home/network-manager/snapd-state.tar.gz
77 switch_netplan_to_network_manager
78 . $TESTSLIB/prepare.sh
79 REBOOT
80@@ -67,8 +64,4 @@ suites:
81 . $TESTSLIB/utilities.sh
82 stop_after_first_reboot
83 switch_netplan_to_networkd
84- # Need to drop the state here as it includes the netplan config
85- # which configures us to use NetworkManager as renderer. The
86- # prepare script run for the next suite will regenerate it.
87- rm -f /home/network-manager/snapd-state.tar.gz
88 REBOOT
89diff --git a/tests/full/wol-enabled-by-default/task.yaml b/tests/full/wol-enabled-by-default/task.yaml
90index 434ef01..4e1989d 100644
91--- a/tests/full/wol-enabled-by-default/task.yaml
92+++ b/tests/full/wol-enabled-by-default/task.yaml
93@@ -44,7 +44,7 @@ execute: |
94 # We can sadly only verify that the value was correctly applied when
95 # we're running the tests on a real device. QEMU doesn't support setting
96 # the WoL value of the ethernet network device.
97- if [ ! cat /proc/cpuinfo | grep QEMU ] ; then
98+ if [ -z "`cat /proc/cpuinfo | grep QEMU`" ] ; then
99 # Get the tools snap to have the ethtool tool available
100 snap install --devmode --edge se-test-tools
101 snap connect se-test-tools:network core
102diff --git a/tests/lib/prepare-all.sh b/tests/lib/prepare-all.sh
103index 6632406..f8b2eb2 100644
104--- a/tests/lib/prepare-all.sh
105+++ b/tests/lib/prepare-all.sh
106@@ -22,6 +22,12 @@ apt install -y --force-yes snapcraft
107 cd /home/network-manager
108 snapcraft clean
109 snapcraft
110+# If we have any hooks we need to copy them in place as long as
111+# snapcraft does not support them
112+if [ -d hooks ]; then
113+ cp -r hooks prime/meta
114+ snapcraft snap prime
115+fi
116 EOF
117 chmod +x /home/test/build-snap.sh
118 sudo classic /home/test/build-snap.sh
119diff --git a/tests/lib/prepare.sh b/tests/lib/prepare.sh
120index d290bbc..57d24b5 100644
121--- a/tests/lib/prepare.sh
122+++ b/tests/lib/prepare.sh
123@@ -1,4 +1,5 @@
124 #!/bin/bash
125+. $TESTSLIB/utilities.sh
126
127 echo "Wait for firstboot change to be ready"
128 while ! snap changes | grep -q "Done"; do
129@@ -21,27 +22,25 @@ done
130 echo "Kernel has a store revision"
131 snap list | grep ^${kernel_name} | grep -E " [0-9]+\s+canonical"
132
133-# If we don't install network-manager here we get a system
134-# without any network connectivity after reboot.
135-if [ -n "$SNAP_CHANNEL" ] ; then
136- # Don't reinstall if we have it installed already
137- if ! snap list | grep network-manager ; then
138- snap install --$SNAP_CHANNEL network-manager
139- fi
140-else
141- # Need first install from store to get all necessary assertions into
142- # place. Second local install will then bring in our locally built
143- # snap.
144- snap install network-manager
145- snap install --dangerous /home/network-manager/network-manager_*_amd64.snap
146-fi
147+# Remove any existing state archive from other test suites
148+rm -f /home/network-manager/snapd-state.tar.gz
149+rm -f /home/network-manager/nm-state.tar.gz
150+
151+snap_install network-manager
152
153 # Snapshot of the current snapd state for a later restore
154-if [ ! -f $SPREAD_PATH/snapd-state.tar.gz ] ; then
155- systemctl stop snapd.service snapd.socket
156- tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd /etc/netplan
157- systemctl start snapd.socket
158-fi
159+systemctl stop snapd.service snapd.socket
160+tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd /etc/netplan
161+systemctl start snapd.socket
162+
163+# And also snapshot NetworkManager's state
164+systemctl stop snap.network-manager.networkmanager
165+tar czf $SPREAD_PATH/nm-state.tar.gz /var/snap/network-manager
166+systemctl start snap.network-manager.networkmanager
167+
168+# Make sure the original netplan configuration is applied and active
169+netplan generate
170+netplan apply
171
172 # For debugging dump all snaps and connected slots/plugs
173 snap list
174diff --git a/tests/lib/restore-each.sh b/tests/lib/restore-each.sh
175index bd397e1..87ae5cb 100644
176--- a/tests/lib/restore-each.sh
177+++ b/tests/lib/restore-each.sh
178@@ -1,6 +1,7 @@
179 #!/bin/bash
180
181 . $TESTSLIB/snap-names.sh
182+. $TESTSLIB/utilities.sh
183
184 # Remove all snaps not being the core, gadget, kernel or snap we're testing
185 for snap in /snap/*; do
186@@ -14,12 +15,6 @@ for snap in /snap/*; do
187 esac
188 done
189
190-# Cleanup all configuration files from NetworkManager so that we have
191-# a fresh start for the next test
192-rm -rf /var/snap/network-manager/common/*
193-rm -rf /var/snap/network-manager/current/*
194-systemctl stop snap.network-manager.networkmanager
195-
196 # Drop any generated or modified netplan configuration files. The original
197 # ones will be restored below.
198 rm -f /etc/netplan/*
199@@ -27,13 +22,15 @@ rm -f /etc/netplan/*
200 # Ensure we have the same state for snapd as we had before
201 systemctl stop snapd.service snapd.socket
202 rm -rf /var/lib/snapd/*
203-$(cd / && tar xzf $SPREAD_PATH/snapd-state.tar.gz)
204+tar xzf $SPREAD_PATH/snapd-state.tar.gz -C /
205 rm -rf /root/.snap
206 systemctl start snapd.service snapd.socket
207
208+systemctl stop snap.network-manager.networkmanager
209+rm -rf /var/snap/network-manager/*
210+tar xzf $SPREAD_PATH/nm-state.tar.gz -C /
211+systemctl start snap.network-manager.networkmanager
212+
213 # Make sure the original netplan configuration is applied and active
214 netplan generate
215 netplan apply
216-
217-# Bringup NetworkManager again now that the system is restored
218-systemctl start snap.network-manager.networkmanager
219diff --git a/tests/lib/utilities.sh b/tests/lib/utilities.sh
220index 000ef74..8ca1418 100644
221--- a/tests/lib/utilities.sh
222+++ b/tests/lib/utilities.sh
223@@ -1,4 +1,20 @@
224 #!/bin/sh
225+snap_install() {
226+ name=$1
227+ if [ -n "$SNAP_CHANNEL" ] ; then
228+ # Don't reinstall if we have it installed already
229+ if ! snap list | grep $name ; then
230+ snap install --$SNAP_CHANNEL $name
231+ fi
232+ else
233+ # Need first install from store to get all necessary assertions into
234+ # place. Second local install will then bring in our locally built
235+ # snap.
236+ snap install $name
237+ snap install --dangerous $PROJECT_PATH/$name*_amd64.snap
238+ fi
239+}
240+
241 switch_netplan_to_network_manager() {
242 if [ -e /etc/netplan/00-default-nm-renderer.yaml ] ; then
243 return 0
244diff --git a/tests/main/wifi-powersave-config-option/task.yaml b/tests/main/wifi-powersave-config-option/task.yaml
245new file mode 100644
246index 0000000..4711069
247--- /dev/null
248+++ b/tests/main/wifi-powersave-config-option/task.yaml
249@@ -0,0 +1,28 @@
250+summary: Verify WiFi powersave can be enabled via a snap config option
251+
252+environment:
253+ WIFI_POWERSAVE_CONF_PATH: /var/snap/network-manager/current/conf.d/wifi-powersave.conf
254+
255+execute: |
256+ . $TESTSLIB/utilities.sh
257+
258+ # The mac80211_hwsim driver does not support the powersave mode
259+ # so we can't check this reliable.
260+
261+ test "`snap get network-manager wifi.powersave`" = "disable"
262+ grep "wifi.powersave = 2" $WIFI_POWERSAVE_CONF_PATH
263+
264+ # Try to enable and disable again
265+ snap set network-manager wifi.powersave=enable
266+ test "`snap get network-manager wifi.powersave`" = "enable"
267+ grep "wifi.powersave = 3" $WIFI_POWERSAVE_CONF_PATH
268+
269+ snap set network-manager wifi.powersave=disable
270+ test "`snap get network-manager wifi.powersave`" = "disable"
271+ grep "wifi.powersave = 2" $WIFI_POWERSAVE_CONF_PATH
272+
273+ # Specifying no value means the snap should use the default
274+ # which is 'disable'
275+ snap set network-manager wifi.powersave=
276+ test "`snap get network-manager wifi.powersave`" = "disable"
277+ grep "wifi.powersave = 2" $WIFI_POWERSAVE_CONF_PATH

Subscribers

People subscribed via source and target branches