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
diff --git a/lib/charms/layer/snap.py b/lib/charms/layer/snap.py
index 141ea1f..56b9bf8 100644
--- a/lib/charms/layer/snap.py
+++ b/lib/charms/layer/snap.py
@@ -235,8 +235,8 @@ def set_refresh_timer(timer=''):
235def get(snapname, key):235def get(snapname, key):
236 '''Gets configuration options for a snap236 '''Gets configuration options for a snap
237237
238 This method returns the output that snapctl get command prints out.238 This method returns the stripped output from the snap get command.
239 This method will fail if snapname is not an installed snap239 This method will fail if snapname is not an installed snap.
240 '''240 '''
241 hookenv.log('Get config {} for snap {}'.format(key, snapname))241 hookenv.log('Get config {} for snap {}'.format(key, snapname))
242 if not reactive.is_flag_set(get_installed_flag(snapname)):242 if not reactive.is_flag_set(get_installed_flag(snapname)):
@@ -245,7 +245,7 @@ def get(snapname, key):
245 snapname), hookenv.WARNING)245 snapname), hookenv.WARNING)
246 return246 return
247247
248 return subprocess.check_output(['snap', 'get', snapname, key])248 return subprocess.check_output(['snap', 'get', snapname, key]).strip()
249249
250def get_installed_version(snapname):250def get_installed_version(snapname):
251 '''Gets the installed version of a snapname.251 '''Gets the installed version of a snapname.

Subscribers

People subscribed via source and target branches

to all changes: