Merge lp:~bac/charms/oneiric/buildbot-master/fix-apt-sources into lp:~yellow/charms/oneiric/buildbot-master/trunk

Proposed by Brad Crittenden
Status: Superseded
Proposed branch: lp:~bac/charms/oneiric/buildbot-master/fix-apt-sources
Merge into: lp:~yellow/charms/oneiric/buildbot-master/trunk
Diff against target: 67 lines (+39/-0)
1 file modified
hooks/install (+39/-0)
To merge this branch: bzr merge lp:~bac/charms/oneiric/buildbot-master/fix-apt-sources
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+100853@code.launchpad.net

This proposal has been superseded by a proposal from 2012-04-05.

Description of the change

Change /etc/apt/sources.list to overcome problems with EC2 repository hash that leaves the EC2 repositories unusable.

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

It's a shame we have to do this, but the branch itself looks good.

review: Approve (code)
42. By Brad Crittenden

Only change sources.list if a call to 'apt-get update' causes an error.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/install'
2--- hooks/install 2012-03-20 15:29:18 +0000
3+++ hooks/install 2012-04-05 15:28:18 +0000
4@@ -3,9 +3,11 @@
5 # Copyright 2012 Canonical Ltd. This software is licensed under the
6 # GNU Affero General Public License version 3 (see the file LICENSE).
7
8+from datetime import datetime
9 import os
10 import shutil
11 import subprocess
12+import textwrap
13
14
15 def run(*args, **kwargs):
16@@ -72,7 +74,43 @@
17 raise
18
19
20+def fix_apt_sources():
21+ # Problems have frequently been seen with the repositories used by ec2 not
22+ # having the correct hash and being unuseable. To avoid that problem, we
23+ # replace /etc/apt/sources.list with known good repositories. The cost of
24+ # this is having to go outside of the ec2 environment to download
25+ # packages.
26+ good_sources = textwrap.dedent("""\
27+ # Installed by the buildbot-master charm installation hook at
28+ # {}
29+ deb http://security.ubuntu.com/ubuntu/ precise-security universe main
30+ deb-src http://security.ubuntu.com/ubuntu/ precise-security universe main
31+ deb http://archive.ubuntu.com/ubuntu precise-updates universe main
32+ deb-src http://archive.ubuntu.com/ubuntu precise-updates universe main
33+ deb http://archive.ubuntu.com/ubuntu precise main universe
34+ deb-src http://archive.ubuntu.com/ubuntu precise main universe
35+ """.format(datetime.now()))
36+ # Move the old sources.list out of the way.
37+ sources_list = '/etc/apt/sources.list'
38+ os.rename(sources_list, sources_list + '.old')
39+ with open(sources_list, 'w') as fd:
40+ fd.write(good_sources)
41+
42+
43 def install_packages():
44+ try:
45+ # Attempt exercising 'apt-get' to see if there are errors in the
46+ # repositories, as frequently seen on EC2. If so, fix the apt sources
47+ # file. This approach will work if the failure is seen initially but
48+ # will not succeed if it is intermittent.
49+ run('apt-get', 'update')
50+ except subprocess.CalledProcessError as e:
51+ log("Error running 'apt-get update':")
52+ log(str(e))
53+ log("Proceeding with re-written /etc/apt/sources.list")
54+ fix_apt_sources()
55+ run('apt-get', 'update')
56+
57 apt_get_install = command('apt-get', 'install', '-y', '--force-yes')
58 apt_get_install('bzr', 'python-boto')
59 install_extra_repository('ppa:yellow/ppa')
60@@ -81,6 +119,7 @@
61
62 install_packages()
63
64+
65 # These modules depend on shelltoolbox being installed so they must not be
66 # imported until that package is available.
67 from helpers import (

Subscribers

People subscribed via source and target branches

to all changes: