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

Proposed by Brad Crittenden on 2012-07-17
Status: Merged
Approved by: Brad Crittenden on 2012-07-17
Approved revision: 69
Merged at revision: 56
Proposed branch: lp:~bac/lpsetup/from-branch
Merge into: lp:lpsetup
Diff against target: 133 lines (+53/-7)
3 files modified
lpsetup/settings.py (+2/-0)
lpsetup/subcommands/initlxc.py (+49/-6)
lpsetup/tests/subcommands/test_initlxc.py (+2/-1)
To merge this branch: bzr merge lp:~bac/lpsetup/from-branch
Reviewer Review Type Date Requested Status
Benji York (community) code 2012-07-17 Approve on 2012-07-17
Review via email: mp+115405@code.launchpad.net

Commit Message

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.

Description of the Change

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

To post a comment you must log in.
Benji York (benji) wrote :

Brad and I discussed a slight simplification on IRC for the temporary lpsetup checkout directory code which he will be doing. Otherwise this branch looks great.

review: Approve (code)
lp:~bac/lpsetup/from-branch updated on 2012-07-17
69. By Brad Crittenden on 2012-07-17

Changes from review

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lpsetup/settings.py'
2--- lpsetup/settings.py 2012-07-16 10:09:48 +0000
3+++ lpsetup/settings.py 2012-07-17 20:19:24 +0000
4@@ -15,6 +15,8 @@
5 )
6 # a2enmod requires apache2.2-common
7 BASE_PACKAGES = ['ssh', 'bzr', 'apache2.2-common']
8+PY26_PACKAGES = ['python-argparse', 'python-shelltoolbox']
9+CHECKOUT_DIR = '~/launchpad/lp-branches'
10 DEPENDENCIES_DIR = '~/launchpad/lp-sourcedeps'
11 HOSTS_CONTENT = (
12 ('127.0.0.88',
13
14=== modified file 'lpsetup/subcommands/initlxc.py'
15--- lpsetup/subcommands/initlxc.py 2012-07-12 22:12:09 +0000
16+++ lpsetup/subcommands/initlxc.py 2012-07-17 20:19:24 +0000
17@@ -22,11 +22,14 @@
18 import os
19 import shutil
20 import subprocess
21+import tempfile
22
23 from shelltoolbox import (
24 apt_get_install,
25 file_append,
26+ get_su_command,
27 mkdirs,
28+ su,
29 )
30
31 from lpsetup import exceptions
32@@ -39,6 +42,7 @@
33 LXC_NAME,
34 LXC_OPTIONS,
35 LXC_PACKAGES,
36+ PY26_PACKAGES,
37 )
38 from lpsetup.subcommands import inithost
39 from lpsetup.utils import (
40@@ -129,11 +133,14 @@
41 apt_get_install('haveged', caller=call)
42
43
44-def install_lpsetup_in_lxc(lxc_name, ssh_key_path, lxc_os):
45+def install_lpsetup_in_lxc(lxc_name, ssh_key_path, lxc_os,
46+ user, home_dir, lpsetup_branch=None):
47 """Initialize LXC container."""
48 # Install python-software-properties in order to get 'apt-add-repository',
49 # which is a pre-requisite to installing our PPA.
50 # http://tinyurl.com/python-software-properties
51+ # Do it even if we're installing from a branch because the repository may
52+ # be needed in the future.
53 ssh(lxc_name,
54 'DEBIAN_FRONTEND=noninteractive '
55 'apt-get install -y python-software-properties',
56@@ -146,10 +153,40 @@
57 'apt-add-repository {assume_yes} {repository}'.format(**args),
58 key=ssh_key_path)
59 ssh(lxc_name, 'apt-get clean && apt-get update', key=ssh_key_path)
60- ssh(lxc_name,
61- 'DEBIAN_FRONTEND=noninteractive '
62- 'apt-get upgrade -y && apt-get install -y lpsetup',
63- key=ssh_key_path)
64+ # Install lpsetup.
65+ if lpsetup_branch is None:
66+ ssh(lxc_name,
67+ 'DEBIAN_FRONTEND=noninteractive '
68+ 'apt-get upgrade -y && apt-get install -y lpsetup',
69+ key=ssh_key_path)
70+ else:
71+ # Make a temporary directory under the user's shared home directory to
72+ # hold the lpsetup branch.
73+ with su(user):
74+ # Using mktemp here despite the warnings since we just need a file
75+ # name in the user's home directory.
76+ dest = tempfile.mktemp(dir=home_dir)
77+ # Bzr requires the use of get_su_command due to the way it
78+ # handles uids.
79+ call(*get_su_command(user, [
80+ 'bzr', 'checkout', '--lightweight', lpsetup_branch, dest]))
81+ if lxc_os == 'lucid':
82+ # If the container is lucid we must manually install a few
83+ # packages. These packages are dependencies of the lpsetup
84+ # package and would normally be installed with the lpsetup
85+ # package.
86+ ssh(lxc_name,
87+ 'DEBIAN_FRONTEND=noninteractive '
88+ 'apt-get install -y {}'.format(' '.join(PY26_PACKAGES)),
89+ key=ssh_key_path)
90+
91+ ssh(lxc_name,
92+ 'DEBIAN_FRONTEND=noninteractive '
93+ 'cd {} && python setup.py install'.format(dest),
94+ key=ssh_key_path)
95+ # Remove the lpsetup tree from the user's directory on the host. This
96+ # must be done as root.
97+ shutil.rmtree(dest)
98
99
100 def inithost_in_lxc(lxc_name, ssh_key_path, user, email, full_name, lpuser,
101@@ -183,7 +220,8 @@
102 wait_for_lxc_step = (wait_for_lxc,
103 'lxc_name', 'ssh_key_path')
104 install_lpsetup_in_lxc_step = (install_lpsetup_in_lxc,
105- 'lxc_name', 'ssh_key_path', 'lxc_os')
106+ 'lxc_name', 'ssh_key_path', 'lxc_os', 'user', 'home_dir',
107+ 'lpsetup_branch')
108 inithost_in_lxc_step = (inithost_in_lxc,
109 'lxc_name', 'ssh_key_path', 'user', 'email', 'full_name', 'lpuser',
110 'private_key', 'public_key', 'ssh_key_name', 'home_dir')
111@@ -232,3 +270,8 @@
112 help='Install subunit in the host machine. Activate this if you '
113 'are using this command to create an automated parallel '
114 'testing environment e.g. for buildbot.')
115+ parser.add_argument(
116+ '-B', '--lpsetup-branch', default=None,
117+ help='The Launchpad branch to use for lpsetup inside the '
118+ 'container. Useful for testing lpsetup changes. '
119+ 'Leave unset to install from a Debian package.')
120
121=== modified file 'lpsetup/tests/subcommands/test_initlxc.py'
122--- lpsetup/tests/subcommands/test_initlxc.py 2012-07-12 18:23:37 +0000
123+++ lpsetup/tests/subcommands/test_initlxc.py 2012-07-17 20:19:24 +0000
124@@ -24,7 +24,8 @@
125 start_lxc_step = (initlxc.start_lxc, ['lxc_name'])
126 wait_for_lxc_step = (initlxc.wait_for_lxc, ['lxc_name', 'ssh_key_path'])
127 install_lpsetup_in_lxc_step = (
128- initlxc.install_lpsetup_in_lxc, ['lxc_name', 'ssh_key_path', 'lxc_os'])
129+ initlxc.install_lpsetup_in_lxc, ['lxc_name', 'ssh_key_path', 'lxc_os',
130+ 'user', 'home_dir', 'lpsetup_branch'])
131 inithost_in_lxc_step = (
132 initlxc.inithost_in_lxc,
133 ['lxc_name', 'ssh_key_path', 'user', 'email', 'full_name', 'lpuser',

Subscribers

People subscribed via source and target branches