Merge ~alfonsosanchezbeato/snappy-hwe-snaps/+git/wifi-ap:gadget into ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master
- Git
- lp:~alfonsosanchezbeato/snappy-hwe-snaps/+git/wifi-ap
- gadget
- Merge into master
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) |
Related bugs: |
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 |
Commit message
Description of the change
Support for default SSID option, set from gadget snap
Simon Fels (morphis) : | # |
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote : | # |
Thanks for the reviews. Comments addressed and branch re-pushed.
Roberto Mier Escandon (rmescandon) wrote : | # |
Just a small comment
Alfonso Sanchez-Beato (alfonsosanchezbeato) : | # |
Roberto Mier Escandon (rmescandon) : | # |
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:4d3b002d8d2
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
System Enablement Bot (system-enablement-ci-bot) wrote : | # |
PASSED: Continuous integration, rev:1aa0ddf048b
https:/
Executed test runs:
SUCCESS: https:/
None: https:/
SUCCESS: https:/
None: https:/
Click here to trigger a rebuild:
https:/
Preview Diff
1 | diff --git a/cmd/client/cmd_config.go b/cmd/client/cmd_config.go | |||
2 | index bdef6ea..f027e18 100644 | |||
3 | --- a/cmd/client/cmd_config.go | |||
4 | +++ b/cmd/client/cmd_config.go | |||
5 | @@ -23,29 +23,9 @@ import ( | |||
6 | 23 | "strings" | 23 | "strings" |
7 | 24 | ) | 24 | ) |
8 | 25 | 25 | ||
31 | 26 | type setCommand struct{} | 26 | type configCommand struct{} |
10 | 27 | |||
11 | 28 | func (cmd *setCommand) Execute(args []string) error { | ||
12 | 29 | if len(args) < 1 { | ||
13 | 30 | return fmt.Errorf("usage: %s set key1=value1 key2=value2 ...\n", os.Args[0]) | ||
14 | 31 | } | ||
15 | 32 | |||
16 | 33 | request := make(map[string]string, len(args)) | ||
17 | 34 | for _, arg := range args { | ||
18 | 35 | i := strings.IndexRune(arg, '=') | ||
19 | 36 | if i <= 0 { | ||
20 | 37 | return fmt.Errorf("%q is not in the key=val format", arg) | ||
21 | 38 | } | ||
22 | 39 | request[arg[:i]] = arg[i+1:] | ||
23 | 40 | } | ||
24 | 41 | |||
25 | 42 | b, err := json.Marshal(request) | ||
26 | 43 | |||
27 | 44 | _, err = sendHTTPRequest(getServiceConfigurationURI(), "POST", bytes.NewReader(b)) | ||
28 | 45 | if err != nil { | ||
29 | 46 | return err | ||
30 | 47 | } | ||
32 | 48 | 27 | ||
33 | 28 | func (cmd *configCommand) Execute(args []string) error { | ||
34 | 49 | return nil | 29 | return nil |
35 | 50 | } | 30 | } |
36 | 51 | 31 | ||
37 | @@ -71,14 +51,34 @@ func (cmd *getCommand) Execute(args []string) error { | |||
38 | 71 | return nil | 51 | return nil |
39 | 72 | } | 52 | } |
40 | 73 | 53 | ||
42 | 74 | type configCommand struct{} | 54 | type setCommand struct{} |
43 | 55 | |||
44 | 56 | func (cmd *setCommand) Execute(args []string) error { | ||
45 | 57 | if len(args) < 1 { | ||
46 | 58 | return fmt.Errorf("usage: %s set key1=value1 key2=value2 ...\n", os.Args[0]) | ||
47 | 59 | } | ||
48 | 60 | |||
49 | 61 | request := make(map[string]string, len(args)) | ||
50 | 62 | for _, arg := range args { | ||
51 | 63 | i := strings.IndexRune(arg, '=') | ||
52 | 64 | if i <= 0 { | ||
53 | 65 | return fmt.Errorf("%q is not in the key=val format", arg) | ||
54 | 66 | } | ||
55 | 67 | request[arg[:i]] = arg[i+1:] | ||
56 | 68 | } | ||
57 | 69 | |||
58 | 70 | b, err := json.Marshal(request) | ||
59 | 71 | |||
60 | 72 | _, err = sendHTTPRequest(getServiceConfigurationURI(), "POST", bytes.NewReader(b)) | ||
61 | 73 | if err != nil { | ||
62 | 74 | return err | ||
63 | 75 | } | ||
64 | 75 | 76 | ||
65 | 76 | func (cmd *configCommand) Execute(args []string) error { | ||
66 | 77 | return nil | 77 | return nil |
67 | 78 | } | 78 | } |
68 | 79 | 79 | ||
69 | 80 | func init() { | 80 | func init() { |
70 | 81 | cmd, _ := addCommand("config", "Adjust the service configuration", "", &configCommand{}) | 81 | cmd, _ := addCommand("config", "Adjust the service configuration", "", &configCommand{}) |
71 | 82 | cmd.AddCommand("set", "", "", &setCommand{}) | ||
72 | 83 | cmd.AddCommand("get", "", "", &getCommand{}) | 82 | cmd.AddCommand("get", "", "", &getCommand{}) |
73 | 83 | cmd.AddCommand("set", "", "", &setCommand{}) | ||
74 | 84 | } | 84 | } |
75 | diff --git a/docs/reference/snap-configuration.md b/docs/reference/snap-configuration.md | |||
76 | index 03e94fe..9e84a92 100644 | |||
77 | --- a/docs/reference/snap-configuration.md | |||
78 | +++ b/docs/reference/snap-configuration.md | |||
79 | @@ -46,3 +46,25 @@ defaults: | |||
80 | 46 | After this snippet is added to the gadget.yaml and an updated version of the | 46 | After this snippet is added to the gadget.yaml and an updated version of the |
81 | 47 | gadget snap is deployed onto the device the automatic setup, of the AP is disabled | 47 | gadget snap is deployed onto the device the automatic setup, of the AP is disabled |
82 | 48 | once the wifi-ap is installed from the Ubuntu Store. | 48 | once the wifi-ap is installed from the Ubuntu Store. |
83 | 49 | |||
84 | 50 | ## default.wifi.ssid | ||
85 | 51 | |||
86 | 52 | The *default.wifi.ssid* option allows a device to specify the default name of | ||
87 | 53 | the wireless network (SSID). This name will be used when creating a network | ||
88 | 54 | unless changed by the user. | ||
89 | 55 | |||
90 | 56 | This option is used only on installation of the wifi-ap snap, and it is ignored | ||
91 | 57 | on updates. Therefore, doing *snap set* on it produces no effect. It must be | ||
92 | 58 | set by setting it as a default in the [gadget | ||
93 | 59 | snap](https://docs.ubuntu.com/core/en/reference/gadget), for instance: | ||
94 | 60 | |||
95 | 61 | ``` | ||
96 | 62 | defaults: | ||
97 | 63 | # The alpha numeric key below is the id of the wifi-ap snap assigned in the | ||
98 | 64 | # Ubuntu Store. Specifying the snap name instead is not possible. | ||
99 | 65 | 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS: | ||
100 | 66 | default.wifi.ssid: MyDeviceSSID | ||
101 | 67 | ``` | ||
102 | 68 | |||
103 | 69 | A gadget snap with this option must be installed before installing wifi-ap for | ||
104 | 70 | it to have effect. | ||
105 | diff --git a/snap/hooks/configure b/snap/hooks/configure | |||
106 | index 6b984cd..0967ade 100755 | |||
107 | --- a/snap/hooks/configure | |||
108 | +++ b/snap/hooks/configure | |||
109 | @@ -21,14 +21,14 @@ set -x | |||
110 | 21 | # being installed. As the configure hook will be called before the | 21 | # being installed. As the configure hook will be called before the |
111 | 22 | # services are being started we can easily create an empty | 22 | # services are being started we can easily create an empty |
112 | 23 | # configuration to fall back to the default one for everything. | 23 | # configuration to fall back to the default one for everything. |
114 | 24 | value=`snapctl get automatic-setup.disable` | 24 | value=$(snapctl get automatic-setup.disable) |
115 | 25 | if [ -n "$value" ]; then | 25 | if [ -n "$value" ]; then |
116 | 26 | case "$value" in | 26 | case "$value" in |
117 | 27 | true) | 27 | true) |
119 | 28 | touch $SNAP_COMMON/.block_auto_wizard | 28 | touch "$SNAP_COMMON"/.block_auto_wizard |
120 | 29 | ;; | 29 | ;; |
121 | 30 | false) | 30 | false) |
123 | 31 | rm $SNAP_COMMON/.block_auto_wizard || true | 31 | rm -f "$SNAP_COMMON"/.block_auto_wizard |
124 | 32 | ;; | 32 | ;; |
125 | 33 | *) | 33 | *) |
126 | 34 | echo "ERROR: invalid value '$value' provided for automatic-setup.disable" | 34 | echo "ERROR: invalid value '$value' provided for automatic-setup.disable" |
127 | @@ -39,9 +39,21 @@ else | |||
128 | 39 | snapctl set automatic-setup.disable=false | 39 | snapctl set automatic-setup.disable=false |
129 | 40 | fi | 40 | fi |
130 | 41 | 41 | ||
136 | 42 | # If we haven't marked ourself as setup yet after the snap was installed | 42 | if [ ! -e "$SNAP_COMMON"/.setup_done ]; then |
137 | 43 | # we do this now so that the already started management service can | 43 | # Get default SSID from gadget only in first installation |
138 | 44 | # continue doing its job. | 44 | config_file="$SNAP_DATA"/config |
139 | 45 | if [ ! -e $SNAP_COMMON/.setup_done ]; then | 45 | if ssid=$(snapctl get default.wifi.ssid) && [ -n "$ssid" ]; then |
140 | 46 | touch $SNAP_COMMON/.setup_done | 46 | echo "Configure ssid to $ssid" |
141 | 47 | |||
142 | 48 | if grep -q "WIFI_SSID=" "$config_file"; then | ||
143 | 49 | sed -i "s/WIFI_SSID=.*/WIFI_SSID=$ssid/" "$config_file" | ||
144 | 50 | else | ||
145 | 51 | echo "WIFI_SSID=$ssid" >> "$config_file" | ||
146 | 52 | fi | ||
147 | 53 | fi | ||
148 | 54 | |||
149 | 55 | # If we haven't marked ourself as setup yet after the snap was installed | ||
150 | 56 | # we do this now so that the already started management service can | ||
151 | 57 | # continue doing its job. | ||
152 | 58 | touch "$SNAP_COMMON"/.setup_done | ||
153 | 47 | fi | 59 | fi |
154 | diff --git a/tests/main/conf-from-gadget/task.yaml b/tests/main/conf-from-gadget/task.yaml | |||
155 | 48 | new file mode 100644 | 60 | new file mode 100644 |
156 | index 0000000..e26d7bf | |||
157 | --- /dev/null | |||
158 | +++ b/tests/main/conf-from-gadget/task.yaml | |||
159 | @@ -0,0 +1,73 @@ | |||
160 | 1 | summary: Verify that the default SSID can be read from a gadget snap | ||
161 | 2 | description: | | ||
162 | 3 | We check that we get the SSID name from the defaults in the gadget | ||
163 | 4 | snap. To do this, we re-package the gadget snap in the store after | ||
164 | 5 | changing gadget.yaml, and then we re-install it. A reboot is needed | ||
165 | 6 | after this. After it, we install the wifi-ap snap and check that the | ||
166 | 7 | SSID name is as expected. | ||
167 | 8 | |||
168 | 9 | prepare: | | ||
169 | 10 | . $TESTSLIB/snap-names.sh | ||
170 | 11 | # We have a reboot in the test, so we store this in permanent storage | ||
171 | 12 | readlink /snap/$gadget_name/current > $HOME/gadget_version | ||
172 | 13 | |||
173 | 14 | restore: | | ||
174 | 15 | . $TESTSLIB/snap-names.sh | ||
175 | 16 | # Restore the original gadget snap so that any following tests don't suffer | ||
176 | 17 | # from our modified gadget. | ||
177 | 18 | read original_revision < $HOME/gadget_version | ||
178 | 19 | current_revision="$(readlink /snap/$gadget_name/current)" | ||
179 | 20 | if [ "$current_revision" != "$original_revision" ]; then | ||
180 | 21 | snap revert --revision=$original_revision $gadget_name | ||
181 | 22 | fi | ||
182 | 23 | rm $HOME/gadget_version | ||
183 | 24 | |||
184 | 25 | execute: | | ||
185 | 26 | . $TESTSLIB/snap-names.sh | ||
186 | 27 | . $TESTSLIB/utilities.sh | ||
187 | 28 | |||
188 | 29 | case "$SPREAD_REBOOT" in | ||
189 | 30 | 0) | ||
190 | 31 | snap remove wifi-ap | ||
191 | 32 | snap install --edge --devmode se-test-tools | ||
192 | 33 | |||
193 | 34 | # We need a custom gadget snap for this so lets fetch one from the store | ||
194 | 35 | # and modify it. | ||
195 | 36 | snap download --stable $gadget_name | ||
196 | 37 | /snap/bin/se-test-tools.unsquashfs -d gadget ${gadget_name}_*.snap | ||
197 | 38 | printf "%s\n" \ | ||
198 | 39 | "defaults:" \ | ||
199 | 40 | " # Below snap ID matches the one assigned for wifi-ap in the Ubuntu Store" \ | ||
200 | 41 | " 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS:" \ | ||
201 | 42 | " default.wifi.ssid: GadgetSnap" \ | ||
202 | 43 | >> gadget/meta/gadget.yaml | ||
203 | 44 | |||
204 | 45 | /snap/bin/se-test-tools.mksquashfs gadget $gadget_name.snap -comp xz -no-xattrs | ||
205 | 46 | snap install --dangerous $gadget_name.snap | ||
206 | 47 | |||
207 | 48 | REBOOT | ||
208 | 49 | ;; | ||
209 | 50 | 1) | ||
210 | 51 | # Applying default configuration from a gadget snap only works when the snap | ||
211 | 52 | # comes from the store. It is not possible for an unasserted snap to be | ||
212 | 53 | # configured with defaults from the gadget. As a workaround, we install from | ||
213 | 54 | # edge and then sideload the snap we are testing. | ||
214 | 55 | snap install --edge wifi-ap | ||
215 | 56 | |||
216 | 57 | # So we run the configure hook | ||
217 | 58 | rm /var/snap/wifi-ap/common/.setup_done | ||
218 | 59 | |||
219 | 60 | # Install prebuilt wifi-ap snap | ||
220 | 61 | snap install --dangerous /home/wifi-ap/wifi-ap_*.snap | ||
221 | 62 | |||
222 | 63 | test "$(snap get wifi-ap default.wifi.ssid)" = "GadgetSnap" | ||
223 | 64 | |||
224 | 65 | # Wait until we can talk to the service | ||
225 | 66 | while ! /snap/bin/wifi-ap.status; do sleep .1 ; done | ||
226 | 67 | |||
227 | 68 | test "$(/snap/bin/wifi-ap.config get wifi.ssid)" = "GadgetSnap" | ||
228 | 69 | ;; | ||
229 | 70 | *) | ||
230 | 71 | echo "Test failed, too many reboots" | ||
231 | 72 | exit 1 | ||
232 | 73 | esac | ||
233 | diff --git a/tests/main/conf-wizard-disabled-from-gadget/task.yaml b/tests/main/conf-wizard-disabled-from-gadget/task.yaml | |||
234 | index 66496a6..84cbbd3 100644 | |||
235 | --- a/tests/main/conf-wizard-disabled-from-gadget/task.yaml | |||
236 | +++ b/tests/main/conf-wizard-disabled-from-gadget/task.yaml | |||
237 | @@ -2,49 +2,64 @@ summary: Verify the wizard can be disabled by default from a gadget snap | |||
238 | 2 | 2 | ||
239 | 3 | prepare: | | 3 | prepare: | |
240 | 4 | . $TESTSLIB/snap-names.sh | 4 | . $TESTSLIB/snap-names.sh |
242 | 5 | echo $(readlink /snap/$gadget_name/current) > /tmp/gadget_version | 5 | # We have a reboot in the test, so we store this in permanent storage |
243 | 6 | readlink /snap/$gadget_name/current > $HOME/gadget_version | ||
244 | 6 | 7 | ||
245 | 7 | restore: | | 8 | restore: | |
246 | 8 | . $TESTSLIB/snap-names.sh | 9 | . $TESTSLIB/snap-names.sh |
247 | 9 | # Restore the original gadget snap so that any following tests don't suffer | 10 | # Restore the original gadget snap so that any following tests don't suffer |
248 | 10 | # from our modified gadget. | 11 | # from our modified gadget. |
250 | 11 | original_revision="$(cat /tmp/gadget_version)" | 12 | read original_revision < $HOME/gadget_version |
251 | 12 | current_revision="$(readlink /snap/$gadget_name/current)" | 13 | current_revision="$(readlink /snap/$gadget_name/current)" |
252 | 13 | if [ "$current_revision" != "$original_revision" ]; then | 14 | if [ "$current_revision" != "$original_revision" ]; then |
253 | 14 | snap revert --revision=$original_revision $gadget_name | 15 | snap revert --revision=$original_revision $gadget_name |
254 | 15 | fi | 16 | fi |
255 | 17 | rm $HOME/gadget_version | ||
256 | 16 | 18 | ||
257 | 17 | execute: | | 19 | execute: | |
258 | 18 | . $TESTSLIB/snap-names.sh | 20 | . $TESTSLIB/snap-names.sh |
259 | 19 | . $TESTSLIB/utilities.sh | 21 | . $TESTSLIB/utilities.sh |
260 | 20 | 22 | ||
291 | 21 | snap remove wifi-ap | 23 | case "$SPREAD_REBOOT" in |
292 | 22 | snap install --edge --devmode se-test-tools | 24 | 0) |
293 | 23 | 25 | snap remove wifi-ap | |
294 | 24 | # We need a custom gadget snap for this so lets fetch one from the store | 26 | snap install --edge --devmode se-test-tools |
295 | 25 | # and modify it. | 27 | |
296 | 26 | snap download --stable $gadget_name | 28 | # We need a custom gadget snap for this so lets fetch one from the store |
297 | 27 | /snap/bin/se-test-tools.unsquashfs -d gadget ${gadget_name}_*.snap | 29 | # and modify it. |
298 | 28 | cat << EOF >> gadget/meta/gadget.yaml | 30 | snap download --stable $gadget_name |
299 | 29 | defaults: | 31 | /snap/bin/se-test-tools.unsquashfs -d gadget ${gadget_name}_*.snap |
300 | 30 | # Below snap ID matches the one assigned for wifi-ap in the Ubuntu Store | 32 | printf "%s\n" \ |
301 | 31 | 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS: | 33 | "defaults:" \ |
302 | 32 | automatic-setup.disable: true | 34 | " # Below snap ID matches the one assigned for wifi-ap in the Ubuntu Store" \ |
303 | 33 | EOF | 35 | " 2rGgvyaY0CCzlWuKAPwFtCWrgwkM8lqS:" \ |
304 | 34 | /snap/bin/se-test-tools.mksquashfs gadget $gadget_name.snap -comp xz -no-xattrs | 36 | " automatic-setup.disable: true" \ |
305 | 35 | snap install --dangerous $gadget_name.snap | 37 | >> gadget/meta/gadget.yaml |
306 | 36 | 38 | ||
307 | 37 | # Applying default configuration from a gadget snap only works when the | 39 | /snap/bin/se-test-tools.mksquashfs gadget $gadget_name.snap -comp xz -no-xattrs |
308 | 38 | # snap is installed and comes from the store. It's not possible for an | 40 | snap install --dangerous $gadget_name.snap |
309 | 39 | # unasserted snap to be configured with defaults from the gadget. | 41 | |
310 | 40 | snap install --edge wifi-ap | 42 | REBOOT |
311 | 41 | 43 | ;; | |
312 | 42 | test "$(snap get wifi-ap automatic-setup.disable)" = true | 44 | 1) |
313 | 43 | 45 | # Applying default configuration from a gadget snap only works when the snap | |
314 | 44 | # Wait until we can talk to the service | 46 | # comes from the store. It is not possible for an unasserted snap to be |
315 | 45 | while ! /snap/bin/wifi-ap.status; do sleep .1 ; done | 47 | # configured with defaults from the gadget. As a workaround, we install from |
316 | 46 | 48 | # edge and then sideload the snap we are testing. | |
317 | 47 | test "$(/snap/bin/wifi-ap.config get disabled)" = true | 49 | snap install --edge wifi-ap |
318 | 48 | /snap/bin/wifi-ap.status | grep "ap.active: false" | 50 | snap install --dangerous /home/wifi-ap/wifi-ap_*.snap |
319 | 49 | ! pgrep dnsmasq | 51 | |
320 | 50 | ! pgrep hostapd | 52 | test "$(snap get wifi-ap automatic-setup.disable)" = true |
321 | 53 | |||
322 | 54 | # Wait until we can talk to the service | ||
323 | 55 | while ! /snap/bin/wifi-ap.status; do sleep .1 ; done | ||
324 | 56 | |||
325 | 57 | test "$(/snap/bin/wifi-ap.config get disabled)" = true | ||
326 | 58 | /snap/bin/wifi-ap.status | grep "ap.active: false" | ||
327 | 59 | ! pgrep dnsmasq | ||
328 | 60 | ! pgrep hostapd | ||
329 | 61 | ;; | ||
330 | 62 | *) | ||
331 | 63 | echo "Test failed, too many reboots" | ||
332 | 64 | exit 1 | ||
333 | 65 | esac |
nice one