How to use boot_kernel method in autotest

Best Python code snippet using autotest_python

test_bootresourceset.py

Source:test_bootresourceset.py Github

copy

Full Screen

1# Copyright 2014-2016 Canonical Ltd. This software is licensed under the2# GNU Affero General Public License version 3 (see the file LICENSE).3"""Tests for `BootResourceSet`."""4import random5from unittest import skip6from maasserver.enum import BOOT_RESOURCE_FILE_TYPE7from maasserver.models.bootresourceset import XINSTALL_TYPES8from maasserver.testing.factory import factory9from maasserver.testing.testcase import MAASServerTestCase10class TestBootResourceSet(MAASServerTestCase):11 """Tests for the `BootResourceSet` model."""12 def make_all_boot_resource_files(self, resource_set, filetypes):13 for filetype in filetypes:14 # We set the filename to the same value as filetype, as in most15 # cases this will always be true. The simplestreams content from16 # maas.io, is formatted this way.17 factory.make_boot_resource_file_with_content(18 resource_set, filename=filetype, filetype=filetype19 )20 def test_commissionable_returns_true_when_all_filetypes_present(self):21 resource = factory.make_BootResource()22 resource_set = factory.make_BootResourceSet(resource)23 commissionable_set = {24 BOOT_RESOURCE_FILE_TYPE.BOOT_KERNEL,25 BOOT_RESOURCE_FILE_TYPE.BOOT_INITRD,26 random.choice(27 [28 BOOT_RESOURCE_FILE_TYPE.SQUASHFS_IMAGE,29 BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE,30 ]31 ),32 }33 self.make_all_boot_resource_files(resource_set, commissionable_set)34 self.assertTrue(resource_set.commissionable)35 def test_commissionable_returns_false_when_missing_filetypes(self):36 resource = factory.make_BootResource()37 resource_set = factory.make_BootResourceSet(resource)38 commissionable_set = {39 BOOT_RESOURCE_FILE_TYPE.BOOT_KERNEL,40 BOOT_RESOURCE_FILE_TYPE.BOOT_INITRD,41 }42 self.make_all_boot_resource_files(resource_set, commissionable_set)43 self.assertFalse(resource_set.commissionable)44 def test_xinstallable_returns_true_when_filetype_present(self):45 resource = factory.make_BootResource()46 resource_set = factory.make_BootResourceSet(resource)47 filetype = random.choice(XINSTALL_TYPES)48 factory.make_boot_resource_file_with_content(49 resource_set, filename=filetype, filetype=filetype50 )51 self.assertTrue(resource_set.xinstallable)52 @skip("XXX: LaMontJones 2016-03-23 bug=1561259: Fails when root-image.gz.")53 def test_xinstallable_returns_false_when_missing_filetypes(self):54 resource = factory.make_BootResource()55 resource_set = factory.make_BootResourceSet(resource)56 filetype = random.choice(57 [58 BOOT_RESOURCE_FILE_TYPE.BOOT_KERNEL,59 BOOT_RESOURCE_FILE_TYPE.BOOT_INITRD,60 BOOT_RESOURCE_FILE_TYPE.SQUASHFS_IMAGE,61 BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE,62 ]63 )64 factory.make_boot_resource_file_with_content(65 resource_set, filename=filetype, filetype=filetype66 )67 self.assertFalse(resource_set.xinstallable)68 def test_total_size(self):69 resource = factory.make_BootResource()70 resource_set = factory.make_BootResourceSet(resource)71 total_size = 072 sizes = [random.randint(512, 1024) for _ in range(3)]73 types = [74 BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE,75 BOOT_RESOURCE_FILE_TYPE.BOOT_KERNEL,76 BOOT_RESOURCE_FILE_TYPE.BOOT_INITRD,77 ]78 for size in sizes:79 total_size += size80 filetype = types.pop()81 largefile = factory.make_LargeFile(size=size)82 factory.make_BootResourceFile(83 resource_set, largefile, filename=filetype, filetype=filetype84 )85 self.assertEqual(total_size, resource_set.total_size)86 def test_size(self):87 resource = factory.make_BootResource()88 resource_set = factory.make_BootResourceSet(resource)89 final_size = 090 sizes = [random.randint(512, 1024) for _ in range(3)]91 total_sizes = [random.randint(1025, 2048) for _ in range(3)]92 types = [93 BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE,94 BOOT_RESOURCE_FILE_TYPE.BOOT_KERNEL,95 BOOT_RESOURCE_FILE_TYPE.BOOT_INITRD,96 ]97 for size in sizes:98 final_size += size99 filetype = types.pop()100 content = factory.make_bytes(size=size)101 largefile = factory.make_LargeFile(102 content=content, size=total_sizes.pop()103 )104 factory.make_BootResourceFile(105 resource_set, largefile, filename=filetype, filetype=filetype106 )107 self.assertEqual(final_size, resource_set.size)108 def test_progress_handles_zero_division(self):109 resource = factory.make_BootResource()110 resource_set = factory.make_BootResourceSet(resource)111 filetype = BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE112 total_size = random.randint(1025, 2048)113 largefile = factory.make_LargeFile(content=b"", size=total_size)114 factory.make_BootResourceFile(115 resource_set, largefile, filename=filetype, filetype=filetype116 )117 self.assertEqual(0, resource_set.progress)118 def test_progress_increases_from_0_to_100(self):119 resource = factory.make_BootResource()120 resource_set = factory.make_BootResourceSet(resource)121 filetype = BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE122 total_size = 100123 current_size = 0124 largefile = factory.make_LargeFile(content=b"", size=total_size)125 factory.make_BootResourceFile(126 resource_set, largefile, filename=filetype, filetype=filetype127 )128 stream = largefile.content.open()129 self.addCleanup(stream.close)130 self.assertEqual(0, resource_set.progress)131 for _ in range(total_size):132 stream.write(b"a")133 largefile.size += 1134 largefile.save()135 current_size += 1136 self.assertAlmostEqual(137 100.0 * current_size / float(total_size), resource_set.progress138 )139 def test_progress_accumulates_all_files(self):140 resource = factory.make_BootResource()141 resource_set = factory.make_BootResourceSet(resource)142 final_size = 0143 final_total_size = 0144 sizes = [random.randint(512, 1024) for _ in range(3)]145 total_sizes = [random.randint(1025, 2048) for _ in range(3)]146 types = [147 BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE,148 BOOT_RESOURCE_FILE_TYPE.BOOT_KERNEL,149 BOOT_RESOURCE_FILE_TYPE.BOOT_INITRD,150 ]151 for size in sizes:152 final_size += size153 total_size = total_sizes.pop()154 final_total_size += total_size155 filetype = types.pop()156 content = factory.make_bytes(size=size)157 largefile = factory.make_LargeFile(158 content=content, size=total_size159 )160 factory.make_BootResourceFile(161 resource_set, largefile, filename=filetype, filetype=filetype162 )163 progress = 100.0 * final_size / float(final_total_size)164 self.assertAlmostEqual(progress, resource_set.progress)165 def test_complete_returns_false_for_no_files(self):166 resource = factory.make_BootResource()167 resource_set = factory.make_BootResourceSet(resource)168 self.assertFalse(resource_set.complete)169 def test_complete_returns_false_for_one_incomplete_file(self):170 resource = factory.make_BootResource()171 resource_set = factory.make_BootResourceSet(resource)172 types = [173 BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE,174 BOOT_RESOURCE_FILE_TYPE.BOOT_KERNEL,175 BOOT_RESOURCE_FILE_TYPE.BOOT_INITRD,176 ]177 for _ in range(2):178 filetype = types.pop()179 factory.make_boot_resource_file_with_content(180 resource_set, filename=filetype, filetype=filetype181 )182 size = random.randint(512, 1024)183 total_size = random.randint(1025, 2048)184 filetype = types.pop()185 content = factory.make_bytes(size=size)186 largefile = factory.make_LargeFile(content=content, size=total_size)187 factory.make_BootResourceFile(188 resource_set, largefile, filename=filetype, filetype=filetype189 )190 self.assertFalse(resource_set.complete)191 def test_complete_returns_true_for_complete_files(self):192 resource = factory.make_BootResource()193 resource_set = factory.make_BootResourceSet(resource)194 types = [195 BOOT_RESOURCE_FILE_TYPE.ROOT_IMAGE,196 BOOT_RESOURCE_FILE_TYPE.BOOT_KERNEL,197 BOOT_RESOURCE_FILE_TYPE.BOOT_INITRD,198 ]199 for _ in range(3):200 filetype = types.pop()201 factory.make_boot_resource_file_with_content(202 resource_set, filename=filetype, filetype=filetype203 )...

Full Screen

Full Screen

cdroot.py

Source:cdroot.py Github

copy

Full Screen

1#!/usr/bin/python2import os, shutil, time3import subprocess4from datetime import datetime5kogaion_molecule_home = os.getenv("KOGAION_MOLECULE_HOME", "/kogaion")6source_chroot_dir = os.getenv('SOURCE_CHROOT_DIR')7chroot_dir = os.getenv('CHROOT_DIR')8cdroot_dir = os.getenv('CDROOT_DIR')9boot_dir = os.path.join(chroot_dir, "boot")10cdroot_boot_dir = os.path.join(cdroot_dir, "boot")11boot_kernel = [x for x in os.listdir(boot_dir) if x.startswith("kernel-")]12if boot_kernel:13 boot_kernel = os.path.join(boot_dir, sorted(boot_kernel)[0])14 shutil.copy2(boot_kernel, os.path.join(cdroot_boot_dir, "kogaion"))15boot_ramfs = [x for x in os.listdir(boot_dir) if x.startswith("initramfs-")]16if boot_ramfs:17 boot_ramfs = os.path.join(boot_dir, sorted(boot_ramfs)[0])18 shutil.copy2(boot_ramfs, os.path.join(cdroot_boot_dir, "kogaion.igz"))19# Write build info20build_info_file = os.path.join(cdroot_dir, "BUILD_INFO")21build_date = str(datetime.fromtimestamp(time.time()))22bf = open(build_info_file, "w")23bf.write("Kogaion ISO image build information\n")24bf.write("Built on: %s\n" % (build_date,))25bf.flush()26bf.close()27def replace_version(path):28 release_version = os.getenv("RELEASE_VERSION", "HEAD")29 cf = open(path, "r")30 new_cf = []31 for line in cf.readlines():32 line = line.replace("__VERSION__", release_version)33 new_cf.append(line)34 cf.close()35 cf_new = open(path+".cdroot", "w")36 cf_new.writelines(new_cf)37 cf_new.flush()38 cf_new.close()39 os.rename(path+".cdroot", path)40# Change txt.cfg and isolinux.txt to match version41isolinux_cfg = os.path.join(cdroot_dir, "isolinux/txt.cfg")42isolinux_txt = os.path.join(cdroot_dir, "isolinux/isolinux.txt")43syslinux_cfg = os.path.join(cdroot_dir, "syslinux/txt.cfg")44syslinux_txt = os.path.join(cdroot_dir, "syslinux/isolinux.txt")45replace_version(isolinux_cfg)46replace_version(isolinux_txt)47replace_version(syslinux_cfg)48replace_version(syslinux_txt)49# Copy pkglist over, if exists50kogaion_pkgs_file = os.path.join(chroot_dir, "etc/kogaion-pkglist")51if os.path.isfile(kogaion_pkgs_file):52 shutil.copy2(kogaion_pkgs_file, os.path.join(cdroot_dir, "pkglist"))53 iso_path = os.getenv("ISO_PATH")54 if iso_path:55 shutil.copy2(kogaion_pkgs_file, iso_path+".pkglist")56# copy back.jpg to proper location57isolinux_img = os.path.join(chroot_dir, "/kogaion/boot/core/isolinux/back.jpg")58syslinux_img = os.path.join(cdroot_dir, "/kogaion/boot/core/syslinux/back.jpg")59if os.path.isfile(isolinux_img):60 shutil.copy2(isolinux_img, os.path.join(cdroot_dir, "isolinux/back.jpg"))61if os.path.isfile(syslinux_img):62 shutil.copy2(syslinux_img, os.path.join(cdroot_dir, "syslinux/back.jpg"))63iso_md5_script = os.path.join(kogaion_molecule_home, "scripts/pre_iso_script_livecd_hash.sh")64exit_st = subprocess.call([iso_md5_script])...

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