Package: vmdebootstrap
Version: 1.6-1
Severity: normal
Tags: patch

The code to create images with swap appears to have bit-rotted; it
looks for self.devices['swapdev'], but the Filesystem handler sets
self.devices['swap']:

    ERROR: In scenario "build a basic Debian 8 image with swap"
    step "WHEN the user runs vmdebootstrap --sparse --extlinux --roottype ext3 
--swap=256M" failed,
    with exit code 1:
    Standard output from shell command:
    Standard error from shell command:
        + [ -e 
/tmp/tmpQstkMI/build_a_basic_Debian_8_image_with_swap/datadir/settings.sh ]
        + . 
/tmp/tmpQstkMI/build_a_basic_Debian_8_image_with_swap/datadir/settings.sh
        + IMAGE=FOO.img
        + IMAGE_SIZE=2147483648
        + cd /tmp/tmpQstkMI/build_a_basic_Debian_8_image_with_swap/datadir
        + PYTHONPATH=/home/user/vmdebootstrap 
/home/user/vmdebootstrap/bin/vmdebootstrap --image FOO.img --mirror 
http://httpredir.debian.org/debian/ --size 2147483648 --sparse --extlinux 
--roottype ext3 --swap=256M
        Traceback (most recent call last):
          File "/usr/lib/python2.7/dist-packages/cliapp/app.py", line 189, in 
_run
            self.process_args(args)
          File "/home/user/vmdebootstrap/bin/vmdebootstrap", line 213, in 
process_args
            self.start_ops()
          File "/home/user/vmdebootstrap/bin/vmdebootstrap", line 303, in 
start_ops
            self._image_preparations()
          File "/home/user/vmdebootstrap/bin/vmdebootstrap", line 230, in 
_image_preparations
            runcmd(['mkswap', filesystem.devices['swapdev']])
          File "/home/user/vmdebootstrap/vmdebootstrap/base.py", line 38, in 
runcmd
            env=env, **kwargs)
          File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
            errread, errwrite)
          File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
            raise child_exception
        TypeError: execv() arg 2 must contain only strings

Additionally, when preparing a UEFI image, the swap partition index is
never set up in the kpartx setup code:

    ERROR: In scenario "build a Debian 8 image with uefi and swap"
    step "WHEN the user runs vmdebootstrap --grub --use-uefi --swap=256M" 
failed,
    with exit code 1:
    Standard output from shell command:
    Standard error from shell command:
        + [ -e 
/tmp/tmpeR2KE5/build_a_Debian_8_image_with_uefi_and_swap/datadir/settings.sh ]
        + . 
/tmp/tmpeR2KE5/build_a_Debian_8_image_with_uefi_and_swap/datadir/settings.sh
        + IMAGE=FOO.img
        + IMAGE_SIZE=2147483648
        + cd /tmp/tmpeR2KE5/build_a_Debian_8_image_with_uefi_and_swap/datadir
        + PYTHONPATH=/home/user/vmdebootstrap 
/home/user/vmdebootstrap/bin/vmdebootstrap --image FOO.img --mirror 
http://httpredir.debian.org/debian/ --size 2147483648 --grub --use-uefi 
--swap=256M
        ERROR: Surprising number of partitions 3:2- check output of losetup -a

I attach proposed patches, containing regression tests reproducing these
issues.

As a follow-up for these fixes, I'm part way through converting the
partition/device handling to be based on a list of named partitions,
so that Filesystem doesn't have to second-guess how the disk would
have been partitioned for a particular combination of options. This
should hopefully make it more robust.

Regards,
    S

-- System Information:
Debian Release: stretch/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing'), (500, 'stable'), (1, 
'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 4.6.0-1-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_GB.utf8, LC_CTYPE=en_GB.utf8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)

Versions of packages vmdebootstrap depends on:
ii  debootstrap         1.0.81
ii  kpartx              0.6.2-2
ii  libjs-sphinxdoc     1.4.5-1
ii  parted              3.2-15
ii  python-cliapp       1.20160724-1
ii  python-distro-info  0.14
ii  python2.7           2.7.12-2
pn  python:any          <none>
ii  qemu-utils          1:2.6+dfsg-3

Versions of packages vmdebootstrap recommends:
ii  dosfstools        4.0-2
ii  extlinux          3:6.03+dfsg-14
ii  grub2-common      2.02~beta2-36
ii  python-guestfs    1:1.32.7-1
ii  qemu-system       1:2.6+dfsg-3
ii  qemu-user-static  1:2.6+dfsg-3
ii  squashfs-tools    1:4.3-3

Versions of packages vmdebootstrap suggests:
ii  cmdtest       0.26-1
ii  mbr           1.1.11-5+b1
ii  pandoc        1.17.0.3~dfsg-2+b3
pn  u-boot:armhf  <none>

-- no debconf information
>From c59fbbbad87d5edc03c23c548f2d0e7178dedd83 Mon Sep 17 00:00:00 2001
From: Simon McVittie <s...@debian.org>
Date: Mon, 15 Aug 2016 10:05:06 +0100
Subject: [PATCH 1/6] Filesystem: fix support for creating swap partition

The Filesystem class created devices['swap'] but the main script
looked for devices['swapdev'].

Signed-off-by: Simon McVittie <s...@debian.org>
---
 vmdebootstrap/filesystem.py     | 2 +-
 yarns/300-slow-build-tests.yarn | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/vmdebootstrap/filesystem.py b/vmdebootstrap/filesystem.py
index b911c05..24a8ba2 100644
--- a/vmdebootstrap/filesystem.py
+++ b/vmdebootstrap/filesystem.py
@@ -131,7 +131,7 @@ class Filesystem(Base):
             swap = '/dev/mapper/%s' % devices[swapindex]
         self.devices['rootdev'] = root
         self.devices['bootdev'] = boot
-        self.devices['swap'] = swap
+        self.devices['swapdev'] = swap
 
     def mkfs(self, device, fstype, opt=None):
         self.message('Creating filesystem %s' % fstype)
diff --git a/yarns/300-slow-build-tests.yarn b/yarns/300-slow-build-tests.yarn
index cf6f7c0..fa06d21 100644
--- a/yarns/300-slow-build-tests.yarn
+++ b/yarns/300-slow-build-tests.yarn
@@ -20,6 +20,15 @@ These tests are slow, since building images is slow.
     AND partition 1 has filename ldlinux.sys
     AND partition 1 has filename extlinux.conf
 
+    SCENARIO build a basic Debian 8 image with swap
+    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 --roottype ext3 --swap=256M
+    THEN the image has the correct size
+    AND the partition count of the image is 2
+    AND partition 1 has an ext3 filesystem
+    AND partition 2 has a swap filesystem
+
     SCENARIO build a basic Debian 8 image with networking
     ASSUMING build tests are requested
     GIVEN user wants to build an image FOO.img that is 2GiB in size
-- 
2.8.1

>From a1f4f4a17184cfe4c0d984fcd1ee89b509110959 Mon Sep 17 00:00:00 2001
From: Simon McVittie <s...@debian.org>
Date: Mon, 15 Aug 2016 10:06:26 +0100
Subject: [PATCH 2/6] Filesystem: allow swap partition to be combined with UEFI

The "elif" cases were the wrong way round, so the case where we
have the complete set of partitions (ESP, root and swap) was never
reached for UEFI systems.

Signed-off-by: Simon McVittie <s...@debian.org>
---
 vmdebootstrap/filesystem.py     |  8 ++++----
 yarns/300-slow-build-tests.yarn | 10 ++++++++++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/vmdebootstrap/filesystem.py b/vmdebootstrap/filesystem.py
index 24a8ba2..fa7a575 100644
--- a/vmdebootstrap/filesystem.py
+++ b/vmdebootstrap/filesystem.py
@@ -94,15 +94,15 @@ class Filesystem(Base):
             rootindex = 1
             swapindex = 2
             parts = 3
-        elif self.settings['use-uefi']:
-            bootindex = 0
-            rootindex = 1
-            parts = 2
         elif self.settings['use-uefi'] and self.settings['swap'] > 0:
             bootindex = 0
             rootindex = 1
             swapindex = 2
             parts = 3
+        elif self.settings['use-uefi']:
+            bootindex = 0
+            rootindex = 1
+            parts = 2
         elif self.settings['bootsize']:
             bootindex = 0
             rootindex = 1
diff --git a/yarns/300-slow-build-tests.yarn b/yarns/300-slow-build-tests.yarn
index fa06d21..309e47f 100644
--- a/yarns/300-slow-build-tests.yarn
+++ b/yarns/300-slow-build-tests.yarn
@@ -85,6 +85,16 @@ These tests are slow, since building images is slow.
     AND partition 1 has an vfat filesystem
     AND partition 2 has file /boot/grub/grub.cfg matching ^### BEGIN /etc/grub.d/00_header ###$
 
+    SCENARIO build a Debian 8 image with uefi and swap
+    ASSUMING build tests are requested
+    GIVEN user wants to build an image FOO.img that is 2GiB in size
+    WHEN the user runs vmdebootstrap --grub --use-uefi --swap=256M
+    THEN the image has the correct size
+    AND the partition count of the image is 3
+    AND partition 1 has an vfat filesystem
+    AND partition 2 has file /boot/grub/grub.cfg matching ^### BEGIN /etc/grub.d/00_header ###$
+    AND partition 3 has a swap filesystem
+
     SCENARIO build a basic Debian 8 qcow image
     ASSUMING build tests are requested
     GIVEN user wants to build an image FOO.img that is 2GiB in size
-- 
2.8.1

Reply via email to