Merge ~kwmonroe/layer-snap:master into ~stub/layer-snap:master

Proposed by Kevin W Monroe
Status: Merged
Merged at revision: 11aefcb91e1f2b63de4ae685a8b90f9babfd9f9f
Proposed branch: ~kwmonroe/layer-snap:master
Merge into: ~stub/layer-snap:master
Diff against target: 24 lines (+3/-3)
1 file modified
lib/charms/layer/snap.py (+3/-3)
Reviewer Review Type Date Requested Status
Stuart Bishop Approve
Review via email: mp+366290@code.launchpad.net

Description of the change

In fixing bug 1823293, we had to take special care to handle whitespace returned by snap.get:

https://git.launchpad.net/layer-snap/tree/lib/charms/layer/snap.py#n248

-----
sudo snap set core refresh.timer=''
...
>>> subprocess.check_output(['sudo', 'snap', 'get', 'core', 'refresh.timer']).decode('utf-8')
'\n'
-----

We *can* work around this by calling foo = snap.get().strip(), but I'm struggling to find a case where I'd want snap.get returning unstripped output. Hence, this MP strips output from the call to 'snap get'.

To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Fine

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/charms/layer/snap.py b/lib/charms/layer/snap.py
2index 141ea1f..56b9bf8 100644
3--- a/lib/charms/layer/snap.py
4+++ b/lib/charms/layer/snap.py
5@@ -235,8 +235,8 @@ def set_refresh_timer(timer=''):
6 def get(snapname, key):
7 '''Gets configuration options for a snap
8
9- This method returns the output that snapctl get command prints out.
10- This method will fail if snapname is not an installed snap
11+ This method returns the stripped output from the snap get command.
12+ This method will fail if snapname is not an installed snap.
13 '''
14 hookenv.log('Get config {} for snap {}'.format(key, snapname))
15 if not reactive.is_flag_set(get_installed_flag(snapname)):
16@@ -245,7 +245,7 @@ def get(snapname, key):
17 snapname), hookenv.WARNING)
18 return
19
20- return subprocess.check_output(['snap', 'get', snapname, key])
21+ return subprocess.check_output(['snap', 'get', snapname, key]).strip()
22
23 def get_installed_version(snapname):
24 '''Gets the installed version of a snapname.

Subscribers

People subscribed via source and target branches

to all changes: