Merge ~alfonsosanchezbeato/snappy-hwe-snaps/+git/wifi-ap:gadget into ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Simon Fels
Approved revision: 1aa0ddf048b804de9fe0ff75433e3e492dfbd2c1
Merged at revision: b3b46924451aa1b370b28dd5db97428a5c40150c
Proposed branch: ~alfonsosanchezbeato/snappy-hwe-snaps/+git/wifi-ap:gadget
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master
Diff against target: 333 lines (+187/-65)
5 files modified
cmd/client/cmd_config.go (+25/-25)
docs/reference/snap-configuration.md (+22/-0)
snap/hooks/configure (+20/-8)
tests/main/conf-from-gadget/task.yaml (+73/-0)
tests/main/conf-wizard-disabled-from-gadget/task.yaml (+47/-32)
Reviewer Review Type Date Requested Status
Simon Fels Approve
System Enablement Bot continuous-integration Approve
Roberto Mier Escandon (community) Approve
Konrad Zapałowicz (community) code Approve
Review via email: mp+325800@code.launchpad.net

Description of the change

Support for default SSID option, set from gadget snap

To post a comment you must log in.
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

nice one

review: Approve (code)
Revision history for this message
Simon Fels (morphis) :
review: Needs Fixing
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Thanks for the reviews. Comments addressed and branch re-pushed.

Revision history for this message
Roberto Mier Escandon (rmescandon) wrote :

Just a small comment

review: Needs Information
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) :
Revision history for this message
Roberto Mier Escandon (rmescandon) :
review: Approve
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
Simon Fels (morphis) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cmd/client/cmd_config.go b/cmd/client/cmd_config.go
index bdef6ea..f027e18 100644
--- a/cmd/client/cmd_config.go
+++ b/cmd/client/cmd_config.go
@@ -23,29 +23,9 @@ import (
23 "strings"23 "strings"
24)24)
2525
26type setCommand struct{}26type configCommand struct{}
27
28func (cmd *setCommand) Execute(args []string) error {
29 if len(args) < 1 {
30 return fmt.Errorf("usage: %s set key1=value1 key2=value2 ...\n", os.Args[0])
31 }
32
33 request := make(map[string]string, len(args))
34 for _, arg := range args {
35 i := strings.IndexRune(arg, '=')
36 if i <= 0 {
37 return fmt.Errorf("%q is not in the key=val format", arg)
38 }
39 request[arg[:i]] = arg[i+1:]
40 }
41
42 b, err := json.Marshal(request)
43
44 _, err = sendHTTPRequest(getServiceConfigurationURI(), "POST", bytes.NewReader(b))
45 if err != nil {
46 return err
47 }
4827
28func (cmd *configCommand) Execute(args []string) error {
49 return nil29 return nil
50}30}
5131
@@ -71,14 +51,34 @@ func (cmd *getCommand) Execute(args []string) error {
71 return nil51 return nil
72}52}
7353
74type configCommand struct{}54type setCommand struct{}
55
56func (cmd *setCommand) Execute(args []string) error {
57 if len(args) < 1 {
58 return fmt.Errorf("usage: %s set key1=value1 key2=value2 ...\n", os.Args[0])
59 }
60
61 request := make(map[string]string, len(args))
62 for _, arg := range args {
63 i := strings.IndexRune(arg, '=')
64 if i <= 0 {
65 return fmt.Errorf("%q is not in the key=val format", arg)
66 }
67 request[arg[:i]] = arg[i+1:]
68 }
69
70 b, err := json.Marshal(request)
71
72 _, err = sendHTTPRequest(getServiceConfigurationURI(), "POST", bytes.NewReader(b))
73 if err != nil {
74 return err
75 }
7576
76func (cmd *configCommand) Execute(args []string) error {
77 return nil77 return nil
78}78}
7979
80func init() {80func init() {
81 cmd, _ := addCommand("config", "Adjust the service configuration", "", &configCommand{})81 cmd, _ := addCommand("config", "Adjust the service configuration", "", &configCommand{})
82 cmd.AddCommand("set", "", "", &setCommand{})
83 cmd.AddCommand("get", "", "", &getCommand{})82 cmd.AddCommand("get", "", "", &getCommand{})
83 cmd.AddCommand("set", "", "", &setCommand{})
84}84}
diff --git a/docs/reference/snap-configuration.md b/docs/reference/snap-configuration.md
index 03e94fe..9e84a92 100644
--- a/docs/reference/snap-configuration.md
+++ b/docs/reference/snap-configuration.md
@@ -46,3 +46,25 @@ defaults:
46After this snippet is added to the gadget.yaml and an updated version of the46After this snippet is added to the gadget.yaml and an updated version of the
47gadget snap is deployed onto the device the automatic setup, of the AP is disabled47gadget snap is deployed onto the device the automatic setup, of the AP is disabled
48once the wifi-ap is installed from the Ubuntu Store.48once the wifi-ap is installed from the Ubuntu Store.
49
50## default.wifi.ssid
51
52The *default.wifi.ssid* option allows a device to specify the default name of
53the wireless network (SSID). This name will be used when creating a network
54unless changed by the user.
55
56This option is used only on installation of the wifi-ap snap, and it is ignored
57on updates. Therefore, doing *snap set* on it produces no effect. It must be
58set by setting it as a default in the [gadget
59snap](https://docs.ubuntu.com/core/en/reference/gadget), for instance:
60
61```
62defaults:
63 # The alpha numeric key below is the id of the wifi-ap snap assigned in the
64 # Ubuntu Store. Specifying the snap name instead is not possible.
65 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS:
66 default.wifi.ssid: MyDeviceSSID
67```
68
69A gadget snap with this option must be installed before installing wifi-ap for
70it to have effect.
diff --git a/snap/hooks/configure b/snap/hooks/configure
index 6b984cd..0967ade 100755
--- a/snap/hooks/configure
+++ b/snap/hooks/configure
@@ -21,14 +21,14 @@ set -x
21# being installed. As the configure hook will be called before the21# being installed. As the configure hook will be called before the
22# services are being started we can easily create an empty22# services are being started we can easily create an empty
23# configuration to fall back to the default one for everything.23# configuration to fall back to the default one for everything.
24value=`snapctl get automatic-setup.disable`24value=$(snapctl get automatic-setup.disable)
25if [ -n "$value" ]; then25if [ -n "$value" ]; then
26 case "$value" in26 case "$value" in
27 true)27 true)
28 touch $SNAP_COMMON/.block_auto_wizard28 touch "$SNAP_COMMON"/.block_auto_wizard
29 ;;29 ;;
30 false)30 false)
31 rm $SNAP_COMMON/.block_auto_wizard || true31 rm -f "$SNAP_COMMON"/.block_auto_wizard
32 ;;32 ;;
33 *)33 *)
34 echo "ERROR: invalid value '$value' provided for automatic-setup.disable"34 echo "ERROR: invalid value '$value' provided for automatic-setup.disable"
@@ -39,9 +39,21 @@ else
39 snapctl set automatic-setup.disable=false39 snapctl set automatic-setup.disable=false
40fi40fi
4141
42# If we haven't marked ourself as setup yet after the snap was installed42if [ ! -e "$SNAP_COMMON"/.setup_done ]; then
43# we do this now so that the already started management service can43 # Get default SSID from gadget only in first installation
44# continue doing its job.44 config_file="$SNAP_DATA"/config
45if [ ! -e $SNAP_COMMON/.setup_done ]; then45 if ssid=$(snapctl get default.wifi.ssid) && [ -n "$ssid" ]; then
46 touch $SNAP_COMMON/.setup_done46 echo "Configure ssid to $ssid"
47
48 if grep -q "WIFI_SSID=" "$config_file"; then
49 sed -i "s/WIFI_SSID=.*/WIFI_SSID=$ssid/" "$config_file"
50 else
51 echo "WIFI_SSID=$ssid" >> "$config_file"
52 fi
53 fi
54
55 # If we haven't marked ourself as setup yet after the snap was installed
56 # we do this now so that the already started management service can
57 # continue doing its job.
58 touch "$SNAP_COMMON"/.setup_done
47fi59fi
diff --git a/tests/main/conf-from-gadget/task.yaml b/tests/main/conf-from-gadget/task.yaml
48new file mode 10064460new file mode 100644
index 0000000..e26d7bf
--- /dev/null
+++ b/tests/main/conf-from-gadget/task.yaml
@@ -0,0 +1,73 @@
1summary: Verify that the default SSID can be read from a gadget snap
2description: |
3 We check that we get the SSID name from the defaults in the gadget
4 snap. To do this, we re-package the gadget snap in the store after
5 changing gadget.yaml, and then we re-install it. A reboot is needed
6 after this. After it, we install the wifi-ap snap and check that the
7 SSID name is as expected.
8
9prepare: |
10 . $TESTSLIB/snap-names.sh
11 # We have a reboot in the test, so we store this in permanent storage
12 readlink /snap/$gadget_name/current > $HOME/gadget_version
13
14restore: |
15 . $TESTSLIB/snap-names.sh
16 # Restore the original gadget snap so that any following tests don't suffer
17 # from our modified gadget.
18 read original_revision < $HOME/gadget_version
19 current_revision="$(readlink /snap/$gadget_name/current)"
20 if [ "$current_revision" != "$original_revision" ]; then
21 snap revert --revision=$original_revision $gadget_name
22 fi
23 rm $HOME/gadget_version
24
25execute: |
26 . $TESTSLIB/snap-names.sh
27 . $TESTSLIB/utilities.sh
28
29 case "$SPREAD_REBOOT" in
30 0)
31 snap remove wifi-ap
32 snap install --edge --devmode se-test-tools
33
34 # We need a custom gadget snap for this so lets fetch one from the store
35 # and modify it.
36 snap download --stable $gadget_name
37 /snap/bin/se-test-tools.unsquashfs -d gadget ${gadget_name}_*.snap
38 printf "%s\n" \
39 "defaults:" \
40 " # Below snap ID matches the one assigned for wifi-ap in the Ubuntu Store" \
41 " 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS:" \
42 " default.wifi.ssid: GadgetSnap" \
43 >> gadget/meta/gadget.yaml
44
45 /snap/bin/se-test-tools.mksquashfs gadget $gadget_name.snap -comp xz -no-xattrs
46 snap install --dangerous $gadget_name.snap
47
48 REBOOT
49 ;;
50 1)
51 # Applying default configuration from a gadget snap only works when the snap
52 # comes from the store. It is not possible for an unasserted snap to be
53 # configured with defaults from the gadget. As a workaround, we install from
54 # edge and then sideload the snap we are testing.
55 snap install --edge wifi-ap
56
57 # So we run the configure hook
58 rm /var/snap/wifi-ap/common/.setup_done
59
60 # Install prebuilt wifi-ap snap
61 snap install --dangerous /home/wifi-ap/wifi-ap_*.snap
62
63 test "$(snap get wifi-ap default.wifi.ssid)" = "GadgetSnap"
64
65 # Wait until we can talk to the service
66 while ! /snap/bin/wifi-ap.status; do sleep .1 ; done
67
68 test "$(/snap/bin/wifi-ap.config get wifi.ssid)" = "GadgetSnap"
69 ;;
70 *)
71 echo "Test failed, too many reboots"
72 exit 1
73 esac
diff --git a/tests/main/conf-wizard-disabled-from-gadget/task.yaml b/tests/main/conf-wizard-disabled-from-gadget/task.yaml
index 66496a6..84cbbd3 100644
--- a/tests/main/conf-wizard-disabled-from-gadget/task.yaml
+++ b/tests/main/conf-wizard-disabled-from-gadget/task.yaml
@@ -2,49 +2,64 @@ summary: Verify the wizard can be disabled by default from a gadget snap
22
3prepare: |3prepare: |
4 . $TESTSLIB/snap-names.sh4 . $TESTSLIB/snap-names.sh
5 echo $(readlink /snap/$gadget_name/current) > /tmp/gadget_version5 # We have a reboot in the test, so we store this in permanent storage
6 readlink /snap/$gadget_name/current > $HOME/gadget_version
67
7restore: |8restore: |
8 . $TESTSLIB/snap-names.sh9 . $TESTSLIB/snap-names.sh
9 # Restore the original gadget snap so that any following tests don't suffer10 # Restore the original gadget snap so that any following tests don't suffer
10 # from our modified gadget.11 # from our modified gadget.
11 original_revision="$(cat /tmp/gadget_version)"12 read original_revision < $HOME/gadget_version
12 current_revision="$(readlink /snap/$gadget_name/current)"13 current_revision="$(readlink /snap/$gadget_name/current)"
13 if [ "$current_revision" != "$original_revision" ]; then14 if [ "$current_revision" != "$original_revision" ]; then
14 snap revert --revision=$original_revision $gadget_name15 snap revert --revision=$original_revision $gadget_name
15 fi16 fi
17 rm $HOME/gadget_version
1618
17execute: |19execute: |
18 . $TESTSLIB/snap-names.sh20 . $TESTSLIB/snap-names.sh
19 . $TESTSLIB/utilities.sh21 . $TESTSLIB/utilities.sh
2022
21 snap remove wifi-ap23 case "$SPREAD_REBOOT" in
22 snap install --edge --devmode se-test-tools24 0)
2325 snap remove wifi-ap
24 # We need a custom gadget snap for this so lets fetch one from the store26 snap install --edge --devmode se-test-tools
25 # and modify it.27
26 snap download --stable $gadget_name28 # We need a custom gadget snap for this so lets fetch one from the store
27 /snap/bin/se-test-tools.unsquashfs -d gadget ${gadget_name}_*.snap29 # and modify it.
28 cat << EOF >> gadget/meta/gadget.yaml30 snap download --stable $gadget_name
29 defaults:31 /snap/bin/se-test-tools.unsquashfs -d gadget ${gadget_name}_*.snap
30 # Below snap ID matches the one assigned for wifi-ap in the Ubuntu Store32 printf "%s\n" \
31 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS:33 "defaults:" \
32 automatic-setup.disable: true34 " # Below snap ID matches the one assigned for wifi-ap in the Ubuntu Store" \
33 EOF35 " 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS:" \
34 /snap/bin/se-test-tools.mksquashfs gadget $gadget_name.snap -comp xz -no-xattrs36 " automatic-setup.disable: true" \
35 snap install --dangerous $gadget_name.snap37 >> gadget/meta/gadget.yaml
3638
37 # Applying default configuration from a gadget snap only works when the39 /snap/bin/se-test-tools.mksquashfs gadget $gadget_name.snap -comp xz -no-xattrs
38 # snap is installed and comes from the store. It's not possible for an40 snap install --dangerous $gadget_name.snap
39 # unasserted snap to be configured with defaults from the gadget.41
40 snap install --edge wifi-ap42 REBOOT
4143 ;;
42 test "$(snap get wifi-ap automatic-setup.disable)" = true44 1)
4345 # Applying default configuration from a gadget snap only works when the snap
44 # Wait until we can talk to the service46 # comes from the store. It is not possible for an unasserted snap to be
45 while ! /snap/bin/wifi-ap.status; do sleep .1 ; done47 # configured with defaults from the gadget. As a workaround, we install from
4648 # edge and then sideload the snap we are testing.
47 test "$(/snap/bin/wifi-ap.config get disabled)" = true49 snap install --edge wifi-ap
48 /snap/bin/wifi-ap.status | grep "ap.active: false"50 snap install --dangerous /home/wifi-ap/wifi-ap_*.snap
49 ! pgrep dnsmasq51
50 ! pgrep hostapd52 test "$(snap get wifi-ap automatic-setup.disable)" = true
53
54 # Wait until we can talk to the service
55 while ! /snap/bin/wifi-ap.status; do sleep .1 ; done
56
57 test "$(/snap/bin/wifi-ap.config get disabled)" = true
58 /snap/bin/wifi-ap.status | grep "ap.active: false"
59 ! pgrep dnsmasq
60 ! pgrep hostapd
61 ;;
62 *)
63 echo "Test failed, too many reboots"
64 exit 1
65 esac

Subscribers

People subscribed via source and target branches