← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~bac/lpsetup/from-branch into lp:lpsetup

 

Brad Crittenden has proposed merging lp:~bac/lpsetup/from-branch into lp:lpsetup.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~bac/lpsetup/from-branch/+merge/115405

Add a -B|--lpsetup-branch option to initlxc and install-lxc to specify
a branch to use for lpsetup in the container instead of installing it
via a package.

This change really helps with testing lpsetup since you no longer have
to manually install the branch in the container.

Usage:

% lp-setup install-lxc -B lp:~bac/lpsetup/from-branch
-- 
https://code.launchpad.net/~bac/lpsetup/from-branch/+merge/115405
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~bac/lpsetup/from-branch into lp:lpsetup.
=== modified file 'lpsetup/settings.py'
--- lpsetup/settings.py	2012-07-16 10:09:48 +0000
+++ lpsetup/settings.py	2012-07-17 18:00:34 +0000
@@ -15,6 +15,8 @@
     )
 # a2enmod requires apache2.2-common
 BASE_PACKAGES = ['ssh', 'bzr', 'apache2.2-common']
+PY26_PACKAGES = ['python-argparse', 'python-shelltoolbox']
+CHECKOUT_DIR = '~/launchpad/lp-branches'
 DEPENDENCIES_DIR = '~/launchpad/lp-sourcedeps'
 HOSTS_CONTENT = (
     ('127.0.0.88',

=== modified file 'lpsetup/subcommands/initlxc.py'
--- lpsetup/subcommands/initlxc.py	2012-07-12 22:12:09 +0000
+++ lpsetup/subcommands/initlxc.py	2012-07-17 18:00:34 +0000
@@ -22,11 +22,14 @@
 import os
 import shutil
 import subprocess
+import tempfile
 
 from shelltoolbox import (
     apt_get_install,
     file_append,
+    get_su_command,
     mkdirs,
+    su,
     )
 
 from lpsetup import exceptions
@@ -39,6 +42,7 @@
     LXC_NAME,
     LXC_OPTIONS,
     LXC_PACKAGES,
+    PY26_PACKAGES,
     )
 from lpsetup.subcommands import inithost
 from lpsetup.utils import (
@@ -129,11 +133,14 @@
     apt_get_install('haveged', caller=call)
 
 
-def install_lpsetup_in_lxc(lxc_name, ssh_key_path, lxc_os):
+def install_lpsetup_in_lxc(lxc_name, ssh_key_path, lxc_os,
+                           user, home_dir, lpsetup_branch=None):
     """Initialize LXC container."""
     # Install python-software-properties in order to get 'apt-add-repository',
     # which is a pre-requisite to installing our PPA.
     # http://tinyurl.com/python-software-properties
+    # Do it even if we're installing from a branch because the repository may
+    # be needed in the future.
     ssh(lxc_name,
         'DEBIAN_FRONTEND=noninteractive '
         'apt-get install -y python-software-properties',
@@ -146,10 +153,40 @@
         'apt-add-repository {assume_yes} {repository}'.format(**args),
         key=ssh_key_path)
     ssh(lxc_name, 'apt-get clean && apt-get update', key=ssh_key_path)
-    ssh(lxc_name,
-        'DEBIAN_FRONTEND=noninteractive '
-        'apt-get upgrade -y && apt-get install -y lpsetup',
-        key=ssh_key_path)
+    # Install lpsetup.
+    if lpsetup_branch is None:
+        ssh(lxc_name,
+            'DEBIAN_FRONTEND=noninteractive '
+            'apt-get upgrade -y && apt-get install -y lpsetup',
+            key=ssh_key_path)
+    else:
+        # Make a temporary directory under the user's shared home directory to
+        # hold the lpsetup branch.
+        with su(user):
+            temp_file = tempfile.NamedTemporaryFile(dir=home_dir)
+            temp_file.close()
+            dest = temp_file.name
+            # Bzr requires the use of get_su_command due to the way it
+            # handles uids.
+            call(*get_su_command(user, [
+                'bzr', 'checkout', '--lightweight', lpsetup_branch, dest]))
+        if lxc_os == 'lucid':
+            # If the container is lucid we must manually install a few
+            # packages.  These packages are dependencies of the lpsetup
+            # package and would normally be installed with the lpsetup
+            # package.
+            ssh(lxc_name,
+                'DEBIAN_FRONTEND=noninteractive '
+                'apt-get install -y {}'.format(' '.join(PY26_PACKAGES)),
+                key=ssh_key_path)
+
+        ssh(lxc_name,
+            'DEBIAN_FRONTEND=noninteractive '
+            'cd {} && python setup.py install'.format(dest),
+            key=ssh_key_path)
+        # Remove the lpsetup tree from the user's directory on the host.  This
+        # must be done as root.
+        shutil.rmtree(dest)
 
 
 def inithost_in_lxc(lxc_name, ssh_key_path, user, email, full_name, lpuser,
@@ -183,7 +220,8 @@
     wait_for_lxc_step = (wait_for_lxc,
         'lxc_name', 'ssh_key_path')
     install_lpsetup_in_lxc_step = (install_lpsetup_in_lxc,
-        'lxc_name', 'ssh_key_path', 'lxc_os')
+        'lxc_name', 'ssh_key_path', 'lxc_os', 'user', 'home_dir',
+        'lpsetup_branch')
     inithost_in_lxc_step = (inithost_in_lxc,
         'lxc_name', 'ssh_key_path', 'user', 'email', 'full_name', 'lpuser',
         'private_key', 'public_key', 'ssh_key_name', 'home_dir')
@@ -232,3 +270,8 @@
             help='Install subunit in the host machine. Activate this if you '
                  'are using this command to create an automated parallel '
                  'testing environment e.g. for buildbot.')
+        parser.add_argument(
+            '-B', '--lpsetup-branch', default=None,
+            help='The Launchpad branch to use for lpsetup inside the '
+                 'container.  Useful for testing lpsetup changes.  '
+                 'Leave unset to install from a Debian package.')

=== modified file 'lpsetup/tests/subcommands/test_initlxc.py'
--- lpsetup/tests/subcommands/test_initlxc.py	2012-07-12 18:23:37 +0000
+++ lpsetup/tests/subcommands/test_initlxc.py	2012-07-17 18:00:34 +0000
@@ -24,7 +24,8 @@
 start_lxc_step = (initlxc.start_lxc, ['lxc_name'])
 wait_for_lxc_step = (initlxc.wait_for_lxc, ['lxc_name', 'ssh_key_path'])
 install_lpsetup_in_lxc_step = (
-    initlxc.install_lpsetup_in_lxc, ['lxc_name', 'ssh_key_path', 'lxc_os'])
+    initlxc.install_lpsetup_in_lxc, ['lxc_name', 'ssh_key_path', 'lxc_os',
+                                     'user', 'home_dir', 'lpsetup_branch'])
 inithost_in_lxc_step = (
     initlxc.inithost_in_lxc,
     ['lxc_name', 'ssh_key_path', 'user', 'email', 'full_name', 'lpuser',