Merge lp:~blake-rouse/curtin/fix-1453869 into lp:~curtin-dev/curtin/trunk

Proposed by Blake Rouse
Status: Merged
Merged at revision: 212
Proposed branch: lp:~blake-rouse/curtin/fix-1453869
Merge into: lp:~curtin-dev/curtin/trunk
Diff against target: 106 lines (+43/-9)
2 files modified
curtin/deps/install.py (+17/-4)
curtin/util.py (+26/-5)
To merge this branch: bzr merge lp:~blake-rouse/curtin/fix-1453869
Reviewer Review Type Date Requested Status
curtin developers Pending
Review via email: mp+261241@code.launchpad.net

Commit message

Retry apt-get update and apt-get install command a maximum of 3 times to make sure no transient issues prevent the deployment from succeeding.

To post a comment you must log in.
lp:~blake-rouse/curtin/fix-1453869 updated
212. By Blake Rouse

Use sleeps between retries. Remove retries on apt-get install.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'curtin/deps/install.py'
2--- curtin/deps/install.py 2015-03-20 20:20:14 +0000
3+++ curtin/deps/install.py 2015-06-05 17:05:49 +0000
4@@ -23,6 +23,7 @@
5 if __name__ == '__main__':
6 import subprocess
7 import sys
8+ import time
9 if sys.version_info[0] == 2:
10 pkgs = ['python-yaml']
11 else:
12@@ -32,8 +33,20 @@
13
14 cmds = [apt_update, apt_install + pkgs]
15 for cmd in cmds:
16- try:
17- subprocess.check_call(cmd)
18- except subprocess.CalledProcessError as e:
19- sys.exit(e.returncode)
20+ # Retry each command with a wait between. The final wait time in this
21+ # list is zero because we don't need to wait at the end of the last
22+ # call.
23+ wait_times = [0.5, 1, 2, 0]
24+ for i, wait in enumerate(wait_times):
25+ try:
26+ subprocess.check_call(cmd)
27+ returncode = 0
28+ except subprocess.CalledProcessError as e:
29+ returncode = e.returncode
30+ if returncode == 0:
31+ break
32+ else:
33+ time.sleep(wait)
34+ if returncode != 0:
35+ sys.exit(returncode)
36 sys.exit(0)
37
38=== modified file 'curtin/util.py'
39--- curtin/util.py 2015-06-05 13:46:46 +0000
40+++ curtin/util.py 2015-06-05 17:05:49 +0000
41@@ -30,8 +30,8 @@
42 _INSTALLED_MAIN = '/usr/bin/curtin'
43
44
45-def subp(args, data=None, rcs=None, env=None, capture=False, shell=False,
46- logstring=False):
47+def _subp(args, data=None, rcs=None, env=None, capture=False, shell=False,
48+ logstring=False):
49 if rcs is None:
50 rcs = [0]
51
52@@ -73,6 +73,25 @@
53 return (out, err)
54
55
56+def subp(*args, **kwargs):
57+ retries = []
58+ if "retries" in kwargs:
59+ retries = kwargs.pop("retries")
60+
61+ # Add the final wait time at the end. It is zero because we want
62+ # to execute the final command and don't want it to wait.
63+ retries.append(0)
64+
65+ # Retry with waits between the retried command.
66+ for i, wait in enumerate(retries):
67+ try:
68+ return _subp(*args, **kwargs)
69+ except ProcessExecutionError:
70+ if i == len(retries) - 1:
71+ raise
72+ time.sleep(wait)
73+
74+
75 def load_command_environment(env=os.environ, strict=False):
76
77 mapping = {'scratch': 'WORKING_DIR', 'fstab': 'OUTPUT_FSTAB',
78@@ -431,7 +450,8 @@
79 return False
80
81
82-def apt_update(target=None, env=None, force=False, comment=None):
83+def apt_update(target=None, env=None, force=False, comment=None,
84+ retries=[0.5, 1, 2]):
85 marker = "tmp/curtin.aptupdate"
86 if target is None:
87 target = "/"
88@@ -451,7 +471,7 @@
89
90 apt_update = ['apt-get', 'update', '--quiet']
91 with RunInChroot(target) as inchroot:
92- inchroot(apt_update, env=env)
93+ inchroot(apt_update, env=env, retries=retries)
94
95 with open(marker, "w") as fp:
96 fp.write(comment + "\n")
97@@ -479,7 +499,8 @@
98
99 apt_update(target, comment=' '.join(pkglist))
100 with RunInChroot(target) as inchroot:
101- return inchroot(emd + apt_inst_cmd + list(pkglist), env=env)
102+ return inchroot(
103+ emd + apt_inst_cmd + list(pkglist), env=env)
104
105
106 def is_uefi_bootable():

Subscribers

People subscribed via source and target branches