← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~bac/lpsetup/refactor-install into lp:lpsetup

 

Brad Crittenden has proposed merging lp:~bac/lpsetup/refactor-install into lp:lpsetup.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~bac/lpsetup/refactor-install/+merge/113753

Move portions of the 'install' subcommand that do not depend on having
a Launchpad tree elsewhere.  Also rename 'install' to
'finish_inithost'.  It is the intent for this command to eventually go
away.
-- 
https://code.launchpad.net/~bac/lpsetup/refactor-install/+merge/113753
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~bac/lpsetup/refactor-install into lp:lpsetup.
=== modified file 'lpsetup/cli.py'
--- lpsetup/cli.py	2012-07-05 18:38:51 +0000
+++ lpsetup/cli.py	2012-07-06 15:01:30 +0000
@@ -16,20 +16,20 @@
     exceptions,
     )
 from lpsetup.subcommands import (
+    finish_inithost,
     inithost,
     initlxc,
     initrepo,
-    install,
     lxcinstall,
     version,
     )
 
 
 subcommands = [
-    ('install', install.SubCommand),
-    ('inithost', inithost.SubCommand),
-    ('initlxc', initlxc.SubCommand),
-    ('initrepo', initrepo.SubCommand),
+    ('finish-init-host', finish_inithost.SubCommand),
+    ('init-host', inithost.SubCommand),
+    ('init-lxc', initlxc.SubCommand),
+    ('init-repo', initrepo.SubCommand),
     ('lxc-install', lxcinstall.SubCommand),
     ('version', version.SubCommand),
     ]

=== renamed file 'lpsetup/subcommands/install.py' => 'lpsetup/subcommands/finish_inithost.py'
--- lpsetup/subcommands/install.py	2012-07-05 18:38:51 +0000
+++ lpsetup/subcommands/finish_inithost.py	2012-07-06 15:01:30 +0000
@@ -17,9 +17,7 @@
 
 from shelltoolbox import (
     cd,
-    file_append,
     get_su_command,
-    mkdirs,
     su,
     )
 
@@ -31,10 +29,6 @@
 from lpsetup.settings import (
     CHECKOUT_DIR,
     DEPENDENCIES_DIR,
-    HOSTS_CONTENT,
-    HOSTS_FILE,
-    LP_APACHE_MODULES,
-    LP_APACHE_ROOTS,
     LP_BRANCH_NAME,
     )
 from lpsetup.utils import call
@@ -75,26 +69,20 @@
     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)
-    with su(user):
-        # Create Apache document roots, to avoid warnings.
-        mkdirs(*LP_APACHE_ROOTS)
-    # Set up Apache modules.
-    for module in LP_APACHE_MODULES.split():
-        call('a2enmod', module)
-    with cd(checkout_dir):
-        # Launchpad database setup.
+
+    # Launchpad database setup.
+    with su(user), cd(checkout_dir):
         call('utilities/launchpad-database-setup', user)
+
     # Make and install launchpad.
     make_launchpad(user, checkout_dir, install=True)
+
     # Change owner of /srv/launchpad.dev/.
     os.chown('/srv/launchpad.dev/', pwd_database.pw_uid, pwd_database.pw_gid)
-    # Set up container hosts file.
-    lines = ['{0}\t{1}\n'.format(ip, names) for ip, names in HOSTS_CONTENT]
-    for line in lines:
-        file_append(HOSTS_FILE, line)
 
 
 def setup_bzr_locations_as_root(user, lpuser, repository):

=== modified file 'lpsetup/subcommands/inithost.py'
--- lpsetup/subcommands/inithost.py	2012-07-05 18:38:51 +0000
+++ lpsetup/subcommands/inithost.py	2012-07-06 15:01:30 +0000
@@ -17,6 +17,7 @@
 
 from shelltoolbox import (
     apt_get_install,
+    file_append,
     generate_ssh_keys,
     mkdirs,
     run,
@@ -34,6 +35,10 @@
 from lpsetup.settings import (
     APT_REPOSITORIES,
     BASE_PACKAGES,
+    HOSTS_CONTENT,
+    HOSTS_FILE,
+    LP_APACHE_MODULES,
+    LP_APACHE_ROOTS,
     LP_PACKAGES,
     SSH_KEY_NAME,
     )
@@ -71,7 +76,7 @@
         ...     '/tmp/foo', 'Hello, world', 'w') # doctest: +ELLIPSIS
         >>> os.remove('/tmp/foo')
 
-    Passing a `mode` other than "a" or "w' will cause an Exception.
+    Passing a `mode` other than "a" or "w" will cause an Exception.
 
         >>> write_file_contents(
         ...     '/tmp/foo', 'Hello, world', 'w+') # doctest: +ELLIPSIS
@@ -130,6 +135,20 @@
         call('bzr', 'whoami', formataddr([full_name, email]))
         if valid_ssh_keys:
             subprocess.call(['bzr', 'lp-login', lpuser])
+
+        # Create Apache document roots, to avoid warnings.
+        mkdirs(*LP_APACHE_ROOTS)
+        # Set up Apache modules.
+        for module in LP_APACHE_MODULES.split():
+            call('a2enmod', module)
+
+    # Set up container hosts file.
+    lines = [get_file_header()]
+    lines.extend(['{0}\t{1}\n'.format(ip, names)
+                  for ip, names in HOSTS_CONTENT])
+    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:

=== renamed file 'lpsetup/tests/subcommands/test_install.py' => 'lpsetup/tests/subcommands/test_finish_inithost.py'
--- lpsetup/tests/subcommands/test_install.py	2012-07-05 18:38:51 +0000
+++ lpsetup/tests/subcommands/test_finish_inithost.py	2012-07-06 15:01:30 +0000
@@ -7,7 +7,7 @@
 import unittest
 
 from lpsetup import handlers
-from lpsetup.subcommands import install
+from lpsetup.subcommands import finish_inithost
 from lpsetup.tests.subcommands import test_inithost
 from lpsetup.tests.utils import (
     get_random_string,
@@ -16,9 +16,10 @@
 
 
 setup_bzr_locations_step = (
-    install.setup_bzr_locations_as_root, ['user', 'lpuser', 'repository'])
+    finish_inithost.setup_bzr_locations_as_root,
+    ['user', 'lpuser', 'repository'])
 setup_launchpad_step = (
-    install.setup_launchpad, ['user', 'dependencies_dir', 'repository',
+    finish_inithost.setup_launchpad, ['user', 'dependencies_dir', 'repository',
     'valid_ssh_keys'])
 
 
@@ -31,7 +32,7 @@
 
 class InstallTest(StepsBasedSubCommandTestMixin, unittest.TestCase):
 
-    sub_command_class = install.SubCommand
+    sub_command_class = finish_inithost.SubCommand
     expected_arguments = get_arguments()
     expected_handlers = (
         handlers.handle_user,