How to use next_step_prepend method in autotest

Best Python code snippet using autotest_python

kernel.py

Source:kernel.py Github

copy

Full Screen

...412 expected_ident = self.get_kernel_build_ident()413 if ident:414 when = int(time.time())415 args += " IDENT=%d" % (when)416 self.job.next_step_prepend(["job.end_reboot_and_verify", when,417 expected_ident, self.subdir,418 self.applied_patches])419 else:420 self.job.next_step_prepend(["job.end_reboot", self.subdir,421 expected_ident, self.applied_patches])422 # Check if the kernel has been installed, if not install423 # as the default tag and boot that.424 if not self.installed_as:425 self.install()426 # Boot the selected tag.427 self.add_to_bootloader(args=args, tag=self.installed_as)428 # Boot it.429 self.job.start_reboot()430 self.job.reboot(tag=self.installed_as)431 def get_kernel_build_ver(self):432 """Check Makefile and .config to return kernel version"""433 version = patchlevel = sublevel = extraversion = localversion = ''434 for line in open(self.build_dir + '/Makefile', 'r').readlines():435 if line.startswith('VERSION'):436 version = line[line.index('=') + 1:].strip()437 if line.startswith('PATCHLEVEL'):438 patchlevel = line[line.index('=') + 1:].strip()439 if line.startswith('SUBLEVEL'):440 sublevel = line[line.index('=') + 1:].strip()441 if line.startswith('EXTRAVERSION'):442 extraversion = line[line.index('=') + 1:].strip()443 for line in open(self.build_dir + '/.config', 'r').readlines():444 if line.startswith('CONFIG_LOCALVERSION='):445 localversion = line.rstrip().split('"')[1]446 return "%s.%s.%s%s%s" %(version, patchlevel, sublevel, extraversion, localversion)447 def set_build_target(self, build_target):448 if build_target:449 self.build_target = build_target450 print 'BUILD TARGET: %s' % self.build_target451 def set_cross_cc(self, target_arch=None, cross_compile=None,452 build_target='bzImage'):453 """Set up to cross-compile.454 This is broken. We need to work out what the default455 compile produces, and if not, THEN set the cross456 compiler.457 """458 if self.target_arch:459 return460 # if someone has set build_target, don't clobber in set_cross_cc461 # run set_build_target before calling set_cross_cc462 if not self.build_target:463 self.set_build_target(build_target)464 # If no 'target_arch' given assume native compilation465 if target_arch is None:466 target_arch = utils.get_current_kernel_arch()467 if target_arch == 'ppc64':468 if self.build_target == 'bzImage':469 self.build_target = 'vmlinux'470 if not cross_compile:471 cross_compile = self.job.config_get('kernel.cross_cc')472 if cross_compile:473 os.environ['CROSS_COMPILE'] = cross_compile474 else:475 if os.environ.has_key('CROSS_COMPILE'):476 del os.environ['CROSS_COMPILE']477 return # HACK. Crap out for now.478 # At this point I know what arch I *want* to build for479 # but have no way of working out what arch the default480 # compiler DOES build for.481 def install_package(package):482 raise NotImplementedError("I don't exist yet!")483 if target_arch == 'ppc64':484 install_package('ppc64-cross')485 cross_compile = os.path.join(self.autodir, 'sources/ppc64-cross/bin')486 elif target_arch == 'x86_64':487 install_package('x86_64-cross')488 cross_compile = os.path.join(self.autodir, 'sources/x86_64-cross/bin')489 os.environ['ARCH'] = self.target_arch = target_arch490 self.cross_compile = cross_compile491 if self.cross_compile:492 os.environ['CROSS_COMPILE'] = self.cross_compile493 def pickle_dump(self, filename):494 """dump a pickle of ourself out to the specified filename495 we can't pickle the backreference to job (it contains fd's),496 nor would we want to. Same for logfile (fd's).497 """498 temp = copy.copy(self)499 temp.job = None500 temp.logfile = None501 pickle.dump(temp, open(filename, 'w'))502class rpm_kernel(object):503 """ Class for installing rpm kernel package504 """505 def __init__(self, job, rpm_package, subdir):506 self.job = job507 self.rpm_package = rpm_package508 self.log_dir = os.path.join(subdir, 'debug')509 self.subdir = os.path.basename(subdir)510 if os.path.exists(self.log_dir):511 utils.system('rm -rf ' + self.log_dir)512 os.mkdir(self.log_dir)513 self.installed_as = None514 @log.record515 @tee_output_logdir_mark516 def install(self, tag='autotest', install_vmlinux=True):517 self.installed_as = tag518 self.image = None519 self.initrd = ''520 for rpm_pack in self.rpm_package:521 rpm_name = utils.system_output('rpm -qp ' + rpm_pack)522 # install523 utils.system('rpm -i --force ' + rpm_pack)524 # get file list525 files = utils.system_output('rpm -ql ' + rpm_name).splitlines()526 # search for vmlinuz527 for file in files:528 if file.startswith('/boot/vmlinuz'):529 self.full_version = file[len('/boot/vmlinuz-'):]530 self.image = file531 self.rpm_flavour = rpm_name.split('-')[1]532 # get version and release number533 self.version, self.release = utils.system_output(534 'rpm --queryformat="%{VERSION}\\n%{RELEASE}\\n" -q '535 + rpm_name).splitlines()[0:2]536 # prefer /boot/kernel-version before /boot/kernel537 if self.full_version:538 break539 # search for initrd540 for file in files:541 if file.startswith('/boot/initrd'):542 self.initrd = file543 # prefer /boot/initrd-version before /boot/initrd544 if len(file) > len('/boot/initrd'):545 break546 if self.image == None:547 errmsg = "specified rpm file(s) don't contain /boot/vmlinuz"548 raise error.TestError(errmsg)549 # install vmlinux550 if install_vmlinux:551 for rpm_pack in self.rpm_package:552 vmlinux = utils.system_output(553 'rpm -q -l -p %s | grep /boot/vmlinux' % rpm_pack)554 utils.system('cd /; rpm2cpio %s | cpio -imuv .%s'555 % (rpm_pack, vmlinux))556 if not os.path.exists(vmlinux):557 raise error.TestError('%s does not exist after installing %s'558 % (vmlinux, rpm_pack))559 def add_to_bootloader(self, tag='autotest', args=''):560 """ Add this kernel to bootloader561 """562 # remove existing entry if present563 self.job.bootloader.remove_kernel(tag)564 # pull the base argument set from the job config565 baseargs = self.job.config_get('boot.default_args')566 if baseargs:567 args = baseargs + ' ' + args568 # otherwise populate from /proc/cmdline569 # if not baseargs:570 # baseargs = open('/proc/cmdline', 'r').readline().strip()571 # NOTE: This is unnecessary, because boottool does it.572 root = None573 roots = [x for x in args.split() if x.startswith('root=')]574 if roots:575 root = re.sub('^root=', '', roots[0])576 arglist = [x for x in args.split() if not x.startswith('root=')]577 args = ' '.join(arglist)578 # add the kernel entry579 self.job.bootloader.add_kernel(self.image, tag, self.initrd,580 args = args, root = root)581 def boot(self, args='', ident=True):582 """ install and boot this kernel583 """584 # Check if the kernel has been installed, if not install585 # as the default tag and boot that.586 if not self.installed_as:587 self.install()588 # If we can check the kernel identity do so.589 expected_ident = self.full_version590 if not expected_ident:591 expected_ident = '-'.join([self.version,592 self.rpm_flavour,593 self.release])594 if ident:595 when = int(time.time())596 args += " IDENT=%d" % (when)597 self.job.next_step_prepend(["job.end_reboot_and_verify",598 when, expected_ident, None, 'rpm'])599 else:600 self.job.next_step_prepend(["job.end_reboot", None,601 expected_ident, []])602 # Boot the selected tag.603 self.add_to_bootloader(args=args, tag=self.installed_as)604 # Boot it.605 self.job.start_reboot()606 self.job.reboot(tag=self.installed_as)607class rpm_kernel_suse(rpm_kernel):608 """ Class for installing openSUSE/SLE rpm kernel package609 """610 def install(self):611 # do not set the new kernel as the default one612 os.environ['PBL_AUTOTEST'] = '1'613 rpm_kernel.install(self, 'dummy')614 self.installed_as = self.job.bootloader.get_title_for_kernel(self.image)...

Full Screen

Full Screen

kernel_unittest.py

Source:kernel_unittest.py Github

copy

Full Screen

1#!/usr/bin/python2import unittest, os, time, re, glob, logging3import common4from autotest_lib.client.common_lib.test_utils import mock5from autotest_lib.client.bin import kernel, job, utils, kernelexpand6from autotest_lib.client.bin import kernel_config, boottool, os_dep7class TestKernel(unittest.TestCase):8 def setUp(self):9 self.god = mock.mock_god()10 logging.disable(logging.CRITICAL)11 self.god.stub_function(time, "time")12 self.god.stub_function(os, "mkdir")13 self.god.stub_function(os, "chdir")14 self.god.stub_function(os, "symlink")15 self.god.stub_function(os, "remove")16 self.god.stub_function(os.path, "isdir")17 self.god.stub_function(os.path, "exists")18 self.god.stub_function(os.path, "isfile")19 self.god.stub_function(os_dep, "commands")20 self.god.stub_function(kernel, "open")21 self.god.stub_function(utils, "system")22 self.god.stub_function(utils, "system_output")23 self.god.stub_function(utils, "get_file")24 self.god.stub_function(utils, "get_current_kernel_arch")25 self.god.stub_function(utils, "cat_file_to_cmd")26 self.god.stub_function(utils, "force_copy")27 self.god.stub_function(utils, "extract_tarball_to_dir")28 self.god.stub_function(utils, "count_cpus")29 self.god.stub_function(utils, "get_os_vendor")30 self.god.stub_function(kernelexpand, "expand_classic")31 self.god.stub_function(kernel_config, "modules_needed")32 self.god.stub_function(glob, "glob")33 def dummy_mark(filename, msg):34 pass35 self.god.stub_with(kernel, '_mark', dummy_mark)36 self.job = self.god.create_mock_class(job.job, "job")37 self.job.bootloader = self.god.create_mock_class(boottool.boottool,38 "boottool")39 class DummyLoggingManager(object):40 def tee_redirect_debug_dir(self, *args, **kwargs):41 pass42 def restore(self, *args, **kwargs):43 pass44 self.job.logging = DummyLoggingManager()45 self.job.autodir = "autodir"46 self.base_tree = "2.6.24"47 self.tmp_dir = "tmpdir"48 self.subdir = "subdir"49 def tearDown(self):50 self.god.unstub_all()51 def construct_kernel(self):52 self.kernel = kernel.kernel.__new__(kernel.kernel)53 self.god.stub_function(self.kernel, "extract")54 # setup55 self.src_dir = os.path.join(self.tmp_dir, 'src')56 self.build_dir = os.path.join(self.tmp_dir, "build_dir")57 self.config_dir = os.path.join(self.subdir, 'config')58 self.log_dir = os.path.join(self.subdir, 'debug')59 self.results_dir = os.path.join(self.subdir, 'results')60 # record61 os.path.isdir.expect_call(self.src_dir).and_return(True)62 utils.system.expect_call('rm -rf ' + self.src_dir)63 os.path.isdir.expect_call(self.build_dir).and_return(True)64 utils.system.expect_call('rm -rf ' + self.build_dir)65 os.path.exists.expect_call(self.src_dir).and_return(False)66 os.mkdir.expect_call(self.src_dir)67 for path in [self.config_dir, self.log_dir, self.results_dir]:68 os.path.exists.expect_call(path).and_return(True)69 utils.system.expect_call('rm -rf ' + path)70 os.mkdir.expect_call(path)71 logpath = os.path.join(self.log_dir, 'build_log')72 self.logfile = self.god.create_mock_class(file, "file")73 kernel.open.expect_call(logpath, 'w+').and_return(self.logfile)74 utils.get_current_kernel_arch.expect_call().and_return('ia64')75 self.logfile.write.expect_call('BASE: %s\n' % self.base_tree)76 self.kernel.extract.expect_call(self.base_tree)77 # finish creation of kernel object and test (and unstub extract)78 self.kernel.__init__(self.job, self.base_tree, self.subdir,79 self.tmp_dir, "build_dir")80 self.god.check_playback()81 self.god.unstub(self.kernel, "extract")82 def test_constructor(self):83 self.construct_kernel()84 def test_kernelexpand1(self):85 self.construct_kernel()86 ret_val = self.kernel.kernelexpand("/path/to/kernel")87 self.assertEquals(ret_val, ["/path/to/kernel"])88 self.god.check_playback()89 def test_kernel_expand2(self):90 self.construct_kernel()91 kernel = "kernel.tar.gz"92 # record93 self.job.config_get.expect_call('mirror.mirrors').and_return('mirror')94 kernelexpand.expand_classic.expect_call(kernel,95 'mirror').and_return('patches')96 # run97 self.assertEquals(self.kernel.kernelexpand(kernel), 'patches')98 self.god.check_playback()99 def test_kernel_expand3(self):100 self.construct_kernel()101 kernel = "kernel.tar.gz"102 # record103 self.job.config_get.expect_call('mirror.mirrors')104 self.job.config_get.expect_call(105 'mirror.ftp_kernel_org').and_return('mirror')106 korg = 'http://www.kernel.org/pub/linux/kernel'107 mirrors = [108 [ korg + '/v2.6', 'mirror' + '/v2.6' ],109 [ korg + '/people/akpm/patches/2.6', 'mirror' + '/akpm' ],110 [ korg + '/people/mbligh', 'mirror' + '/mbligh' ],111 ]112 kernelexpand.expand_classic.expect_call(kernel,113 mirrors).and_return('patches')114 # run115 self.assertEquals(self.kernel.kernelexpand(kernel), 'patches')116 self.god.check_playback()117 def test_extract1(self):118 self.construct_kernel()119 # setup120 self.god.stub_function(self.kernel, "get_kernel_tree")121 # record122 os.path.exists.expect_call(self.base_tree).and_return(True)123 self.kernel.get_kernel_tree.expect_call(self.base_tree)124 self.job.record.expect_call('GOOD', self.subdir, 'kernel.extract')125 # run126 self.kernel.extract(self.base_tree)127 self.god.check_playback()128 self.god.unstub(self.kernel, "get_kernel_tree")129 def test_extract2(self):130 self.construct_kernel()131 # setup132 self.god.stub_function(self.kernel, "kernelexpand")133 self.god.stub_function(self.kernel, "get_kernel_tree")134 self.god.stub_function(self.kernel, "patch")135 # record136 os.path.exists.expect_call(self.base_tree).and_return(False)137 components = ["component0", "component1"]138 self.kernel.kernelexpand.expect_call(self.base_tree).and_return(139 components)140 self.kernel.get_kernel_tree.expect_call(components[0])141 self.kernel.patch.expect_call(components[1])142 self.job.record.expect_call('GOOD', self.subdir, 'kernel.extract')143 # run144 self.kernel.extract(self.base_tree)145 self.god.check_playback()146 self.god.unstub(self.kernel, "kernelexpand")147 self.god.unstub(self.kernel, "get_kernel_tree")148 self.god.unstub(self.kernel, "patch")149 def test_patch1(self):150 self.construct_kernel()151 patches = ('patch1', 'patch2')152 self.god.stub_function(self.kernel, "apply_patches")153 self.god.stub_function(self.kernel, "get_patches")154 #record155 self.kernel.get_patches.expect_call(patches).and_return(patches)156 self.kernel.apply_patches.expect_call(patches)157 self.job.record.expect_call('GOOD', self.subdir, 'kernel.patch')158 #run159 self.kernel.patch(*patches)160 self.god.check_playback()161 self.god.unstub(self.kernel, "apply_patches")162 self.god.unstub(self.kernel, "get_patches")163 def test_patch2(self):164 self.construct_kernel()165 patches = []166 # record167 self.job.record.expect_call('GOOD', self.subdir, 'kernel.patch')168 # run169 self.kernel.patch(*patches)170 self.god.check_playback()171 def test_config(self):172 self.construct_kernel()173 # setup174 self.god.stub_function(self.kernel, "set_cross_cc")175 self.god.stub_class(kernel_config, "kernel_config")176 # record177 self.kernel.set_cross_cc.expect_call()178 kernel_config.kernel_config.expect_new(self.job, self.build_dir,179 self.config_dir, '', None,180 False, self.base_tree, None)181 self.job.record.expect_call('GOOD', self.subdir, 'kernel.config')182 # run183 self.kernel.config()184 self.god.check_playback()185 self.god.unstub(self.kernel, "set_cross_cc")186 def test_get_patches(self):187 self.construct_kernel()188 # setup189 patches = ['patch1', 'patch2', 'patch3']190 local_patches = []191 # record192 for patch in patches:193 dest = os.path.join(self.src_dir, os.path.basename(patch))194 utils.get_file.expect_call(patch, dest)195 utils.system_output.expect_call(196 'md5sum ' + dest).and_return('md5sum')197 local_patches.append((patch, dest, 'md5sum'))198 # run and check199 self.assertEquals(self.kernel.get_patches(patches), local_patches)200 self.god.check_playback()201 def test_apply_patches(self):202 self.construct_kernel()203 # setup204 patches = []205 patches.append(('patch1', 'patch1.gz', 'md5sum1'))206 patches.append(('patch2', 'patch2.bz2', 'md5sum2'))207 patches.append(('patch3', 'patch3', 'md5sum3'))208 applied_patches = []209 # record210 os.chdir.expect_call(self.build_dir)211 patch_id = "%s %s %s" % ('patch1', 'patch1', 'md5sum1')212 log = "PATCH: " + patch_id + "\n"213 utils.cat_file_to_cmd.expect_call('patch1.gz',214 'patch -p1 > /dev/null')215 self.logfile.write.expect_call(log)216 applied_patches.append(patch_id)217 patch_id = "%s %s %s" % ('patch2', 'patch2', 'md5sum2')218 log = "PATCH: " + patch_id + "\n"219 utils.cat_file_to_cmd.expect_call('patch2.bz2',220 'patch -p1 > /dev/null')221 self.logfile.write.expect_call(log)222 applied_patches.append(patch_id)223 utils.force_copy.expect_call('patch3',224 self.results_dir).and_return('local_patch3')225 self.job.relative_path.expect_call('local_patch3').and_return(226 'rel_local_patch3')227 patch_id = "%s %s %s" % ('patch3', 'rel_local_patch3', 'md5sum3')228 log = "PATCH: " + patch_id + "\n"229 utils.cat_file_to_cmd.expect_call('patch3',230 'patch -p1 > /dev/null')231 self.logfile.write.expect_call(log)232 applied_patches.append(patch_id)233 # run and test234 self.kernel.apply_patches(patches)235 self.assertEquals(self.kernel.applied_patches, applied_patches)236 self.god.check_playback()237 def test_get_kernel_tree1(self):238 self.construct_kernel()239 # record240 os.path.isdir.expect_call(self.base_tree).and_return(True)241 os.symlink.expect_call(self.base_tree, self.build_dir)242 # run and check243 self.kernel.get_kernel_tree(self.base_tree)244 self.god.check_playback()245 def test_get_kernel_tree2(self):246 self.construct_kernel()247 # record248 os.path.isdir.expect_call(self.base_tree).and_return(False)249 os.chdir.expect_call(os.path.dirname(self.src_dir))250 tarball = os.path.join(self.src_dir, os.path.basename(self.base_tree))251 utils.get_file.expect_call(self.base_tree, tarball)252 utils.extract_tarball_to_dir.expect_call(tarball,253 self.build_dir)254 # run and check255 self.kernel.get_kernel_tree(self.base_tree)256 self.god.check_playback()257 def test_extraversion(self):258 self.construct_kernel()259 tag = "tag"260 # record261 os.chdir.expect_call(self.build_dir)262 extraversion_sub = r's/^EXTRAVERSION =\s*\(.*\)/EXTRAVERSION = '263 p = extraversion_sub + '\\1-%s/' % tag264 utils.system.expect_call('mv Makefile Makefile.old')265 utils.system.expect_call('sed "%s" < Makefile.old > Makefile' % p)266 # run and check267 self.kernel.extraversion(tag)268 self.god.check_playback()269 def test_build(self):270 self.construct_kernel()271 self.god.stub_function(self.kernel, "extraversion")272 self.god.stub_function(self.kernel, "set_cross_cc")273 self.god.stub_function(self.kernel, "get_kernel_build_ver")274 self.kernel.build_target = 'build_target'275 # record276 os_dep.commands.expect_call('gcc', 'make')277 logfile = os.path.join(self.log_dir, 'kernel_build')278 os.chdir.expect_call(self.build_dir)279 self.kernel.extraversion.expect_call('autotest')280 self.kernel.set_cross_cc.expect_call()281 utils.system.expect_call('make dep', ignore_status=True)282 utils.count_cpus.expect_call().and_return(4)283 threads = 2 * 4284 build_string = 'make -j %d %s %s' % (threads, '', 'build_target')285 utils.system.expect_call(build_string)286 kernel_config.modules_needed.expect_call('.config').and_return(True)287 utils.system.expect_call('make -j %d modules' % (threads))288 self.kernel.get_kernel_build_ver.expect_call().and_return('2.6.24')289 kernel_version = re.sub('-autotest', '', '2.6.24')290 self.logfile.write.expect_call('BUILD VERSION: %s\n' % kernel_version)291 utils.force_copy.expect_call(self.build_dir+'/System.map',292 self.results_dir)293 self.job.record.expect_call('GOOD', self.subdir, 'kernel.build')294 # run and check295 self.kernel.build()296 self.god.check_playback()297 def test_build_timed(self):298 self.construct_kernel()299 self.god.stub_function(self.kernel, "set_cross_cc")300 self.god.stub_function(self.kernel, "clean")301 # record302 os.chdir.expect_call(self.build_dir)303 self.kernel.set_cross_cc.expect_call()304 self.kernel.clean.expect_call(logged=False)305 build_string = "/usr/bin/time -o /dev/null make -j 8 vmlinux"306 build_string += ' > /dev/null 2>&1'307 utils.system.expect_call(build_string)308 os.path.isfile.expect_call('vmlinux').and_return(True)309 # run and check310 self.kernel.build_timed(threads=8)311 self.god.check_playback()312 def test_clean(self):313 self.construct_kernel()314 # record315 os.chdir.expect_call(self.build_dir)316 utils.system.expect_call('make clean > /dev/null 2> /dev/null')317 self.job.record.expect_call('GOOD', self.subdir, 'kernel.clean')318 # run and check319 self.kernel.clean()320 self.god.check_playback()321 def test_mkinitrd(self):322 self.construct_kernel()323 # record324 utils.get_os_vendor.expect_call().and_return('Ubuntu')325 os.path.isfile.expect_call('initrd').and_return(True)326 os.remove.expect_call('initrd')327 self.job.config_get.expect_call(328 'kernel.mkinitrd_extra_args').and_return(None)329 args = ''330 os.path.isfile.expect_call('/usr/sbin/mkinitrd').and_return(True)331 cmd = '/usr/sbin/mkinitrd'332 utils.system.expect_call('%s %s -o initrd 2.6.24' % (cmd, args))333 self.job.record.expect_call('GOOD', self.subdir, 'kernel.mkinitrd')334 # run and check335 self.kernel.mkinitrd(version="2.6.24", image="image",336 system_map="system_map", initrd="initrd")337 self.god.check_playback()338 def test_install(self):339 self.construct_kernel()340 tag = 'autotest'341 prefix = '/'342 self.kernel.build_image = None343 self.kernel.build_target = 'build_target'344 self.god.stub_function(self.kernel, "get_kernel_build_ver")345 self.god.stub_function(self.kernel, "mkinitrd")346 # record347 os.chdir.expect_call(self.build_dir)348 os.path.isdir.expect_call(prefix).and_return(False)349 os.mkdir.expect_call(prefix)350 boot_dir = os.path.join(prefix, 'boot')351 os.path.isdir.expect_call(boot_dir).and_return(False)352 os.mkdir.expect_call(boot_dir)353 glob.glob.expect_call(354 'arch/*/boot/' + 'build_target').and_return('')355 build_image = self.kernel.build_target356 utils.force_copy.expect_call('vmlinux',357 '/boot/vmlinux-autotest')358 utils.force_copy.expect_call('build_target',359 '/boot/vmlinuz-autotest')360 utils.force_copy.expect_call('System.map',361 '/boot/System.map-autotest')362 utils.force_copy.expect_call('.config',363 '/boot/config-autotest')364 kernel_config.modules_needed.expect_call('.config').and_return(True)365 utils.system.expect_call('make modules_install INSTALL_MOD_PATH=%s'366 % prefix)367 initrd = boot_dir + '/initrd-' + tag368 self.kernel.get_kernel_build_ver.expect_call().and_return('2.6.24')369 self.kernel.mkinitrd.expect_call('2.6.24', '/boot/vmlinuz-autotest',370 '/boot/System.map-autotest', '/boot/initrd-autotest')371 self.job.record.expect_call('GOOD', self.subdir, 'kernel.install')372 # run and check373 self.kernel.install()374 self.god.check_playback()375 def test_add_to_bootloader(self):376 self.construct_kernel()377 # setup378 tag = 'autotest'379 args = ''380 self.kernel.image = "image"381 self.kernel.initrd = "initrd"382 # record383 self.job.bootloader.remove_kernel.expect_call(tag)384 self.job.config_get.expect_call(385 'boot.default_args').and_return('baseargs')386 args = 'baseargs' + " " + args387 self.job.bootloader.add_kernel.expect_call('image', 'autotest',388 'initrd', args='baseargs', root=None)389 # run and check390 self.kernel.add_to_bootloader()391 self.god.check_playback()392 def test_get_kernel_build_arch1(self):393 self.construct_kernel()394 # record395 utils.get_current_kernel_arch.expect_call().and_return("i386")396 # run and check397 self.assertEquals(self.kernel.get_kernel_build_arch(), "i386")398 self.god.check_playback()399 def test_get_kernel_build_arch2(self):400 self.construct_kernel()401 # run and check402 self.assertEquals(self.kernel.get_kernel_build_arch('i586'), "i386")403 self.god.check_playback()404 def test_get_kernel_build_release(self):405 self.construct_kernel()406 mock_file = self.god.create_mock_class(file, "file")407 # record408 for f in [self.build_dir + "/include/linux/version.h",409 self.build_dir + "/include/linux/utsrelease.h"]:410 os.path.exists.expect_call(f).and_return(True)411 kernel.open.expect_call(f, 'r').and_return(mock_file)412 mock_file.readlines.expect_call().and_return("Some lines")413 mock_file.close.expect_call()414 f = self.build_dir + "/include/linux/compile.h"415 os.path.exists.expect_call(f).and_return(False)416 # run and test417 self.kernel.get_kernel_build_release()418 self.god.check_playback()419 def test_get_kernel_build_ident(self):420 self.construct_kernel()421 self.god.stub_function(self.kernel, "get_kernel_build_release")422 # record423 self.kernel.get_kernel_build_release.expect_call().and_return(424 ("AwesomeRelease", "1.0"))425 # run and check426 self.assertEquals(self.kernel.get_kernel_build_ident(),427 "AwesomeRelease::1.0")428 self.god.check_playback()429 def test_boot(self):430 self.construct_kernel()431 self.god.stub_function(self.kernel, "get_kernel_build_ident")432 self.god.stub_function(self.kernel, "install")433 self.god.stub_function(self.kernel, "add_to_bootloader")434 self.kernel.applied_patches = "applied_patches"435 when = 1436 args = ''437 self.kernel.installed_as = False438 # record439 self.kernel.get_kernel_build_ident.expect_call().and_return("ident")440 time.time.expect_call().and_return(when)441 args += " IDENT=%d" % (when)442 self.job.next_step_prepend.expect_call(["job.end_reboot_and_verify",443 when, "ident", self.subdir, self.kernel.applied_patches])444 self.kernel.install.expect_call()445 self.kernel.add_to_bootloader.expect_call(args=args,446 tag=False)447 self.job.start_reboot.expect_call()448 self.job.reboot.expect_call(tag=False)449 # run and check450 self.kernel.boot()451 self.god.check_playback()452 def test_boot_without_ident(self):453 self.construct_kernel()454 self.god.stub_function(self.kernel, "get_kernel_build_ident")455 self.god.stub_function(self.kernel, "install")456 self.god.stub_function(self.kernel, "add_to_bootloader")457 self.kernel.applied_patches = "applied_patches"458 when = 1459 args = ''460 self.kernel.installed_as = False461 # record462 self.kernel.get_kernel_build_ident.expect_call().and_return("ident")463 self.job.next_step_prepend.expect_call(["job.end_reboot",464 self.subdir, "ident", self.kernel.applied_patches])465 self.kernel.install.expect_call()466 self.kernel.add_to_bootloader.expect_call(args=args,467 tag=False)468 self.job.start_reboot.expect_call()469 self.job.reboot.expect_call(tag=False)470 # run and check471 self.kernel.boot(ident=False)472 self.god.check_playback()473if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful