Merge lp:~frankban/launchpad/setuplxc-scripts-shh-keys into lp:launchpad

Proposed by Francesco Banconi on 2012-03-05
Status: Rejected
Rejected by: William Grant on 2012-10-02
Proposed branch: lp:~frankban/launchpad/setuplxc-scripts-shh-keys
Merge into: lp:launchpad
Diff against target: 105 lines (+33/-19)
1 file modified
utilities/setuplxc.py (+33/-19)
To merge this branch: bzr merge lp:~frankban/launchpad/setuplxc-scripts-shh-keys
Reviewer Review Type Date Requested Status
Graham Binns (community) code 2012-03-05 Approve on 2012-03-06
Review via email: mp+95903@code.launchpad.net

Description of the Change

== Changes ==

This branch changes the way the management scripts are created in setuplxc:

- the scripts now use the ssh key given as argument when running setuplxc
- the scripts are now dynamically generated
- the scripts are now generated in a separate setuplxc "action"
- updated the arguments passed to lxc-start-ephemeral

To post a comment you must log in.
14905. By Francesco Banconi on 2012-03-05

Fixed args parsing.

14906. By Francesco Banconi on 2012-03-05

Checkout directory in scripts is now correctly quoted.

Graham Binns (gmb) wrote :

Hi Francesco,

Nice branch, r=me with just one change:

[1]

35 + mapping = {
36 + 'user': user,
37 + 'lxcname': lxcname,
38 + 'ssh_key_path': ssh_key_path,
39 + 'checkout_dir': os.path.join(directory, LP_CHECKOUT),
40 + }

Nitpick: these should be alphabetised.

review: Approve (code)
Francesco Banconi (frankban) wrote :

Thanks Graham.

14907. By Francesco Banconi on 2012-03-06

Fixes from review.

Unmerged revisions

14907. By Francesco Banconi on 2012-03-06

Fixes from review.

14906. By Francesco Banconi on 2012-03-05

Checkout directory in scripts is now correctly quoted.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utilities/setuplxc.py'
2--- utilities/setuplxc.py 2012-03-02 14:20:12 +0000
3+++ utilities/setuplxc.py 2012-03-06 13:10:23 +0000
4@@ -9,6 +9,7 @@
5 'ArgumentParser',
6 'cd',
7 'create_lxc',
8+ 'create_scripts',
9 'file_append',
10 'file_prepend',
11 'get_container_path',
12@@ -663,7 +664,8 @@
13 'rather than bzr+ssh.')
14 parser.add_argument(
15 '-a', '--actions', nargs='+',
16- choices=('initialize_host', 'create_lxc', 'initialize_lxc', 'stop_lxc'),
17+ choices=('initialize_host', 'create_scripts', 'create_lxc',
18+ 'initialize_lxc', 'stop_lxc'),
19 help='Only for debugging. Call one or more internal functions.')
20 parser.add_argument(
21 '-n', '--lxc-name', default=LXC_NAME,
22@@ -750,46 +752,57 @@
23 path = os.path.join(dependencies_dir, subdir)
24 if not os.path.exists(path):
25 os.makedirs(path)
26+ with cd(dependencies_dir):
27+ with su(user) as env:
28+ subprocess.call([
29+ 'bzr', 'co', '--lightweight',
30+ LP_SOURCE_DEPS, 'download-cache'])
31+
32+
33+def create_scripts(user, directory, lxcname, ssh_key_path):
34+ """Create scripts to update the Launchpad environment and run tests."""
35+ mapping = {
36+ 'checkout_dir': os.path.join(directory, LP_CHECKOUT),
37+ 'lxcname': lxcname,
38+ 'ssh_key_path': ssh_key_path,
39+ 'user': user,
40+ }
41 # We need a script that will run the LP build inside LXC. It is run as
42 # root (see below) but drops root once inside the LXC container.
43 build_script_file = '/usr/local/bin/launchpad-lxc-build'
44 with open(build_script_file, 'w') as script:
45- script.write(textwrap.dedent("""\
46+ script.write(textwrap.dedent("""
47 #!/bin/sh
48 set -uex
49- lxc-start -n lptests -d
50- lxc-wait -n lptests -s RUNNING
51- sleep 30 # aparently RUNNING isn't quite enough
52- su buildbot -c "/usr/bin/ssh -o StrictHostKeyChecking=no lptests \\
53- make -C /var/lib/buildbot/lp schema"
54- lxc-stop -n lptests
55- lxc-wait -n lptests -s STOPPED
56- """))
57+ lxc-start -n {lxcname} -d
58+ lxc-wait -n {lxcname} -s RUNNING
59+ sleep 30 # aparently RUNNING isn't quite enough
60+ su {user} -c "/usr/bin/ssh -o StrictHostKeyChecking=no \\
61+ -i '{ssh_key_path}' {lxcname} make -C '{checkout_dir}' schema"
62+ lxc-stop -n {lxcname}
63+ lxc-wait -n {lxcname} -s STOPPED
64+ """.format(**mapping)))
65 os.chmod(build_script_file, 0555)
66+ # We need a script to test launchpad using LXC ephemeral instances.
67 test_script_file = '/usr/local/bin/launchpad-lxc-test'
68 with open(test_script_file, 'w') as script:
69 script.write(textwrap.dedent("""
70 #!/bin/sh
71 set -uex
72- lxc-start-ephemeral -o lptests -b $PWD -- xvfb-run \\
73- --error-file=/var/tmp/xvfb-errors.log \\
74+ lxc-start-ephemeral -u {user} -S '{ssh_key_path}' -o {lxcname} \\
75+ -b $PWD -- xvfb-run --error-file=/var/tmp/xvfb-errors.log \\
76 --server-args='-screen 0 1024x768x24' \\
77 -a $PWD/bin/test --subunit $@
78- """))
79+ """.format(**mapping)))
80 os.chmod(test_script_file, 0555)
81 # Add a file to sudoers.d that will let the buildbot user run the above.
82- sudoers_file = '/etc/sudoers.d/launchpad-buildbot'
83+ sudoers_file = '/etc/sudoers.d/launchpad-' + user
84 with open(sudoers_file, 'w') as sudoers:
85 sudoers.write('{} ALL = (ALL) NOPASSWD:'.format(user))
86 sudoers.write(' /usr/local/bin/launchpad-lxc-build,')
87 sudoers.write(' /usr/local/bin/launchpad-lxc-test\n')
88 # The sudoers must have this mode or it will be ignored.
89 os.chmod(sudoers_file, 0440)
90- with cd(dependencies_dir):
91- with su(user) as env:
92- subprocess.call([
93- 'bzr', 'co', '--lightweight',
94- LP_SOURCE_DEPS, 'download-cache'])
95
96
97 def create_lxc(user, lxcname, ssh_key_path):
98@@ -935,6 +948,7 @@
99 ('initialize_host', (
100 user, fullname, email, lpuser, private_key, public_key,
101 ssh_key_path, dependencies_dir, directory)),
102+ ('create_scripts', (user, directory, lxc_name, ssh_key_path)),
103 ('create_lxc', (user, lxc_name, ssh_key_path)),
104 ('initialize_lxc', (
105 user, dependencies_dir, directory, lxc_name, ssh_key_path)),