Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(372)

Side by Side Diff: client/bin/kernel.py

Issue 3541002: Revert "Merge remote branch 'cros/upstream' into tempbranch2" (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/autotest.git
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/bin/job.py ('k') | client/bin/kernel_unittest.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 BootableKernel(object): 67 class kernel(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):
112 """ Class for compiling kernels. 68 """ Class for compiling kernels.
113 69
114 Data for the object includes the src files 70 Data for the object includes the src files
115 used to create the kernel, patches applied, config (base + changes), 71 used to create the kernel, patches applied, config (base + changes),
116 the build directory itself, and logged output 72 the build directory itself, and logged output
117 73
118 Properties: 74 Properties:
119 job 75 job
120 Backpointer to the job object we're part of 76 Backpointer to the job object we're part of
121 autodir 77 autodir
(...skipping 24 matching lines...) Expand all
146 3. A local directory (will symlink it) 102 3. A local directory (will symlink it)
147 4. A shorthand expandable (eg '2.6.11-git3') 103 4. A shorthand expandable (eg '2.6.11-git3')
148 subdir 104 subdir
149 subdir in the results directory (eg "build") 105 subdir in the results directory (eg "build")
150 (holds config/, debug/, results/) 106 (holds config/, debug/, results/)
151 tmp_dir 107 tmp_dir
152 108
153 leave 109 leave
154 Boolean, whether to leave existing tmpdir or not 110 Boolean, whether to leave existing tmpdir or not
155 """ 111 """
156 super(kernel, self).__init__(job) 112 self.job = job
157 self.autodir = job.autodir 113 self.autodir = job.autodir
158 114
159 self.src_dir = os.path.join(tmp_dir, 'src') 115 self.src_dir = os.path.join(tmp_dir, 'src')
160 self.build_dir = os.path.join(tmp_dir, build_dir) 116 self.build_dir = os.path.join(tmp_dir, build_dir)
161 # created by get_kernel_tree 117 # created by get_kernel_tree
162 self.config_dir = os.path.join(subdir, 'config') 118 self.config_dir = os.path.join(subdir, 'config')
163 self.log_dir = os.path.join(subdir, 'debug') 119 self.log_dir = os.path.join(subdir, 'debug')
164 self.results_dir = os.path.join(subdir, 'results') 120 self.results_dir = os.path.join(subdir, 'results')
165 self.subdir = os.path.basename(subdir) 121 self.subdir = os.path.basename(subdir)
166 122
123 self.installed_as = None
124
167 if not leave: 125 if not leave:
168 if os.path.isdir(self.src_dir): 126 if os.path.isdir(self.src_dir):
169 utils.system('rm -rf ' + self.src_dir) 127 utils.system('rm -rf ' + self.src_dir)
170 if os.path.isdir(self.build_dir): 128 if os.path.isdir(self.build_dir):
171 utils.system('rm -rf ' + self.build_dir) 129 utils.system('rm -rf ' + self.build_dir)
172 130
173 if not os.path.exists(self.src_dir): 131 if not os.path.exists(self.src_dir):
174 os.mkdir(self.src_dir) 132 os.mkdir(self.src_dir)
175 for path in [self.config_dir, self.log_dir, self.results_dir]: 133 for path in [self.config_dir, self.log_dir, self.results_dir]:
176 if os.path.exists(path): 134 if os.path.exists(path):
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
485 if not kernel_config.modules_needed('.config'): 443 if not kernel_config.modules_needed('.config'):
486 return 444 return
487 445
488 utils.system('make modules_install INSTALL_MOD_PATH=%s' % prefix) 446 utils.system('make modules_install INSTALL_MOD_PATH=%s' % prefix)
489 if prefix == '/': 447 if prefix == '/':
490 self.initrd = self.boot_dir + '/initrd-' + tag 448 self.initrd = self.boot_dir + '/initrd-' + tag
491 self.mkinitrd(self.get_kernel_build_ver(), self.image, 449 self.mkinitrd(self.get_kernel_build_ver(), self.image,
492 self.system_map, self.initrd) 450 self.system_map, self.initrd)
493 451
494 452
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
495 def get_kernel_build_arch(self, arch=None): 463 def get_kernel_build_arch(self, arch=None):
496 """ 464 """
497 Work out the current kernel architecture (as a kernel arch) 465 Work out the current kernel architecture (as a kernel arch)
498 """ 466 """
499 if not arch: 467 if not arch:
500 arch = utils.get_current_kernel_arch() 468 arch = utils.get_current_kernel_arch()
501 if re.match('i.86', arch): 469 if re.match('i.86', arch):
502 return 'i386' 470 return 'i386'
503 elif re.match('sun4u', arch): 471 elif re.match('sun4u', arch):
504 return 'sparc64' 472 return 'sparc64'
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 raise error.JobError('kernel has no identity') 519 raise error.JobError('kernel has no identity')
552 520
553 return release + '::' + version 521 return release + '::' + version
554 522
555 523
556 def boot(self, args='', ident=True): 524 def boot(self, args='', ident=True):
557 """ install and boot this kernel, do not care how 525 """ install and boot this kernel, do not care how
558 just make it happen. 526 just make it happen.
559 """ 527 """
560 528
561 # If the kernel has not yet been installed, 529 # If we can check the kernel identity do so.
562 # install it now as default tag. 530 expected_ident = self.get_kernel_build_ident()
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.
563 if not self.installed_as: 543 if not self.installed_as:
564 self.install() 544 self.install()
565 545
566 expected_ident = self.get_kernel_build_ident() 546 # Boot the selected tag.
567 self._boot_kernel(args, ident, expected_ident, 547 self.add_to_bootloader(args=args, tag=self.installed_as)
568 self.subdir, self.applied_patches) 548
549 # Boot it.
550 self.job.start_reboot()
551 self.job.reboot(tag=self.installed_as)
569 552
570 553
571 def get_kernel_build_ver(self): 554 def get_kernel_build_ver(self):
572 """Check Makefile and .config to return kernel version""" 555 """Check Makefile and .config to return kernel version"""
573 version = patchlevel = sublevel = extraversion = localversion = '' 556 version = patchlevel = sublevel = extraversion = localversion = ''
574 557
575 for line in open(self.build_dir + '/Makefile', 'r').readlines(): 558 for line in open(self.build_dir + '/Makefile', 'r').readlines():
576 if line.startswith('VERSION'): 559 if line.startswith('VERSION'):
577 version = line[line.index('=') + 1:].strip() 560 version = line[line.index('=') + 1:].strip()
578 if line.startswith('PATCHLEVEL'): 561 if line.startswith('PATCHLEVEL'):
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 639
657 we can't pickle the backreference to job (it contains fd's), 640 we can't pickle the backreference to job (it contains fd's),
658 nor would we want to. Same for logfile (fd's). 641 nor would we want to. Same for logfile (fd's).
659 """ 642 """
660 temp = copy.copy(self) 643 temp = copy.copy(self)
661 temp.job = None 644 temp.job = None
662 temp.logfile = None 645 temp.logfile = None
663 pickle.dump(temp, open(filename, 'w')) 646 pickle.dump(temp, open(filename, 'w'))
664 647
665 648
666 class rpm_kernel(BootableKernel): 649 class rpm_kernel(object):
667 """ 650 """
668 Class for installing a binary rpm kernel package 651 Class for installing a binary rpm kernel package
669 """ 652 """
670 653
671 def __init__(self, job, rpm_package, subdir): 654 def __init__(self, job, rpm_package, subdir):
672 super(rpm_kernel, self).__init__(job) 655 self.job = job
673 self.rpm_package = rpm_package 656 self.rpm_package = rpm_package
674 self.log_dir = os.path.join(subdir, 'debug') 657 self.log_dir = os.path.join(subdir, 'debug')
675 self.subdir = os.path.basename(subdir) 658 self.subdir = os.path.basename(subdir)
676 if os.path.exists(self.log_dir): 659 if os.path.exists(self.log_dir):
677 utils.system('rm -rf ' + self.log_dir) 660 utils.system('rm -rf ' + self.log_dir)
678 os.mkdir(self.log_dir) 661 os.mkdir(self.log_dir)
662 self.installed_as = None
679 663
680 664
681 def build(self, *args, **dargs): 665 def build(self, *args, **dargs):
682 """ 666 """
683 Dummy function, binary kernel so nothing to build. 667 Dummy function, binary kernel so nothing to build.
684 """ 668 """
685 pass 669 pass
686 670
687 671
688 @log.record 672 @log.record
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 for rpm_pack in self.rpm_package: 718 for rpm_pack in self.rpm_package:
735 vmlinux = utils.system_output( 719 vmlinux = utils.system_output(
736 'rpm -q -l -p %s | grep /boot/vmlinux' % rpm_pack) 720 'rpm -q -l -p %s | grep /boot/vmlinux' % rpm_pack)
737 utils.system('cd /; rpm2cpio %s | cpio -imuv .%s 2>&1' 721 utils.system('cd /; rpm2cpio %s | cpio -imuv .%s 2>&1'
738 % (rpm_pack, vmlinux)) 722 % (rpm_pack, vmlinux))
739 if not os.path.exists(vmlinux): 723 if not os.path.exists(vmlinux):
740 raise error.TestError('%s does not exist after installing %s' 724 raise error.TestError('%s does not exist after installing %s'
741 % (vmlinux, rpm_pack)) 725 % (vmlinux, rpm_pack))
742 726
743 727
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
744 def boot(self, args='', ident=True): 736 def boot(self, args='', ident=True):
745 """ install and boot this kernel 737 """ install and boot this kernel
746 """ 738 """
747 739
748 # If the kernel has not yet been installed, 740 # Check if the kernel has been installed, if not install
749 # install it now as default tag. 741 # as the default tag and boot that.
750 if not self.installed_as: 742 if not self.installed_as:
751 self.install() 743 self.install()
752 744
745 # If we can check the kernel identity do so.
753 expected_ident = self.full_version 746 expected_ident = self.full_version
754 if not expected_ident: 747 if not expected_ident:
755 expected_ident = '-'.join([self.version, 748 expected_ident = '-'.join([self.version,
756 self.rpm_flavour, 749 self.rpm_flavour,
757 self.release]) 750 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, []])
758 759
759 self._boot_kernel(args, ident, expected_ident, 760 # Boot the selected tag.
760 None, 'rpm') 761 self.add_to_bootloader(args=args, tag=self.installed_as)
762
763 # Boot it.
764 self.job.start_reboot()
765 self.job.reboot(tag=self.installed_as)
761 766
762 767
763 class rpm_kernel_suse(rpm_kernel): 768 class rpm_kernel_suse(rpm_kernel):
764 """ Class for installing openSUSE/SLE rpm kernel package 769 """ Class for installing openSUSE/SLE rpm kernel package
765 """ 770 """
766 771
767 def install(self): 772 def install(self):
768 # do not set the new kernel as the default one 773 # do not set the new kernel as the default one
769 os.environ['PBL_AUTOTEST'] = '1' 774 os.environ['PBL_AUTOTEST'] = '1'
770 775
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
833 # kernel from that specific path. 838 # kernel from that specific path.
834 job.pkgmgr.fetch_pkg(rpm_name, os.path.join(job.pkgdir, rpm_name ), 839 job.pkgmgr.fetch_pkg(rpm_name, os.path.join(job.pkgdir, rpm_name ),
835 repo_url=os.path.dirname(kernel_path)) 840 repo_url=os.path.dirname(kernel_path))
836 841
837 rpm_paths.append(os.path.join(job.pkgdir, rpm_name)) 842 rpm_paths.append(os.path.join(job.pkgdir, rpm_name))
838 return rpm_kernel_vendor(job, rpm_paths, subdir) 843 return rpm_kernel_vendor(job, rpm_paths, subdir)
839 else: 844 else:
840 if len(kernel_paths) > 1: 845 if len(kernel_paths) > 1:
841 raise error.TestError("don't know what to do with more than one non- rpm kernel file") 846 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) 847 return kernel(job,kernel_paths[0], subdir, tmp_dir, build_dir, leave)
OLDNEW
« no previous file with comments | « client/bin/job.py ('k') | client/bin/kernel_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698