Merge ~kzapalowicz/snappy-hwe-snaps/+git/udisks2:feature/add-debug-config-option into ~snappy-hwe-team/snappy-hwe-snaps/+git/udisks2:master

Proposed by Konrad Zapałowicz
Status: Merged
Approved by: Simon Fels
Approved revision: 8118fb0ffbf930962c3b0572f63d98ab09add425
Merged at revision: 1024b0f6cb4d383a9456863d94c826e8c3e47feb
Proposed branch: ~kzapalowicz/snappy-hwe-snaps/+git/udisks2:feature/add-debug-config-option
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/udisks2:master
Diff against target: 228 lines (+130/-5)
8 files modified
docs/installation.md (+1/-0)
docs/metadata.yaml (+2/-0)
docs/reference/snap-configuration/debug.md (+50/-0)
docs/report-bug.md (+10/-2)
snap/hooks/configure (+24/-3)
tests/main/conf-debug/task.yaml (+30/-0)
tests/main/no-automount-for-boot-devices/task.yaml (+1/-0)
udisks2/udisks2.go (+12/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Simon Fels Approve
Review via email: mp+324922@code.launchpad.net

Description of the change

Add debug.enable configuration option

This option switches on/off the logging to the journal from
udisks2 package.

To post a comment you must log in.
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
Simon Fels (morphis) :
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: 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
Simon Fels (morphis) :
review: Needs Fixing
Revision history for this message
Simon Fels (morphis) wrote :

LGTM

review: Approve
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/docs/installation.md b/docs/installation.md
2index 8abb851..d56d4b2 100644
3--- a/docs/installation.md
4+++ b/docs/installation.md
5@@ -54,3 +54,4 @@ Now you have udisks2 successfully installed.
6 ## Next Steps
7
8 * [Enable Automount Support](reference/snap-configuration/automount.md)
9+ * [Enable Debug Support](reference/snap-configuration/debug.md)
10diff --git a/docs/metadata.yaml b/docs/metadata.yaml
11index b5f1394..6b2d00d 100644
12--- a/docs/metadata.yaml
13+++ b/docs/metadata.yaml
14@@ -15,6 +15,8 @@ navigation:
15 children:
16 - title: Automount Support
17 location: reference/snap-configuration/automount.md
18+ - title: Debug Support
19+ location: reference/snap-configuration/debug.md
20 - title: Supported Filesystems
21 location: reference/supported-filesystems.md
22 - title: Available Commands
23diff --git a/docs/reference/snap-configuration/debug.md b/docs/reference/snap-configuration/debug.md
24new file mode 100644
25index 0000000..d6e4b2f
26--- /dev/null
27+++ b/docs/reference/snap-configuration/debug.md
28@@ -0,0 +1,50 @@
29+---
30+title: Debug
31+table_of_contents: True
32+---
33+
34+# Debug
35+
36+Debug is a feature that controls the amount of logs produced by the udisks2
37+snap. It is useful for collecting information required to either report a bug or
38+investigate a udisks2 failure (if happens).
39+
40+The default is disabled by default and has to be explicitely turned on for
41+usage.
42+
43+## Enable Debug
44+
45+The udisks2 snap provides a single configuration option which can be used to
46+turn the debug feature either on or off:
47+
48+ * **debug.enable**
49+
50+The option takes a boolean value. The meaning of the possible values are:
51+
52+ * **true:** Enable logging debug information
53+ * **false (default):** Disable logging debug information
54+
55+Chnaging the **debug.enable** configuration option does not have immediate
56+effect and require a restart of the ciborium service.
57+
58+**Example:** Enable debug feature
59+
60+```
61+$ snap set udisks2 debug.enable=true
62+```
63+
64+<br/>
65+**Example:** Disable debug feature.
66+
67+```
68+$ snap set udisks2 debug.enable=false
69+```
70+
71+## Viewing logs
72+
73+The debug information, when enabled, will be available in the journal and can
74+be viewed with:
75+
76+```
77+$ journalctl --no-pager -u snap.udisks2.ciborium
78+```
79diff --git a/docs/report-bug.md b/docs/report-bug.md
80index 311a239..32f1a4c 100644
81--- a/docs/report-bug.md
82+++ b/docs/report-bug.md
83@@ -7,9 +7,17 @@ table_of_contents: False
84
85 Bugs can be reported [here](https://bugs.launchpad.net/snappy-hwe-snaps/+filebug).
86
87-When submitting a bug report, please attach:
88+When submitting a bug report, please first enable logging by setting the
89+**debug.enabled** snao option to **true** and restarting the ciborium service.
90
91- * */var/log/syslog*
92+```
93+$ sudo snap set udisks2 debug.enable=true
94+$ sudo systemctl restart snap.udisks2.ciborium.service
95+```
96+
97+Now repeat the steps that lead to the failure and, please attach:
98+
99+ * $ journalctl --no-pager > system-log
100
101 And the output of the following two commands:
102
103diff --git a/snap/hooks/configure b/snap/hooks/configure
104index 12d498d..6d047f3 100755
105--- a/snap/hooks/configure
106+++ b/snap/hooks/configure
107@@ -1,6 +1,7 @@
108 #!/bin/sh
109
110-FLAG_FILE="$SNAP_COMMON/.automount_enabled"
111+# Option automount
112+AUTOMOUNT_FILE="$SNAP_COMMON/.automount_enabled"
113
114 value=$(snapctl get automount.enable)
115 if [ -z "$value" ]; then
116@@ -10,10 +11,30 @@ if [ -z "$value" ]; then
117 fi
118
119 if [ "$value" = "true" ]; then
120- touch "$FLAG_FILE"
121+ if [ ! -f "$AUTOMOUNT_FILE" ]; then
122+ touch "$AUTOMOUNT_FILE"
123+ fi
124 elif [ "$value" = "false" ]; then
125- rm -f "$FLAG_FILE"
126+ if [ -f "$AUTOMOUNT_FILE" ]; then
127+ rm -f "$AUTOMOUNT_FILE"
128+ fi
129 fi
130
131+# Option debug
132+DEBUG_FILE="$SNAP_COMMON/.debug_enabled"
133
134+value=$(snapctl get debug.enable)
135+if [ -z "$value" ]; then
136+ snapctl set debug.enable="false"
137+ "$value"="false"
138+fi
139
140+if [ "$value" = "true" ]; then
141+ if [ ! -f "$DEBUG_FILE" ]; then
142+ touch "$DEBUG_FILE"
143+ fi
144+elif [ "$value" = "false" ]; then
145+ if [ -f "$DEBUG_FILE" ]; then
146+ rm -f "$DEBUG_FILE"
147+ fi
148+fi
149diff --git a/tests/main/conf-debug/task.yaml b/tests/main/conf-debug/task.yaml
150new file mode 100644
151index 0000000..b774b79
152--- /dev/null
153+++ b/tests/main/conf-debug/task.yaml
154@@ -0,0 +1,30 @@
155+summary: Test udisks2 snap debug configuration
156+
157+execute: |
158+ . $TESTSLIB/utilities.sh
159+ DATE=`date +"%F %T"`
160+
161+ # Service should be up and running
162+ wait_for_systemd_service snap.udisks2.udisksd
163+
164+ # .. so should ciborium
165+ wait_for_systemd_service snap.udisks2.ciborium
166+
167+ # Check that automount is disabled by default
168+ test "$(snap get udisks2 debug.enable)" = false
169+ test ! -e /var/snap/udisks2/common/.debug_enabled
170+ journalctl --no-pager -u snap.udisks2.ciborium.service -b -S "$DATE" | grep -vPzq ".go"
171+
172+ # Check that enabling debug DTRT
173+ snap set udisks2 debug.enable=true
174+ test "$(snap get udisks2 debug.enable)" = true
175+ DATE=`date +"%F %T"`
176+ sudo systemctl restart snap.udisks2.ciborium.service
177+ wait_for_systemd_service snap.udisks2.ciborium
178+ test -e /var/snap/udisks2/common/.debug_enabled
179+ journalctl --no-pager -u snap.udisks2.ciborium.service -b -S "$DATE" | grep -Pzq ".go"
180+
181+ # And for disabling
182+ snap set udisks2 debug.enable=false
183+ test "$(snap get udisks2 debug.enable)" = false
184+ test ! -e /var/snap/udisks2/common/.debug_enabled
185diff --git a/tests/main/no-automount-for-boot-devices/task.yaml b/tests/main/no-automount-for-boot-devices/task.yaml
186index d4d86c6..1548217 100644
187--- a/tests/main/no-automount-for-boot-devices/task.yaml
188+++ b/tests/main/no-automount-for-boot-devices/task.yaml
189@@ -42,6 +42,7 @@ execute: |
190 # wouldn't do otherwise if we keep it running (which we could as it
191 # automatically detects if automount is enabled or not).
192 snap set udisks2 automount.enable=true
193+ snap set udisks2 debug.enable=true
194 systemctl restart snap.udisks2.ciborium
195
196 wait_for_systemd_service snap.udisks2.ciborium
197diff --git a/udisks2/udisks2.go b/udisks2/udisks2.go
198index ec8217c..954dfa3 100644
199--- a/udisks2/udisks2.go
200+++ b/udisks2/udisks2.go
201@@ -23,6 +23,7 @@ package udisks2
202 import (
203 "errors"
204 "fmt"
205+ "io/ioutil"
206 "os"
207 "path"
208 "path/filepath"
209@@ -52,8 +53,19 @@ const (
210 dbusAddedSignal = "InterfacesAdded"
211 dbusRemovedSignal = "InterfacesRemoved"
212 defaultMaximumWaitTime = 64
213+ debugEnabledFlagFile = ".debug_enabled"
214 )
215
216+func init() {
217+ snapCommon := os.Getenv("SNAP_COMMON")
218+ path := filepath.Join(snapCommon, debugEnabledFlagFile)
219+
220+ // File does not exists which means debug is not enabled
221+ if _, err := os.Stat(path); os.IsNotExist(err) {
222+ log.SetOutput(ioutil.Discard)
223+ }
224+}
225+
226 type MountEvent struct {
227 Path dbus.ObjectPath
228 Mountpoint string

Subscribers

People subscribed via source and target branches