launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #09797
[Merge] lp:~bac/lpsetup/mv-initialize-lxc into lp:lpsetup
Brad Crittenden has proposed merging lp:~bac/lpsetup/mv-initialize-lxc into lp:lpsetup.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~bac/lpsetup/mv-initialize-lxc/+merge/114239
Move most of initialize_lxc to init-host.
Rename lxc-install to install-lxc.
Add commands.rst, which lays out what each subcommand does, its relationships to other commands, the environment in which it is to be run, and whether it performs actions as root or the user.
Updated the docstrings, and thus the help strings, for the subcommands. Also updated the module-level docstrings for each subcommand.
NOTE:
finish-init-host and install-lxc are broken as a result of these changes and need to be refactored. Their tests have been disabled.
Since I modified setup.cfg for nosetest options to ignore 'disabled_' tests, I decided to move with-doctest to that file from the pre-commit.sh. For some reason this is now triggering a warning about the version of distribute being used.
--
https://code.launchpad.net/~bac/lpsetup/mv-initialize-lxc/+merge/114239
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~bac/lpsetup/mv-initialize-lxc into lp:lpsetup.
=== added file 'commands.rst'
--- commands.rst 1970-01-01 00:00:00 +0000
+++ commands.rst 2012-07-10 18:00:33 +0000
@@ -0,0 +1,127 @@
+lpsetup subcommands
+===================
+
+./lp-setup -h
+~~~~~~~~~~~~~
+
+usage: lp-setup [-h]
+
+ {finish-init-host,init-host,init-lxc,init-repo,install-lxc,update,version,help}
+ ...
+
+Create and update Launchpad development and testing environments.
+
+optional arguments:
+ -h, --help show this help message and exit
+
+subcommands:
+ {finish-init-host,init-host,init-lxc,init-repo,install-lxc,update,version,help}
+ Each subcommand accepts --h or --help to describe it.
+ finish-init-host Finish the initialization of a Launchpad development
+ host.
+ init-host Prepare a machine to run Launchpad. May be an LXC
+ container or not.
+ init-lxc Create an LXC container suitable for later installing
+ a Launchpad development environment.
+ init-repo Get the Launchpad code and dependent source code.
+ install-lxc Completely sets up an LXC environment with Launchpad
+ using the sandbox development model.
+ update Updates an existing Launchpad development environment.
+ Gets new versions of Launchpad source and external
+ sources.
+ version Display the software version.
+ help More help on a command.
+
+
+
+Terminology
+~~~~~~~~~~~
+
+`host machine` - An Ubuntu machine that is the host for an LXC container.
+`lxc container` - An LXC container that will host the Launchpad development environment.
+`Launchpad target` - The environment where Launchpad development will
+ occur. It will either be an LXC container or an
+ Ubuntu machine.
+
+install-lxc
+~~~~~~~~~~~
+
+Completely sets up an LXC environment with Launchpad using the sandbox development model:
+
+~/launchpad - bzr repository with --no-trees option
+~/launchpad/devel - branch with no trees of trunk
+~/launchpad/sandbox - lightweight checkout with a tree of ../devel
+~/launchpad/bug-xyz - branch with no trees of trunk where bug work is
+ done via switching inside sandbox
+
+Can be run as root in the host machine passing the username or as a
+user with sudo privileges.
+
+init-lxc
+~~~~~~~~
+
+Create an LXC container suitable for later installing a Launchpad
+development environment. The `lpsetup` package is installed in the
+container and `init-host` is called. The LXC container is shutdown at
+the end of the command.
+
+Run as root on the host machine.
+
+
+init-host
+~~~~~~~~~
+
+Prepare a machine to run Launchpad. It may be a host machine or an
+LXC container. It installs the base packages, creates the specified
+user if it does not exist, installs/verifies SSH keys, creates
+directories required by Launchpad, configures Apache, and performs the
+required modifications to `/etc/hosts`. The standard Ubuntu
+repositories are installed as are the Launchpad and Bazaar PPAs. The
+Launchpad-specific packages are installed.
+
+Iff running in an LXC container, the necessary work-arounds for LXC are
+installed.
+
+In the future this command will be used to apply new work-arounds and
+unapply work-arounds that are now obsolete.
+
+Run as root in the Launchpad target, either a host machine or LXC container.
+
+TODO: rename to init-target
+
+init-repo
+~~~~~~~~~
+
+Prepares the user's Launchpad directory structure and downloads the
+latest Launchpad source code. Sets up ~/.bazaar/locations.conf
+appropriately. The repository uses the sandbox development model as
+specified in `lxc-install`.
+
+Run as the user in the Launchpad target, either a host machine or LXC
+container.
+
+finish-init-host
+~~~~~~~~~~~~~~~~
+
+Finish the initialization of a Launchpad development host.
+
+Perform all tasks required to be run to initialize a Launchpad development
+host that need to be done after the Launchpad tree has been retrieved and
+run as root.
+
+Run as root in the Launchpad target, either a host machine or LXC
+container. Must be done after `init-host` and `init-repo` have
+completed.
+
+TODO: rename to finish-init-target
+
+update
+~~~~~~
+
+Updates an existing Launchpad development environment. Creates eggs,
+yui, sourcecode directories. Updates or checks out download-cache.
+Does a 'bzr pull' in the Launchpad tree (defaults to current working
+directory).
+
+Run as the user in the Launchpad target, either a host machine or LXC
+container.
=== modified file 'lpsetup/handlers.py'
--- lpsetup/handlers.py 2012-07-09 17:05:28 +0000
+++ lpsetup/handlers.py 2012-07-10 18:00:33 +0000
@@ -247,7 +247,6 @@
"""
if getattr(namespace, 'testing', False):
namespace.create_scripts = True
- namespace.feed_random = True
namespace.install_subunit = True
namespace.stop_lxc = True
=== modified file 'lpsetup/subcommands/finish_inithost.py'
--- lpsetup/subcommands/finish_inithost.py 2012-07-09 15:19:13 +0000
+++ lpsetup/subcommands/finish_inithost.py 2012-07-10 18:00:33 +0000
@@ -2,7 +2,12 @@
# Copyright 2012 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
-"""Install subcommand: create a Launchpad development environment."""
+"""Finish the initialization of a Launchpad development host.
+
+Perform all tasks required to be run to initialize a Launchpad development
+host that need to be done 1) after the Launchpad tree has been retrieved and
+2) run as root.
+"""
__metaclass__ = type
__all__ = [
@@ -11,6 +16,7 @@
'SubCommand',
]
+from contextlib import nested
import os
import pwd
import subprocess
@@ -75,7 +81,8 @@
user, checkout_dir, dependencies_dir, valid_ssh_keys)
# Launchpad database setup.
- with su(user), cd(checkout_dir):
+ # nested is required for use by python 2.6.
+ with nested(su(user), cd(checkout_dir)):
call('utilities/launchpad-database-setup', user)
# Make and install launchpad.
@@ -91,10 +98,12 @@
class SubCommand(inithost.SubCommand):
- """Install the Launchpad environment."""
+ """Finish the initialization of a Launchpad development host."""
# The steps for "install" are a superset of the steps for "inithost".
+ help = __doc__
+
@property
def steps(self):
# Break import loop (and break it here because this subcommand is
=== modified file 'lpsetup/subcommands/inithost.py'
--- lpsetup/subcommands/inithost.py 2012-07-09 16:32:26 +0000
+++ lpsetup/subcommands/inithost.py 2012-07-10 18:00:33 +0000
@@ -7,12 +7,14 @@
__metaclass__ = type
__all__ = [
'initialize',
+ 'initialize_base',
'setup_apt',
'SubCommand',
]
from email.Utils import formataddr
import os
+import shutil
import subprocess
from shelltoolbox import (
@@ -45,16 +47,17 @@
from lpsetup.utils import (
call,
get_file_header,
+ render_to_file,
+ running_in_container,
)
-def write_file_contents(filename, contents, mode):
+def write_file_contents(filename, contents, mode, header=None):
"""Write `contents` to filename and chmod it to 0644.
>>> write_file_contents('/tmp/foo', 'Hello, world', 'w')
>>> print open('/tmp/foo', 'r').read()
Hello, world
- <BLANKLINE>
>>> os.remove('/tmp/foo')
If the file already exists, `mode` is set to 'w', and the file's
@@ -93,7 +96,9 @@
else:
return
with open(filename, mode) as f:
- f.write(contents + '\n')
+ if header is not None:
+ f.write(header + '\n')
+ f.write(contents)
os.chmod(filename, 0644)
@@ -112,12 +117,10 @@
>>> print public_keyfile.read() # doctest: +ELLIPSIS
# This file created at ...
Public key
- <BLANKLINE>
>>> private_keyfile = open('/tmp/test_key', 'r')
>>> print private_keyfile.read() # doctest: +ELLIPSIS
# This file created at ...
Private key
- <BLANKLINE>
Two other files will have been generated: authorized_keys and known_hosts
@@ -125,7 +128,6 @@
... '/tmp/authorized_keys', 'r').read() # doctest: +ELLIPSIS
# This file created at ...
Public key
- <BLANKLINE>
>>> print open('/tmp/known_hosts', 'r').read() # doctest: +ELLIPSIS
# This file created at ...
bazaar.launchpad.net ...
@@ -162,8 +164,8 @@
public_key = open(pub_key_path).read()
auth_file = os.path.join(ssh_dir, 'authorized_keys')
known_hosts = os.path.join(ssh_dir, 'known_hosts')
- known_host_content = subprocess.check_output([
- 'ssh-keyscan', '-t', 'rsa', 'bazaar.launchpad.net'])
+ known_host_content = run(
+ 'ssh-keyscan', '-t', 'rsa', 'bazaar.launchpad.net')
files_to_write = [
(auth_file, public_key, 'a'),
(known_hosts, known_host_content, 'a'),
@@ -174,21 +176,25 @@
files_to_write.append((ssh_key_path, private_key, 'w'))
files_to_write.append((pub_key_path, public_key, 'w'))
for filename, contents, mode in files_to_write:
- contents = "{0}\n{1}".format(get_file_header(), contents)
- write_file_contents(filename, contents, mode)
+ write_file_contents(filename, contents, mode, header=get_file_header())
os.chmod(ssh_key_path, 0600)
-def initialize(
- user, full_name, email, lpuser, private_key, public_key, valid_ssh_keys,
- ssh_key_path, feed_random):
- """Initialize host machine."""
+def initialize_base(user):
+ """Perform base initialization shared by inithost and initlxc."""
# Install necessary deb packages. This requires Oneiric or later.
call('apt-get', 'update')
apt_get_install(*BASE_PACKAGES, caller=call)
# Create the user (if he does not exist).
if not user_exists(user):
call('useradd', '-m', '-s', '/bin/bash', '-U', user)
+
+
+def initialize(
+ user, full_name, email, lpuser, private_key, public_key, valid_ssh_keys,
+ ssh_key_path):
+ """Initialize host machine."""
+ initialize_base(user)
with su(user) as env:
ssh_dir = os.path.join(env.home, '.ssh')
ensure_ssh_keys(
@@ -201,10 +207,16 @@
# Create Apache document roots, to avoid warnings.
mkdirs(*LP_APACHE_ROOTS)
+<<<<<<< TREE
# Set up Apache modules.
for module in LP_APACHE_MODULES.split():
call('a2enmod', module)
+=======
+ # Set up Apache modules.
+ for module in LP_APACHE_MODULES.split():
+ call('a2enmod', module)
+>>>>>>> MERGE-SOURCE
# Set up container hosts file.
lines = [get_file_header()]
@@ -213,37 +225,58 @@
for line in lines:
file_append(HOSTS_FILE, line)
- # haveged is used to fill /dev/random, avoiding
- # entropy exhaustion during automated parallel tests.
- if feed_random:
- apt_get_install('haveged', caller=call)
-
-
-def setup_apt(no_repositories=True):
+
+def initialize_lxc():
+ """Initialize LXC container."""
+ lxc_os = get_distro()
+ # XXX benji 2012-03-19 bug=959352: this is so graphviz will work in an
+ # ephemeral container
+ mkdirs('/rootfs/usr/lib')
+ os.symlink('/usr/lib/graphviz', '/rootfs/usr/lib/graphviz')
+ # XXX gary 2012-06-26 bug=1014916: this fixes a bug in Lucid LXC
+ # containers.
+ if lxc_os == 'lucid':
+ # Change /var/lib/lxc/lptests/rootfs/etc/init/networking.conf to not
+ # wait for udev (that is, use start on (local-filesystems)).
+ udevtrigger = '/etc/init/udevtrigger.conf'
+ shutil.move(udevtrigger, udevtrigger + '.orig')
+ networking = '/etc/init/networking.conf'
+ shutil.move(networking, networking + '.orig')
+ render_to_file('networking.conf', {}, networking)
+
+
+def get_distro():
+ return run('lsb_release', '-cs').strip()
+
+
+def setup_apt():
"""Setup, update and upgrade deb packages."""
- if not no_repositories:
- distro = run('lsb_release', '-cs').strip()
- # APT repository update.
- for reposirory in APT_REPOSITORIES:
- assume_yes = None if distro == 'lucid' else '-y'
- call('add-apt-repository', assume_yes,
- reposirory.format(distro=distro))
+ distro = get_distro()
+ # APT repository update.
+ for repository in APT_REPOSITORIES:
+ assume_yes = None if distro == 'lucid' else '-y'
+ call('add-apt-repository', assume_yes,
+ repository.format(distro=distro))
call('apt-get', 'update')
# Install base and Launchpad deb packages.
apt_get_install(*LP_PACKAGES, LC_ALL='C', caller=call)
class SubCommand(argparser.StepsBasedSubCommand):
- """Prepare a host machine to run Launchpad."""
+ """Prepare a machine to run Launchpad. May be an LXC container or not."""
initialize_step = (initialize,
'user', 'full_name', 'email', 'lpuser',
'private_key', 'public_key', 'valid_ssh_keys', 'ssh_key_path',
- 'feed_random')
-
- setup_apt_step = (setup_apt,
- 'no_repositories')
-
- steps = (initialize_step, setup_apt_step)
+ )
+
+ initialize_lxc_step = (initialize_lxc, )
+
+ setup_apt_step = (setup_apt, )
+
+ steps = (
+ initialize_step,
+ initialize_lxc_step,
+ setup_apt_step)
help = __doc__
needs_root = True
@@ -254,6 +287,11 @@
handle_ssh_keys,
)
+ def call_initialize_lxc(self, namespace, step, args):
+ """Caller that only initialize lxc if we are in an LXC."""
+ if running_in_container():
+ return step(*args)
+
def add_arguments(self, parser):
super(SubCommand, self).add_arguments(parser)
parser.add_argument(
@@ -294,10 +332,3 @@
help='{0} [DEFAULT={1}]'.format(
'The ssh key name used to connect to Launchpad.',
SSH_KEY_NAME))
- parser.add_argument(
- '-N', '--no-repositories', action='store_true',
- help='Do not add APT repositories.')
- parser.add_argument(
- '--feed-random', action='store_true',
- help='Use haveged to maintain a pool of random bytes used to '
- 'fill /dev/random and avoid entropy exhaustion.')
=== modified file 'lpsetup/subcommands/initlxc.py'
--- lpsetup/subcommands/initlxc.py 2012-07-03 18:02:41 +0000
+++ lpsetup/subcommands/initlxc.py 2012-07-10 18:00:33 +0000
@@ -2,16 +2,20 @@
# Copyright 2012 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
-"""initlxc subcommand: prepare an LXC container to run Launchpad."""
+"""initlxc subcommand: prepare an LXC container to run Launchpad.
+
+Run as root on the host machine to create an LXC container that can later be
+used to install a Launchpad development environment.
+"""
__metaclass__ = type
__all__ = [
'create_lxc',
- 'initialize_lxc',
- 'SubCommand',
- 'setup_lxc',
+ 'inithost_in_lxc',
+ 'install_lpsetup_in_lxc',
'start_lxc',
'stop_lxc',
+ 'SubCommand',
'wait_for_lxc',
]
@@ -27,7 +31,6 @@
from lpsetup import exceptions
from lpsetup.settings import (
- BASE_PACKAGES,
LPSETUP_PPA,
LXC_CONFIG_TEMPLATE,
LXC_GUEST_ARCH,
@@ -44,7 +47,6 @@
get_file_header,
get_lxc_gateway,
lxc_stopped,
- render_to_file,
retry,
sshlxc as ssh,
this_command,
@@ -119,12 +121,22 @@
retry_ssh(lxc_name, 'true', key=ssh_key_path)
-def initialize_lxc(lxc_name, ssh_key_path, lxc_os):
+def initialize(user):
+ """Initialize the LXC host."""
+ inithost.initialize_base(user)
+ # haveged is used to fill /dev/random, avoiding
+ # entropy exhaustion during automated parallel tests.
+ apt_get_install('haveged', caller=call)
+
+
+def install_lpsetup_in_lxc(lxc_name, ssh_key_path, lxc_os):
"""Initialize LXC container."""
- base_packages = list(BASE_PACKAGES) + ['python-software-properties']
+ # 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
ssh(lxc_name,
'DEBIAN_FRONTEND=noninteractive '
- 'apt-get install -y ' + ' '.join(base_packages),
+ 'apt-get install -y python-software-properties',
key=ssh_key_path)
args = {
'assume_yes': '' if lxc_os == 'lucid' else '-y',
@@ -138,29 +150,16 @@
'DEBIAN_FRONTEND=noninteractive '
'apt-get upgrade -y && apt-get install -y lpsetup',
key=ssh_key_path)
- # XXX benji 2012-03-19 bug=959352: this is so graphviz will work in an
- # ephemeral container
- ssh(lxc_name, 'mkdir -p /rootfs/usr/lib', key=ssh_key_path)
- ssh(lxc_name,
- 'ln -s /usr/lib/graphviz /rootfs/usr/lib/graphviz',
- key=ssh_key_path)
- # XXX gary 2012-06-26 bug=1014916: this fixes a bug in Lucid LXC
- # containers.
- if lxc_os == 'lucid':
- # Change /var/lib/lxc/lptests/rootfs/etc/init/networking.conf to not
- # wait for udev (that is, use start on (local-filesystems)).
- udevtrigger = get_container_path(
- lxc_name, '/etc/init/udevtrigger.conf')
- call('mv', udevtrigger, udevtrigger + '.orig')
- networking = get_container_path(lxc_name, '/etc/init/networking.conf')
- call('mv', networking, networking + '.orig')
- render_to_file('networking.conf', {}, networking)
-
-
-def setup_lxc(lxc_name, ssh_key_path, user, home_dir):
+
+
+def inithost_in_lxc(lxc_name, ssh_key_path, user, email, full_name, lpuser,
+ private_key, public_key, ssh_key_name, home_dir):
"""Prepare the Launchpad environment inside an LXC."""
# Use ssh to call this script from inside the container.
- args = ['inithost', '-u', user, '-s', 'setup_apt']
+ args = ['init-host', '-u', user, '-e', email, '-f', full_name,
+ '-l', lpuser, '-S', ssh_key_name,
+ ]
+
cmd = this_command(home_dir, args)
ssh(lxc_name, cmd, key=ssh_key_path)
@@ -173,7 +172,9 @@
class SubCommand(inithost.SubCommand):
- """Prepare an LXC container to run Launchpad."""
+ """Create an LXC container suitable for later installing a Launchpad
+ development environment.
+ """
create_lxc_step = (create_lxc,
'lxc_name', 'lxc_arch', 'lxc_os', 'user')
@@ -181,20 +182,21 @@
'lxc_name')
wait_for_lxc_step = (wait_for_lxc,
'lxc_name', 'ssh_key_path')
- initialize_lxc_step = (initialize_lxc,
+ install_lpsetup_in_lxc_step = (install_lpsetup_in_lxc,
'lxc_name', 'ssh_key_path', 'lxc_os')
- setup_lxc_step = (setup_lxc,
- 'lxc_name', 'ssh_key_path', 'user', 'home_dir')
+ 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')
stop_lxc_step = (stop_lxc,
'lxc_name', 'ssh_key_path')
steps = (
- inithost.SubCommand.initialize_step,
+ (initialize, 'user'),
create_lxc_step,
start_lxc_step,
wait_for_lxc_step,
- initialize_lxc_step,
- setup_lxc_step,
+ install_lpsetup_in_lxc_step,
+ inithost_in_lxc_step,
stop_lxc_step,
)
=== modified file 'lpsetup/subcommands/initrepo.py'
--- lpsetup/subcommands/initrepo.py 2012-07-10 16:16:39 +0000
+++ lpsetup/subcommands/initrepo.py 2012-07-10 18:00:33 +0000
@@ -66,7 +66,7 @@
class SubCommand(argparser.StepsBasedSubCommand):
- """Get the Launchpad source"""
+ """Get the Launchpad code and dependent source code."""
steps = (
(fetch, 'source', 'repository', 'branch_name', 'checkout_name'),
=== modified file 'lpsetup/subcommands/install_lxc.py'
--- lpsetup/subcommands/install_lxc.py 2012-07-09 15:19:13 +0000
+++ lpsetup/subcommands/install_lxc.py 2012-07-10 18:00:33 +0000
@@ -145,7 +145,9 @@
class SubCommand(initlxc.SubCommand):
- """Install the Launchpad environment inside an LXC."""
+ """Completely sets up an LXC environment with Launchpad using the sandbox
+ development model.
+ """
fetch_step = (fetch,
'user', 'repository', 'dependencies_dir', 'valid_ssh_keys')
@@ -158,7 +160,7 @@
initlxc.SubCommand.create_lxc_step + ('install_subunit',),
initlxc.SubCommand.start_lxc_step,
initlxc.SubCommand.wait_for_lxc_step,
- initlxc.SubCommand.initialize_lxc_step,
+ # XXX initlxc.SubCommand.initialize_lxc_step,
(setup_lxc,
'lxc_name', 'ssh_key_path', 'user', 'dependencies_dir', 'repository'),
initlxc.SubCommand.stop_lxc_step,
=== modified file 'lpsetup/subcommands/update.py'
--- lpsetup/subcommands/update.py 2012-07-06 21:36:53 +0000
+++ lpsetup/subcommands/update.py 2012-07-10 18:00:33 +0000
@@ -60,7 +60,10 @@
class SubCommand(argparser.StepsBasedSubCommand):
- """Update the Launchpad source and external sources."""
+ """Updates an existing Launchpad development environment.
+
+ Gets new versions of Launchpad source and external sources.
+ """
steps = (
(initialize_directories, 'external_path'),
@@ -77,7 +80,7 @@
def add_arguments(self, parser):
super(SubCommand, self).add_arguments(parser)
parser.add_argument(
- '-e', '--external-path',
+ '-e', '--external-path', default='.',
help='Path to directory that contains sourcecode '
'and download-cache directories.'
)
=== renamed file 'lpsetup/tests/subcommands/test_finish_inithost.py' => 'lpsetup/tests/subcommands/disabled_test_finish_inithost.py'
=== renamed file 'lpsetup/tests/subcommands/test_install_lxc.py' => 'lpsetup/tests/subcommands/disabled_test_install_lxc.py'
=== modified file 'lpsetup/tests/subcommands/test_inithost.py'
--- lpsetup/tests/subcommands/test_inithost.py 2012-07-05 18:38:51 +0000
+++ lpsetup/tests/subcommands/test_inithost.py 2012-07-10 18:00:33 +0000
@@ -17,8 +17,10 @@
initialize_step = (
inithost.initialize, ['user', 'full_name', 'email', 'lpuser',
'private_key', 'public_key', 'valid_ssh_keys', 'ssh_key_path',
- 'feed_random'])
-setup_apt_step = (inithost.setup_apt, ['no_repositories'])
+ ])
+initialize_lxc_step = (
+ inithost.initialize_lxc, [])
+setup_apt_step = (inithost.setup_apt, [])
def get_arguments():
@@ -44,5 +46,8 @@
handlers.handle_userdata,
handlers.handle_ssh_keys,
)
- expected_steps = (initialize_step, setup_apt_step)
+ expected_steps = (
+ initialize_step,
+ initialize_lxc_step,
+ setup_apt_step,)
needs_root = True
=== modified file 'lpsetup/tests/subcommands/test_initlxc.py'
--- lpsetup/tests/subcommands/test_initlxc.py 2012-07-05 18:38:51 +0000
+++ lpsetup/tests/subcommands/test_initlxc.py 2012-07-10 18:00:33 +0000
@@ -18,15 +18,17 @@
StepsBasedSubCommandTestMixin,
)
-
+initialize_step = (initlxc.initialize, ['user'])
create_lxc_step = (
initlxc.create_lxc, ['lxc_name', 'lxc_arch', 'lxc_os', 'user'])
start_lxc_step = (initlxc.start_lxc, ['lxc_name'])
wait_for_lxc_step = (initlxc.wait_for_lxc, ['lxc_name', 'ssh_key_path'])
-initialize_lxc_step = (
- initlxc.initialize_lxc, ['lxc_name', 'ssh_key_path', 'lxc_os'])
-setup_lxc_step = (
- initlxc.setup_lxc, ['lxc_name', 'ssh_key_path', 'user', 'home_dir'])
+install_lpsetup_in_lxc_step = (
+ initlxc.install_lpsetup_in_lxc, ['lxc_name', 'ssh_key_path', 'lxc_os'])
+inithost_in_lxc_step = (
+ initlxc.inithost_in_lxc,
+ ['lxc_name', 'ssh_key_path', 'user', 'email', 'full_name', 'lpuser',
+ 'private_key', 'public_key', 'ssh_key_name', 'home_dir'])
stop_lxc_step = (initlxc.stop_lxc, ['lxc_name', 'ssh_key_path'])
@@ -51,12 +53,12 @@
handlers.handle_ssh_keys,
)
expected_steps = (
- test_inithost.initialize_step,
+ initialize_step,
create_lxc_step,
start_lxc_step,
wait_for_lxc_step,
- initialize_lxc_step,
- setup_lxc_step,
+ install_lpsetup_in_lxc_step,
+ inithost_in_lxc_step,
stop_lxc_step,
)
needs_root = True
=== modified file 'lpsetup/tests/test_handlers.py'
--- lpsetup/tests/test_handlers.py 2012-07-05 18:38:51 +0000
+++ lpsetup/tests/test_handlers.py 2012-07-10 18:00:33 +0000
@@ -156,7 +156,6 @@
ctx = {
'create_scripts': True,
- 'feed_random': False,
'install_subunit': False,
'stop_lxc': False,
}
=== modified file 'lpsetup/utils.py'
--- lpsetup/utils.py 2012-07-03 18:02:41 +0000
+++ lpsetup/utils.py 2012-07-10 18:00:33 +0000
@@ -17,6 +17,7 @@
'lxc_stopped',
'render_to_file',
'retry',
+ 'running_in_container',
'Scrubber',
'sshlxc',
'this_command',
@@ -28,6 +29,7 @@
partial,
wraps,
)
+import errno
import glob
import os
import re
@@ -91,6 +93,23 @@
return os.path.join(base_path, lxc_name, 'rootfs', path.lstrip('/'))
+def get_file_header(program=sys.argv[0], now=None,
+ initial_indent='# ', subsequent_indent='# '):
+ if now is None:
+ now = datetime.utcnow()
+ header = (
+ 'This file created at {date}UTC by {program}, '
+ 'version {version}.'.format(
+ date=datetime.isoformat(now),
+ program=program,
+ version=get_version(),
+ )
+ )
+ return textwrap.fill(
+ header, initial_indent=initial_indent,
+ subsequent_indent=subsequent_indent)
+
+
def get_lxc_gateway(candidates=('lxcbr0', 'virbr0'), interface_lookup=None):
"""Return the gateway bridge name to be used by LXC containers.
@@ -149,23 +168,6 @@
lxc_stopped = partial(lxc_in_state, 'STOPPED')
-def get_file_header(program=sys.argv[0], now=None,
- initial_indent='# ', subsequent_indent='# '):
- if now is None:
- now = datetime.utcnow()
- header = (
- 'This file created at {date}UTC by {program}, '
- 'version {version}.'.format(
- date=datetime.isoformat(now),
- program=program,
- version=get_version(),
- )
- )
- return textwrap.fill(
- header, initial_indent=initial_indent,
- subsequent_indent=subsequent_indent)
-
-
def render_to_file(template_name, context, dest, templates_dir=None):
"""Render `template_name` using `context`. Write the result inside `dest`.
@@ -207,6 +209,21 @@
return decorator
+def running_in_container():
+ """Are we running in a container?"""
+ # 'running-in-container' is Precise and greater; 'lxc-is-container' is
+ # Lucid. These are provided by the lxcguest package.
+ for cmd in ('running-in-container', 'lxc-is-container'):
+ try:
+ return not subprocess.call([cmd])
+ except OSError, err:
+ # ENOENT means "No such file or
+ # directory."
+ if err.errno != errno.ENOENT:
+ raise
+ return False
+
+
class Scrubber(object):
"""Scrubber will cleanup after lxc ephemeral uncleanliness.
=== modified file 'pre-commit.sh'
--- pre-commit.sh 2012-07-06 17:12:36 +0000
+++ pre-commit.sh 2012-07-10 18:00:33 +0000
@@ -1,4 +1,4 @@
#!/bin/bash
pyfiles=`find . -name "*.py" | grep -v distribute_setup.py `
-pocketlint $pyfiles && pep8 $pyfiles && nosetests --with-doctest
+pocketlint $pyfiles && pep8 $pyfiles && nosetests
=== modified file 'setup.cfg'
--- setup.cfg 2012-04-25 15:19:13 +0000
+++ setup.cfg 2012-07-10 18:00:33 +0000
@@ -1,5 +1,7 @@
[nosetests]
detailed-errors=1
exclude=handle_testing
+ignore-files=disabled*
with-coverage=1
cover-package=lpsetup
+with-doctest=1
Follow ups