← Back to team overview

yellow team mailing list archive

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

 

Brad Crittenden has proposed merging lp:~bac/charms/oneiric/buildbot-master/fix-apt-sources into lp:~yellow/charms/oneiric/buildbot-master/trunk.

Requested reviews:
  Benji York (benji): code

For more details, see:
https://code.launchpad.net/~bac/charms/oneiric/buildbot-master/fix-apt-sources/+merge/100992

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

This version only updates sources.list if an attempt to 'apt-get update' fails.  Subsequent failures are not handled.

-- 
https://code.launchpad.net/~bac/charms/oneiric/buildbot-master/fix-apt-sources/+merge/100992
Your team Launchpad Yellow Squad is subscribed to branch lp:~yellow/charms/oneiric/buildbot-master/trunk.
=== modified file 'hooks/install'
--- hooks/install	2012-03-20 15:29:18 +0000
+++ hooks/install	2012-04-05 15:33:19 +0000
@@ -3,9 +3,11 @@
 # Copyright 2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
+from datetime import datetime
 import os
 import shutil
 import subprocess
+import textwrap
 
 
 def run(*args, **kwargs):
@@ -72,7 +74,43 @@
         raise
 
 
+def fix_apt_sources():
+    # Problems have frequently been seen with the repositories used by ec2 not
+    # having the correct hash and being unuseable.  To avoid that problem, we
+    # replace /etc/apt/sources.list with known good repositories.  The cost of
+    # this is having to go outside of the ec2 environment to download
+    # packages.
+    good_sources = textwrap.dedent("""\
+    # Installed by the buildbot-master charm installation hook at
+    # {}
+    deb http://security.ubuntu.com/ubuntu/ precise-security universe main
+    deb-src http://security.ubuntu.com/ubuntu/ precise-security universe main
+    deb http://archive.ubuntu.com/ubuntu precise-updates universe main
+    deb-src http://archive.ubuntu.com/ubuntu precise-updates universe main
+    deb http://archive.ubuntu.com/ubuntu precise main universe
+    deb-src http://archive.ubuntu.com/ubuntu precise main universe
+    """.format(datetime.now()))
+    # Move the old sources.list out of the way.
+    sources_list = '/etc/apt/sources.list'
+    os.rename(sources_list, sources_list + '.old')
+    with open(sources_list, 'w') as fd:
+        fd.write(good_sources)
+
+
 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')
+
     apt_get_install = command('apt-get', 'install', '-y', '--force-yes')
     apt_get_install('bzr', 'python-boto')
     install_extra_repository('ppa:yellow/ppa')
@@ -81,6 +119,7 @@
 
 install_packages()
 
+
 # These modules depend on shelltoolbox being installed so they must not be
 # imported until that package is available.
 from helpers import (


Follow ups