Merge ~robertliu/snappy-hwe-snaps/+git/modme-manager:conditional-restart-service into ~snappy-hwe-team/snappy-hwe-snaps/+git/modem-manager:snap-22

Proposed by Robert Liu
Status: Needs review
Proposed branch: ~robertliu/snappy-hwe-snaps/+git/modme-manager:conditional-restart-service
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/modem-manager:snap-22
Diff against target: 489 lines (+300/-38)
14 files modified
bin/modemmanager (+11/-3)
bin/snap-config.sh (+28/-0)
bin/snap-prop.sh (+47/-0)
docs/installation.md (+1/-0)
docs/metadata.yaml (+2/-0)
docs/reference/snap-configuration/test-options.md (+55/-0)
hooks/configure (+34/-28)
snapcraft.yaml (+2/-0)
tests/lib/utilities.sh (+27/-2)
tests/main/debug-config-option/task.yaml (+14/-4)
tests/main/installation/task.yaml (+16/-0)
tests/main/network-manager-autoconn/task.yaml (+1/-1)
tests/main/test-no-suspend-resume-option/task.yaml (+31/-0)
tests/main/test-quick-suspend-resume-option/task.yaml (+31/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Alfonso Sanchez-Beato Pending
Review via email: mp+434168@code.launchpad.net

Description of the change

this implementation is inspired by the nextcloud snap[1][2].

Two additional variables are used to store the runtime settings and determine if the settings are changed and the service has to be started.

[1] https://github.com/nextcloud-snap/nextcloud-snap/blob/master/src/hooks/bin/configure
[2] https://github.com/nextcloud-snap/nextcloud-snap/blob/master/src/apache/utilities/apache-utilities

To post a comment you must log in.
Revision history for this message
Robert Liu (robertliu) wrote (last edit ):

ran simple tests to verify the implementation.

1. install/update the MM snap
{
 "debug": {
  "enable": false
 },
 "private": {
  "test": {
   "no-suspend-resume": false,
   "quick-suspend-resume": false
  }
 },
 "test": {
  "no-suspend-resume": false,
  "quick-suspend-resume": false
 }
}

   6327 ? Dsl 0:00 /snap/modem-manager/x1/usr/sbin/ModemManager --filter-policy=STRICT

2. set test.quick-suspend-resume=false
{
 "debug": {
  "enable": false
 },
 "private": {
  "test": {
   "no-suspend-resume": false,
   "quick-suspend-resume": false
  }
 },
 "test": {
  "no-suspend-resume": false,
  "quick-suspend-resume": false
 }
}

   6327 ? Ssl 0:00 /snap/modem-manager/x1/usr/sbin/ModemManager --filter-policy=STRICT

3. set test.quick-suspend-reume=true
{
 "debug": {
  "enable": false
 },
 "private": {
  "test": {
   "no-suspend-resume": false,
   "quick-suspend-resume": true
  }
 },
 "test": {
  "no-suspend-resume": false,
  "quick-suspend-resume": true
 }
}

  6716 ? Dsl 0:00 /snap/modem-manager/x1/usr/sbin/ModemManager --filter-policy=STRICT --log-level=INFO --test-quick-suspend-resume

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 7085e2db755aca5fea2d7ba1051f0ab60fc992b0

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1577/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Doing it this way is an option, but tbh I don't like too much adding those "private" properties, which are still seen by the user in the end. And we use a file in SNAP_DATA in network-manager snap [1] that does pretty much the same in a similar way, so for maintenability I prefer to do it the same way in all the system snaps.

[1] https://git.launchpad.net/~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager/tree/snap/hooks/configure

97029b0... by Robert Liu

Restart service when any test options is changed

Signed-off-by: Robert Liu <email address hidden>

e21c758... by Robert Liu

docs: add a new page for test options

Signed-off-by: Robert Liu <email address hidden>

Revision history for this message
Robert Liu (robertliu) wrote :

re-write to use the same mechanism as Network-Manager

# after installation
$ sudo snap get -d modem-manager && ps ax|grep modem && cat /var/snap/modem-manager/current/current_snap_props
{
 "debug": {
  "enable": false
 },
 "test": {
  "no-suspend-resume": false,
  "quick-suspend-resume": false
 }
}
 120290 ? Ssl 0:01 /snap/modem-manager/x1/usr/sbin/ModemManager --filter-policy=STRICT --log-level=INFO
 120650 pts/0 S+ 0:00 grep --color=auto modem
debug_enable=false
test_no_suspend_resume=false
test_quick_suspend_resume=false

# enable debug & test.no-suspend-resume
$ sudo snap set modem-manager debug.enable=true test.no-suspend-resume=true
$ sudo snap get -d modem-manager && ps ax|grep modem && cat /var/snap/modem-manager/current/current_snap_props
{
 "debug": {
  "enable": true
 },
 "test": {
  "no-suspend-resume": true,
  "quick-suspend-resume": false
 }
}
 121199 ? Ssl 0:01 /snap/modem-manager/x1/usr/sbin/ModemManager --filter-policy=STRICT --debug --log-level=DEBUG --test-no-suspend-resume
 121255 pts/0 S+ 0:00 grep --color=auto modem
debug_enable=true
test_no_suspend_resume=true
test_quick_suspend_resume=false

# disable debug and test.no-suspend-resume
$ sudo snap set modem-manager debug.enable! test.no-suspend-resume=false
$ sudo snap get -d modem-manager && ps ax|grep modem && cat /var/snap/modem-manager/current/current_snap_props
{
 "debug": {
  "enable": false
 },
 "test": {
  "no-suspend-resume": false,
  "quick-suspend-resume": false
 }
}
 121338 ? Ssl 0:01 /snap/modem-manager/x1/usr/sbin/ModemManager --filter-policy=STRICT --log-level=INFO
 121394 pts/0 S+ 0:00 grep --color=auto modem
debug_enable=false
test_no_suspend_resume=false
test_quick_suspend_resume=false

# enable only test.quick-suspend-resume
$ sudo snap set modem-manager test.quick-suspend-resume=true
$ sudo snap get -d modem-manager && ps ax|grep modem && cat /var/snap/modem-manager/current/current_snap_props
{
 "debug": {
  "enable": false
 },
 "test": {
  "no-suspend-resume": false,
  "quick-suspend-resume": true
 }
}
 121575 ? Ssl 0:01 /snap/modem-manager/x1/usr/sbin/ModemManager --filter-policy=STRICT --log-level=INFO --test-quick-suspend-resume
 121652 pts/0 S+ 0:00 grep --color=auto modem
debug_enable=false
test_no_suspend_resume=false
test_quick_suspend_resume=true

Revision history for this message
Robert Liu (robertliu) wrote :

I also added a new page of docs to describe these new options.

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: dd6edf4266022f72baf449af2fb4776456253e77

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1586/

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 :

PASSED: Successfully build documentation, rev: b2f92d7f61d750b6b5cc38b3ecdc7f6c2246f4fc

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1587/

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 :

PASSED: Successfully build documentation, rev: 714adfe9e7f0b69ddd3cf0ca05960399e7c9bd35

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1588/

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 :

PASSED: Successfully build documentation, rev: ff4e4311c6d2820b5232db483a5cb76562c49425

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1589/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
793ef40... by Robert Liu

t/m/network-manager-autoconn: fix track of network-manager

Signed-off-by: Robert Liu <email address hidden>

faa6d8e... by Robert Liu

tests: updates for new test options

Signed-off-by: Robert Liu <email address hidden>

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: f64ce75085653ede5c3b4c05beffa0896745b782

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1590/

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 :

PASSED: Successfully build documentation, rev: 4427abaaec844458886c58127e77903ecedab88f

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1591/

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 :

PASSED: Successfully build documentation, rev: 25a883477604fabfd7f4b1d2910402a539b174fc

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1592/

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 :

PASSED: Successfully build documentation, rev: 7766faf94cfd81114beb16af20dde3da40dd685f

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1593/

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 :

PASSED: Successfully build documentation, rev: 68459295468eac5678555b31a210ad158286ca14

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1594/

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 :

PASSED: Successfully build documentation, rev: 7ece5ecd530cea23a79f07ec9d8106b52f0ea120

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1595/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
8a9485b... by Robert Liu

t/l/utilities.sh: fix channel setting of mm

Signed-off-by: Robert Liu <email address hidden>

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: b057142a49aaee64061073559da00a10a6a9d2d1

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1596/

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 :

PASSED: Successfully build documentation, rev: 78b25df1f7093d56bb8cfcfec867494dfe102ff2

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1597/

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 :

PASSED: Successfully build documentation, rev: 58dd23698aafc1cc8eb91c370ebc0615b9a4cf70

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1598/

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 :

PASSED: Successfully build documentation, rev: ce44b30557636c68c23427441bcf23e113d267ed

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1599/

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 :

PASSED: Successfully build documentation, rev: adbbb53028cee16cbddf5c7bedabb69a2c5a0251

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1600/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Liu (robertliu) wrote :

I wasn't aware of the spread tests and spent some time on studying and updating the test cases. Now I've added two new cases for the test.* options.

Summary of this MP:
1. add current_snap_props to store snap settings and use it to restart service dynamically when a setting is changed.
  - remove .debg_enabled file. I think the props file would be enough for detection of setting changes.
2. add new page of docs for the new test.* options
3. specify 22/stable as the channel of NM and MM snaps
4. add new test cases

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: fc588db69872b786313c4c6c2defaf4c5add9f93

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1601/

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 :

PASSED: Successfully build documentation, rev: 0292716139f8d2cf6432a4f8c774aefbb77519da

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1602/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Liu (robertliu) wrote :

I have no idea why the CI validation failed in comment https://code.launchpad.net/~robertliu/snappy-hwe-snaps/+git/modme-manager/+merge/434168/comments/1154244
I didn't change any code, but only reword a comment message. I don't have permission to trigger the job, so I regenerated a commit id to make the bot re-run the job.

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

It is failing when running:

snap set modem-manager test.quick-suspend-resume=true

See https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-test/3658/console

Revision history for this message
Robert Liu (robertliu) wrote :

It seems the "snap restart ..." in the configure hook cannot run right after the generation of props file. I was able to reproduce the failure easily with
  for i in $(seq 10); do echo ========== $i ==========; sudo snap set modem-manager test.quick-suspend-resume=true || break; sudo snap set modem-manager test.quick-suspend-resume=false || break; done

After adding a delay (sleep 1) between writing props file and restarting service, I cannot reproduce the issue in a 50-run test.

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: faa6d8e096f8832f25df0598c2cdb7e04b6ecb00

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1606/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Robert Liu (robertliu) wrote :

re-trigger the above build and verify the fix via Jenkins

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: faa6d8e096f8832f25df0598c2cdb7e04b6ecb00

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1607/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

Thanks, this looks really nice. However the "sleep 1" between writing the properties and restarting MM should not be really necessary, and I would be surprised if it is because of the file being written late. Note also that for the network-manager snap this sleep is not necessary.

Could you maybe find the service state and the journal when things fail? That would help us find the cause. Maybe the problem is too fast re-starts or similar.

Unmerged commits

faa6d8e... by Robert Liu

tests: updates for new test options

Signed-off-by: Robert Liu <email address hidden>

8a9485b... by Robert Liu

t/l/utilities.sh: fix channel setting of mm

Signed-off-by: Robert Liu <email address hidden>

793ef40... by Robert Liu

t/m/network-manager-autoconn: fix track of network-manager

Signed-off-by: Robert Liu <email address hidden>

e21c758... by Robert Liu

docs: add a new page for test options

Signed-off-by: Robert Liu <email address hidden>

97029b0... by Robert Liu

Restart service when any test options is changed

Signed-off-by: Robert Liu <email address hidden>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/modemmanager b/bin/modemmanager
2index d8c22a6..73561f1 100755
3--- a/bin/modemmanager
4+++ b/bin/modemmanager
5@@ -7,20 +7,28 @@ set -ex
6 # loader happy and find the plugins at the right location
7 export SNAP_APP_PATH=$SNAP
8
9+. "$SNAP"/bin/snap-prop.sh
10+. "$SNAP"/bin/snap-config.sh
11+
12+# Create default properties file if there is not one
13+if [ ! -f "$props_file" ]; then
14+ write_current_props_file
15+fi
16+
17 LOG_LEVEL="INFO"
18 DEBUG=""
19-if [ -f "$SNAP_DATA"/.debug_enabled ]; then
20+if [ "$(get_debug_enable)" = "true" ]; then
21 LOG_LEVEL="DEBUG"
22 DEBUG="--debug"
23 fi
24
25 TEST_NO_SUSPEND_RESUME=""
26-if [ "$(snapctl get test.no-suspend-resume)" = "true" ]; then
27+if [ "$(get_test_no_suspend_resume)" = "true" ]; then
28 TEST_NO_SUSPEND_RESUME="--test-no-suspend-resume"
29 fi
30
31 TEST_QUICK_SUSPEND_RESUME=""
32-if [ "$(snapctl get test.quick-suspend-resume)" = "true" ]; then
33+if [ "$(get_test_quick_suspend_resume)" = "true" ]; then
34 TEST_QUICK_SUSPEND_RESUME="--test-quick-suspend-resume"
35 fi
36
37diff --git a/bin/snap-config.sh b/bin/snap-config.sh
38new file mode 100644
39index 0000000..578efa3
40--- /dev/null
41+++ b/bin/snap-config.sh
42@@ -0,0 +1,28 @@
43+#!/bin/sh -ex
44+# Copyright (C) 2022 Canonical Ltd
45+#
46+# This program is free software; you can redistribute it and/or modify
47+# it under the terms of the GNU General Public License as published by
48+# the Free Software Foundation; either version 2 of the License, or
49+# (at your option) any later version.
50+#
51+# This program is distributed in the hope that it will be useful,
52+# but WITHOUT ANY WARRANTY; without even the implied warranty of
53+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54+# GNU General Public License for more details.
55+#
56+# You should have received a copy of the GNU General Public License
57+# along with this program. If not, see <http://www.gnu.org/licenses/>.
58+
59+props_file="$SNAP_DATA"/current_snap_props
60+
61+
62+# Functions to apply snap settings
63+
64+write_props_content() {
65+ echo "$1" > "$props_file"
66+}
67+
68+write_current_props_file() {
69+ write_props_content "$(get_all_props)"
70+}
71diff --git a/bin/snap-prop.sh b/bin/snap-prop.sh
72new file mode 100644
73index 0000000..d618bf3
74--- /dev/null
75+++ b/bin/snap-prop.sh
76@@ -0,0 +1,47 @@
77+#!/bin/sh -ex
78+# Copyright (C) 2022 Canonical Ltd
79+#
80+# This program is free software; you can redistribute it and/or modify
81+# it under the terms of the GNU General Public License as published by
82+# the Free Software Foundation; either version 2 of the License, or
83+# (at your option) any later version.
84+#
85+# This program is distributed in the hope that it will be useful,
86+# but WITHOUT ANY WARRANTY; without even the implied warranty of
87+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
88+# GNU General Public License for more details.
89+#
90+# You should have received a copy of the GNU General Public License
91+# along with this program. If not, see <http://www.gnu.org/licenses/>.
92+
93+# Getters for snap properties. They write the current value to stdout.
94+
95+get_debug_enable() {
96+ value=$(snapctl get debug.enable) || true
97+ if [ -z "$value" ]; then
98+ value=false
99+ fi
100+ echo "$value"
101+}
102+
103+get_test_no_suspend_resume() {
104+ value=$(snapctl get test.no-suspend-resume) || true
105+ if [ -z "$value" ]; then
106+ value=false
107+ fi
108+ echo "$value"
109+}
110+
111+get_test_quick_suspend_resume() {
112+ value=$(snapctl get test.quick-suspend-resume) || true
113+ if [ -z "$value" ]; then
114+ value=false
115+ fi
116+ echo "$value"
117+}
118+
119+get_all_props() {
120+ printf "debug_enable=$(get_debug_enable)\n"
121+ printf "test_no_suspend_resume=$(get_test_no_suspend_resume)\n"
122+ printf "test_quick_suspend_resume=$(get_test_quick_suspend_resume)\n"
123+}
124diff --git a/docs/installation.md b/docs/installation.md
125index c74fda3..b6223a2 100644
126--- a/docs/installation.md
127+++ b/docs/installation.md
128@@ -69,3 +69,4 @@ we use _sudo_ with them.
129 * [Entering SIM Passwords](entering-sim-passwords.md)
130 * [Configuring Cellular Connections](configuring-cellular-connections.md)
131 * [Enable Debug Support](reference/snap-configuration/debug.md)
132+ * [Enable Test Options](reference/snap-configuration/test-options.md)
133diff --git a/docs/metadata.yaml b/docs/metadata.yaml
134index dc2d961..fb8b5c1 100644
135--- a/docs/metadata.yaml
136+++ b/docs/metadata.yaml
137@@ -21,6 +21,8 @@ navigation:
138 children:
139 - title: Debug
140 location: reference/snap-configuration/debug.md
141+ - title: Test Options
142+ location: reference/snap-configuration/test-options.md
143 - title: Available Commands
144 location: reference/available-commands.md
145 - title: DBUS API
146diff --git a/docs/reference/snap-configuration/test-options.md b/docs/reference/snap-configuration/test-options.md
147new file mode 100644
148index 0000000..f3ffd43
149--- /dev/null
150+++ b/docs/reference/snap-configuration/test-options.md
151@@ -0,0 +1,55 @@
152+---
153+title: Test Options
154+table_of_contents: True
155+---
156+
157+# Test Options
158+
159+The test options enable testing features of modem-manager. Currently
160+modem-manager snap only supports:
161+ * `--test-no-suspend-resume`
162+ * `--test-quick-suspend-resume`
163+
164+It is disabled by default and has to be explicitly turned on for usage. The
165+snap configuration options are under the `test` catalog.
166+
167+## No Suspend Resume
168+
169+This feature is controlled by the `test.no-suspend-resume` option. Switching
170+this on means **disable** suspend/resume support at runtime. This is useful
171+for modems which are never turned off or suspended when the host suspends.
172+
173+The option takes a boolean value. The meaning of the possible values are:
174+
175+ * **true:** No suspend/resume support
176+ * **false (default):** Support suspend/resume
177+
178+## Quick Suspend Resume
179+
180+This feature is controlled by the `test.quick-suspend-resume` option.
181+Switching this on means use quick suspend/resume method for synchronizing
182+the interfaces when resuming. Some WWAN modules may need this if they
183+don't support suspend/resume correctly.
184+
185+The option takes a boolean value. The meaning of the possible values are:
186+
187+ * **true:** Use quick suspend/resume method
188+ * **false (default):** Use default suspend/resume method
189+
190+# Set Test Options
191+Changing the configuration option has immediate effect and also affects
192+future executions of the MM daemon.
193+
194+**Example:** Enable no-suspend-resume feature
195+
196+```
197+$ snap set modem-manager test.no-suspend-resume=true
198+```
199+
200+<br/>
201+**Example:** Disable quick-suspend-resume feature.
202+
203+```
204+$ snap set modem-manager test.quick-suspend-resume=false
205+```
206+
207diff --git a/hooks/configure b/hooks/configure
208index a8d980c..fcdfcb4 100755
209--- a/hooks/configure
210+++ b/hooks/configure
211@@ -2,37 +2,43 @@
212
213 set -ex
214
215-# $1 true/false for enabling/disabling debug log level in MM
216-# We create/remove the file for future executions and also change
217-# the logging level of the running daemon.
218-switch_debug_enable() {
219- DEBUG_FILE=$SNAP_DATA/.debug_enabled
220- # Note that on installation MM will not be running, so we make sure
221- # that the call to mmcli does not fail.
222- if [ "$1" = "true" ]; then
223- "$SNAP"/bin/mmcli-internal --set-logging=DEBUG || true
224- touch "$DEBUG_FILE"
225- else
226- "$SNAP"/bin/mmcli-internal --set-logging=INFO || true
227- rm -f "$DEBUG_FILE"
228- fi
229+# Configure hook has two missions:
230+# 1. Set properties defaults on installation, so users can see them
231+# 2. Re-start daemon if a property has changed
232+
233+. "$SNAP"/bin/snap-prop.sh
234+. "$SNAP"/bin/snap-config.sh
235+
236+_create_props_content() {
237+ printf "debug_enable=%s\n" "$debug_enable"
238+ printf "test_no_suspend_resume=%s\n" "$test_no_suspend_resume"
239+ printf "test_quick_suspend_resume=%s\n" "$test_quick_suspend_resume"
240 }
241
242-value=$(snapctl get debug.enable)
243-if [ -z "$value" ]; then
244- value="false"
245- snapctl set debug.enable="$value"
246-fi
247-switch_debug_enable "$value"
248+debug_enable=$(get_debug_enable)
249+test_no_suspend_resume=$(get_test_no_suspend_resume)
250+test_quick_suspend_resume=$(get_test_quick_suspend_resume)
251
252-value=$(snapctl get test.no-suspend-resume)
253-if [ -z "$value" ]; then
254- value="false"
255- snapctl set test.no-suspend-resume="$value"
256+# Store always, so we show defaults when properties are set to empty strings
257+snapctl set debug.enable="$debug_enable"
258+snapctl set test.no-suspend-resume="$test_no_suspend_resume"
259+snapctl set test.quick-suspend-resume="$test_quick_suspend_resume"
260+
261+content=$(_create_props_content)
262+
263+if [ ! -e "$props_file" ]; then
264+ # Installation or refresh from old snap. Assign defaults.
265+ write_props_content "$content"
266+ exit 0
267 fi
268
269-value=$(snapctl get test.quick-suspend-resume)
270-if [ -z "$value" ]; then
271- value="false"
272- snapctl set test.quick-suspend-resume="$value"
273+old_content=$(cat "$props_file")
274+if [ "$content" = "$old_content" ]; then
275+ # No change in properties, this must be a snap refresh
276+ exit 0
277 fi
278+
279+# Some property changed, store new values and re-start daemon to apply changes
280+write_props_content "$content"
281+sleep 1 # wait a bit for props file to be written
282+snapctl restart "$SNAP_NAME"
283diff --git a/snapcraft.yaml b/snapcraft.yaml
284index 604ff7f..cc82a3a 100644
285--- a/snapcraft.yaml
286+++ b/snapcraft.yaml
287@@ -66,6 +66,8 @@ parts:
288 modemmanager: bin/modemmanager
289 mmcli: bin/mmcli
290 mmcli-internal: bin/mmcli-internal
291+ snap-config.sh: bin/snap-config.sh
292+ snap-prop.sh: bin/snap-prop.sh
293
294 changelog:
295 plugin: nil
296diff --git a/tests/lib/utilities.sh b/tests/lib/utilities.sh
297index f0aa6d7..a69a827 100644
298--- a/tests/lib/utilities.sh
299+++ b/tests/lib/utilities.sh
300@@ -19,11 +19,11 @@ install_snap_under_test() {
301 if [ -n "$SNAP_CHANNEL" ] ; then
302 # Don't reinstall if we have it installed already
303 if ! snap list | grep "$SNAP_NAME"; then
304- snap install --"$SNAP_CHANNEL" "$SNAP_NAME"
305+ snap install --channel "$SNAP_CHANNEL" "$SNAP_NAME"
306 fi
307 else
308 # Install first from store to avoid error when performing the connection
309- snap install "$SNAP_NAME"
310+ snap install --channel 22/stable "$SNAP_NAME"
311 # Install prebuilt snap
312 snap install --dangerous "$PROJECT_PATH"/"$SNAP_NAME"_*_"$SNAP_ARCH".snap
313 if [ -n "$SNAP_AUTO_ALIASES" ]; then
314@@ -38,3 +38,28 @@ install_snap_under_test() {
315 fi
316 fi
317 }
318+
319+# $1 instruction to execute repeatedly until complete or max times
320+# $2 sleep time between retries. Default 1sec
321+# $3 max_iterations. Default 20
322+repeat_until_done() {
323+ timeout=1
324+ if [ $# -ge 2 ]; then
325+ timeout=$2
326+ fi
327+
328+ max_iterations=20
329+ if [ $# -ge 3 ]; then
330+ max_iterations=$3
331+ fi
332+
333+ i=0
334+ while [ $i -lt $max_iterations ] ; do
335+ if $(eval $1) ; then
336+ break
337+ fi
338+ sleep $timeout
339+ let i=i+1
340+ done
341+ test $i -lt $max_iterations
342+}
343diff --git a/tests/main/debug-config-option/task.yaml b/tests/main/debug-config-option/task.yaml
344index 3d54557..822cd6c 100644
345--- a/tests/main/debug-config-option/task.yaml
346+++ b/tests/main/debug-config-option/task.yaml
347@@ -4,17 +4,27 @@ execute: |
348 . $TESTSLIB/utilities.sh
349
350 test "$(snap get modem-manager debug.enable)" = "false"
351+ # MM will create the file after being configured, wait a bit
352+ repeat_until_done "test '$(grep -c debug_enable=false /var/snap/modem-manager/current/current_snap_props)' -eq 1" 5
353+ sleep 2
354
355 journalctl --rotate; journalctl --vacuum-time=1ms
356 snap set modem-manager debug.enable=true
357 test "$(snap get modem-manager debug.enable)" = "true"
358- test -e /var/snap/modem-manager/current/.debug_enabled
359+ # MM will create the file after being configured, wait a bit
360+ repeat_until_done "test '$(grep -c debug_enable=true /var/snap/modem-manager/current/current_snap_props)' -eq 1" 5
361+ sleep 2
362 journalctl --no-pager -u snap.modem-manager.modemmanager.service |
363- MATCH "logging: level 'DEBUG'"
364+ grep "\/sbin\/ModemManager" |
365+ grep -c -e "--debug --log-level=DEBUG" |
366+ MATCH "1"
367
368 journalctl --rotate; journalctl --vacuum-time=1ms
369 snap set modem-manager debug.enable=false
370 test "$(snap get modem-manager debug.enable)" = "false"
371- test ! -e /var/snap/modem-manager/current/.debug_enabled
372+ # MM will create the file after being configured, wait a bit
373+ repeat_until_done "test '$(grep -c debug_enable=false /var/snap/modem-manager/current/current_snap_props)' -eq 1" 5
374+ sleep 2
375 journalctl --no-pager -u snap.modem-manager.modemmanager.service |
376- MATCH "logging: level 'INFO'"
377+ grep -c -e "--debug --log-level=DEBUG" |
378+ MATCH "0"
379diff --git a/tests/main/installation/task.yaml b/tests/main/installation/task.yaml
380index 9cb5aa6..d6b43ac 100644
381--- a/tests/main/installation/task.yaml
382+++ b/tests/main/installation/task.yaml
383@@ -19,3 +19,19 @@ execute: |
384 if sudo journalctl --unit=snap.modem-manager.modemmanager.service | MATCH "<debug>"; then
385 exit 1
386 fi
387+
388+ # Make sure test-no-suspend-resume is disabled
389+ if sudo journalctl --unit=snap.modem-manager.modemmanager.service |
390+ grep "\/sbin\/ModemManager" | MATCH "--test-no-suspend-resume"; then
391+ exit 1
392+ fi
393+
394+ # Make sure test-quick-suspend-resume is disabled
395+ if sudo journalctl --unit=snap.modem-manager.modemmanager.service |
396+ grep "\/sbin\/ModemManager" | MATCH "--test-quick-suspend-resume"; then
397+ exit 1
398+ fi
399+
400+ # For debugging dump all snaps and connected slots/plugs
401+ snap list
402+ snap connections --all
403diff --git a/tests/main/network-manager-autoconn/task.yaml b/tests/main/network-manager-autoconn/task.yaml
404index 9add642..30b458d 100644
405--- a/tests/main/network-manager-autoconn/task.yaml
406+++ b/tests/main/network-manager-autoconn/task.yaml
407@@ -6,7 +6,7 @@ execute: |
408 # Service should be up an running
409 wait_for_modem_manager
410
411- snap install --channel=20/stable network-manager
412+ snap install --channel=22/stable network-manager
413 sleep 5
414
415 # Ensure all necessary plugs/slots are connected
416diff --git a/tests/main/test-no-suspend-resume-option/task.yaml b/tests/main/test-no-suspend-resume-option/task.yaml
417new file mode 100644
418index 0000000..b366d06
419--- /dev/null
420+++ b/tests/main/test-no-suspend-resume-option/task.yaml
421@@ -0,0 +1,31 @@
422+summary: Test modem-manager snap test.no-suspend-resume configuration
423+
424+execute: |
425+ . $TESTSLIB/utilities.sh
426+
427+ test "$(snap get modem-manager test.no-suspend-resume)" = "false"
428+ # MM will create the file after being configured, wait a bit
429+ repeat_until_done "test '$(grep -c test_no_suspend_resume=false /var/snap/modem-manager/current/current_snap_props)' -eq 1" 5
430+ sleep 2
431+
432+ journalctl --rotate; journalctl --vacuum-time=1ms
433+ snap set modem-manager test.no-suspend-resume=true
434+ test "$(snap get modem-manager test.no-suspend-resume)" = "true"
435+ # MM will create the file after being configured, wait a bit
436+ repeat_until_done "test '$(grep -c test_no_suspend_resume=true /var/snap/modem-manager/current/current_snap_props)' -eq 1" 5
437+ sleep 2
438+ journalctl --no-pager -u snap.modem-manager.modemmanager.service |
439+ grep "\/sbin\/ModemManager" |
440+ grep -c -e "--test-no-suspend-resume" |
441+ MATCH "1"
442+
443+ journalctl --rotate; journalctl --vacuum-time=1ms
444+ snap set modem-manager test.no-suspend-resume=false
445+ test "$(snap get modem-manager test.no-suspend-resume)" = "false"
446+ # MM will create the file after being configured, wait a bit
447+ repeat_until_done "test '$(grep -c test_no_suspend_resume=false /var/snap/modem-manager/current/current_snap_props)' -eq 1" 5
448+ sleep 2
449+ journalctl --no-pager -u snap.modem-manager.modemmanager.service |
450+ grep "\/sbin\/ModemManager" |
451+ grep -c -e "--test-no-suspend-resume" |
452+ MATCH "0"
453diff --git a/tests/main/test-quick-suspend-resume-option/task.yaml b/tests/main/test-quick-suspend-resume-option/task.yaml
454new file mode 100644
455index 0000000..70da4f9
456--- /dev/null
457+++ b/tests/main/test-quick-suspend-resume-option/task.yaml
458@@ -0,0 +1,31 @@
459+summary: Test modem-manager snap test.quick-suspend-resume configuration
460+
461+execute: |
462+ . $TESTSLIB/utilities.sh
463+
464+ test "$(snap get modem-manager test.quick-suspend-resume)" = "false"
465+ # MM will create the file after being configured, wait a bit
466+ repeat_until_done "test '$(grep -c test_quick_suspend_resume=false /var/snap/modem-manager/current/current_snap_props)' -eq 1" 5
467+ sleep 2
468+
469+ journalctl --rotate; journalctl --vacuum-time=1ms
470+ snap set modem-manager test.quick-suspend-resume=true
471+ test "$(snap get modem-manager test.quick-suspend-resume)" = "true"
472+ # MM will create the file after being configured, wait a bit
473+ repeat_until_done "test '$(grep -c test_quick_suspend_resume=true /var/snap/modem-manager/current/current_snap_props)' -eq 1" 5
474+ sleep 2
475+ journalctl --no-pager -u snap.modem-manager.modemmanager.service |
476+ grep "\/sbin\/ModemManager" |
477+ grep -c -e "--test-quick-suspend-resume" |
478+ MATCH "1"
479+
480+ journalctl --rotate; journalctl --vacuum-time=1ms
481+ snap set modem-manager test.quick-suspend-resume=false
482+ test "$(snap get modem-manager test.quick-suspend-resume)" = "false"
483+ # MM will create the file after being configured, wait a bit
484+ repeat_until_done "test '$(grep -c test_quick_suspend_resume=false /var/snap/modem-manager/current/current_snap_props)' -eq 1" 5
485+ sleep 2
486+ journalctl --no-pager -u snap.modem-manager.modemmanager.service |
487+ grep "\/sbin\/ModemManager" |
488+ grep -c -e "--test-quick-suspend-resume" |
489+ MATCH "0"

Subscribers

People subscribed via source and target branches

to all changes: