Merge ~gnuoy/layer-snap:bug/1934163 into layer-snap:master

Proposed by Liam Young
Status: Merged
Merged at revision: c6596fd57129581b338da6fb59b6e4395d1e85b7
Proposed branch: ~gnuoy/layer-snap:bug/1934163
Merge into: layer-snap:master
Diff against target: 49 lines (+19/-16)
1 file modified
lib/charms/layer/snap.py (+19/-16)
Reviewer Review Type Date Requested Status
Tom Haddon Approve
Cory Johns (community) Approve
Aurelien Lourot (community) Approve
Review via email: mp+405019@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aurelien Lourot (aurelien-lourot) wrote :

LGTM, thanks!

review: Approve
Revision history for this message
Cory Johns (johnsca) wrote :

LGTM as well. The loop pattern was added in 6.0.0 [1] but the decorator pattern has always been supported.

[1]: https://github.com/jd/tenacity/commit/3646aea1602a4854779eaae66a613e3262c7b5d0

review: Approve
Revision history for this message
Tom Haddon (mthaddon) wrote :

LGTM, have merged

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 88b8d89..6909748 100644
3--- a/lib/charms/layer/snap.py
4+++ b/lib/charms/layer/snap.py
5@@ -351,25 +351,28 @@ def _install_store(snapname, **kw):
6 cmd.append(snapname)
7 hookenv.log("Installing {} from store".format(snapname))
8
9- for attempt in tenacity.Retrying(
10+ # Use tenacity decorator for Trusty support (See LP Bug #1934163)
11+ @tenacity.retry(
12 wait=tenacity.wait_fixed(10), # seconds
13 stop=tenacity.stop_after_attempt(3),
14 reraise=True,
15- ):
16- with attempt:
17- try:
18- out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
19- hookenv.log(
20- 'Installation successful cmd="{}" output="{}"'.format(cmd, out),
21- level=hookenv.DEBUG,
22- )
23- reactive.clear_flag(get_local_flag(snapname))
24- except subprocess.CalledProcessError as cp:
25- hookenv.log(
26- 'Installation failed cmd="{}" returncode={} output="{}"'.format(cmd, cp.returncode, cp.output),
27- level=hookenv.ERROR,
28- )
29- raise
30+ )
31+ def _run_install():
32+ try:
33+ out = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
34+ hookenv.log(
35+ 'Installation successful cmd="{}" output="{}"'.format(cmd, out),
36+ level=hookenv.DEBUG,
37+ )
38+ reactive.clear_flag(get_local_flag(snapname))
39+ except subprocess.CalledProcessError as cp:
40+ hookenv.log(
41+ 'Installation failed cmd="{}" returncode={} output="{}"'.format(cmd, cp.returncode, cp.output),
42+ level=hookenv.ERROR,
43+ )
44+ raise
45+
46+ _run_install()
47
48
49 def _refresh_store(snapname, **kw):

Subscribers

People subscribed via source and target branches