Merge lp:~smoser/charm-helpers/no-translation-errors into lp:charm-helpers

Proposed by Scott Moser
Status: Needs review
Proposed branch: lp:~smoser/charm-helpers/no-translation-errors
Merge into: lp:charm-helpers
Diff against target: 48 lines (+32/-0)
1 file modified
charmhelpers/fetch/__init__.py (+32/-0)
To merge this branch: bzr merge lp:~smoser/charm-helpers/no-translation-errors
Reviewer Review Type Date Requested Status
Stuart Bishop (community) Abstain
Review via email: mp+273750@code.launchpad.net

Commit message

Heavily reduce number of files downloaded by apt-get update

apt-get update downloads loads of files. 2 types of files not likely used on a system that is installing charms are apt-source files and translation files.

This will stop apt from downloading either of those, and by nature of reducing files downloaded, reduce the chance for the dreaded Hash sum mismatch.

To post a comment you must log in.
463. By Scott Moser

fix missing import

Revision history for this message
Ryan Harper (raharper) :
464. By Scott Moser

Drop the source entries also.

Revision history for this message
Scott Moser (smoser) wrote :

In a less permanent path to the same end, curtin now has
  https://code.launchpad.net/~smoser/curtin/trunk.no-translations/+merge/275451

That basically filters out deb-src lines and and then runs apt-get update with
   --option=Acquire::Languages=none

Revision history for this message
Stuart Bishop (stub) :
review: Abstain

Unmerged revisions

464. By Scott Moser

Drop the source entries also.

463. By Scott Moser

fix missing import

462. By Scott Moser

disable use of translation files by apt before an apt-get update

translation files are the largest source of Hash sum mismatch
These should be permanently fixed in the 16.04 cycle for 16.04
and later under LP: #804252 and LP: #1430011. But because of the
prevalence of errors and proxies that do not handle these specially
(LP: #1474417) we just configure apt to not use translation files.

Even in a world where 'Hash Sum mismatch' errors do not occur, this
is still a win in that we do not download data that no one would
ever read.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'charmhelpers/fetch/__init__.py'
2--- charmhelpers/fetch/__init__.py 2015-08-10 13:34:31 +0000
3+++ charmhelpers/fetch/__init__.py 2015-10-07 20:57:23 +0000
4@@ -26,6 +26,7 @@
5 config,
6 log,
7 )
8+import glob
9 import os
10
11 import six
12@@ -208,6 +209,37 @@
13
14 def apt_update(fatal=False):
15 """Update local apt cache"""
16+
17+ # translation files are the largest source of Hash sum mismatch
18+ # These should be permanently fixed in the 16.04 cycle for 16.04
19+ # and later under LP: #804252 and LP: #1430011. But because of the
20+ # prevalence of errors and proxies that do not handle these specially
21+ # (LP: #1474417) we just configure apt to not use translation files.
22+ notrans_f = "/etc/apt/apt.conf.d/99notranslations"
23+ if not os.path.isfile(notrans_f):
24+ with open(notrans_f, "w") as fp:
25+ fp.write('Acquire::Languages "none";\n')
26+ for tfile in glob.glob("/var/lib/apt/lists/*Translation*"):
27+ if os.path.isfile(tfile):
28+ os.unlink(tfile)
29+
30+ listfiles = glob.glob("/etc/apt/sources.list")
31+ listfiles += glob.glob("/etc/apt/sources.list.d/*.list")
32+ for sfile in listfiles:
33+ if not os.path.isfile(sfile):
34+ continue
35+ with open(sfile, "r") as fp:
36+ contents = fp.read()
37+
38+ startswith = contents.startswith("deb-src")
39+ if not startswith and "\ndeb-src" not in contents:
40+ continue
41+
42+ with open(sfile, "w") as fp:
43+ if startswith:
44+ fp.write("# ")
45+ fp.write(contents.replace("\ndeb-src", "\n# deb-src"))
46+
47 cmd = ['apt-get', 'update']
48 _run_apt_command(cmd, fatal)
49

Subscribers

People subscribed via source and target branches