Changeset 1695:5ead0b1ceb91
- Timestamp:
- 07/10/08 12:05:18 (2 months ago)
- Author:
- klai@…
- Branch:
- default
- Message:
-
Get better debugging from failed system commands
- Location:
- src/Tycoon/Virtualization
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r1663
|
r1695
|
|
| 153 | 153 | find_file = staticmethod(find_file) |
| 154 | 154 | |
| 155 | | def do(cmd, *args): |
| 156 | | """Run a command and get the return status. |
| 157 | | """ |
| 158 | | s = cmd + ' ' + ' '.join(args) |
| 159 | | INFO(s + ' started') |
| 160 | | d = utils.getProcessValue(cmd, args) |
| 161 | | yield d |
| 162 | | if type(d.result) != int: |
| 163 | | ERROR(s + " returned %s" % (d.result,)) |
| 164 | | yield False |
| 165 | | else: |
| 166 | | INFO(s + ' returned %d' % (d.result,)) |
| 167 | | yield True |
| 168 | | |
| 169 | | do = staticmethod(deferredGenerator(do)) |
| 170 | | |
| 171 | | def do2(reactor, cmd, *args): |
| | 155 | def do2(reactor, cmd, *args, **flags): |
| 172 | 156 | """Run a command and get return status, stdout, and stderr. |
| 173 | 157 | """ |
| … |
… |
|
| 178 | 162 | reactor.spawnProcess(protocol, cmd, (cmd,) + args) |
| 179 | 163 | yield d |
| 180 | | INFO(s + ' returned %d' % (d.result[0],)) |
| 181 | | #INFO(s + '"%s"' % (d.result[1],)) |
| 182 | | #INFO(s + '"%s"' % (d.result[2],)) |
| | 164 | if d.result[0] != 0 and not 'ignore_error' in flags: |
| | 165 | ERROR("%s failed with %s" % (cmd, d.result,)) |
| | 166 | else: |
| | 167 | INFO(s + ' succeeded with value %d' % (d.result[0])) |
| 183 | 168 | yield d.result |
| 184 | 169 | |
| … |
… |
|
| 222 | 207 | get_dir_size = staticmethod(deferredGenerator(get_dir_size)) |
| 223 | 208 | |
| 224 | | def grow_sparse_file_system(file_system, new_size, old_size): |
| | 209 | def grow_sparse_file_system(reactor, file_system, new_size, old_size): |
| 225 | 210 | # Write a single byte at the last seek position. |
| 226 | | d = OSUtil.do( |
| 227 | | '/bin/dd', 'if=/dev/zero', 'of=%s' % (file_system,), |
| | 211 | d = OSUtil.do2( |
| | 212 | reactor, '/bin/dd', 'if=/dev/zero', 'of=%s' % (file_system,), |
| 228 | 213 | 'seek=%d' % (new_size - 1,), 'bs=1', 'count=1') |
| 229 | 214 | return d |
| 230 | 215 | grow_sparse_file_system = staticmethod(grow_sparse_file_system) |
| 231 | 216 | |
| 232 | | def grow_dense_file_system(file_system, new_size, old_size): |
| | 217 | def grow_dense_file_system(reactor, file_system, new_size, old_size): |
| 233 | 218 | m = (new_size - old_size) / 1048576 |
| 234 | 219 | seek = old_size / 1048576 |
| 235 | | d = OSUtil.do( |
| 236 | | '/bin/dd', 'if=/dev/zero', 'of=%s' % (file_system,), |
| | 220 | d = OSUtil.do2( |
| | 221 | reactor, '/bin/dd', 'if=/dev/zero', 'of=%s' % (file_system,), |
| 237 | 222 | 'seek=%d' % (seek,), 'bs=1M', 'count=%d' % (m,)) |
| 238 | 223 | return d |
| 239 | 224 | grow_dense_file_system = staticmethod(grow_dense_file_system) |
| 240 | 225 | |
| 241 | | def resize_file_system(file_system, size): |
| | 226 | def resize_file_system(reactor, file_system, size): |
| 242 | 227 | """Resize a file system file. |
| 243 | 228 | """ |
| … |
… |
|
| 253 | 238 | if sparse: |
| 254 | 239 | d = OSUtil.grow_sparse_file_system( |
| 255 | | file_system, real_size, old_size) |
| | 240 | reactor, file_system, real_size, old_size) |
| 256 | 241 | else: |
| 257 | 242 | d = OSUtil.grow_dense_file_system( |
| 258 | | file_system, real_size, old_size) |
| | 243 | reactor, file_system, real_size, old_size) |
| 259 | 244 | yield d |
| 260 | | d = OSUtil.do('/sbin/e2fsck','-f', '-y', file_system) |
| | 245 | d = OSUtil.do2( |
| | 246 | reactor, '/sbin/e2fsck','-f', '-y', file_system, ignore_error=1) |
| 261 | 247 | yield d |
| 262 | | d = OSUtil.do('/sbin/resize2fs', file_system) |
| | 248 | d = OSUtil.do2(reactor, '/sbin/resize2fs', file_system) |
| 263 | 249 | yield d |
| 264 | 250 | elif real_size < old_size: |
| 265 | | d = OSUtil.do('/sbin/e2fsck','-f', '-y', file_system) |
| | 251 | d = OSUtil.do2( |
| | 252 | reactor, '/sbin/e2fsck','-f', '-y', file_system, ignore_error=1) |
| 266 | 253 | yield d |
| 267 | | d = OSUtil.do('/sbin/resize2fs', file_system, "%dM" % (m,)) |
| | 254 | d = OSUtil.do2( |
| | 255 | reactor, '/sbin/resize2fs', file_system, "%dM" % (m,)) |
| 268 | 256 | yield d |
| 269 | 257 | f = file(file_system, "a+") |
| … |
… |
|
| 280 | 268 | d = OSUtil.do2(reactor, s, root, '/usr/sbin/useradd', account_name) |
| 281 | 269 | yield d |
| 282 | | if d.result[0] != 0: |
| 283 | | ERROR(d.result) |
| 284 | 270 | d = OSUtil.do2(reactor, s, root, '/usr/bin/id', account_name) |
| 285 | 271 | #o = os.popen("%s %s id %s" % (s, root, account_name)).readline() |
| 286 | 272 | yield d |
| 287 | | if d.result[0] != 0: |
| 288 | | ERROR(d.result) |
| 289 | 273 | r = re.compile("uid=([0-9]+)\([a-z0-9_]+\) gid=([0-9]+)\([a-z0-9_]+\)") |
| 290 | 274 | m = r.match(d.result[1]) |
| … |
… |
|
| 416 | 400 | |
| 417 | 401 | quota = False |
| 418 | | d = OSUtil.do2(reactor, '/sbin/quotaon', '-p', root) |
| | 402 | d = OSUtil.do2(reactor, '/sbin/quotaon', '-p', root, ignore_error=1) |
| 419 | 403 | yield d |
| 420 | 404 | # Quotaon returns stderr on error instead a proper status code. |
-
|
r1688
|
r1695
|
|
| 288 | 288 | """ |
| 289 | 289 | """ |
| 290 | | d = OSUtil.resize_file_system(file_system_path, new_size) |
| | 290 | d = OSUtil.resize_file_system( |
| | 291 | self.__reactor, file_system_path, new_size) |
| 291 | 292 | yield d |
| 292 | 293 | account['file_system_size'] = d.result |
-
|
r1692
|
r1695
|
|
| 490 | 490 | "Requested file system size %d is too small for file system image size %d" % (file_system_size, size)) |
| 491 | 491 | |
| 492 | | d = OSUtil.resize_file_system(dest, file_system_size) |
| | 492 | d = OSUtil.resize_file_system(self.__reactor, dest, file_system_size) |
| 493 | 493 | yield d |
| 494 | 494 | yield dest, d.result |
| … |
… |
|
| 505 | 505 | else: |
| 506 | 506 | os.mkdir(mount_dir) |
| 507 | | |
| | 507 | |
| 508 | 508 | d = OSUtil.do2( |
| 509 | 509 | self.__reactor, "/bin/mount", "-o", "loop", file_system_fn, |
| … |
… |
|
| 511 | 511 | yield d |
| 512 | 512 | if d.result[0] != 0: |
| 513 | | INFO("/bin/mount failed with value %d" % (d.result,)) |
| 514 | 513 | yield False |
| 515 | 514 | else: |