Merge lp:~lool/linaro-image-tools/testsuite-when-installed into lp:linaro-image-tools/11.11
- testsuite-when-installed
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 284 |
Proposed branch: | lp:~lool/linaro-image-tools/testsuite-when-installed |
Merge into: | lp:linaro-image-tools/11.11 |
Prerequisite: | lp:~lool/linaro-image-tools/optional-sudo |
Diff against target: |
228 lines (+104/-13) (has conflicts) 4 files modified
linaro-media-create (+22/-1) linaro_media_create/hwpack.py (+11/-9) linaro_media_create/tests/test_media_create.py (+39/-3) linaro_media_create/utils.py (+32/-0) Text conflict in linaro-media-create |
To merge this branch: | bzr merge lp:~lool/linaro-image-tools/testsuite-when-installed |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Westby (community) | Approve | ||
Review via email: mp+48193@code.launchpad.net |
This proposal supersedes a proposal from 2011-02-01.
Commit message
Description of the change
Loïc Minier (lool) wrote : | # |
(Thanks for adding the dep on the sudo branch; I failed to push the sudo branch after merging it locally -- it's merged in trunk now)
The isbas(__file__) test is just a test for whether or not we're running from bzr.
Note that __file__ is the possibly relative pathname of the current module, so of hwpack.py or utils.py.
The assumptions are:
* if you're running from a checkout, __file__ is relative, you're in the top directory and commands are in the current directory
* if you're not running from a checkout, __file__ is absolute, commands are in the PATH
Loïc Minier (lool) wrote : | # |
Followup IRC chat:
15:09 < james_w> lool, We have to be very careful to use a matching
15:10 < james_w> lool, so when looking for that command, I think we should
15:10 < james_w> I think your change will approximate that in most cases, but
15:11 < lool> james_w: So you're saying, additionally to all things I've
where linaro-media-create is, then fallback to PATH?
15:13 < james_w> lool, that's what I think
15:13 < lool> james_w: It makes sense
15:14 < lool> james_w: albeit I can think that if you have multiple
don't point at the same versions in the same order
15:14 < james_w> lool, indeed
15:15 < lool> james_w: Do you still want this covered? We could do it either
by passing directories across calls, or by prepending PATH
15:15 < lool> But prepending PATH might have side effects when looking for
other commands
15:16 < james_w> lool, right, I imagine it should just be for
Loïc Minier (lool) wrote : | # |
Ok; I pushed up to r280 to implement support for preferring the dir with which linaro-media-create is run; it was a bit more intrusive than I wished for
- 278. By Loïc Minier
-
Add an optional prefer_dir arg to find_command to allow searching a specific
directory first. - 279. By Loïc Minier
-
Pass a tools dir (preferred directory) to install_hwpacks; should be the
directory of linaro-media-create when it's run with an explicit directory, or
"." when running from a bzr checkout. - 280. By Loïc Minier
-
More explicit handling of empty PATH components as "." in find_command.
Loïc Minier (lool) wrote : | # |
I tried supporting hwpack.tests as well, and had to add r281 for this; with r281 and this diff:
=== modified file 'hwpack/
--- hwpack/
+++ hwpack/
@@ -31,6 +31,7 @@
IsHardware
TestCaseWi
)
+from linaro_
class ScriptTests(
@@ -38,26 +39,16 @@
def setUp(self):
- self.script_path = self.find_script()
+
+ prefer_dir = None
+ # running from bzr checkout?
+ if not os.path.
+ prefer_dir = os.getcwd()
+
+ self.script_path = find_command(
+ 'linaro-
- def find_script(self):
- script_name = "linaro-
- this_path = os.path.
- parent_path = this_path
- for i in range(3):
- parent_path = os.path.
- possible_paths = [
- os.path.
- os.path.join("usr", "local", "bin", script_name),
- os.path.join("usr", "bin", script_name),
- ]
- for script_path in possible_paths:
- if os.path.
- return script_path
- raise AssertionError(
- "Could not find linaro-
-
def run_script(self, args, expected_
cmdline = [self.script_path] + args
proc = subprocess.Popen(
all tests pass from a bzr checkout and when installed.
- 281. By Loïc Minier
-
Default to os.getcwd() instead of "." as "." breaks with some
ChdirToTempdirFixture based tests.
James Westby (james-w) wrote : | # |
Looks good, aside from the merge conflicts.
Thanks,
James
Preview Diff
1 | === modified file 'linaro-media-create' | |||
2 | --- linaro-media-create 2011-02-02 12:08:05 +0000 | |||
3 | +++ linaro-media-create 2011-02-02 16:43:03 +0000 | |||
4 | @@ -62,6 +62,7 @@ | |||
5 | 62 | Before doing so, make sure BOOT_DISK and ROOT_DISK are not mounted. | 62 | Before doing so, make sure BOOT_DISK and ROOT_DISK are not mounted. |
6 | 63 | """ | 63 | """ |
7 | 64 | devnull = open('/dev/null', 'w') | 64 | devnull = open('/dev/null', 'w') |
8 | 65 | <<<<<<< TREE | ||
9 | 65 | # ignore non-zero return codes | 66 | # ignore non-zero return codes |
10 | 66 | for disk in BOOT_DISK, ROOT_DISK: | 67 | for disk in BOOT_DISK, ROOT_DISK: |
11 | 67 | if disk is not None: | 68 | if disk is not None: |
12 | @@ -70,10 +71,26 @@ | |||
13 | 70 | stdout=devnull, stderr=devnull, as_root=True).wait() | 71 | stdout=devnull, stderr=devnull, as_root=True).wait() |
14 | 71 | except cmd_runner.SubcommandNonZeroReturnValue: | 72 | except cmd_runner.SubcommandNonZeroReturnValue: |
15 | 72 | pass | 73 | pass |
16 | 74 | ======= | ||
17 | 75 | # ignore non-zero return codes | ||
18 | 76 | try: | ||
19 | 77 | if BOOT_DISK is not None: | ||
20 | 78 | cmd_runner.Popen(['umount', BOOT_DISK], | ||
21 | 79 | stdout=devnull, stderr=devnull, as_root=True).wait() | ||
22 | 80 | if ROOT_DISK is not None: | ||
23 | 81 | cmd_runner.Popen(['umount', ROOT_DISK], | ||
24 | 82 | stdout=devnull, stderr=devnull, as_root=True).wait() | ||
25 | 83 | except SubcommandNonZeroReturnValue: | ||
26 | 84 | pass | ||
27 | 85 | >>>>>>> MERGE-SOURCE | ||
28 | 73 | # Remove TMP_DIR as root because some files written there are | 86 | # Remove TMP_DIR as root because some files written there are |
29 | 74 | # owned by root. | 87 | # owned by root. |
30 | 75 | if TMP_DIR is not None: | 88 | if TMP_DIR is not None: |
31 | 89 | <<<<<<< TREE | ||
32 | 76 | cmd_runner.run(['rm', '-rf', TMP_DIR], as_root=True).wait() | 90 | cmd_runner.run(['rm', '-rf', TMP_DIR], as_root=True).wait() |
33 | 91 | ======= | ||
34 | 92 | cmd_runner.Popen(['rm', '-rf', TMP_DIR], as_root=True).wait() | ||
35 | 93 | >>>>>>> MERGE-SOURCE | ||
36 | 77 | 94 | ||
37 | 78 | 95 | ||
38 | 79 | def ensure_required_commands(args): | 96 | def ensure_required_commands(args): |
39 | @@ -121,7 +138,11 @@ | |||
40 | 121 | unpack_binary_tarball(args.binary, TMP_DIR) | 138 | unpack_binary_tarball(args.binary, TMP_DIR) |
41 | 122 | 139 | ||
42 | 123 | hwpacks = args.hwpacks | 140 | hwpacks = args.hwpacks |
44 | 124 | install_hwpacks(ROOTFS_DIR, TMP_DIR, args.hwpack_force_yes, *hwpacks) | 141 | lmc_dir = os.path.dirname(__file__) |
45 | 142 | if lmc_dir == '': | ||
46 | 143 | lmc_dir = None | ||
47 | 144 | install_hwpacks( | ||
48 | 145 | ROOTFS_DIR, TMP_DIR, lmc_dir, args.hwpack_force_yes, *hwpacks) | ||
49 | 125 | 146 | ||
50 | 126 | boot_partition, root_partition = setup_partitions( | 147 | boot_partition, root_partition = setup_partitions( |
51 | 127 | board_config, media, args.image_size, args.boot_label, args.rfs_label, | 148 | board_config, media, args.image_size, args.boot_label, args.rfs_label, |
52 | 128 | 149 | ||
53 | === modified file 'linaro_media_create/hwpack.py' | |||
54 | --- linaro_media_create/hwpack.py 2011-02-01 17:07:04 +0000 | |||
55 | +++ linaro_media_create/hwpack.py 2011-02-02 16:43:03 +0000 | |||
56 | @@ -21,7 +21,10 @@ | |||
57 | 21 | import sys | 21 | import sys |
58 | 22 | 22 | ||
59 | 23 | from linaro_media_create import cmd_runner | 23 | from linaro_media_create import cmd_runner |
61 | 24 | from linaro_media_create.utils import is_arm_host | 24 | from linaro_media_create.utils import ( |
62 | 25 | is_arm_host, | ||
63 | 26 | find_command, | ||
64 | 27 | ) | ||
65 | 25 | 28 | ||
66 | 26 | 29 | ||
67 | 27 | # It'd be nice if we could use atexit here, but all the things we need to undo | 30 | # It'd be nice if we could use atexit here, but all the things we need to undo |
68 | @@ -29,7 +32,8 @@ | |||
69 | 29 | # functions would only be called after l-m-c.py exits. | 32 | # functions would only be called after l-m-c.py exits. |
70 | 30 | local_atexit = [] | 33 | local_atexit = [] |
71 | 31 | 34 | ||
73 | 32 | def install_hwpacks(chroot_dir, tmp_dir, hwpack_force_yes, *hwpack_files): | 35 | def install_hwpacks( |
74 | 36 | chroot_dir, tmp_dir, tools_dir, hwpack_force_yes, *hwpack_files): | ||
75 | 33 | """Install the given hwpacks onto the given chroot.""" | 37 | """Install the given hwpacks onto the given chroot.""" |
76 | 34 | 38 | ||
77 | 35 | chroot_etc = os.path.join(chroot_dir, 'etc') | 39 | chroot_etc = os.path.join(chroot_dir, 'etc') |
78 | @@ -40,13 +44,11 @@ | |||
79 | 40 | copy_file('/usr/bin/qemu-arm-static', | 44 | copy_file('/usr/bin/qemu-arm-static', |
80 | 41 | os.path.join(chroot_dir, 'usr', 'bin')) | 45 | os.path.join(chroot_dir, 'usr', 'bin')) |
81 | 42 | 46 | ||
89 | 43 | # FIXME: This is an ugly hack to make sure we use the l-h-i script from | 47 | linaro_hwpack_install_path = find_command( |
90 | 44 | # the current development tree when possible. | 48 | 'linaro-hwpack-install', prefer_dir=tools_dir) |
91 | 45 | here = os.path.dirname(__file__) | 49 | # FIXME: shouldn't use chroot/usr/bin as this might conflict with installed |
92 | 46 | linaro_hwpack_install_path = os.path.join( | 50 | # packages; would be best to use some custom directory like |
93 | 47 | here, '..', 'linaro-hwpack-install') | 51 | # chroot/linaro-image-tools/bin |
87 | 48 | if not os.path.exists(linaro_hwpack_install_path): | ||
88 | 49 | linaro_hwpack_install_path = '/usr/bin/linaro-hwpack-install' | ||
94 | 50 | copy_file(linaro_hwpack_install_path, | 52 | copy_file(linaro_hwpack_install_path, |
95 | 51 | os.path.join(chroot_dir, 'usr', 'bin')) | 53 | os.path.join(chroot_dir, 'usr', 'bin')) |
96 | 52 | 54 | ||
97 | 53 | 55 | ||
98 | === modified file 'linaro_media_create/tests/test_media_create.py' | |||
99 | --- linaro_media_create/tests/test_media_create.py 2011-02-01 17:29:25 +0000 | |||
100 | +++ linaro_media_create/tests/test_media_create.py 2011-02-02 16:43:03 +0000 | |||
101 | @@ -21,6 +21,7 @@ | |||
102 | 21 | import glob | 21 | import glob |
103 | 22 | import os | 22 | import os |
104 | 23 | import random | 23 | import random |
105 | 24 | import stat | ||
106 | 24 | import string | 25 | import string |
107 | 25 | import subprocess | 26 | import subprocess |
108 | 26 | import sys | 27 | import sys |
109 | @@ -82,6 +83,7 @@ | |||
110 | 82 | from linaro_media_create.unpack_binary_tarball import unpack_binary_tarball | 83 | from linaro_media_create.unpack_binary_tarball import unpack_binary_tarball |
111 | 83 | from linaro_media_create.utils import ( | 84 | from linaro_media_create.utils import ( |
112 | 84 | ensure_command, | 85 | ensure_command, |
113 | 86 | find_command, | ||
114 | 85 | install_package_providing, | 87 | install_package_providing, |
115 | 86 | UnableToFindPackageProvidingCommand, | 88 | UnableToFindPackageProvidingCommand, |
116 | 87 | ) | 89 | ) |
117 | @@ -121,6 +123,32 @@ | |||
118 | 121 | utils, 'install_package_providing', mock_func)) | 123 | utils, 'install_package_providing', mock_func)) |
119 | 122 | 124 | ||
120 | 123 | 125 | ||
121 | 126 | class TestFindCommand(TestCaseWithFixtures): | ||
122 | 127 | |||
123 | 128 | def test_preferred_dir(self): | ||
124 | 129 | tempdir = self.useFixture(CreateTempDirFixture()).get_temp_dir() | ||
125 | 130 | lmc = 'linaro-media-create' | ||
126 | 131 | path = os.path.join(tempdir, lmc) | ||
127 | 132 | open(path, 'w').close() | ||
128 | 133 | os.chmod(path, stat.S_IXUSR) | ||
129 | 134 | self.assertEquals(path, find_command(lmc, tempdir)) | ||
130 | 135 | |||
131 | 136 | def test_existing_command(self): | ||
132 | 137 | lmc = 'linaro-media-create' | ||
133 | 138 | # running from bzr checkout? | ||
134 | 139 | if os.path.isabs(__file__): | ||
135 | 140 | expected, _ = cmd_runner.run( | ||
136 | 141 | ['which', lmc, ], | ||
137 | 142 | stdout=subprocess.PIPE).communicate() | ||
138 | 143 | expected = expected.strip() | ||
139 | 144 | else: | ||
140 | 145 | expected = os.path.join(os.getcwd(), lmc) | ||
141 | 146 | self.assertEquals(expected, find_command(lmc)) | ||
142 | 147 | |||
143 | 148 | def test_nonexisting_command(self): | ||
144 | 149 | self.assertEquals(find_command('linaro-moo'), None) | ||
145 | 150 | |||
146 | 151 | |||
147 | 124 | class TestInstallPackageProviding(TestCaseWithFixtures): | 152 | class TestInstallPackageProviding(TestCaseWithFixtures): |
148 | 125 | 153 | ||
149 | 126 | def test_found_package(self): | 154 | def test_found_package(self): |
150 | @@ -1083,8 +1111,17 @@ | |||
151 | 1083 | sys, 'stdout', open('/dev/null', 'w'))) | 1111 | sys, 'stdout', open('/dev/null', 'w'))) |
152 | 1084 | fixture = self.useFixture(MockCmdRunnerPopenFixture()) | 1112 | fixture = self.useFixture(MockCmdRunnerPopenFixture()) |
153 | 1085 | force_yes = True | 1113 | force_yes = True |
154 | 1114 | |||
155 | 1115 | prefer_dir = None | ||
156 | 1116 | # running from bzr checkout? | ||
157 | 1117 | if not os.path.isabs(__file__): | ||
158 | 1118 | prefer_dir = os.getcwd() | ||
159 | 1119 | |||
160 | 1086 | install_hwpacks( | 1120 | install_hwpacks( |
162 | 1087 | 'chroot', '/tmp/dir', force_yes, 'hwpack1.tgz', 'hwpack2.tgz') | 1121 | 'chroot', '/tmp/dir', prefer_dir, force_yes, 'hwpack1.tgz', |
163 | 1122 | 'hwpack2.tgz') | ||
164 | 1123 | linaro_hwpack_install = find_command( | ||
165 | 1124 | 'linaro-hwpack-install', prefer_dir=prefer_dir) | ||
166 | 1088 | self.assertEquals( | 1125 | self.assertEquals( |
167 | 1089 | [['sudo', 'mv', '-f', 'chroot/etc/resolv.conf', | 1126 | [['sudo', 'mv', '-f', 'chroot/etc/resolv.conf', |
168 | 1090 | '/tmp/dir/resolv.conf'], | 1127 | '/tmp/dir/resolv.conf'], |
169 | @@ -1092,8 +1129,7 @@ | |||
170 | 1092 | ['sudo', 'mv', '-f', 'chroot/etc/hosts', '/tmp/dir/hosts'], | 1129 | ['sudo', 'mv', '-f', 'chroot/etc/hosts', '/tmp/dir/hosts'], |
171 | 1093 | ['sudo', 'cp', '/etc/hosts', 'chroot/etc'], | 1130 | ['sudo', 'cp', '/etc/hosts', 'chroot/etc'], |
172 | 1094 | ['sudo', 'cp', '/usr/bin/qemu-arm-static', 'chroot/usr/bin'], | 1131 | ['sudo', 'cp', '/usr/bin/qemu-arm-static', 'chroot/usr/bin'], |
175 | 1095 | ['sudo', 'cp', 'linaro_media_create/../linaro-hwpack-install', | 1132 | ['sudo', 'cp', linaro_hwpack_install, 'chroot/usr/bin'], |
174 | 1096 | 'chroot/usr/bin'], | ||
176 | 1097 | ['sudo', 'mount', 'proc', 'chroot/proc', '-t', 'proc'], | 1133 | ['sudo', 'mount', 'proc', 'chroot/proc', '-t', 'proc'], |
177 | 1098 | ['sudo', 'cp', 'hwpack1.tgz', 'chroot'], | 1134 | ['sudo', 'cp', 'hwpack1.tgz', 'chroot'], |
178 | 1099 | ['sudo', 'chroot', 'chroot', 'linaro-hwpack-install', | 1135 | ['sudo', 'chroot', 'chroot', 'linaro-hwpack-install', |
179 | 1100 | 1136 | ||
180 | === modified file 'linaro_media_create/utils.py' | |||
181 | --- linaro_media_create/utils.py 2011-01-28 19:50:48 +0000 | |||
182 | +++ linaro_media_create/utils.py 2011-02-02 16:43:03 +0000 | |||
183 | @@ -17,6 +17,7 @@ | |||
184 | 17 | # You should have received a copy of the GNU General Public License | 17 | # You should have received a copy of the GNU General Public License |
185 | 18 | # along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>. | 18 | # along with Linaro Image Tools. If not, see <http://www.gnu.org/licenses/>. |
186 | 19 | 19 | ||
187 | 20 | import os | ||
188 | 20 | import platform | 21 | import platform |
189 | 21 | 22 | ||
190 | 22 | try: | 23 | try: |
191 | @@ -61,6 +62,37 @@ | |||
192 | 61 | except cmd_runner.SubcommandNonZeroReturnValue: | 62 | except cmd_runner.SubcommandNonZeroReturnValue: |
193 | 62 | install_package_providing(command) | 63 | install_package_providing(command) |
194 | 63 | 64 | ||
195 | 65 | def find_command(name, prefer_dir=None): | ||
196 | 66 | """Finds a linaro-image-tools command. | ||
197 | 67 | |||
198 | 68 | Prefers specified directory, otherwise searches only the current directory | ||
199 | 69 | when running from a checkout, or only PATH when running from an installed | ||
200 | 70 | version. | ||
201 | 71 | """ | ||
202 | 72 | assert name != "" | ||
203 | 73 | assert os.path.dirname(name) == "" | ||
204 | 74 | |||
205 | 75 | if not os.environ.has_key("PATH"): | ||
206 | 76 | os.environ["PATH"] = ":/bin:usr/bin" | ||
207 | 77 | |||
208 | 78 | # default to searching in current directory when running from a bzr | ||
209 | 79 | # checkout | ||
210 | 80 | dirs = [os.getcwd(),] | ||
211 | 81 | if os.path.isabs(__file__): | ||
212 | 82 | dirs = os.environ["PATH"].split(os.pathsep) | ||
213 | 83 | # empty dir in PATH means current directory | ||
214 | 84 | dirs = map(lambda x: x == '' and '.' or x, dirs) | ||
215 | 85 | |||
216 | 86 | if prefer_dir is not None: | ||
217 | 87 | dirs.insert(0, prefer_dir) | ||
218 | 88 | |||
219 | 89 | for dir in dirs: | ||
220 | 90 | path = os.path.join(dir, name) | ||
221 | 91 | if os.path.exists(path) and os.access(path, os.X_OK): | ||
222 | 92 | return path | ||
223 | 93 | |||
224 | 94 | return None | ||
225 | 95 | |||
226 | 64 | 96 | ||
227 | 65 | def is_arm_host(): | 97 | def is_arm_host(): |
228 | 66 | return platform.machine().startswith('arm') | 98 | return platform.machine().startswith('arm') |
I'm not sure that the
116 + if os.path. isabs(_ _file__ ):
check is really what we want.
I think that if there is a linaro- hwpack- install alongside the linaro- media-create,
then we should always use it, regardless of $PATH, or how it is being executed.
That's probably not true of all commands though.
It's probably worth looking back over the discussion around using the correct hwpack- install from when the code to use one in the current dir was
linaro-
added.
Thanks,
James