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

Proposed by Brad Crittenden
Status: Merged
Merged at revision: 26
Proposed branch: lp:~bac/charms/oneiric/buildbot-slave/fix-apt-sources
Merge into: lp:~yellow/charms/oneiric/buildbot-slave/trunk
Diff against target: 59 lines (+37/-0)
1 file modified
hooks/install (+37/-0)
To merge this branch: bzr merge lp:~bac/charms/oneiric/buildbot-slave/fix-apt-sources
Reviewer Review Type Date Requested Status
Gary Poster (community) Approve
Review via email: mp+101007@code.launchpad.net

Description of the change

Duplicated changes from the buildbot-master to redo /etc/apt/sources.list if there are problems.

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

On Thu, Apr 5, 2012 at 1:18 PM, Brad Crittenden <email address hidden> wrote:
> Brad Crittenden has proposed merging lp:~bac/charms/oneiric/buildbot-slave/fix-apt-sources into lp:~yellow/charms/oneiric/buildbot-slave/trunk.

>  def install_packages():
> +    try:
> +        # Attempt exercising 'apt-get' to see if there are errors in the
> +        # repositories, as frequently seen on EC2.  If so, fix the apt sources
> +        # file.  This approach will work if the failure is seen initially but
> +        # will not succeed if it is intermittent.
> +        run('apt-get', 'update')
> +    except subprocess.CalledProcessError as e:
> +        log("Error running 'apt-get update':")
> +        log(str(e))
> +        log("Proceeding with re-written /etc/apt/sources.list")
> +        fix_apt_sources()
> +        run('apt-get', 'update')
>     install_extra_repository('ppa:yellow/ppa')
>     apt_get_install('python-shelltoolbox')

Since "apt-get update" returns a specific exit code (100) shouldn't we
only rewrite sources.list if it fails with that result?
--
Benji York

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:09 +0000
3+++ hooks/install 2012-04-05 17:17:26 +0000
4@@ -3,11 +3,13 @@
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 shlex
11 import subprocess
12 import sys
13 import tempfile
14+import textwrap
15
16
17 def run(*args, **kwargs):
18@@ -75,7 +77,42 @@
19 raise
20
21
22+def fix_apt_sources():
23+ # Problems have frequently been seen with the repositories used by ec2 not
24+ # having the correct hash and being unuseable. To avoid that problem, we
25+ # replace /etc/apt/sources.list with known good repositories. The cost of
26+ # this is having to go outside of the ec2 environment to download
27+ # packages.
28+ good_sources = textwrap.dedent("""\
29+ # Installed by the buildbot-master charm installation hook at
30+ # {}
31+ deb http://security.ubuntu.com/ubuntu/ precise-security universe main
32+ deb-src http://security.ubuntu.com/ubuntu/ precise-security universe main
33+ deb http://archive.ubuntu.com/ubuntu precise-updates universe main
34+ deb-src http://archive.ubuntu.com/ubuntu precise-updates universe main
35+ deb http://archive.ubuntu.com/ubuntu precise main universe
36+ deb-src http://archive.ubuntu.com/ubuntu precise main universe
37+ """.format(datetime.now()))
38+ # Move the old sources.list out of the way.
39+ sources_list = '/etc/apt/sources.list'
40+ os.rename(sources_list, sources_list + '.old')
41+ with open(sources_list, 'w') as fd:
42+ fd.write(good_sources)
43+
44+
45 def install_packages():
46+ try:
47+ # Attempt exercising 'apt-get' to see if there are errors in the
48+ # repositories, as frequently seen on EC2. If so, fix the apt sources
49+ # file. This approach will work if the failure is seen initially but
50+ # will not succeed if it is intermittent.
51+ run('apt-get', 'update')
52+ except subprocess.CalledProcessError as e:
53+ log("Error running 'apt-get update':")
54+ log(str(e))
55+ log("Proceeding with re-written /etc/apt/sources.list")
56+ fix_apt_sources()
57+ run('apt-get', 'update')
58 install_extra_repository('ppa:yellow/ppa')
59 apt_get_install('python-shelltoolbox')
60

Subscribers

People subscribed via source and target branches

to all changes: