Merge lp:~frankban/lpsetup/install-subunit into lp:lpsetup

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 14
Proposed branch: lp:~frankban/lpsetup/install-subunit
Merge into: lp:lpsetup
Diff against target: 160 lines (+63/-5)
4 files modified
lpsetup/handlers.py (+12/-0)
lpsetup/settings.py (+1/-1)
lpsetup/subcommands/lxcinstall.py (+26/-4)
lpsetup/tests/test_handlers.py (+24/-0)
To merge this branch: bzr merge lp:~frankban/lpsetup/install-subunit
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+102874@code.launchpad.net

Description of the change

== Changes ==

Added the --install-subunit option to the lxc-install sub command. This flag can be used to let lp-setup install subunit in the host.

lp-setup lxc-install now accepts a --testing flag as an alias for --use-urandom --create-scripts --install-subunit, and for all future tweaks needed in parallel tests.

The `initialize_lxc` step of the lxc-install sub command upgrades the debian packages of the newly created container.

== Tests ==

$ bin/test
Running zope.testrunner.layer.UnitTests tests:
  Set up zope.testrunner.layer.UnitTests in 0.000 seconds.
  Ran 48 tests with 0 failures and 0 errors in 0.478 seconds.
Tearing down left over layers:
  Tear down zope.testrunner.layer.UnitTests in 0.000 seconds.

To post a comment you must log in.
lp:~frankban/lpsetup/install-subunit updated
20. By Francesco Banconi

Checkpoint.

Revision history for this message
Benji York (benji) wrote :

Looks good. I like the --testing alias.

review: Approve (code)
Revision history for this message
Francesco Banconi (frankban) wrote :

Thanks Benji.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lpsetup/handlers.py'
2--- lpsetup/handlers.py 2012-03-16 16:49:23 +0000
3+++ lpsetup/handlers.py 2012-04-20 14:59:18 +0000
4@@ -9,6 +9,7 @@
5 'handle_directories',
6 'handle_lpuser',
7 'handle_ssh_keys',
8+ 'handle_testing',
9 'handle_user',
10 'handle_userdata',
11 ]
12@@ -243,3 +244,14 @@
13 'argument {0} does not reside under the home '
14 'directory of the system user.'.format(attr))
15 setattr(namespace, attr, directory)
16+
17+
18+def handle_testing(namespace):
19+ """Handle the `testing` flag.
20+
21+ Set the parallel testing related options to True if `testing` is True.
22+ """
23+ if getattr(namespace, 'testing', False):
24+ namespace.create_scripts = True
25+ namespace.install_subunit = True
26+ namespace.use_urandom = True
27
28=== modified file 'lpsetup/settings.py'
29--- lpsetup/settings.py 2012-04-10 17:16:25 +0000
30+++ lpsetup/settings.py 2012-04-20 14:59:18 +0000
31@@ -73,7 +73,7 @@
32 lxc.network.link = {interface}
33 lxc.network.flags = up
34 """
35-LXC_PACKAGES = ['lxc', 'libvirt-bin']
36+LXC_PACKAGES = ('lxc', 'libvirt-bin')
37 LXC_PATH = '/var/lib/lxc/'
38 RESOLV_FILE = '/etc/resolv.conf'
39 SCRIPTS = ('lp-setup-lxc-build', 'lp-setup-lxc-cleanup', 'lp-setup-lxc-test')
40
41=== modified file 'lpsetup/subcommands/lxcinstall.py'
42--- lpsetup/subcommands/lxcinstall.py 2012-04-18 10:02:33 +0000
43+++ lpsetup/subcommands/lxcinstall.py 2012-04-20 14:59:18 +0000
44@@ -29,6 +29,7 @@
45 ssh,
46 )
47
48+from lpsetup import handlers
49 from lpsetup.settings import (
50 BASE_PACKAGES,
51 DHCP_FILE,
52@@ -90,14 +91,17 @@
53 f.write('0\n')
54
55
56-def create_lxc(user, lxc_name, lxc_arch, lxc_os):
57+def create_lxc(user, lxc_name, lxc_arch, lxc_os, install_subunit):
58 """Create the LXC named `lxc_name` sharing `user` home directory.
59
60 The container will be used as development environment or as base template
61 for parallel testing using ephemeral instances.
62 """
63 # Install necessary deb packages.
64- apt_get_install(*LXC_PACKAGES, caller=call)
65+ packages = list(LXC_PACKAGES)
66+ if install_subunit:
67+ packages.append('subunit')
68+ apt_get_install(*packages, caller=call)
69 # XXX 2012-02-02 gmb bug=925024:
70 # These calls need to be removed once the lxc vs. apparmor bug
71 # is resolved, since having apparmor enabled for lxc is very
72@@ -175,7 +179,10 @@
73 'repository': LPSETUP_PPA,
74 }
75 sshcall('apt-add-repository {assume_yes} {repository}'.format(**args))
76- sshcall('apt-get clean && apt-get update && apt-get install -y lpsetup')
77+ sshcall('apt-get clean && apt-get update')
78+ sshcall(
79+ 'DEBIAN_FRONTEND=noninteractive '
80+ 'apt-get upgrade -y && apt-get install -y lpsetup')
81
82
83 def setup_launchpad_lxc(
84@@ -208,7 +215,7 @@
85 (create_scripts,
86 'user', 'lxc_name', 'ssh_key_path'),
87 (create_lxc,
88- 'user', 'lxc_name', 'lxc_arch', 'lxc_os'),
89+ 'user', 'lxc_name', 'lxc_arch', 'lxc_os', 'install_subunit'),
90 (start_lxc,
91 'lxc_name'),
92 (wait_for_lxc,
93@@ -225,6 +232,10 @@
94 ssh_key_name_help = ('The ssh key name used to connect to Launchpad '
95 'and to to the LXC container.')
96
97+ def get_validators(self, namespace):
98+ validators = super(SubCommand, self).get_validators(namespace)
99+ return validators + (handlers.handle_testing,)
100+
101 def call_create_scripts(self, namespace, step, args):
102 """Run the `create_scripts` step only if the related flag is set."""
103 if namespace.create_scripts:
104@@ -248,3 +259,14 @@
105 parser.add_argument(
106 '-C', '--create-scripts', action='store_true',
107 help='Create the scripts used by buildbot for parallel testing.')
108+ # The following flag is not present in the install sub command since
109+ # subunit is always installed there as a dependency of
110+ # launchpad-developer-dependencies.
111+ parser.add_argument(
112+ '--install-subunit', action='store_true',
113+ help='Install subunit in the host machine. Activate this if you '
114+ 'are using this command to create an automated parallel '
115+ 'testing environment e.g. for buildbot.')
116+ parser.add_argument(
117+ '--testing', action='store_true',
118+ help='Same as --use-urandom --create-scripts --install-subunit.')
119
120=== modified file 'lpsetup/tests/test_handlers.py'
121--- lpsetup/tests/test_handlers.py 2012-04-11 10:40:05 +0000
122+++ lpsetup/tests/test_handlers.py 2012-04-20 14:59:18 +0000
123@@ -15,6 +15,7 @@
124 handle_directories,
125 handle_lpuser,
126 handle_ssh_keys,
127+ handle_testing,
128 handle_user,
129 handle_userdata,
130 )
131@@ -151,6 +152,29 @@
132 handle_ssh_keys(namespace)
133
134
135+class HandleTestingTest(unittest.TestCase):
136+
137+ context = {
138+ 'create_scripts': True,
139+ 'install_subunit': False,
140+ 'use_urandom': False,
141+ }
142+
143+ def test_true(self):
144+ # Ensure aliased options are set to True if testing is True.
145+ namespace = argparse.Namespace(testing=True, **self.context)
146+ handle_testing(namespace)
147+ for key in self.context:
148+ self.assertTrue(getattr(namespace, key))
149+
150+ def test_false(self):
151+ # Ensure no changes are made to aliased options if testing is False.
152+ namespace = argparse.Namespace(testing=False, **self.context)
153+ handle_testing(namespace)
154+ for key, value in self.context.items():
155+ self.assertEqual(value, getattr(namespace, key))
156+
157+
158 class HandleUserTest(HandlersTestMixin, unittest.TestCase):
159
160 def test_home_dir(self):

Subscribers

People subscribed via source and target branches

to all changes: