OLD | NEW |
---|---|
1 import os, shutil, copy, pickle, re, glob, time, logging | 1 import os, shutil, copy, pickle, re, glob, time, logging |
2 from autotest_lib.client.bin import kernel_config, os_dep, kernelexpand, test | 2 from autotest_lib.client.bin import kernel_config, os_dep, kernelexpand, test |
3 from autotest_lib.client.bin import utils | 3 from autotest_lib.client.bin import utils |
4 from autotest_lib.client.common_lib import log, error, packages | 4 from autotest_lib.client.common_lib import log, error, packages |
5 | 5 |
6 | 6 |
7 def tee_output_logdir_mark(fn): | 7 def tee_output_logdir_mark(fn): |
8 def tee_logdir_mark_wrapper(self, *args, **dargs): | 8 def tee_logdir_mark_wrapper(self, *args, **dargs): |
9 mark = self.__class__.__name__ + "." + fn.__name__ | 9 mark = self.__class__.__name__ + "." + fn.__name__ |
10 logging.info("--- START %s ---", mark) | 10 logging.info("--- START %s ---", mark) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
52 for arg in args.split(): | 52 for arg in args.split(): |
53 if arg.startswith(root_prefix): | 53 if arg.startswith(root_prefix): |
54 # set the current root value with the one from the argument | 54 # set the current root value with the one from the argument |
55 # thus after processing all the arguments we keep the last | 55 # thus after processing all the arguments we keep the last |
56 # root value (so root= options from args overrides any from | 56 # root value (so root= options from args overrides any from |
57 # base_args) | 57 # base_args) |
58 root = arg[len(root_prefix):] | 58 root = arg[len(root_prefix):] |
59 else: | 59 else: |
60 arglist.append(arg) | 60 arglist.append(arg) |
61 | 61 |
62 # add the kernel entry | 62 # Add the kernel entry. it will keep all arguments from the default entry. |
63 bootloader.add_kernel(image, tag, initrd=initrd, args=' '.join(arglist), | 63 # args='_dummy_' is used to workaround a boottool limitation of not being |
64 root=root) | 64 # able to add arguments to a kernel that does not already have any of its |
65 # own by way of its own append= section below the image= line in lilo.conf. | |
66 bootloader.add_kernel(image, tag, initrd=initrd, root=root, args='_dummy_') | |
67 # Now, for each argument in arglist, try to add it to the kernel that was | |
68 # just added. In each step, if the arg already existed on the args string, | |
69 # that particular arg will be skipped | |
70 for a in arglist: | |
71 bootloader.add_args(kernel=tag, args=a) | |
72 bootloader.remove_args(kernel=tag, args='_dummy_') | |
65 | 73 |
66 | 74 |
67 class BootableKernel(object): | 75 class BootableKernel(object): |
68 | 76 |
69 def __init__(self, job): | 77 def __init__(self, job): |
70 self.job = job | 78 self.job = job |
71 self.installed_as = None # kernel choice in bootloader menu | 79 self.installed_as = None # kernel choice in bootloader menu |
72 self.image = None | 80 self.image = None |
73 self.initrd = '' | 81 self.initrd = '' |
74 | 82 |
75 | 83 |
76 def _boot_kernel(self, args, ident_check, expected_ident, subdir, notes): | 84 def _boot_kernel(self, args, ident_check, expected_ident, subdir, notes): |
77 """ | 85 """ |
78 Boot a kernel, with post-boot kernel id check | 86 Boot a kernel, with post-boot kernel id check |
79 | 87 |
80 @param args: kernel cmdline arguments | 88 @param args: kernel cmdline arguments |
81 @param ident_check: check kernel id after boot | 89 @param ident_check: check kernel id after boot |
82 @param expected_ident: | 90 @param expected_ident: |
83 @param subdir: job-step qualifier in status log | 91 @param subdir: job-step qualifier in status log |
84 @param notes: additional comment in status log | 92 @param notes: additional comment in status log |
85 """ | 93 """ |
86 | |
87 # If we can check the kernel identity do so. | 94 # If we can check the kernel identity do so. |
88 if ident_check: | 95 if ident_check: |
89 when = int(time.time()) | 96 when = int(time.time()) |
90 args += " IDENT=%d" % when | 97 args += " IDENT=%d" % when |
91 self.job.next_step_prepend(["job.end_reboot_and_verify", when, | 98 self.job.next_step_prepend(["job.end_reboot_and_verify", when, |
92 expected_ident, subdir, notes]) | 99 expected_ident, subdir, notes]) |
93 else: | 100 else: |
94 self.job.next_step_prepend(["job.end_reboot", subdir, | 101 self.job.next_step_prepend(["job.end_reboot", subdir, |
95 expected_ident, notes]) | 102 expected_ident, notes]) |
96 | 103 |
97 # Point bootloader to the selected tag. | 104 self.add_to_bootloader(args) |
98 _add_kernel_to_bootloader(self.job.bootloader, | |
99 self.job.config_get('boot.default_args'), | |
100 self.installed_as, args, self.image, | |
101 self.initrd) | |
102 | 105 |
103 # defer fsck for next reboot, to avoid reboots back to default kernel | 106 # defer fsck for next reboot, to avoid reboots back to default kernel |
104 utils.system('touch /fastboot') # this file is removed automatically | 107 utils.system('touch /fastboot') # this file is removed automatically |
105 | 108 |
106 # Boot it. | 109 # Boot it. |
107 self.job.start_reboot() | 110 self.job.start_reboot() |
108 self.job.reboot(tag=self.installed_as) | 111 self.job.reboot(tag=self.installed_as) |
109 | 112 |
110 | 113 |
114 def add_to_bootloader(self, args=''): | |
115 # Point bootloader to the selected tag. | |
116 _add_kernel_to_bootloader(self.job.bootloader, | |
117 self.job.config_get('boot.default_args'), | |
118 self.installed_as, args, self.image, | |
119 self.initrd) | |
120 | |
121 | |
111 class kernel(BootableKernel): | 122 class kernel(BootableKernel): |
112 """ Class for compiling kernels. | 123 """ Class for compiling kernels. |
113 | 124 |
114 Data for the object includes the src files | 125 Data for the object includes the src files |
115 used to create the kernel, patches applied, config (base + changes), | 126 used to create the kernel, patches applied, config (base + changes), |
116 the build directory itself, and logged output | 127 the build directory itself, and logged output |
117 | 128 |
118 Properties: | 129 Properties: |
119 job | 130 job |
120 Backpointer to the job object we're part of | 131 Backpointer to the job object we're part of |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 self.logfile.write(log) | 311 self.logfile.write(log) |
301 self.applied_patches.append(patch_id) | 312 self.applied_patches.append(patch_id) |
302 | 313 |
303 | 314 |
304 def get_kernel_tree(self, base_tree): | 315 def get_kernel_tree(self, base_tree): |
305 """Extract/link base_tree to self.build_dir""" | 316 """Extract/link base_tree to self.build_dir""" |
306 | 317 |
307 # if base_tree is a dir, assume uncompressed kernel | 318 # if base_tree is a dir, assume uncompressed kernel |
308 if os.path.isdir(base_tree): | 319 if os.path.isdir(base_tree): |
309 print 'Symlinking existing kernel source' | 320 print 'Symlinking existing kernel source' |
321 if os.path.islink(self.build_dir): | |
322 os.remove(self.build_dir) | |
310 os.symlink(base_tree, self.build_dir) | 323 os.symlink(base_tree, self.build_dir) |
311 | 324 |
312 # otherwise, extract tarball | 325 # otherwise, extract tarball |
313 else: | 326 else: |
314 os.chdir(os.path.dirname(self.src_dir)) | 327 os.chdir(os.path.dirname(self.src_dir)) |
315 # Figure out local destination for tarball | 328 # Figure out local destination for tarball |
316 tarball = os.path.join(self.src_dir, os.path.basename(base_tree.spli t(';')[0])) | 329 tarball = os.path.join(self.src_dir, os.path.basename(base_tree.spli t(';')[0])) |
317 utils.get_file(base_tree, tarball) | 330 utils.get_file(base_tree, tarball) |
318 print 'Extracting kernel tarball:', tarball, '...' | 331 print 'Extracting kernel tarball:', tarball, '...' |
319 utils.extract_tarball_to_dir(tarball, self.build_dir) | 332 utils.extract_tarball_to_dir(tarball, self.build_dir) |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 utils.force_copy(self.build_dir+'/System.map', | 378 utils.force_copy(self.build_dir+'/System.map', |
366 self.results_dir) | 379 self.results_dir) |
367 | 380 |
368 | 381 |
369 def build_timed(self, threads, timefile = '/dev/null', make_opts = '', | 382 def build_timed(self, threads, timefile = '/dev/null', make_opts = '', |
370 output = '/dev/null'): | 383 output = '/dev/null'): |
371 """time the bulding of the kernel""" | 384 """time the bulding of the kernel""" |
372 os.chdir(self.build_dir) | 385 os.chdir(self.build_dir) |
373 self.set_cross_cc() | 386 self.set_cross_cc() |
374 | 387 |
375 self.clean(logged=False) | 388 self.clean() |
376 build_string = "/usr/bin/time -o %s make %s -j %s vmlinux" \ | 389 build_string = "/usr/bin/time -o %s make %s -j %s vmlinux" \ |
377 % (timefile, make_opts, threads) | 390 % (timefile, make_opts, threads) |
378 build_string += ' > %s 2>&1' % output | 391 build_string += ' > %s 2>&1' % output |
379 print build_string | 392 print build_string |
380 utils.system(build_string) | 393 utils.system(build_string) |
381 | 394 |
382 if (not os.path.isfile('vmlinux')): | 395 if (not os.path.isfile('vmlinux')): |
383 errmsg = "no vmlinux found, kernel build failed" | 396 errmsg = "no vmlinux found, kernel build failed" |
384 raise error.TestError(errmsg) | 397 raise error.TestError(errmsg) |
385 | 398 |
(...skipping 27 matching lines...) Expand all Loading... | |
413 if os.path.isfile(initrd): | 426 if os.path.isfile(initrd): |
414 print "Existing %s file, will remove it." % initrd | 427 print "Existing %s file, will remove it." % initrd |
415 os.remove(initrd) | 428 os.remove(initrd) |
416 | 429 |
417 args = self.job.config_get('kernel.mkinitrd_extra_args') | 430 args = self.job.config_get('kernel.mkinitrd_extra_args') |
418 | 431 |
419 # don't leak 'None' into mkinitrd command | 432 # don't leak 'None' into mkinitrd command |
420 if not args: | 433 if not args: |
421 args = '' | 434 args = '' |
422 | 435 |
436 # It is important to match the version with a real directory inside | |
437 # /lib/modules | |
438 real_version_list = glob.glob('/lib/modules/%s*' % version) | |
439 rl = len(real_version_list) | |
440 if rl == 0: | |
441 logging.error("No directory %s found under /lib/modules. Initramfs" | |
442 "creation will most likely fail and your new kernel" | |
443 "will fail to build", version) | |
444 else: | |
445 if rl > 1: | |
446 logging.warning("Found more than one possible match for " | |
447 "kernel version %s under /lib/modules", version) | |
448 version = os.path.basename(real_version_list[0]) | |
449 | |
423 if vendor in ['Red Hat', 'Fedora Core']: | 450 if vendor in ['Red Hat', 'Fedora Core']: |
424 utils.system('mkinitrd %s %s %s' % (args, initrd, version)) | 451 try: |
452 cmd = os_dep.command('dracut') | |
453 full_cmd = '%s -f %s %s' % (cmd, initrd, version) | |
454 except ValueError: | |
455 cmd = os_dep.command('mkinitrd') | |
456 full_cmd = '%s %s %s %s' % (cmd, args, initrd, version) | |
457 utils.system(full_cmd) | |
425 elif vendor in ['SUSE']: | 458 elif vendor in ['SUSE']: |
426 utils.system('mkinitrd %s -k %s -i %s -M %s' % | 459 utils.system('mkinitrd %s -k %s -i %s -M %s' % |
427 (args, image, initrd, system_map)) | 460 (args, image, initrd, system_map)) |
428 elif vendor in ['Debian', 'Ubuntu']: | 461 elif vendor in ['Debian', 'Ubuntu']: |
429 if os.path.isfile('/usr/sbin/mkinitrd'): | 462 if os.path.isfile('/usr/sbin/mkinitrd'): |
430 cmd = '/usr/sbin/mkinitrd' | 463 cmd = '/usr/sbin/mkinitrd' |
431 elif os.path.isfile('/usr/sbin/mkinitramfs'): | 464 elif os.path.isfile('/usr/sbin/mkinitramfs'): |
432 cmd = '/usr/sbin/mkinitramfs' | 465 cmd = '/usr/sbin/mkinitramfs' |
433 else: | 466 else: |
434 raise error.TestError('No Debian initrd builder') | 467 raise error.TestError('No Debian initrd builder') |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
712 self.version, self.release = utils.system_output( | 745 self.version, self.release = utils.system_output( |
713 'rpm --queryformat="%{VERSION}\\n%{RELEASE}\\n" -q ' | 746 'rpm --queryformat="%{VERSION}\\n%{RELEASE}\\n" -q ' |
714 + rpm_name).splitlines()[0:2] | 747 + rpm_name).splitlines()[0:2] |
715 | 748 |
716 # prefer /boot/kernel-version before /boot/kernel | 749 # prefer /boot/kernel-version before /boot/kernel |
717 if self.full_version: | 750 if self.full_version: |
718 break | 751 break |
719 | 752 |
720 # search for initrd | 753 # search for initrd |
721 for file in files: | 754 for file in files: |
722 if file.startswith('/boot/initrd'): | 755 if file.startswith('/boot/init'): |
truty
2010/11/15 19:32:09
I don't know enough but this looks unnecessary.
| |
723 self.initrd = file | 756 self.initrd = file |
724 # prefer /boot/initrd-version before /boot/initrd | 757 # prefer /boot/initrd-version before /boot/initrd |
725 if len(file) > len('/boot/initrd'): | 758 if len(file) > len('/boot/initrd'): |
726 break | 759 break |
727 | 760 |
728 if self.image == None: | 761 if self.image == None: |
729 errmsg = "specified rpm file(s) don't contain /boot/vmlinuz" | 762 errmsg = "specified rpm file(s) don't contain /boot/vmlinuz" |
730 raise error.TestError(errmsg) | 763 raise error.TestError(errmsg) |
731 | 764 |
732 # install vmlinux | 765 # install vmlinux |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
833 # kernel from that specific path. | 866 # kernel from that specific path. |
834 job.pkgmgr.fetch_pkg(rpm_name, os.path.join(job.pkgdir, rpm_name ), | 867 job.pkgmgr.fetch_pkg(rpm_name, os.path.join(job.pkgdir, rpm_name ), |
835 repo_url=os.path.dirname(kernel_path)) | 868 repo_url=os.path.dirname(kernel_path)) |
836 | 869 |
837 rpm_paths.append(os.path.join(job.pkgdir, rpm_name)) | 870 rpm_paths.append(os.path.join(job.pkgdir, rpm_name)) |
838 return rpm_kernel_vendor(job, rpm_paths, subdir) | 871 return rpm_kernel_vendor(job, rpm_paths, subdir) |
839 else: | 872 else: |
840 if len(kernel_paths) > 1: | 873 if len(kernel_paths) > 1: |
841 raise error.TestError("don't know what to do with more than one non- rpm kernel file") | 874 raise error.TestError("don't know what to do with more than one non- rpm kernel file") |
842 return kernel(job,kernel_paths[0], subdir, tmp_dir, build_dir, leave) | 875 return kernel(job,kernel_paths[0], subdir, tmp_dir, build_dir, leave) |
OLD | NEW |