Merge lp:~cjwatson/click/chroot-name into lp:click/devel

Proposed by Colin Watson on 2014-09-25
Status: Merged
Approved by: Colin Watson on 2014-09-26
Approved revision: 525
Merged at revision: 523
Proposed branch: lp:~cjwatson/click/chroot-name
Merge into: lp:click/devel
Diff against target: 201 lines (+52/-34)
3 files modified
click/commands/chroot.py (+19/-9)
click/tests/integration/test_chroot.py (+31/-25)
debian/changelog (+2/-0)
To merge this branch: bzr merge lp:~cjwatson/click/chroot-name
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve on 2014-09-25
Michael Vogt 2014-09-25 Approve on 2014-09-25
Review via email: mp+235971@code.launchpad.net

Commit message

Add new -n/--name option to "click chroot", defaulting to "click".

Description of the change

It would apparently be helpful in the SDK test suite to be able to vary the name of created click chroots. This facility is available in the click.chroot library, but not exposed in the CLI. This branch fixes that.

To post a comment you must log in.
Michael Vogt (mvo) wrote :

This looks great, two small comments in the tests that are not critical, its fine IMO to land as it is.

review: Approve
lp:~cjwatson/click/chroot-name updated on 2014-09-26
524. By Colin Watson on 2014-09-26

Add docstring for TestChrootName.

525. By Colin Watson on 2014-09-26

Clarify test_exists_different_name.

Colin Watson (cjwatson) wrote :

Thanks, I've fixed those two things.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'click/commands/chroot.py'
2--- click/commands/chroot.py 2014-07-01 07:12:49 +0000
3+++ click/commands/chroot.py 2014-09-26 17:27:16 +0000
4@@ -61,7 +61,8 @@
5 "debootstrap not installed and configured; install click-dev and "
6 "debootstrap")
7 requires_root(parser)
8- chroot = ClickChroot(args.architecture, args.framework, series=args.series)
9+ chroot = ClickChroot(
10+ args.architecture, args.framework, name=args.name, series=args.series)
11 with message_on_error(
12 ClickChrootAlreadyExistsException, ErrorMessages.EXISTS):
13 return chroot.create(args.keep_broken_chroot)
14@@ -71,7 +72,7 @@
15
16 def install(parser, args):
17 packages = args.packages
18- chroot = ClickChroot(args.architecture, args.framework)
19+ chroot = ClickChroot(args.architecture, args.framework, name=args.name)
20 with message_on_error(
21 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
22 return chroot.install(*packages)
23@@ -82,7 +83,7 @@
24 def destroy(parser, args):
25 requires_root(parser)
26 # ask for confirmation?
27- chroot = ClickChroot(args.architecture, args.framework)
28+ chroot = ClickChroot(args.architecture, args.framework, name=args.name)
29 with message_on_error(
30 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
31 return chroot.destroy()
32@@ -95,7 +96,8 @@
33 if not program:
34 program = ["/bin/bash"]
35 chroot = ClickChroot(
36- args.architecture, args.framework, session=args.session)
37+ args.architecture, args.framework, name=args.name,
38+ session=args.session)
39 with message_on_error(
40 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
41 return chroot.run(*program)
42@@ -108,7 +110,8 @@
43 if not program:
44 program = ["/bin/bash"]
45 chroot = ClickChroot(
46- args.architecture, args.framework, session=args.session)
47+ args.architecture, args.framework, name=args.name,
48+ session=args.session)
49 with message_on_error(
50 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
51 return chroot.maint(*program)
52@@ -117,7 +120,7 @@
53
54
55 def upgrade(parser, args):
56- chroot = ClickChroot(args.architecture, args.framework)
57+ chroot = ClickChroot(args.architecture, args.framework, name=args.name)
58 with message_on_error(
59 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
60 return chroot.upgrade()
61@@ -127,7 +130,8 @@
62
63 def begin_session(parser, args):
64 chroot = ClickChroot(
65- args.architecture, args.framework, session=args.session)
66+ args.architecture, args.framework, name=args.name,
67+ session=args.session)
68 with message_on_error(
69 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
70 return chroot.begin_session()
71@@ -137,7 +141,8 @@
72
73 def end_session(parser, args):
74 chroot = ClickChroot(
75- args.architecture, args.framework, session=args.session)
76+ args.architecture, args.framework, name=args.name,
77+ session=args.session)
78 with message_on_error(
79 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
80 return chroot.end_session()
81@@ -146,7 +151,7 @@
82
83
84 def exists(parser, args):
85- chroot = ClickChroot(args.architecture, args.framework)
86+ chroot = ClickChroot(args.architecture, args.framework, name=args.name)
87 # return shell exit codes 0 on success, 1 on failure
88 if chroot.exists():
89 return 0
90@@ -169,6 +174,11 @@
91 "-s", "--series",
92 help="series to use for a newly-created chroot (defaults to a series "
93 "appropriate for the framework)")
94+ parser.add_argument(
95+ "-n", "--name", default="click",
96+ help=(
97+ "name of the chroot (default: click; the framework and "
98+ "architecture will be appended)"))
99 create_parser = subparsers.add_parser(
100 "create",
101 help="create a chroot of the provided architecture")
102
103=== modified file 'click/tests/integration/test_chroot.py'
104--- click/tests/integration/test_chroot.py 2014-09-05 09:04:33 +0000
105+++ click/tests/integration/test_chroot.py 2014-09-26 17:27:16 +0000
106@@ -27,52 +27,58 @@
107 class TestChroot(ClickTestCase):
108
109 @classmethod
110+ def command(cls, arch, *args):
111+ return [cls.click_binary, "chroot", "-a", arch] + list(args)
112+
113+ @classmethod
114 def setUpClass(cls):
115 super(TestChroot, cls).setUpClass()
116 require_root()
117 require_network()
118 cls.arch = subprocess.check_output(
119 ["dpkg", "--print-architecture"], universal_newlines=True).strip()
120- subprocess.check_call([
121- cls.click_binary,
122- "chroot", "-a", cls.arch,
123- "create"])
124+ subprocess.check_call(cls.command(cls.arch, "create"))
125
126 @classmethod
127 def tearDownClass(cls):
128- subprocess.check_call([
129- cls.click_binary,
130- "chroot", "-a", cls.arch,
131- "destroy"])
132+ subprocess.check_call(cls.command(cls.arch, "destroy"))
133
134 def test_upgrade(self):
135- subprocess.check_call([
136- self.click_binary, "chroot", "-a", self.arch,
137- "upgrade"])
138+ subprocess.check_call(self.command(self.arch, "upgrade"))
139
140 def test_install(self):
141- subprocess.check_call([
142- self.click_binary, "chroot", "-a", self.arch,
143- "install", "apt-utils"])
144+ subprocess.check_call(self.command(self.arch, "install", "apt-utils"))
145
146 def test_run(self):
147- output = subprocess.check_output([
148- self.click_binary, "chroot", "-a", self.arch,
149- "run", "echo", "hello world"], universal_newlines=True)
150+ output = subprocess.check_output(
151+ self.command(self.arch, "run", "echo", "hello world"),
152+ universal_newlines=True)
153 self.assertEqual(output, "hello world\n")
154
155 def test_maint(self):
156- output = subprocess.check_output([
157- self.click_binary, "chroot", "-a", self.arch,
158- "maint", "id"], universal_newlines=True)
159+ output = subprocess.check_output(
160+ self.command(self.arch, "maint", "id"),
161+ universal_newlines=True)
162 self.assertEqual(output, "uid=0(root) gid=0(root) groups=0(root)\n")
163
164 def test_exists_ok(self):
165- subprocess.check_call([
166- self.click_binary, "chroot", "-a", self.arch, "exists"])
167+ subprocess.check_call(self.command(self.arch, "exists"))
168
169 def test_exists_no(self):
170 with self.assertRaises(subprocess.CalledProcessError):
171- subprocess.check_call([
172- self.click_binary,
173- "chroot", "-a", "arch-that-does-not-exist"])
174+ subprocess.check_call(self.command("arch-that-does-not-exist"))
175+
176+
177+class TestChrootName(TestChroot):
178+ """Run the chroot tests again with a different --name."""
179+
180+ @classmethod
181+ def command(cls, arch, *args):
182+ return super(TestChrootName, cls).command(
183+ arch, "-n", "testname", *args)
184+
185+ def test_exists_different_name_fails(self):
186+ # "click chroot exists" fails for a non-existent name.
187+ with self.assertRaises(subprocess.CalledProcessError):
188+ subprocess.check_call(super(TestChrootName, self).command(
189+ self.arch, "-n", "testname2", "exists"))
190
191=== modified file 'debian/changelog'
192--- debian/changelog 2014-09-19 10:46:15 +0000
193+++ debian/changelog 2014-09-26 17:27:16 +0000
194@@ -11,6 +11,8 @@
195 @gcinuse registration which never really worked properly.
196 * Run garbage-collection immediately before running system hooks on system
197 startup (LP: #1342858).
198+ * Add new -n/--name option to "click chroot", defaulting to "click"
199+ (LP: #1364327).
200
201 -- Colin Watson <cjwatson@ubuntu.com> Wed, 10 Sep 2014 12:47:46 +0100
202

Subscribers

People subscribed via source and target branches

to all changes: