Merge lp:~frankban/lpsetup/ssh-call into lp:lpsetup

Proposed by Francesco Banconi
Status: Merged
Merged at revision: 8
Proposed branch: lp:~frankban/lpsetup/ssh-call
Merge into: lp:lpsetup
Diff against target: 134 lines (+37/-22)
3 files modified
lpsetup/subcommands/lxcinstall.py (+4/-7)
lpsetup/tests/test_utils.py (+26/-1)
lpsetup/utils.py (+7/-14)
To merge this branch: bzr merge lp:~frankban/lpsetup/ssh-call
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Review via email: mp+99010@code.launchpad.net

Description of the change

== Changes ==

Updated the way the script is called inside LXC containers: lpsetup is no longer present in the Launchpad checkout, it's a standalone project installed using apt.
Added tests for this_command utility.
Removed python-argparse installation in lucid containers: this should be handled by apt.

== Tests ==

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

To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

These changes look good Francesco.

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

Thank you Brad.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lpsetup/subcommands/lxcinstall.py'
2--- lpsetup/subcommands/lxcinstall.py 2012-03-22 10:48:50 +0000
3+++ lpsetup/subcommands/lxcinstall.py 2012-03-23 11:54:36 +0000
4@@ -116,12 +116,9 @@
5 break
6
7
8-def initialize_lxc(lxc_name, lxc_os, ssh_key_path):
9+def initialize_lxc(lxc_name, ssh_key_path):
10 """Initialize LXC container."""
11- base_packages = list(BASE_PACKAGES)
12- if lxc_os == 'lucid':
13- # Install argparse to be able to run this script inside a lucid lxc.
14- base_packages.append('python-argparse')
15+ base_packages = list(BASE_PACKAGES) + ['lpsetup']
16 sshcall = ssh(lxc_name, key=ssh_key_path)
17 sshcall(
18 'DEBIAN_FRONTEND=noninteractive '
19@@ -133,7 +130,7 @@
20 """Set up the Launchpad environment inside an LXC."""
21 # Use ssh to call this script from inside the container.
22 args = [
23- 'install', '-u', user, '-a', 'setup_apt', 'setup_launchpad',
24+ 'install', '-u', user, '-s', 'setup_apt', 'setup_launchpad',
25 '-d', dependencies_dir, '-c', directory
26 ]
27 cmd = this_command(directory, args)
28@@ -161,7 +158,7 @@
29 (wait_for_lxc,
30 'lxc_name', 'ssh_key_path'),
31 (initialize_lxc,
32- 'lxc_name', 'lxc_os', 'ssh_key_path'),
33+ 'lxc_name', 'ssh_key_path'),
34 (setup_launchpad_lxc,
35 'user', 'dependencies_dir', 'directory',
36 'valid_ssh_keys', 'ssh_key_path', 'lxc_name'),
37
38=== modified file 'lpsetup/tests/test_utils.py'
39--- lpsetup/tests/test_utils.py 2012-03-16 11:01:10 +0000
40+++ lpsetup/tests/test_utils.py 2012-03-23 11:54:36 +0000
41@@ -4,9 +4,13 @@
42
43 """Tests for the utils module."""
44
45+import sys
46 import unittest
47
48-from lpsetup.utils import get_container_path
49+from lpsetup.utils import (
50+ get_container_path,
51+ this_command,
52+ )
53
54
55 class GetContainerPathTest(unittest.TestCase):
56@@ -25,3 +29,24 @@
57 self.assertEqual(
58 '/var/lib/lxc/mycontainer/rootfs/home',
59 get_container_path('mycontainer', 'home'))
60+
61+
62+class ThisCommandTest(unittest.TestCase):
63+
64+ script_name = sys.argv[0]
65+ directory = '/home/user/lp/branches'
66+
67+ def check_command(self, cmd, args):
68+ expected = ['cd', self.directory, '&&', self.script_name, args]
69+ self.assertEqual(' '.join(expected), cmd)
70+
71+ def test_directory(self):
72+ # Ensure the returned command will execute this script from
73+ # the given `directory`.
74+ cmd = this_command(self.directory, ['install'])
75+ self.check_command(cmd, 'install')
76+
77+ def test_args_are_quoted(self):
78+ # Ensure arguments are correctly quoted.
79+ cmd = this_command(self.directory, ['-arg', 'quote me'])
80+ self.check_command(cmd, "-arg 'quote me'")
81
82=== modified file 'lpsetup/utils.py'
83--- lpsetup/utils.py 2012-03-09 10:14:32 +0000
84+++ lpsetup/utils.py 2012-03-23 11:54:36 +0000
85@@ -19,6 +19,7 @@
86 import os
87 import platform
88 import subprocess
89+import sys
90 import time
91
92 from shelltoolbox import (
93@@ -26,10 +27,7 @@
94 run,
95 )
96
97-from lpsetup.settings import (
98- LP_CHECKOUT,
99- LXC_PATH,
100- )
101+from lpsetup.settings import LXC_PATH
102
103
104 call = partial(run, stdout=None)
105@@ -88,24 +86,19 @@
106 def this_command(directory, args):
107 """Return a command line to re-launch this script using given `args`.
108
109- The command returned will execute this script from `directory`::
110+ The returned command will execute this script from `directory`::
111
112- >>> import os
113- >>> script_name = os.path.basename(__file__)
114+ >>> script_name = sys.argv[0]
115
116 >>> cmd = this_command('/home/user/lp/branches', ['install'])
117- >>> cmd == ('cd /home/user/lp/branches && devel/utilities/' +
118- ... script_name + ' install')
119+ >>> cmd == 'cd /home/user/lp/branches && ' + script_name + ' install'
120 True
121
122 Arguments are correctly quoted::
123
124 >>> cmd = this_command('/path', ['-arg', 'quote me'])
125- >>> cmd == ('cd /path && devel/utilities/' +
126- ... script_name + " -arg 'quote me'")
127+ >>> cmd == ('cd /path && ' + script_name + " -arg 'quote me'")
128 True
129 """
130- script = join_command([
131- os.path.join(LP_CHECKOUT, 'utilities', os.path.basename(__file__)),
132- ] + list(args))
133+ script = join_command(sys.argv[:1] + list(args))
134 return join_command(['cd', directory]) + ' && ' + script

Subscribers

People subscribed via source and target branches

to all changes: