Merge ~alfonsosanchezbeato/snappy-hwe-snaps/+git/modem-manager:add-debug-hook into ~snappy-hwe-team/snappy-hwe-snaps/+git/modem-manager:master

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Roberto Mier Escandon
Approved revision: 3018d407a97c4e1202c86d2fc7160471343bbcab
Merged at revision: 6fc7f8627dfb9fdcf7e986e4bc1175510e0a317e
Proposed branch: ~alfonsosanchezbeato/snappy-hwe-snaps/+git/modem-manager:add-debug-hook
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/modem-manager:master
Diff against target: 271 lines (+165/-10)
10 files modified
.gitignore (+1/-0)
bin/mmcli-internal (+25/-0)
bin/modemmanager (+9/-3)
docs/installation.md (+1/-0)
docs/metadata.yaml (+4/-0)
docs/reference/snap-configuration/debug.md (+51/-0)
docs/report-bug.md (+5/-1)
hooks/configure (+26/-0)
snapcraft.yaml (+23/-6)
tests/main/debug-config-option/task.yaml (+20/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Roberto Mier Escandon (community) Approve
Simon Fels Approve
Review via email: mp+333120@code.launchpad.net

Description of the change

Add configure hook with debug option

To post a comment you must log in.
Revision history for this message
Simon Fels (morphis) wrote :

LGTM

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

a pair of comments

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

@Roberto, thanks for the comments. MP re-pushed.

Revision history for this message
Roberto Mier Escandon (rmescandon) 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 :

PASSED: Successfully build documentation, rev: 3018d407a97c4e1202c86d2fc7160471343bbcab

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

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

PASSED: Successfully build documentation, rev: 5059c9be388f89bba3bf94afc859512fd2394711

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

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/.gitignore b/.gitignore
2index 363fb44..d21a10c 100644
3--- a/.gitignore
4+++ b/.gitignore
5@@ -1,6 +1,7 @@
6 parts
7 prime
8 stage
9+snap
10 .tests-extras
11 .spread-reuse*
12 *.snap
13diff --git a/bin/mmcli-internal b/bin/mmcli-internal
14new file mode 100755
15index 0000000..cea01b0
16--- /dev/null
17+++ b/bin/mmcli-internal
18@@ -0,0 +1,25 @@
19+#!/bin/sh
20+
21+# This file is for internal use from hooks only
22+
23+case $SNAP_ARCH in
24+amd64)
25+ TRIPLET="x86_64-linux-gnu"
26+ ;;
27+armhf)
28+ TRIPLET="arm-linux-gnueabihf"
29+ ;;
30+arm64)
31+ TRIPLET="aarch64-linux-gnu"
32+ ;;
33+*)
34+ TRIPLET="$SNAP_ARCH-linux-gnu"
35+ ;;
36+esac
37+
38+export PATH="$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:$SNAP/bin:$PATH"
39+export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/lib:$SNAP/usr/lib:$SNAP/lib/$TRIPLET:$SNAP/usr/lib/$TRIPLET"
40+export LD_LIBRARY_PATH="$SNAP/lib:$SNAP/usr/lib:$SNAP/usr/lib/$TRIPLET:$LD_LIBRARY_PATH"
41+export LD_LIBRARY_PATH=$SNAP_LIBRARY_PATH:$LD_LIBRARY_PATH
42+
43+exec "$SNAP"/usr/bin/mmcli "$@"
44diff --git a/bin/modemmanager b/bin/modemmanager
45index bafdfbc..6088439 100755
46--- a/bin/modemmanager
47+++ b/bin/modemmanager
48@@ -1,11 +1,17 @@
49 #!/bin/sh
50
51-set -e
52-set -x
53+set -ex
54
55 # Until we've reworked the patch which adds snappy support to
56 # ModemManager we keep this as a rework to make the plugin
57 # loader happy and find the plugins at the right location
58 export SNAP_APP_PATH=$SNAP
59
60-exec $SNAP/usr/sbin/ModemManager "$@"
61+LOG_LEVEL="INFO"
62+DEBUG=""
63+if [ -f "$SNAP_DATA"/.debug_enabled ]; then
64+ LOG_LEVEL="DEBUG"
65+ DEBUG="--debug"
66+fi
67+
68+exec "$SNAP"/usr/sbin/ModemManager $DEBUG --log-level="$LOG_LEVEL" "$@"
69diff --git a/docs/installation.md b/docs/installation.md
70index 3d193dd..c74fda3 100644
71--- a/docs/installation.md
72+++ b/docs/installation.md
73@@ -68,3 +68,4 @@ we use _sudo_ with them.
74 * [Gathering Modem Information](gathering-modem-information.md)
75 * [Entering SIM Passwords](entering-sim-passwords.md)
76 * [Configuring Cellular Connections](configuring-cellular-connections.md)
77+ * [Enable Debug Support](reference/snap-configuration/debug.md)
78diff --git a/docs/metadata.yaml b/docs/metadata.yaml
79index 7b9567d..dc2d961 100644
80--- a/docs/metadata.yaml
81+++ b/docs/metadata.yaml
82@@ -17,6 +17,10 @@ navigation:
83 location: configuring-cellular-connections.md
84 - title: Reference
85 children:
86+ - title: Snap Configuration
87+ children:
88+ - title: Debug
89+ location: reference/snap-configuration/debug.md
90 - title: Available Commands
91 location: reference/available-commands.md
92 - title: DBUS API
93diff --git a/docs/reference/snap-configuration/debug.md b/docs/reference/snap-configuration/debug.md
94new file mode 100644
95index 0000000..16b3bd8
96--- /dev/null
97+++ b/docs/reference/snap-configuration/debug.md
98@@ -0,0 +1,51 @@
99+---
100+title: Debug
101+table_of_contents: True
102+---
103+
104+# Debug
105+
106+The debug configuration option controls the amount of logs produced by the
107+modem-manager snap. It is useful for collecting information required to either
108+report a bug or investigate a modem-manager failure.
109+
110+It is disabled by default and has to be explicitely turned on for usage.
111+
112+Note that the debug logs may contain sensitive information.
113+
114+## Enable Debug
115+
116+The modem-manager snap provides a single configuration option which can be used to
117+turn the debug feature either on or off:
118+
119+ * **debug.enable**
120+
121+The option takes a boolean value. The meaning of the possible values are:
122+
123+ * **true:** Enable logging debug information
124+ * **false (default):** Disable logging debug information
125+
126+Changing the **debug** configuration option has immediate effect and also
127+affects future executions of the MM daemon.
128+
129+**Example:** Enable debug feature
130+
131+```
132+$ snap set modem-manager debug.enable=true
133+```
134+
135+<br/>
136+**Example:** Disable debug feature.
137+
138+```
139+$ snap set modem-manager debug.enable=false
140+```
141+
142+## Viewing logs
143+
144+The debug information, when enabled, will be available in the journal and can
145+be viewed with:
146+
147+```
148+$ journalctl --no-pager -u snap.modem-manager.modemmanager.service
149+```
150diff --git a/docs/report-bug.md b/docs/report-bug.md
151index 48f661a..b263433 100644
152--- a/docs/report-bug.md
153+++ b/docs/report-bug.md
154@@ -7,7 +7,11 @@ table_of_contents: False
155
156 Bugs can be reported [here](https://bugs.launchpad.net/snappy-hwe-snaps/+filebug).
157
158-When submitting a bug report, please attach system log coming from the journal:
159+If the bug can be reproduced, [enabling the debug
160+output](reference/snap-configuration/debug.md) before doing so is
161+highly recommended.
162+
163+When submitting the bug report, please attach system log coming from the journal:
164
165 * $ journalctl --no-pager > system-log
166
167diff --git a/hooks/configure b/hooks/configure
168new file mode 100755
169index 0000000..c4fd410
170--- /dev/null
171+++ b/hooks/configure
172@@ -0,0 +1,26 @@
173+#!/bin/bash
174+
175+set -ex
176+
177+exec > "$SNAP_COMMON"/hook-log.txt 2>&1
178+
179+# $1 true/false for enabling/disabling debug log level in MM
180+# We create/remove the file for future executions and also change
181+# the logging level of the running daemon.
182+switch_debug_enable() {
183+ DEBUG_FILE=$SNAP_DATA/.debug_enabled
184+ if [ "$1" = "true" ]; then
185+ "$SNAP"/bin/mmcli-internal --set-logging=DEBUG
186+ touch "$DEBUG_FILE"
187+ else
188+ "$SNAP"/bin/mmcli-internal --set-logging=INFO
189+ rm -f "$DEBUG_FILE"
190+ fi
191+}
192+
193+value=$(snapctl get debug.enable)
194+if [ -z "$value" ]; then
195+ value="false"
196+ snapctl set debug.enable="$value"
197+fi
198+switch_debug_enable "$value"
199diff --git a/snapcraft.yaml b/snapcraft.yaml
200index edd364d..77b3b8c 100644
201--- a/snapcraft.yaml
202+++ b/snapcraft.yaml
203@@ -17,6 +17,10 @@ slots:
204 plugs:
205 mmcli: modem-manager
206
207+hooks:
208+ configure:
209+ plugs: [mmcli]
210+
211 apps:
212 mmcli:
213 command: bin/mmcli
214@@ -28,12 +32,25 @@ apps:
215 slots: [service]
216
217 parts:
218- modemmanager-common:
219- plugin: copy
220- files:
221- bin/modemmanager: bin/modemmanager
222- bin/mmcli: bin/mmcli
223- data/copyright: usr/share/doc/modem-manager/copyright
224+ modemmanager-hooks:
225+ plugin: dump
226+ source: hooks
227+ organize:
228+ configure: meta/hooks/configure
229+
230+ modemmanager-bin:
231+ plugin: dump
232+ source: bin
233+ organize:
234+ modemmanager: bin/modemmanager
235+ mmcli: bin/mmcli
236+ mmcli-internal: bin/mmcli-internal
237+
238+ modemmanager-data:
239+ plugin: dump
240+ source: data
241+ organize:
242+ copyright: usr/share/doc/modem-manager/copyright
243
244 libmbim:
245 plugin: autotools
246diff --git a/tests/main/debug-config-option/task.yaml b/tests/main/debug-config-option/task.yaml
247new file mode 100644
248index 0000000..3d54557
249--- /dev/null
250+++ b/tests/main/debug-config-option/task.yaml
251@@ -0,0 +1,20 @@
252+summary: Test modem-manager snap debug configuration
253+
254+execute: |
255+ . $TESTSLIB/utilities.sh
256+
257+ test "$(snap get modem-manager debug.enable)" = "false"
258+
259+ journalctl --rotate; journalctl --vacuum-time=1ms
260+ snap set modem-manager debug.enable=true
261+ test "$(snap get modem-manager debug.enable)" = "true"
262+ test -e /var/snap/modem-manager/current/.debug_enabled
263+ journalctl --no-pager -u snap.modem-manager.modemmanager.service |
264+ MATCH "logging: level 'DEBUG'"
265+
266+ journalctl --rotate; journalctl --vacuum-time=1ms
267+ snap set modem-manager debug.enable=false
268+ test "$(snap get modem-manager debug.enable)" = "false"
269+ test ! -e /var/snap/modem-manager/current/.debug_enabled
270+ journalctl --no-pager -u snap.modem-manager.modemmanager.service |
271+ MATCH "logging: level 'INFO'"

Subscribers

People subscribed via source and target branches