From bf7ff4d22260e0217d73d60723a0ba545582a25e Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Fri, 1 Jul 2016 19:21:35 +0200 Subject: [PATCH] Put the udebs in a pool type directory structure Signed-off-by: Neil Williams --- bin/lwr | 6 +++-- lwr/apt_udeb.py | 11 +++++++- lwr/grub.py | 1 + lwr/vm.py | 6 ++--- lwr/xorriso.py | 2 +- yarns/300-slow-build-tests.yarn | 34 +++++++++++++++++++++++ yarns/900-implements.yarn | 48 +++------------------------------ 7 files changed, 57 insertions(+), 51 deletions(-) create mode 100644 yarns/300-slow-build-tests.yarn diff --git a/bin/lwr b/bin/lwr index 08fee27..cefccd2 100755 --- a/bin/lwr +++ b/bin/lwr @@ -145,6 +145,8 @@ class LiveWrapper(cliapp.Application): '(default: %default)', default=False, group="Bootloaders") def process_args(self, args): + if os.path.exists(self.settings['image_output']): + raise cliapp.AppException("Image '%s' already exists" % self.settings['image_output']) if not self.settings['isolinux'] and not self.settings['grub']: raise cliapp.AppException("You must enable at least one bootloader!") if self.settings['grub'] and self.settings['grub-loopback-only']: @@ -180,9 +182,9 @@ class LiveWrapper(cliapp.Application): logging.info("Running vmdebootstrap...") print("Running vmdebootstrap...") - # Run vmdebootstrap + # Run vmdebootstrap, putting files in /live/ vm = VMDebootstrap(self.settings['distribution'], - self.settings['mirror']) + self.settings['mirror'], self.cdroot) vm.run() # Fetch D-I helper archive if needed diff --git a/lwr/apt_udeb.py b/lwr/apt_udeb.py index 4957aff..1148875 100644 --- a/lwr/apt_udeb.py +++ b/lwr/apt_udeb.py @@ -75,7 +75,15 @@ class AptUdebDownloader(object): def download_udebs(self, exclude_list): if not self.cache: raise RuntimeError('No cache available.') + main_pool = os.path.join(self.destdir, 'pool', 'main') + os.makedirs(main_pool) for pkg_name in self.cache.keys(): + prefix = pkg_name[0] + # destdir is just a base, needs pool/main/[index]/[name] + if pkg_name[:3] == 'lib': + prefix = pkg_name[:4] + pkg_dir = os.path.join(main_pool, prefix, pkg_name) + os.makedirs(pkg_dir) if pkg_name in exclude_list: continue pkg = self.cache[pkg_name] @@ -89,8 +97,9 @@ class AptUdebDownloader(object): version = pkg.versions[0] if not version.uri: continue + # FIXME: still need a Packages file and Release. try: - version.fetch_binary(destdir=self.destdir) + version.fetch_binary(destdir=pkg_dir) except TypeError as exc: continue except apt.package.FetchError as exc: diff --git a/lwr/grub.py b/lwr/grub.py index 0c4a176..23169c7 100644 --- a/lwr/grub.py +++ b/lwr/grub.py @@ -28,6 +28,7 @@ class GrubConfig(object): def generate_cfg(self): ret = ("if [ ${iso_path} ] ; then\nset loopback=\"" + "findiso=${iso_path}\"\nfi\n\n") + # FIXME: identify grub module prefix, e.g. boot/grub/x86_64-efi self.versions.sort(reverse=True) for version in self.versions: ret += "menuentry \"Debian GNU/Linux Live (kernel %s)\" {\n" % (version,) diff --git a/lwr/vm.py b/lwr/vm.py index 4f702f9..3cdf49f 100644 --- a/lwr/vm.py +++ b/lwr/vm.py @@ -19,12 +19,12 @@ from vmdebootstrap.base import runcmd class VMDebootstrap: - def __init__(self, distribution, mirror=None): + def __init__(self, distribution, mirror=None, cdroot='/tmp/'): self.args = ["vmdebootstrap", "--sudo", "--lock-root-password", "--enable-dhcp", "--configure-apt", "--verbose", - "--log", "vmdebootstrap.log", "--squash=cdroot/live/", - "--log-level", "debug", "--customize", + "--log", "vmdebootstrap.log", "--squash=%s/live/" % cdroot, + "--log-level", "debug", "--customize", "--use-uefi", "hooks/customise.sh"] self.args.extend(["--distribution", distribution]) diff --git a/lwr/xorriso.py b/lwr/xorriso.py index d925381..8ae2cd4 100644 --- a/lwr/xorriso.py +++ b/lwr/xorriso.py @@ -44,7 +44,6 @@ class Xorriso: self.args.extend(['-as', 'mkisofs', '-eltorito-alt-boot', '-e', 'boot/grub/efi.img', '-no-emul-boot', '-isohybrid-gpt-basdat']) - return self.args def build_image(self): @@ -61,4 +60,5 @@ class Xorriso: if len(self.args) == 1: cliapp.AppException("Attempted to run xorriso before building " "arguments!") + print(self.args) runcmd(self.args) diff --git a/yarns/300-slow-build-tests.yarn b/yarns/300-slow-build-tests.yarn new file mode 100644 index 0000000..b2982c8 --- /dev/null +++ b/yarns/300-slow-build-tests.yarn @@ -0,0 +1,34 @@ +# Slow image building tests + +In this chapter, we have test scenarios that actually build an image +and test the output. The images are not booted, but that may be added +later. Instead, all the tests on the images are static. + +These tests are slow, since building images is slow. + + +## Build a very basic Debian 8 image + + SCENARIO build a basic Debian 8 image + ASSUMING build tests are requested + GIVEN user wants to build an image FOO.img that is 2GiB in size + WHEN the user runs vmdebootstrap --sparse --extlinux + THEN the image has the correct size + AND the partition count of the image is 1 + AND partition 1 has the boot flag set + AND partition 1 has an ext4 filesystem + AND partition 1 has file /etc/debian_version matching ^8\..*$ + +# need a test that xorriso builds a bootable disk. +# Eltorito validation header: +# Hid 1 +# Arch 239 (Unknown Arch) +# ID '' +# Key 55 AA +# Eltorito defaultboot header: +# Bootid 88 (bootable) +# Boot media 0 (No Emulation Boot) +# Load segment 0 +# Sys type 0 +# Nsect 340 +# Bootoff 6C 108 diff --git a/yarns/900-implements.yarn b/yarns/900-implements.yarn index 4291863..bed8803 100644 --- a/yarns/900-implements.yarn +++ b/yarns/900-implements.yarn @@ -73,48 +73,8 @@ The steps in this section do static tests of disk image. These all operate on the image specified in the step "GIVEN user wants to build...". -Test the size of an image. This tests the length, not disk usage, of -the image. +# isoinfo -i jessie-live-uefi.iso -ld +# CD-ROM is in ISO 9660 format +# El Torito VD version 1 found, boot catalog is in sector 3031 +# Bootid 88 (bootable) - IMPLEMENTS THEN the image has the correct size - actual="$(stat -c %s "$IMAGE")" - [ "$actual" = "$IMAGE_SIZE" ] - -Check the partition table on the image. - - IMPLEMENTS THEN the partition count of the image is (\d+) - parted --script "$IMAGE" print | - sed '1,/^Number/d' | - grep -c . | - grep -Fx $MATCH_1 - -Check partition boot flag. - - IMPLEMENTS THEN partition (\d+) has the boot flag set - parted --script "$IMAGE" print | - awk -v "PART=$MATCH_1" '/^ [0-9]+ / && $1 == PART && $7 ~ "^boot,?$"' | - grep . - - IMPLEMENTS THEN partition (\d+) has the lba flag set - parted --script "$IMAGE" print | - awk -v "PART=$MATCH_1" '/^ [0-9]+ / && $1 == PART && $8 ~ "^lba?$"' | - grep . - -Check filesystem on a partition. This checks the actual filesystem, -not a type declared in the partition table. - - IMPLEMENTS THEN partition (\d+) has an? (\S+) filesystem - device="$(kpartx_image_partition "$IMAGE" "$MATCH_1")" - trap "unkpartx_image \"$IMAGE\"" EXIT - blkid "$device" | grep "TYPE=\"$MATCH_2\"" - -Check that the partition contains a file with some content matching a -regular expression. - - IMPLEMENTS THEN partition (\d+) has file (\S+) matching (.+) - device="$(kpartx_image_partition "$IMAGE" "$MATCH_1")" - trap "unkpartx_image \"$IMAGE\"" EXIT - mp="$(mktemp -d)" - mount -r "$device" "$mp" - trap "umount \"$mp\"; unkpartx_image \"$IMAGE\"" EXIT - grep -P -e "$MATCH_3" "$mp/$MATCH_2"