| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 63 bootloader.add_kernel(image, tag, initrd=initrd, args=' '.join(arglist), | 63 bootloader.add_kernel(image, tag, initrd=initrd, args=' '.join(arglist), |
| 64 root=root) | 64 root=root) |
| 65 | 65 |
| 66 | 66 |
| 67 class kernel(object): | 67 class BootableKernel(object): |
| 68 |
| 69 def __init__(self, job): |
| 70 self.job = job |
| 71 self.installed_as = None # kernel choice in bootloader menu |
| 72 self.image = None |
| 73 self.initrd = '' |
| 74 |
| 75 |
| 76 def _boot_kernel(self, args, ident_check, expected_ident, subdir, notes): |
| 77 """ |
| 78 Boot a kernel, with post-boot kernel id check |
| 79 |
| 80 @param args: kernel cmdline arguments |
| 81 @param ident_check: check kernel id after boot |
| 82 @param expected_ident: |
| 83 @param subdir: job-step qualifier in status log |
| 84 @param notes: additional comment in status log |
| 85 """ |
| 86 |
| 87 # If we can check the kernel identity do so. |
| 88 if ident_check: |
| 89 when = int(time.time()) |
| 90 args += " IDENT=%d" % when |
| 91 self.job.next_step_prepend(["job.end_reboot_and_verify", when, |
| 92 expected_ident, subdir, notes]) |
| 93 else: |
| 94 self.job.next_step_prepend(["job.end_reboot", subdir, |
| 95 expected_ident, notes]) |
| 96 |
| 97 # Point bootloader to the selected tag. |
| 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 |
| 103 # defer fsck for next reboot, to avoid reboots back to default kernel |
| 104 utils.system('touch /fastboot') # this file is removed automatically |
| 105 |
| 106 # Boot it. |
| 107 self.job.start_reboot() |
| 108 self.job.reboot(tag=self.installed_as) |
| 109 |
| 110 |
| 111 class kernel(BootableKernel): |
| 68 """ Class for compiling kernels. | 112 """ Class for compiling kernels. |
| 69 | 113 |
| 70 Data for the object includes the src files | 114 Data for the object includes the src files |
| 71 used to create the kernel, patches applied, config (base + changes), | 115 used to create the kernel, patches applied, config (base + changes), |
| 72 the build directory itself, and logged output | 116 the build directory itself, and logged output |
| 73 | 117 |
| 74 Properties: | 118 Properties: |
| 75 job | 119 job |
| 76 Backpointer to the job object we're part of | 120 Backpointer to the job object we're part of |
| 77 autodir | 121 autodir |
| (...skipping 24 matching lines...) Expand all Loading... |
| 102 3. A local directory (will symlink it) | 146 3. A local directory (will symlink it) |
| 103 4. A shorthand expandable (eg '2.6.11-git3') | 147 4. A shorthand expandable (eg '2.6.11-git3') |
| 104 subdir | 148 subdir |
| 105 subdir in the results directory (eg "build") | 149 subdir in the results directory (eg "build") |
| 106 (holds config/, debug/, results/) | 150 (holds config/, debug/, results/) |
| 107 tmp_dir | 151 tmp_dir |
| 108 | 152 |
| 109 leave | 153 leave |
| 110 Boolean, whether to leave existing tmpdir or not | 154 Boolean, whether to leave existing tmpdir or not |
| 111 """ | 155 """ |
| 112 self.job = job | 156 super(kernel, self).__init__(job) |
| 113 self.autodir = job.autodir | 157 self.autodir = job.autodir |
| 114 | 158 |
| 115 self.src_dir = os.path.join(tmp_dir, 'src') | 159 self.src_dir = os.path.join(tmp_dir, 'src') |
| 116 self.build_dir = os.path.join(tmp_dir, build_dir) | 160 self.build_dir = os.path.join(tmp_dir, build_dir) |
| 117 # created by get_kernel_tree | 161 # created by get_kernel_tree |
| 118 self.config_dir = os.path.join(subdir, 'config') | 162 self.config_dir = os.path.join(subdir, 'config') |
| 119 self.log_dir = os.path.join(subdir, 'debug') | 163 self.log_dir = os.path.join(subdir, 'debug') |
| 120 self.results_dir = os.path.join(subdir, 'results') | 164 self.results_dir = os.path.join(subdir, 'results') |
| 121 self.subdir = os.path.basename(subdir) | 165 self.subdir = os.path.basename(subdir) |
| 122 | 166 |
| 123 self.installed_as = None | |
| 124 | |
| 125 if not leave: | 167 if not leave: |
| 126 if os.path.isdir(self.src_dir): | 168 if os.path.isdir(self.src_dir): |
| 127 utils.system('rm -rf ' + self.src_dir) | 169 utils.system('rm -rf ' + self.src_dir) |
| 128 if os.path.isdir(self.build_dir): | 170 if os.path.isdir(self.build_dir): |
| 129 utils.system('rm -rf ' + self.build_dir) | 171 utils.system('rm -rf ' + self.build_dir) |
| 130 | 172 |
| 131 if not os.path.exists(self.src_dir): | 173 if not os.path.exists(self.src_dir): |
| 132 os.mkdir(self.src_dir) | 174 os.mkdir(self.src_dir) |
| 133 for path in [self.config_dir, self.log_dir, self.results_dir]: | 175 for path in [self.config_dir, self.log_dir, self.results_dir]: |
| 134 if os.path.exists(path): | 176 if os.path.exists(path): |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 if not kernel_config.modules_needed('.config'): | 485 if not kernel_config.modules_needed('.config'): |
| 444 return | 486 return |
| 445 | 487 |
| 446 utils.system('make modules_install INSTALL_MOD_PATH=%s' % prefix) | 488 utils.system('make modules_install INSTALL_MOD_PATH=%s' % prefix) |
| 447 if prefix == '/': | 489 if prefix == '/': |
| 448 self.initrd = self.boot_dir + '/initrd-' + tag | 490 self.initrd = self.boot_dir + '/initrd-' + tag |
| 449 self.mkinitrd(self.get_kernel_build_ver(), self.image, | 491 self.mkinitrd(self.get_kernel_build_ver(), self.image, |
| 450 self.system_map, self.initrd) | 492 self.system_map, self.initrd) |
| 451 | 493 |
| 452 | 494 |
| 453 def add_to_bootloader(self, tag='autotest', args=''): | |
| 454 """ add this kernel to bootloader, taking an | |
| 455 optional parameter of space separated parameters | |
| 456 e.g.: kernel.add_to_bootloader('mykernel', 'ro acpi=off') | |
| 457 """ | |
| 458 _add_kernel_to_bootloader(self.job.bootloader, | |
| 459 self.job.config_get('boot.default_args'), | |
| 460 tag, args, self.image, self.initrd) | |
| 461 | |
| 462 | |
| 463 def get_kernel_build_arch(self, arch=None): | 495 def get_kernel_build_arch(self, arch=None): |
| 464 """ | 496 """ |
| 465 Work out the current kernel architecture (as a kernel arch) | 497 Work out the current kernel architecture (as a kernel arch) |
| 466 """ | 498 """ |
| 467 if not arch: | 499 if not arch: |
| 468 arch = utils.get_current_kernel_arch() | 500 arch = utils.get_current_kernel_arch() |
| 469 if re.match('i.86', arch): | 501 if re.match('i.86', arch): |
| 470 return 'i386' | 502 return 'i386' |
| 471 elif re.match('sun4u', arch): | 503 elif re.match('sun4u', arch): |
| 472 return 'sparc64' | 504 return 'sparc64' |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 raise error.JobError('kernel has no identity') | 551 raise error.JobError('kernel has no identity') |
| 520 | 552 |
| 521 return release + '::' + version | 553 return release + '::' + version |
| 522 | 554 |
| 523 | 555 |
| 524 def boot(self, args='', ident=True): | 556 def boot(self, args='', ident=True): |
| 525 """ install and boot this kernel, do not care how | 557 """ install and boot this kernel, do not care how |
| 526 just make it happen. | 558 just make it happen. |
| 527 """ | 559 """ |
| 528 | 560 |
| 529 # If we can check the kernel identity do so. | 561 # If the kernel has not yet been installed, |
| 530 expected_ident = self.get_kernel_build_ident() | 562 # install it now as default tag. |
| 531 if ident: | |
| 532 when = int(time.time()) | |
| 533 args += " IDENT=%d" % (when) | |
| 534 self.job.next_step_prepend(["job.end_reboot_and_verify", when, | |
| 535 expected_ident, self.subdir, | |
| 536 self.applied_patches]) | |
| 537 else: | |
| 538 self.job.next_step_prepend(["job.end_reboot", self.subdir, | |
| 539 expected_ident, self.applied_patches]) | |
| 540 | |
| 541 # Check if the kernel has been installed, if not install | |
| 542 # as the default tag and boot that. | |
| 543 if not self.installed_as: | 563 if not self.installed_as: |
| 544 self.install() | 564 self.install() |
| 545 | 565 |
| 546 # Boot the selected tag. | 566 expected_ident = self.get_kernel_build_ident() |
| 547 self.add_to_bootloader(args=args, tag=self.installed_as) | 567 self._boot_kernel(args, ident, expected_ident, |
| 548 | 568 self.subdir, self.applied_patches) |
| 549 # Boot it. | |
| 550 self.job.start_reboot() | |
| 551 self.job.reboot(tag=self.installed_as) | |
| 552 | 569 |
| 553 | 570 |
| 554 def get_kernel_build_ver(self): | 571 def get_kernel_build_ver(self): |
| 555 """Check Makefile and .config to return kernel version""" | 572 """Check Makefile and .config to return kernel version""" |
| 556 version = patchlevel = sublevel = extraversion = localversion = '' | 573 version = patchlevel = sublevel = extraversion = localversion = '' |
| 557 | 574 |
| 558 for line in open(self.build_dir + '/Makefile', 'r').readlines(): | 575 for line in open(self.build_dir + '/Makefile', 'r').readlines(): |
| 559 if line.startswith('VERSION'): | 576 if line.startswith('VERSION'): |
| 560 version = line[line.index('=') + 1:].strip() | 577 version = line[line.index('=') + 1:].strip() |
| 561 if line.startswith('PATCHLEVEL'): | 578 if line.startswith('PATCHLEVEL'): |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 | 656 |
| 640 we can't pickle the backreference to job (it contains fd's), | 657 we can't pickle the backreference to job (it contains fd's), |
| 641 nor would we want to. Same for logfile (fd's). | 658 nor would we want to. Same for logfile (fd's). |
| 642 """ | 659 """ |
| 643 temp = copy.copy(self) | 660 temp = copy.copy(self) |
| 644 temp.job = None | 661 temp.job = None |
| 645 temp.logfile = None | 662 temp.logfile = None |
| 646 pickle.dump(temp, open(filename, 'w')) | 663 pickle.dump(temp, open(filename, 'w')) |
| 647 | 664 |
| 648 | 665 |
| 649 class rpm_kernel(object): | 666 class rpm_kernel(BootableKernel): |
| 650 """ | 667 """ |
| 651 Class for installing a binary rpm kernel package | 668 Class for installing a binary rpm kernel package |
| 652 """ | 669 """ |
| 653 | 670 |
| 654 def __init__(self, job, rpm_package, subdir): | 671 def __init__(self, job, rpm_package, subdir): |
| 655 self.job = job | 672 super(rpm_kernel, self).__init__(job) |
| 656 self.rpm_package = rpm_package | 673 self.rpm_package = rpm_package |
| 657 self.log_dir = os.path.join(subdir, 'debug') | 674 self.log_dir = os.path.join(subdir, 'debug') |
| 658 self.subdir = os.path.basename(subdir) | 675 self.subdir = os.path.basename(subdir) |
| 659 if os.path.exists(self.log_dir): | 676 if os.path.exists(self.log_dir): |
| 660 utils.system('rm -rf ' + self.log_dir) | 677 utils.system('rm -rf ' + self.log_dir) |
| 661 os.mkdir(self.log_dir) | 678 os.mkdir(self.log_dir) |
| 662 self.installed_as = None | |
| 663 | 679 |
| 664 | 680 |
| 665 def build(self, *args, **dargs): | 681 def build(self, *args, **dargs): |
| 666 """ | 682 """ |
| 667 Dummy function, binary kernel so nothing to build. | 683 Dummy function, binary kernel so nothing to build. |
| 668 """ | 684 """ |
| 669 pass | 685 pass |
| 670 | 686 |
| 671 | 687 |
| 672 @log.record | 688 @log.record |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 718 for rpm_pack in self.rpm_package: | 734 for rpm_pack in self.rpm_package: |
| 719 vmlinux = utils.system_output( | 735 vmlinux = utils.system_output( |
| 720 'rpm -q -l -p %s | grep /boot/vmlinux' % rpm_pack) | 736 'rpm -q -l -p %s | grep /boot/vmlinux' % rpm_pack) |
| 721 utils.system('cd /; rpm2cpio %s | cpio -imuv .%s 2>&1' | 737 utils.system('cd /; rpm2cpio %s | cpio -imuv .%s 2>&1' |
| 722 % (rpm_pack, vmlinux)) | 738 % (rpm_pack, vmlinux)) |
| 723 if not os.path.exists(vmlinux): | 739 if not os.path.exists(vmlinux): |
| 724 raise error.TestError('%s does not exist after installing %s' | 740 raise error.TestError('%s does not exist after installing %s' |
| 725 % (vmlinux, rpm_pack)) | 741 % (vmlinux, rpm_pack)) |
| 726 | 742 |
| 727 | 743 |
| 728 def add_to_bootloader(self, tag='autotest', args=''): | |
| 729 """ Add this kernel to bootloader | |
| 730 """ | |
| 731 _add_kernel_to_bootloader(self.job.bootloader, | |
| 732 self.job.config_get('boot.default_args'), | |
| 733 tag, args, self.image, self.initrd) | |
| 734 | |
| 735 | |
| 736 def boot(self, args='', ident=True): | 744 def boot(self, args='', ident=True): |
| 737 """ install and boot this kernel | 745 """ install and boot this kernel |
| 738 """ | 746 """ |
| 739 | 747 |
| 740 # Check if the kernel has been installed, if not install | 748 # If the kernel has not yet been installed, |
| 741 # as the default tag and boot that. | 749 # install it now as default tag. |
| 742 if not self.installed_as: | 750 if not self.installed_as: |
| 743 self.install() | 751 self.install() |
| 744 | 752 |
| 745 # If we can check the kernel identity do so. | |
| 746 expected_ident = self.full_version | 753 expected_ident = self.full_version |
| 747 if not expected_ident: | 754 if not expected_ident: |
| 748 expected_ident = '-'.join([self.version, | 755 expected_ident = '-'.join([self.version, |
| 749 self.rpm_flavour, | 756 self.rpm_flavour, |
| 750 self.release]) | 757 self.release]) |
| 751 if ident: | |
| 752 when = int(time.time()) | |
| 753 args += " IDENT=%d" % (when) | |
| 754 self.job.next_step_prepend(["job.end_reboot_and_verify", | |
| 755 when, expected_ident, None, 'rpm']) | |
| 756 else: | |
| 757 self.job.next_step_prepend(["job.end_reboot", None, | |
| 758 expected_ident, []]) | |
| 759 | 758 |
| 760 # Boot the selected tag. | 759 self._boot_kernel(args, ident, expected_ident, |
| 761 self.add_to_bootloader(args=args, tag=self.installed_as) | 760 None, 'rpm') |
| 762 | |
| 763 # Boot it. | |
| 764 self.job.start_reboot() | |
| 765 self.job.reboot(tag=self.installed_as) | |
| 766 | 761 |
| 767 | 762 |
| 768 class rpm_kernel_suse(rpm_kernel): | 763 class rpm_kernel_suse(rpm_kernel): |
| 769 """ Class for installing openSUSE/SLE rpm kernel package | 764 """ Class for installing openSUSE/SLE rpm kernel package |
| 770 """ | 765 """ |
| 771 | 766 |
| 772 def install(self): | 767 def install(self): |
| 773 # do not set the new kernel as the default one | 768 # do not set the new kernel as the default one |
| 774 os.environ['PBL_AUTOTEST'] = '1' | 769 os.environ['PBL_AUTOTEST'] = '1' |
| 775 | 770 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 838 # kernel from that specific path. | 833 # kernel from that specific path. |
| 839 job.pkgmgr.fetch_pkg(rpm_name, os.path.join(job.pkgdir, rpm_name
), | 834 job.pkgmgr.fetch_pkg(rpm_name, os.path.join(job.pkgdir, rpm_name
), |
| 840 repo_url=os.path.dirname(kernel_path)) | 835 repo_url=os.path.dirname(kernel_path)) |
| 841 | 836 |
| 842 rpm_paths.append(os.path.join(job.pkgdir, rpm_name)) | 837 rpm_paths.append(os.path.join(job.pkgdir, rpm_name)) |
| 843 return rpm_kernel_vendor(job, rpm_paths, subdir) | 838 return rpm_kernel_vendor(job, rpm_paths, subdir) |
| 844 else: | 839 else: |
| 845 if len(kernel_paths) > 1: | 840 if len(kernel_paths) > 1: |
| 846 raise error.TestError("don't know what to do with more than one non-
rpm kernel file") | 841 raise error.TestError("don't know what to do with more than one non-
rpm kernel file") |
| 847 return kernel(job,kernel_paths[0], subdir, tmp_dir, build_dir, leave) | 842 return kernel(job,kernel_paths[0], subdir, tmp_dir, build_dir, leave) |
| OLD | NEW |