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
diff --git a/README.md b/README.md
index a8fec2f..8b92863 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,21 @@
22
3This is the snap to package the NetworkManager management service.3This is the snap to package the NetworkManager management service.
44
5## Hook support
6
7All implemented hooks are stored inside the hooks directory.
8
9As snapcraft has no support as of today (09/12/2016) to include
10hooks in a snap this always needs to be done manually. For this
11
12$ snapcraft
13$ cp -r hooks prime/meta/
14$ snapcraft snap prime
15
16does the job. Please note that none of the snaps available from the
17store will have these hooks included until snapcraft receives
18support for hooks.
19
5## Running tests20## Running tests
621
7We have a set of spread (https://github.com/snapcore/spread) tests which22We have a set of spread (https://github.com/snapcore/spread) tests which
diff --git a/hooks/configure b/hooks/configure
8new file mode 10075523new file mode 100755
index 0000000..1d3399e
--- /dev/null
+++ b/hooks/configure
@@ -0,0 +1,33 @@
1#!/bin/bash
2wifi_powersave_default="disable"
3wifi_powersave_conf_path=$SNAP_DATA/conf.d/wifi-powersave.conf
4
5switch_wifi_powersave() {
6 # See https://developer.gnome.org/libnm/stable/NMSettingWireless.html#NMSettingWirelessPowersave
7 # for the meaning of the different values for the wifi.powersave option.
8 case $1 in
9 enable)
10 cat << EOF > $wifi_powersave_conf_path
11[connection]
12wifi.powersave = 3
13EOF
14 ;;
15 disable)
16 cat << EOF > $wifi_powersave_conf_path
17[connection]
18wifi.powersave = 2
19EOF
20 ;;
21 *)
22 echo "WARNING: invalid value '$1' supplied for wifi.powersave configuration option"
23 ;;
24 esac
25}
26
27wifi_powersave="`snapctl get wifi.powersave`"
28if [ -n "$wifi_powersave" ]; then
29 switch_wifi_powersave $wifi_powersave
30else
31 snapctl set wifi.powersave=$wifi_powersave_default
32 switch_wifi_powersave $wifi_powersave_default
33fi
diff --git a/spread.yaml b/spread.yaml
index d718813..0ae35a2 100644
--- a/spread.yaml
+++ b/spread.yaml
@@ -55,9 +55,6 @@ suites:
55 prepare: |55 prepare: |
56 . $TESTSLIB/utilities.sh56 . $TESTSLIB/utilities.sh
57 stop_after_first_reboot57 stop_after_first_reboot
58 # Force snapd state to be regenerated so that it also preserves
59 # the netplan renderer switch configuration file.
60 rm -f /home/network-manager/snapd-state.tar.gz
61 switch_netplan_to_network_manager58 switch_netplan_to_network_manager
62 . $TESTSLIB/prepare.sh59 . $TESTSLIB/prepare.sh
63 REBOOT60 REBOOT
@@ -67,8 +64,4 @@ suites:
67 . $TESTSLIB/utilities.sh64 . $TESTSLIB/utilities.sh
68 stop_after_first_reboot65 stop_after_first_reboot
69 switch_netplan_to_networkd66 switch_netplan_to_networkd
70 # Need to drop the state here as it includes the netplan config
71 # which configures us to use NetworkManager as renderer. The
72 # prepare script run for the next suite will regenerate it.
73 rm -f /home/network-manager/snapd-state.tar.gz
74 REBOOT67 REBOOT
diff --git a/tests/full/wol-enabled-by-default/task.yaml b/tests/full/wol-enabled-by-default/task.yaml
index 434ef01..4e1989d 100644
--- a/tests/full/wol-enabled-by-default/task.yaml
+++ b/tests/full/wol-enabled-by-default/task.yaml
@@ -44,7 +44,7 @@ execute: |
44 # We can sadly only verify that the value was correctly applied when44 # We can sadly only verify that the value was correctly applied when
45 # we're running the tests on a real device. QEMU doesn't support setting45 # we're running the tests on a real device. QEMU doesn't support setting
46 # the WoL value of the ethernet network device.46 # the WoL value of the ethernet network device.
47 if [ ! cat /proc/cpuinfo | grep QEMU ] ; then47 if [ -z "`cat /proc/cpuinfo | grep QEMU`" ] ; then
48 # Get the tools snap to have the ethtool tool available48 # Get the tools snap to have the ethtool tool available
49 snap install --devmode --edge se-test-tools49 snap install --devmode --edge se-test-tools
50 snap connect se-test-tools:network core50 snap connect se-test-tools:network core
diff --git a/tests/lib/prepare-all.sh b/tests/lib/prepare-all.sh
index 6632406..f8b2eb2 100644
--- a/tests/lib/prepare-all.sh
+++ b/tests/lib/prepare-all.sh
@@ -22,6 +22,12 @@ apt install -y --force-yes snapcraft
22cd /home/network-manager22cd /home/network-manager
23snapcraft clean23snapcraft clean
24snapcraft24snapcraft
25# If we have any hooks we need to copy them in place as long as
26# snapcraft does not support them
27if [ -d hooks ]; then
28 cp -r hooks prime/meta
29 snapcraft snap prime
30fi
25EOF31EOF
26chmod +x /home/test/build-snap.sh32chmod +x /home/test/build-snap.sh
27sudo classic /home/test/build-snap.sh33sudo classic /home/test/build-snap.sh
diff --git a/tests/lib/prepare.sh b/tests/lib/prepare.sh
index d290bbc..57d24b5 100644
--- a/tests/lib/prepare.sh
+++ b/tests/lib/prepare.sh
@@ -1,4 +1,5 @@
1#!/bin/bash1#!/bin/bash
2. $TESTSLIB/utilities.sh
23
3echo "Wait for firstboot change to be ready"4echo "Wait for firstboot change to be ready"
4while ! snap changes | grep -q "Done"; do5while ! snap changes | grep -q "Done"; do
@@ -21,27 +22,25 @@ done
21echo "Kernel has a store revision"22echo "Kernel has a store revision"
22snap list | grep ^${kernel_name} | grep -E " [0-9]+\s+canonical"23snap list | grep ^${kernel_name} | grep -E " [0-9]+\s+canonical"
2324
24# If we don't install network-manager here we get a system25# Remove any existing state archive from other test suites
25# without any network connectivity after reboot.26rm -f /home/network-manager/snapd-state.tar.gz
26if [ -n "$SNAP_CHANNEL" ] ; then27rm -f /home/network-manager/nm-state.tar.gz
27 # Don't reinstall if we have it installed already28
28 if ! snap list | grep network-manager ; then29snap_install network-manager
29 snap install --$SNAP_CHANNEL network-manager
30 fi
31else
32 # Need first install from store to get all necessary assertions into
33 # place. Second local install will then bring in our locally built
34 # snap.
35 snap install network-manager
36 snap install --dangerous /home/network-manager/network-manager_*_amd64.snap
37fi
3830
39# Snapshot of the current snapd state for a later restore31# Snapshot of the current snapd state for a later restore
40if [ ! -f $SPREAD_PATH/snapd-state.tar.gz ] ; then32systemctl stop snapd.service snapd.socket
41 systemctl stop snapd.service snapd.socket33tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd /etc/netplan
42 tar czf $SPREAD_PATH/snapd-state.tar.gz /var/lib/snapd /etc/netplan34systemctl start snapd.socket
43 systemctl start snapd.socket35
44fi36# And also snapshot NetworkManager's state
37systemctl stop snap.network-manager.networkmanager
38tar czf $SPREAD_PATH/nm-state.tar.gz /var/snap/network-manager
39systemctl start snap.network-manager.networkmanager
40
41# Make sure the original netplan configuration is applied and active
42netplan generate
43netplan apply
4544
46# For debugging dump all snaps and connected slots/plugs45# For debugging dump all snaps and connected slots/plugs
47snap list46snap list
diff --git a/tests/lib/restore-each.sh b/tests/lib/restore-each.sh
index bd397e1..87ae5cb 100644
--- a/tests/lib/restore-each.sh
+++ b/tests/lib/restore-each.sh
@@ -1,6 +1,7 @@
1#!/bin/bash1#!/bin/bash
22
3. $TESTSLIB/snap-names.sh3. $TESTSLIB/snap-names.sh
4. $TESTSLIB/utilities.sh
45
5# Remove all snaps not being the core, gadget, kernel or snap we're testing6# Remove all snaps not being the core, gadget, kernel or snap we're testing
6for snap in /snap/*; do7for snap in /snap/*; do
@@ -14,12 +15,6 @@ for snap in /snap/*; do
14 esac15 esac
15done16done
1617
17# Cleanup all configuration files from NetworkManager so that we have
18# a fresh start for the next test
19rm -rf /var/snap/network-manager/common/*
20rm -rf /var/snap/network-manager/current/*
21systemctl stop snap.network-manager.networkmanager
22
23# Drop any generated or modified netplan configuration files. The original18# Drop any generated or modified netplan configuration files. The original
24# ones will be restored below.19# ones will be restored below.
25rm -f /etc/netplan/*20rm -f /etc/netplan/*
@@ -27,13 +22,15 @@ rm -f /etc/netplan/*
27# Ensure we have the same state for snapd as we had before22# Ensure we have the same state for snapd as we had before
28systemctl stop snapd.service snapd.socket23systemctl stop snapd.service snapd.socket
29rm -rf /var/lib/snapd/*24rm -rf /var/lib/snapd/*
30$(cd / && tar xzf $SPREAD_PATH/snapd-state.tar.gz)25tar xzf $SPREAD_PATH/snapd-state.tar.gz -C /
31rm -rf /root/.snap26rm -rf /root/.snap
32systemctl start snapd.service snapd.socket27systemctl start snapd.service snapd.socket
3328
29systemctl stop snap.network-manager.networkmanager
30rm -rf /var/snap/network-manager/*
31tar xzf $SPREAD_PATH/nm-state.tar.gz -C /
32systemctl start snap.network-manager.networkmanager
33
34# Make sure the original netplan configuration is applied and active34# Make sure the original netplan configuration is applied and active
35netplan generate35netplan generate
36netplan apply36netplan apply
37
38# Bringup NetworkManager again now that the system is restored
39systemctl start snap.network-manager.networkmanager
diff --git a/tests/lib/utilities.sh b/tests/lib/utilities.sh
index 000ef74..8ca1418 100644
--- a/tests/lib/utilities.sh
+++ b/tests/lib/utilities.sh
@@ -1,4 +1,20 @@
1#!/bin/sh1#!/bin/sh
2snap_install() {
3 name=$1
4 if [ -n "$SNAP_CHANNEL" ] ; then
5 # Don't reinstall if we have it installed already
6 if ! snap list | grep $name ; then
7 snap install --$SNAP_CHANNEL $name
8 fi
9 else
10 # Need first install from store to get all necessary assertions into
11 # place. Second local install will then bring in our locally built
12 # snap.
13 snap install $name
14 snap install --dangerous $PROJECT_PATH/$name*_amd64.snap
15 fi
16}
17
2switch_netplan_to_network_manager() {18switch_netplan_to_network_manager() {
3 if [ -e /etc/netplan/00-default-nm-renderer.yaml ] ; then19 if [ -e /etc/netplan/00-default-nm-renderer.yaml ] ; then
4 return 020 return 0
diff --git a/tests/main/wifi-powersave-config-option/task.yaml b/tests/main/wifi-powersave-config-option/task.yaml
5new file mode 10064421new file mode 100644
index 0000000..4711069
--- /dev/null
+++ b/tests/main/wifi-powersave-config-option/task.yaml
@@ -0,0 +1,28 @@
1summary: Verify WiFi powersave can be enabled via a snap config option
2
3environment:
4 WIFI_POWERSAVE_CONF_PATH: /var/snap/network-manager/current/conf.d/wifi-powersave.conf
5
6execute: |
7 . $TESTSLIB/utilities.sh
8
9 # The mac80211_hwsim driver does not support the powersave mode
10 # so we can't check this reliable.
11
12 test "`snap get network-manager wifi.powersave`" = "disable"
13 grep "wifi.powersave = 2" $WIFI_POWERSAVE_CONF_PATH
14
15 # Try to enable and disable again
16 snap set network-manager wifi.powersave=enable
17 test "`snap get network-manager wifi.powersave`" = "enable"
18 grep "wifi.powersave = 3" $WIFI_POWERSAVE_CONF_PATH
19
20 snap set network-manager wifi.powersave=disable
21 test "`snap get network-manager wifi.powersave`" = "disable"
22 grep "wifi.powersave = 2" $WIFI_POWERSAVE_CONF_PATH
23
24 # Specifying no value means the snap should use the default
25 # which is 'disable'
26 snap set network-manager wifi.powersave=
27 test "`snap get network-manager wifi.powersave`" = "disable"
28 grep "wifi.powersave = 2" $WIFI_POWERSAVE_CONF_PATH

Subscribers

People subscribed via source and target branches