Merge ~jason-hobbs/layer-snap:fix-1819231 into ~stub/layer-snap:master

Proposed by Jason Hobbs
Status: Merged
Merged at revision: d5e4d3ad3bc878c1f4810172c78111bd3f290996
Proposed branch: ~jason-hobbs/layer-snap:fix-1819231
Merge into: ~stub/layer-snap:master
Diff against target: 121 lines (+10/-44)
1 file modified
lib/charms/layer/snap.py (+10/-44)
Reviewer Review Type Date Requested Status
Stuart Bishop Approve
Review via email: mp+366424@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Stuart Bishop (stub) wrote :

Looks ok, but the print statements need tweaking to avoid ugly output in the logs (b'...').

Are all the bug fixes backported to trusty snapd?

review: Needs Information
Revision history for this message
Jason Hobbs (jason-hobbs) wrote :

trusty has the same snapd version as bionic - 2.38 - so we're good there.

The decode you suggested leads to the same problem all over again:

http://paste.ubuntu.com/p/TF5x72ZMgN/

We can't decode to utf-8 and then try to print if python thinks the locale is ascii:

http://paste.ubuntu.com/p/gHJ3smCQqw/

I think it should stay as is - it's not too ugly in the log.

Revision history for this message
Stuart Bishop (stub) wrote :

ack. Would need to encode('ascii', 'replace') in lieu of a real locale.

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 25e3135..c8f97c2 100644
3--- a/lib/charms/layer/snap.py
4+++ b/lib/charms/layer/snap.py
5@@ -21,7 +21,6 @@ from charmhelpers.core import hookenv
6 from charms import layer
7 from charms import reactive
8 from charms.reactive.helpers import any_file_changed, data_changed
9-from time import sleep
10 from datetime import datetime, timedelta
11
12
13@@ -96,8 +95,7 @@ def refresh(snapname, **kw):
14
15 def remove(snapname):
16 hookenv.log('Removing snap {}'.format(snapname))
17- subprocess.check_call(['snap', 'remove', snapname],
18- universal_newlines=True)
19+ subprocess.check_call(['snap', 'remove', snapname])
20 reactive.clear_flag(get_installed_flag(snapname))
21
22
23@@ -108,8 +106,7 @@ def connect(plug, slot):
24 the two arguments to the 'snap connect' command.
25 '''
26 hookenv.log('Connecting {} to {}'.format(plug, slot), hookenv.DEBUG)
27- subprocess.check_call(['snap', 'connect', plug, slot],
28- universal_newlines=True)
29+ subprocess.check_call(['snap', 'connect', plug, slot])
30
31
32 def connect_all():
33@@ -139,8 +136,7 @@ def disable(snapname):
34 snapname), hookenv.WARNING)
35 return
36
37- subprocess.check_call(['snap', 'disable', snapname],
38- universal_newlines=True)
39+ subprocess.check_call(['snap', 'disable', snapname])
40 reactive.set_flag(get_disabled_flag(snapname))
41
42
43@@ -159,8 +155,7 @@ def enable(snapname):
44 snapname), hookenv.WARNING)
45 return
46
47- subprocess.check_call(['snap', 'enable', snapname],
48- universal_newlines=True)
49+ subprocess.check_call(['snap', 'enable', snapname])
50 reactive.clear_flag(get_disabled_flag(snapname))
51
52
53@@ -177,8 +172,7 @@ def restart(snapname):
54 snapname), hookenv.WARNING)
55 return
56
57- subprocess.check_call(['snap', 'restart', snapname],
58- universal_newlines=True)
59+ subprocess.check_call(['snap', 'restart', snapname])
60
61
62 def set(snapname, key, value):
63@@ -298,7 +292,7 @@ def _install_local(path, **kw):
64 cmd.append('--dangerous')
65 cmd.append(path)
66 hookenv.log('Installing {} from local resource'.format(path))
67- subprocess.check_call(cmd, universal_newlines=True)
68+ subprocess.check_call(cmd)
69
70
71 def _install_store(snapname, **kw):
72@@ -306,26 +300,8 @@ def _install_store(snapname, **kw):
73 cmd.extend(_snap_args(**kw))
74 cmd.append(snapname)
75 hookenv.log('Installing {} from store'.format(snapname))
76- # Attempting the snap install 3 times to resolve unexpected EOF.
77- # This is a work around to lp:1677557. Stop doing this once it
78- # is resolved everywhere.
79- for attempt in range(3):
80- try:
81- out = subprocess.check_output(cmd, universal_newlines=True,
82- stderr=subprocess.STDOUT)
83- print(out)
84- break
85- except subprocess.CalledProcessError as x:
86- print(x.output)
87- # Per https://bugs.launchpad.net/bugs/1622782, we don't
88- # get a useful error code out of 'snap install', much like
89- # 'snap refresh' below. Remove this when we can rely on
90- # snap installs everywhere returning 0 for 'already insatlled'
91- if "already installed" in x.output:
92- break
93- if attempt == 2:
94- raise
95- sleep(5)
96+ out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
97+ print(out)
98
99
100 def _refresh_store(snapname, **kw):
101@@ -337,18 +313,8 @@ def _refresh_store(snapname, **kw):
102 cmd.extend(_snap_args(**kw))
103 cmd.append(snapname)
104 hookenv.log('Refreshing {} from store'.format(snapname))
105- # Per https://bugs.launchpad.net/layer-snap/+bug/1588322 we don't get
106- # a useful error code out of 'snap refresh'. We are forced to parse
107- # the output to see if it is a non-fatal error.
108- # subprocess.check_call(cmd, universal_newlines=True)
109- try:
110- out = subprocess.check_output(cmd, universal_newlines=True,
111- stderr=subprocess.STDOUT)
112- print(out)
113- except subprocess.CalledProcessError as x:
114- print(x.output)
115- if "has no updates available" not in x.output:
116- raise
117+ out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
118+ print(out)
119
120
121 def _resource_get(snapname):

Subscribers

People subscribed via source and target branches

to all changes: