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

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
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
Michael Vogt Approve
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.
Revision history for this message
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
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~cjwatson/click/chroot-name updated
524. By Colin Watson

Add docstring for TestChrootName.

525. By Colin Watson

Clarify test_exists_different_name.

Revision history for this message
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
=== modified file 'click/commands/chroot.py'
--- click/commands/chroot.py 2014-07-01 07:12:49 +0000
+++ click/commands/chroot.py 2014-09-26 17:27:16 +0000
@@ -61,7 +61,8 @@
61 "debootstrap not installed and configured; install click-dev and "61 "debootstrap not installed and configured; install click-dev and "
62 "debootstrap")62 "debootstrap")
63 requires_root(parser)63 requires_root(parser)
64 chroot = ClickChroot(args.architecture, args.framework, series=args.series)64 chroot = ClickChroot(
65 args.architecture, args.framework, name=args.name, series=args.series)
65 with message_on_error(66 with message_on_error(
66 ClickChrootAlreadyExistsException, ErrorMessages.EXISTS):67 ClickChrootAlreadyExistsException, ErrorMessages.EXISTS):
67 return chroot.create(args.keep_broken_chroot)68 return chroot.create(args.keep_broken_chroot)
@@ -71,7 +72,7 @@
7172
72def install(parser, args):73def install(parser, args):
73 packages = args.packages74 packages = args.packages
74 chroot = ClickChroot(args.architecture, args.framework)75 chroot = ClickChroot(args.architecture, args.framework, name=args.name)
75 with message_on_error(76 with message_on_error(
76 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):77 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
77 return chroot.install(*packages)78 return chroot.install(*packages)
@@ -82,7 +83,7 @@
82def destroy(parser, args):83def destroy(parser, args):
83 requires_root(parser)84 requires_root(parser)
84 # ask for confirmation?85 # ask for confirmation?
85 chroot = ClickChroot(args.architecture, args.framework)86 chroot = ClickChroot(args.architecture, args.framework, name=args.name)
86 with message_on_error(87 with message_on_error(
87 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):88 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
88 return chroot.destroy()89 return chroot.destroy()
@@ -95,7 +96,8 @@
95 if not program:96 if not program:
96 program = ["/bin/bash"]97 program = ["/bin/bash"]
97 chroot = ClickChroot(98 chroot = ClickChroot(
98 args.architecture, args.framework, session=args.session)99 args.architecture, args.framework, name=args.name,
100 session=args.session)
99 with message_on_error(101 with message_on_error(
100 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):102 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
101 return chroot.run(*program)103 return chroot.run(*program)
@@ -108,7 +110,8 @@
108 if not program:110 if not program:
109 program = ["/bin/bash"]111 program = ["/bin/bash"]
110 chroot = ClickChroot(112 chroot = ClickChroot(
111 args.architecture, args.framework, session=args.session)113 args.architecture, args.framework, name=args.name,
114 session=args.session)
112 with message_on_error(115 with message_on_error(
113 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):116 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
114 return chroot.maint(*program)117 return chroot.maint(*program)
@@ -117,7 +120,7 @@
117120
118121
119def upgrade(parser, args):122def upgrade(parser, args):
120 chroot = ClickChroot(args.architecture, args.framework)123 chroot = ClickChroot(args.architecture, args.framework, name=args.name)
121 with message_on_error(124 with message_on_error(
122 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):125 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
123 return chroot.upgrade()126 return chroot.upgrade()
@@ -127,7 +130,8 @@
127130
128def begin_session(parser, args):131def begin_session(parser, args):
129 chroot = ClickChroot(132 chroot = ClickChroot(
130 args.architecture, args.framework, session=args.session)133 args.architecture, args.framework, name=args.name,
134 session=args.session)
131 with message_on_error(135 with message_on_error(
132 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):136 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
133 return chroot.begin_session()137 return chroot.begin_session()
@@ -137,7 +141,8 @@
137141
138def end_session(parser, args):142def end_session(parser, args):
139 chroot = ClickChroot(143 chroot = ClickChroot(
140 args.architecture, args.framework, session=args.session)144 args.architecture, args.framework, name=args.name,
145 session=args.session)
141 with message_on_error(146 with message_on_error(
142 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):147 ClickChrootDoesNotExistException, ErrorMessages.NOT_EXISTS):
143 return chroot.end_session()148 return chroot.end_session()
@@ -146,7 +151,7 @@
146151
147152
148def exists(parser, args):153def exists(parser, args):
149 chroot = ClickChroot(args.architecture, args.framework)154 chroot = ClickChroot(args.architecture, args.framework, name=args.name)
150 # return shell exit codes 0 on success, 1 on failure155 # return shell exit codes 0 on success, 1 on failure
151 if chroot.exists():156 if chroot.exists():
152 return 0157 return 0
@@ -169,6 +174,11 @@
169 "-s", "--series",174 "-s", "--series",
170 help="series to use for a newly-created chroot (defaults to a series "175 help="series to use for a newly-created chroot (defaults to a series "
171 "appropriate for the framework)")176 "appropriate for the framework)")
177 parser.add_argument(
178 "-n", "--name", default="click",
179 help=(
180 "name of the chroot (default: click; the framework and "
181 "architecture will be appended)"))
172 create_parser = subparsers.add_parser(182 create_parser = subparsers.add_parser(
173 "create",183 "create",
174 help="create a chroot of the provided architecture")184 help="create a chroot of the provided architecture")
175185
=== modified file 'click/tests/integration/test_chroot.py'
--- click/tests/integration/test_chroot.py 2014-09-05 09:04:33 +0000
+++ click/tests/integration/test_chroot.py 2014-09-26 17:27:16 +0000
@@ -27,52 +27,58 @@
27class TestChroot(ClickTestCase):27class TestChroot(ClickTestCase):
2828
29 @classmethod29 @classmethod
30 def command(cls, arch, *args):
31 return [cls.click_binary, "chroot", "-a", arch] + list(args)
32
33 @classmethod
30 def setUpClass(cls):34 def setUpClass(cls):
31 super(TestChroot, cls).setUpClass()35 super(TestChroot, cls).setUpClass()
32 require_root()36 require_root()
33 require_network()37 require_network()
34 cls.arch = subprocess.check_output(38 cls.arch = subprocess.check_output(
35 ["dpkg", "--print-architecture"], universal_newlines=True).strip()39 ["dpkg", "--print-architecture"], universal_newlines=True).strip()
36 subprocess.check_call([40 subprocess.check_call(cls.command(cls.arch, "create"))
37 cls.click_binary,
38 "chroot", "-a", cls.arch,
39 "create"])
4041
41 @classmethod42 @classmethod
42 def tearDownClass(cls):43 def tearDownClass(cls):
43 subprocess.check_call([44 subprocess.check_call(cls.command(cls.arch, "destroy"))
44 cls.click_binary,
45 "chroot", "-a", cls.arch,
46 "destroy"])
4745
48 def test_upgrade(self):46 def test_upgrade(self):
49 subprocess.check_call([47 subprocess.check_call(self.command(self.arch, "upgrade"))
50 self.click_binary, "chroot", "-a", self.arch,
51 "upgrade"])
5248
53 def test_install(self):49 def test_install(self):
54 subprocess.check_call([50 subprocess.check_call(self.command(self.arch, "install", "apt-utils"))
55 self.click_binary, "chroot", "-a", self.arch,
56 "install", "apt-utils"])
5751
58 def test_run(self):52 def test_run(self):
59 output = subprocess.check_output([53 output = subprocess.check_output(
60 self.click_binary, "chroot", "-a", self.arch,54 self.command(self.arch, "run", "echo", "hello world"),
61 "run", "echo", "hello world"], universal_newlines=True)55 universal_newlines=True)
62 self.assertEqual(output, "hello world\n")56 self.assertEqual(output, "hello world\n")
6357
64 def test_maint(self):58 def test_maint(self):
65 output = subprocess.check_output([59 output = subprocess.check_output(
66 self.click_binary, "chroot", "-a", self.arch,60 self.command(self.arch, "maint", "id"),
67 "maint", "id"], universal_newlines=True)61 universal_newlines=True)
68 self.assertEqual(output, "uid=0(root) gid=0(root) groups=0(root)\n")62 self.assertEqual(output, "uid=0(root) gid=0(root) groups=0(root)\n")
6963
70 def test_exists_ok(self):64 def test_exists_ok(self):
71 subprocess.check_call([65 subprocess.check_call(self.command(self.arch, "exists"))
72 self.click_binary, "chroot", "-a", self.arch, "exists"])
7366
74 def test_exists_no(self):67 def test_exists_no(self):
75 with self.assertRaises(subprocess.CalledProcessError):68 with self.assertRaises(subprocess.CalledProcessError):
76 subprocess.check_call([69 subprocess.check_call(self.command("arch-that-does-not-exist"))
77 self.click_binary,70
78 "chroot", "-a", "arch-that-does-not-exist"])71
72class TestChrootName(TestChroot):
73 """Run the chroot tests again with a different --name."""
74
75 @classmethod
76 def command(cls, arch, *args):
77 return super(TestChrootName, cls).command(
78 arch, "-n", "testname", *args)
79
80 def test_exists_different_name_fails(self):
81 # "click chroot exists" fails for a non-existent name.
82 with self.assertRaises(subprocess.CalledProcessError):
83 subprocess.check_call(super(TestChrootName, self).command(
84 self.arch, "-n", "testname2", "exists"))
7985
=== modified file 'debian/changelog'
--- debian/changelog 2014-09-19 10:46:15 +0000
+++ debian/changelog 2014-09-26 17:27:16 +0000
@@ -11,6 +11,8 @@
11 @gcinuse registration which never really worked properly.11 @gcinuse registration which never really worked properly.
12 * Run garbage-collection immediately before running system hooks on system12 * Run garbage-collection immediately before running system hooks on system
13 startup (LP: #1342858).13 startup (LP: #1342858).
14 * Add new -n/--name option to "click chroot", defaulting to "click"
15 (LP: #1364327).
1416
15 -- Colin Watson <cjwatson@ubuntu.com> Wed, 10 Sep 2014 12:47:46 +010017 -- Colin Watson <cjwatson@ubuntu.com> Wed, 10 Sep 2014 12:47:46 +0100
1618

Subscribers

People subscribed via source and target branches

to all changes: