← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~bac/lpsetup/fix-inithost-install-lxc into lp:lpsetup

 

Brad Crittenden has proposed merging lp:~bac/lpsetup/fix-inithost-install-lxc into lp:lpsetup.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~bac/lpsetup/fix-inithost-install-lxc/+merge/114486

A previous branch refactored away some methods that install-lxc and finish-init-host needed.  Those commands were neutered and their tests disabled.

This branch fixes them properly.  Some stuff from finish-init-host was moved to init-host so that everything in the latter stage all depend upon a Launchpad tree existing.

I poked and prodded setup.cfg and with Francesco's help got a work-around that seems to appease nose.
-- 
https://code.launchpad.net/~bac/lpsetup/fix-inithost-install-lxc/+merge/114486
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~bac/lpsetup/fix-inithost-install-lxc into lp:lpsetup.
=== modified file 'README.rst'
--- README.rst	2012-07-10 20:00:37 +0000
+++ README.rst	2012-07-11 18:47:20 +0000
@@ -11,7 +11,14 @@
 ~~~~~~~~~~~~
 
 lp-setup requires:
-Python >= 2.7, `python-shelltoolbox`, and `pep8`.
+  lxc
+  Python >= 2.7
+  pep8
+  python-shelltoolbox
+  python-pocket-lint
+  python-nose
+  python-coverage (optional)
+
 The package `python-argparse` is required to run lp-setup using Python 2.6.
 
 
@@ -40,8 +47,10 @@
 
 To run *lpsetup* tests install nose and run `nosetests` from this directory::
 
-    apt-get install python-nose
+    apt-get install python-nose python-coverage
     nosetests
+    or
+    ./pre-commit.sh
 
 
 Integration tests
@@ -69,7 +78,6 @@
 
 Install pocketlint::
 
-    sudo apt-add-repository ppa:sinzui/ppa
     sudo apt-get update
     sudo apt-get install python-pocket-lint
 

=== modified file 'lpsetup/handlers.py'
--- lpsetup/handlers.py	2012-07-10 18:11:30 +0000
+++ lpsetup/handlers.py	2012-07-11 18:47:20 +0000
@@ -220,18 +220,21 @@
 
 
 def handle_directories(namespace):
-    """Handle checkout and dependencies directories.
+    """Handle repository, code_dir, and dependencies directories.
 
     - The ~ construction is automatically expanded.
     - The validation fails for directories not residing inside the home.
     - The validation fails if the directory contains spaces.
     """
-    if ' ' in namespace.repository:
-        raise ValidationError('argument directory can not contain spaces.')
-    for attr in ('repository', 'dependencies_dir'):
+    for attr in ('repository', 'code_dir', 'dependencies_dir'):
         directory = getattr(namespace, attr, None)
         if directory is None:
             continue
+        if ' ' in directory:
+            err = ("argument directory cannot contain "
+                   "spaces: '{0}'".format(directory))
+            raise ValidationError(err)
+
         directory = directory.replace('~', namespace.home_dir)
         if not directory.startswith(namespace.home_dir + os.path.sep):
             raise ValidationError(

=== modified file 'lpsetup/settings.py'
--- lpsetup/settings.py	2012-07-10 15:50:26 +0000
+++ lpsetup/settings.py	2012-07-11 18:47:20 +0000
@@ -3,6 +3,7 @@
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Global settings and defaults for lpsetup."""
+import os.path
 
 
 APT_REPOSITORIES = (
@@ -53,12 +54,13 @@
     }
 LP_BRANCH_NAME = 'devel'
 LP_CHECKOUT_NAME = 'sandbox'
+LP_CODE_DIR = os.path.join(CHECKOUT_DIR, LP_CHECKOUT_NAME)
 LP_PACKAGES = [
     # "launchpad-database-dependencies-9.1" can be removed once 8.x is
     # no longer an option in "launchpad-developer-dependencies.
     'launchpad-database-dependencies-9.1',
     'launchpad-developer-dependencies', 'apache2',
-    'apache2-mpm-worker', 'libapache2-mod-wsgi'
+    'apache2-mpm-worker', 'libapache2-mod-wsgi',
     ]
 LP_HTTP_REPO = 'http://bazaar.launchpad.net/~launchpad-pqm/launchpad/devel'
 LP_SSH_REPO = 'lp:launchpad'

=== modified file 'lpsetup/subcommands/finish_inithost.py'
--- lpsetup/subcommands/finish_inithost.py	2012-07-10 15:41:13 +0000
+++ lpsetup/subcommands/finish_inithost.py	2012-07-11 18:47:20 +0000
@@ -19,7 +19,6 @@
 from contextlib import nested
 import os
 import pwd
-import subprocess
 
 from shelltoolbox import (
     cd,
@@ -27,68 +26,40 @@
     su,
     )
 
-from lpsetup.handlers import handle_directories
+from lpsetup.handlers import (
+    handle_directories,
+    handle_user,
+    )
 from lpsetup.subcommands import (
     inithost,
     initrepo,
     )
-from lpsetup.settings import (
-    CHECKOUT_DIR,
-    DEPENDENCIES_DIR,
-    LP_BRANCH_NAME,
-    )
+from lpsetup.settings import LP_CODE_DIR
 from lpsetup.utils import call
 
 
-def make_launchpad(user, checkout_dir, install=False):
+def make_launchpad(user, code_dir, install=False):
     """Make and optionally install Launchpad."""
-    # Using real su because mailman make script uses uid.
-    call(*get_su_command(user, ['make', '-C', checkout_dir]))
-    if install:
-        call('make', '-C', checkout_dir, 'install')
-
-
-def setup_external_sourcecode(
-    user, sandbox_dir, checkout_dir, dependencies_dir, valid_ssh_keys=True):
-    """Update and link external sourcecode."""
-    cmd = (
-        'utilities/update-sourcecode',
-        None if valid_ssh_keys else '--use-http',
-        os.path.join(dependencies_dir, 'sourcecode'),
-        )
-    if os.path.exists(sandbox_dir):
-        build_dir = sandbox_dir
-    elif os.path.exists(checkout_dir):
-        build_dir = checkout_dir
-
-    with cd(build_dir):
-        # Using real su because update-sourcecode uses uid.
-        call(*get_su_command(user, cmd))
-        with su(user):
-            call('utilities/link-external-sourcecode', dependencies_dir)
-
-
-def setup_launchpad(user, dependencies_dir, repository, valid_ssh_keys):
+    with cd(code_dir):
+        # Using real su because mailman make script uses uid.
+        call(*get_su_command(user, ['make', 'schema']))
+        if install:
+            call('make', 'install')
+
+
+def setup_launchpad(user, code_dir):
     """Set up the Launchpad environment."""
-    # User configuration.
-    subprocess.call(['adduser', user, 'sudo'])
-    pwd_database = pwd.getpwnam(user)
-    subprocess.call(['addgroup', '--gid', str(pwd_database.pw_gid), user])
-    # Set up Launchpad dependencies.
-    # XXX: Eventually move to 'update'.
-    checkout_dir = os.path.join(repository, LP_BRANCH_NAME)
-    setup_external_sourcecode(
-        user, checkout_dir, dependencies_dir, valid_ssh_keys)
 
     # Launchpad database setup.
     # nested is required for use by python 2.6.
-    with nested(su(user), cd(checkout_dir)):
+    with nested(su(user), cd(code_dir)):
         call('utilities/launchpad-database-setup', user)
 
     # Make and install launchpad.
-    make_launchpad(user, checkout_dir, install=True)
+    make_launchpad(user, code_dir, install=True)
 
     # Change owner of /srv/launchpad.dev/.
+    pwd_database = pwd.getpwnam(user)
     os.chown('/srv/launchpad.dev/', pwd_database.pw_uid, pwd_database.pw_gid)
 
 
@@ -98,45 +69,32 @@
 
 
 class SubCommand(inithost.SubCommand):
-    """Finish the initialization of a Launchpad development host."""
+    """Finish the initialization of a Launchpad development host.
+
+    Run the commands as root in the Launchpad target machine that must be done
+    after the Launchpad tree is available.
+    """
 
     # 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
-        # going away soon).
-        import install_lxc
-        return (
-            inithost.SubCommand.initialize_step,
-            install_lxc.SubCommand.fetch_step,
-            (setup_bzr_locations_as_root,
-             'user', 'lpuser', 'repository'),
-            inithost.SubCommand.setup_apt_step,
-            (setup_launchpad,
-            'user', 'dependencies_dir', 'repository', 'valid_ssh_keys'),
-            )
+    steps = (
+        (setup_launchpad, 'user', 'code_dir'),
+        )
 
-    def get_handlers(self, namespace):
-        handlers = super(SubCommand, self).get_handlers(namespace)
-        return handlers + (handle_directories,)
+    handlers = (
+        handle_user,
+        handle_directories,
+        )
 
     def add_arguments(self, parser):
         super(SubCommand, self).add_arguments(parser)
         parser.add_argument(
-            '-d', '--dependencies-dir', default=DEPENDENCIES_DIR,
-            help='The directory of the Launchpad dependencies to be created. '
-                 'The directory must reside under the home directory of the '
-                 'given user (see -u argument). '
-                 '[DEFAULT={0}]'.format(DEPENDENCIES_DIR))
-        parser.add_argument(
-            '-r', '--repository', default=CHECKOUT_DIR,
-            help='The directory of the Launchpad repository to be created. '
-                 'The directory must reside under the home directory of the '
-                 'given user (see -u argument). '
-                 '[DEFAULT={0}]'.format(CHECKOUT_DIR))
+            '-c', '--code-dir', default=LP_CODE_DIR,
+            help='The directory of the Launchpad code checkout.  '
+                 'The directory must reside under the home directory of the '
+                 'given user (see -u argument). '
+                 '[DEFAULT={0}]'.format(LP_CODE_DIR))
         parser.add_argument(
             '-t', '--with-trees', action='store_false', dest='lightweight',
             default=True, help='Do not use a lightweight checkout.')

=== modified file 'lpsetup/subcommands/inithost.py'
--- lpsetup/subcommands/inithost.py	2012-07-11 11:25:22 +0000
+++ lpsetup/subcommands/inithost.py	2012-07-11 18:47:20 +0000
@@ -14,6 +14,7 @@
 
 from email.Utils import formataddr
 import os
+import pwd
 import shutil
 import subprocess
 
@@ -109,6 +110,12 @@
     if not user_exists(user):
         call('useradd', '-m', '-s', '/bin/bash', '-U', user)
 
+    # Add user to the sudo group.
+    subprocess.call(['adduser', user, 'sudo'])
+    # Add the user to his own group.
+    pwd_database = pwd.getpwnam(user)
+    subprocess.call(['addgroup', '--gid', str(pwd_database.pw_gid), user])
+
 
 def initialize(
     user, full_name, email, lpuser, private_key, public_key, valid_ssh_keys,

=== modified file 'lpsetup/subcommands/install_lxc.py'
--- lpsetup/subcommands/install_lxc.py	2012-07-10 19:06:12 +0000
+++ lpsetup/subcommands/install_lxc.py	2012-07-11 18:47:20 +0000
@@ -160,9 +160,7 @@
         initlxc.SubCommand.create_lxc_step + ('install_subunit',),
         initlxc.SubCommand.start_lxc_step,
         initlxc.SubCommand.wait_for_lxc_step,
-        # XXX bac, the following step no longer exists.  The functionality for
-        # this step needs to be refactored or removed.
-        # initlxc.SubCommand.initialize_lxc_step,
+        inithost.SubCommand.initialize_lxc_step,
         (setup_lxc,
          'lxc_name', 'ssh_key_path', 'user', 'dependencies_dir', 'repository'),
         initlxc.SubCommand.stop_lxc_step,

=== renamed file 'lpsetup/tests/subcommands/disabled_test_finish_inithost.py' => 'lpsetup/tests/subcommands/test_finish_inithost.py' (properties changed: +x to -x)
--- lpsetup/tests/subcommands/disabled_test_finish_inithost.py	2012-07-10 19:35:18 +0000
+++ lpsetup/tests/subcommands/test_finish_inithost.py	2012-07-11 18:47:20 +0000
@@ -2,7 +2,7 @@
 # Copyright 2012 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
-"""Tests for the install sub command."""
+"""Tests for the finish-init-host sub command."""
 
 import unittest
 
@@ -15,19 +15,14 @@
     )
 
 
-setup_bzr_locations_step = (
-    finish_inithost.setup_bzr_locations_as_root,
-    ['user', 'lpuser', 'repository'])
 setup_launchpad_step = (
-    finish_inithost.setup_launchpad, ['user', 'dependencies_dir', 'repository',
-    'valid_ssh_keys'])
+    finish_inithost.setup_launchpad, ['user', 'code_dir'])
 
 
 def get_arguments():
     inithost_arguments = test_inithost.get_arguments()
-    dependencies_dir = '~/' + get_random_string()
-    repository = '~/' + get_random_string()
-    return inithost_arguments + ('-d', dependencies_dir, '-r', repository)
+    code_dir = '~/' + get_random_string()
+    return inithost_arguments + ('-c', code_dir)
 
 
 class InstallTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
@@ -36,20 +31,12 @@
     expected_arguments = get_arguments()
     expected_handlers = (
         handlers.handle_user,
-        handlers.handle_lpuser_as_username,
-        handlers.handle_userdata,
-        handlers.handle_ssh_keys,
         handlers.handle_directories,
         )
 
     @property
     def expected_steps(self):
-        from lpsetup.tests.subcommands import test_install_lxc
         return (
-            test_inithost.initialize_step,
-            test_install_lxc.fetch_step,
-            setup_bzr_locations_step,
-            test_inithost.setup_apt_step,
             setup_launchpad_step,
             )
     needs_root = True

=== renamed file 'lpsetup/tests/subcommands/disabled_test_install_lxc.py' => 'lpsetup/tests/subcommands/test_install_lxc.py' (properties changed: +x to -x)
--- lpsetup/tests/subcommands/disabled_test_install_lxc.py	2012-07-10 19:35:18 +0000
+++ lpsetup/tests/subcommands/test_install_lxc.py	2012-07-11 18:47:20 +0000
@@ -58,7 +58,7 @@
         create_lxc_step,
         test_initlxc.start_lxc_step,
         test_initlxc.wait_for_lxc_step,
-        test_initlxc.initialize_lxc_step,
+        test_inithost.initialize_lxc_step,
         setup_lxc_step,
         test_initlxc.stop_lxc_step,
         )

=== modified file 'pre-commit.sh'
--- pre-commit.sh	2012-07-10 17:58:00 +0000
+++ pre-commit.sh	2012-07-11 18:47:20 +0000
@@ -1,4 +1,4 @@
 #!/bin/bash
 
-pyfiles=`find . -name "*.py" | grep -v distribute_setup.py `
+pyfiles=`find . -name "*.py" | grep -v distribute_setup.py`
 pocketlint $pyfiles && pep8 $pyfiles && nosetests

=== modified file 'setup.cfg'
--- setup.cfg	2012-07-10 19:35:18 +0000
+++ setup.cfg	2012-07-11 18:47:20 +0000
@@ -1,11 +1,10 @@
 [nosetests]
 detailed-errors=1
 exclude=handle_testing
-with-coverage=0
+with-coverage=1
 cover-package=lpsetup
 with-doctest=1
-# Including ignore-files here or on the command line causes the tests
-# to fail with a complaint about the version of distribute.  As a
-# work-around, rename disabled tests to 'disabled_'+test_name and set
-# the execute bit. 
-#ignore-files=disabled*
+# Specifying 'where' should not be required but it is a work-around
+# for a problem presented by having 'ignore-files'.
+where=lpsetup
+ignore-files=disabled*


Follow ups