Your message dated Fri, 11 Mar 2016 09:50:00 +0000
with message-id <[email protected]>
and subject line Bug#800845: fixed in autopkgtest 3.20
has caused the Debian Bug report #800845,
regarding autopkgtest: Add support for nested VMs
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [email protected]
immediately.)


-- 
800845: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=800845
Debian Bug Tracking System
Contact [email protected] with problems
--- Begin Message ---
Package: autopkgtest
Version: 3.17.2
Severity: wishlist
Tags: patch

Hello Martin,

as per our discussion on the autopkgtest mailing list [1], I'd like to
be able to have autopkgtest support nested VMs for testing of network
clients in the kernel such as NFS, CIFS, iSCSI, NBD, etc.

The logic would be to

 - have the test environment run a simple server that the client may
   connect to
 - have a copy of the qcow2 base image in the test environment
 - create a QEMU/KVM VM in the test environment that then tests the
   client (this can again be done with adt-run inside the test env)

I've attached two patches that implement the necessary changes to
autopkgtest. They are quire minimal in fact:

 1. Have adt-virt-qemu add an additional drive to the VM that
    maps (read-only) to the qcow2 base image (but without QEMU
    interpreting the image, just passing it through via format=raw).

    This allows the drive to be used as a base image, e.g.
    qemu-img create -f qcow2 -b /dev/vdb overlay.img
    (Running KVM on top of something like that works, btw., in case
    you were wondering - you can easily try that by creating a loop
    device, i.e. losetup --show -f base.img and then doing
    adt-run ... --- adt-virt-qemu /dev/loopX.)

 2. Have adt-virt-qemu provide an environment variable to the tests
    so that they may make use of it. (ADT_QCOW2_BASEIMAGE)

 3. Have adt-virt-qemu export the capability provides-qcow2-baseimage.

 4. Add new restriction needs-qcow2-baseimage that is checked against
    that capability. (The base image logic is done unconditionally by
    adt-virt-qemu, regardless of the restriction. In principle this
    would allow people to just do vmdebootstrap inside the VM if the
    base image were not to be exported.)

 5. If in KVM mode, add -cpu host option to the emulator command, since
    that is required (but not sufficient) for nested KVM to work.

    Note that nested KVM will also require a module option to be set.
    (nested=1 for either the kvm_intel or kvm_amd module.) Setting
    -cpu host has no negative side effects even if nested=0 is set on
    the host - then the kvm_* modules will not load in the VM and KVM
    will simply be not available - same as without -cpu host.

    On the other hand, nested KVM is nice-to-have, but not required for
    a nested VM - the VM inside could be a non-accelerated QEMU VM.

Once could in principle also add support for nested KVM to adt-virt-lxc
by simply allowing the administrator to specify an additional qcow2
base image on the command line. That could be done in an additional
step.

I've updated the documentation to reflect the base image changes.

It would be great if that could be added to autopkgtest.

Thanks!

Regards,
Christian
From d091f958e1a61cbf4d3296c4267d011ba3c6dbd4 Mon Sep 17 00:00:00 2001
From: Christian Seiler <[email protected]>
Date: Sun, 4 Oct 2015 12:25:39 +0200
Subject: [PATCH 1/2] Add 'needs-qcow2-baseimage' restriction

Add restrictions that allows tests to require a qcow2 base image be
present inside the test environment, so that e.g. nested VM tests are
possible.
---
 doc/README.package-tests.rst | 20 ++++++++++++++++++++
 lib/testdesc.py              |  9 ++++++++-
 virt-subproc/adt-virt-qemu   | 25 ++++++++++++++++++++++---
 virt-subproc/adt-virt-qemu.1 | 10 ++++++++++
 4 files changed, 60 insertions(+), 4 deletions(-)

diff --git a/doc/README.package-tests.rst b/doc/README.package-tests.rst
index e1127cb..5872617 100644
--- a/doc/README.package-tests.rst
+++ b/doc/README.package-tests.rst
@@ -202,6 +202,26 @@ needs-recommends
     Enable installation of recommended packages in apt for the test
     dependencies. This does not affect build dependencies.
 
+needs-qcow2-baseimage
+    The test needs to have a read-only qcow2 base image available so it
+    may create an overlay and start a qemu/KVM virtual machine inside
+    the test environment.
+
+    This is useful for testing network client packages that require
+    kernel support (NFS, CIFS, iSCSI, NBD, etc.): the external testing
+    environment sets up a minimalistic server environment and then
+    starts a virtual machine that tests the client.
+
+    While currently only adt-virt-qemu supports this, this options is
+    independent of the isolation level. If the setup of the server also
+    needs a specific isolation level, that should be specified
+    additionally.
+
+    The environment variable ADT_QCOW2_BASEIMAGE will be set to the
+    absolute path of the qcow2 base image. If the test environment
+    supports it, this variable will be available irrespective of
+    whether this restriction was added to the test or not.
+
 Defined features
 ----------------
 
diff --git a/lib/testdesc.py b/lib/testdesc.py
index 260b2fa..33fdb7f 100644
--- a/lib/testdesc.py
+++ b/lib/testdesc.py
@@ -42,7 +42,8 @@ import adtlog
 
 known_restrictions = ['rw-build-tree', 'breaks-testbed', 'needs-root',
                       'build-needed', 'allow-stderr', 'isolation-container',
-                      'isolation-machine', 'needs-recommends']
+                      'isolation-machine', 'needs-recommends',
+                      'needs-qcow2-baseimage']
 
 
 class Unsupported(Exception):
@@ -161,6 +162,12 @@ class Test:
                               'Test needs root on testbed which is not '
                               'available')
 
+        if 'needs-qcow2-baseimage' in self.restrictions and \
+           'provides-qcow2-baseimage' not in caps:
+            raise Unsupported(self.name,
+                              'Test needs qcow2 testimage inside testbed which '
+                              'is not available')
+
 #
 # Parsing for Debian source packages
 #
diff --git a/virt-subproc/adt-virt-qemu b/virt-subproc/adt-virt-qemu
index 6e3989a..2bed237 100755
--- a/virt-subproc/adt-virt-qemu
+++ b/virt-subproc/adt-virt-qemu
@@ -80,6 +80,8 @@ def parse_args():
                         help='Enable debugging output')
     parser.add_argument('--qemu-options',
                         help='Pass through arguments to QEMU command.')
+    parser.add_argument('--nested-qcow2-baseimage',
+                        help='qcow2 VM base image for use inside the VM (nested VMs)')
     parser.add_argument('image', nargs='+',
                         help='disk image to add to the VM (in order)')
 
@@ -87,6 +89,8 @@ def parse_args():
 
     if args.debug:
         adtlog.verbosity = 2
+    if args.nested_qcow2_baseimage == None and len(args.image) == 1:
+        args.nested_qcow2_baseimage = args.image[0]
 
 
 def prepare_overlay():
@@ -274,6 +278,10 @@ EOF
 def make_auxverb(shared_dir):
     '''Create auxverb script'''
 
+    envvars = ''
+    if args.nested_qcow2_baseimage != None:
+        envvars += 'export ADT_QCOW2_BASEIMAGE=/dev/vd%c ; ' % chr(ord('a') + len(args.image))
+
     auxverb = os.path.join(workdir, 'runcmd')
     with open(auxverb, 'w') as f:
         f.write('''#!%(py)s
@@ -340,7 +348,8 @@ t_stderr.start()
 s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
 s.connect('%(tty)s')
 cmd = '/bin/eofcat %%(d)s/stdin_eof %%(d)s/exit.tmp < %%(d)s/stdin | ' \\
-      '(%%(c)s >> %%(d)s/stdout 2>> %%(d)s/stderr; echo $? > %%(d)s/exit.tmp);' \\
+      '(%(envvars)s ' \\
+      '%%(c)s >> %%(d)s/stdout 2>> %%(d)s/stderr; echo $? > %%(d)s/exit.tmp);' \\
       'mv %%(d)s/exit.tmp %%(d)s/exit\\n' %% \\
        {'d': job_guest, 'c': ' '.join(map(pipes.quote, sys.argv[1:]))}
 s.send(cmd.encode())
@@ -369,7 +378,8 @@ t_stdin.join()
 t_stdout.join()
 t_stderr.join()
 sys.exit(rc)
-''' % {'py': sys.executable, 'tty': os.path.join(workdir, 'ttyS1'), 'dir': shared_dir})
+''' % {'py': sys.executable, 'tty': os.path.join(workdir, 'ttyS1'), 'dir': shared_dir,
+       'envvars' : envvars})
 
     os.chmod(auxverb, 0o755)
 
@@ -475,6 +485,13 @@ def hook_open():
     for i, image in enumerate(args.image[1:]):
         argv.append('-drive')
         argv.append('file=%s,if=virtio,index=%i,readonly' % (image, i + 1))
+    if args.nested_qcow2_baseimage != None:
+        # export base image as drive (it's the easiest way to get
+        # it into QEMU), but make sure format=raw is set, because
+        # we want the VM to be able to see it as a qcow2 image and
+        # not have QEMU interpret it
+        argv.append('-drive')
+        argv.append('file=%s,if=virtio,index=%i,readonly,format=raw' % (args.nested_qcow2_baseimage, len(args.image)))
 
     if os.path.exists('/dev/kvm'):
         argv.append('-enable-kvm')
@@ -550,13 +567,15 @@ def hook_forked_inchild():
 
 
 def hook_capabilities():
-    global normal_user
+    global normal_user, args
     caps = ['revert', 'revert-full-system', 'root-on-testbed',
             'isolation-machine', 'reboot']
     # disabled, see hook_downtmp()
     # caps.append('downtmp-host=%s' % os.path.join(workdir, 'shared', 'tmp'))
     if normal_user:
         caps.append('suggested-normal-user=' + normal_user)
+    if args.nested_qcow2_baseimage != None:
+        caps.append('provides-qcow2-baseimage')
     return caps
 
 
diff --git a/virt-subproc/adt-virt-qemu.1 b/virt-subproc/adt-virt-qemu.1
index 0c5718f..19f2f1d 100644
--- a/virt-subproc/adt-virt-qemu.1
+++ b/virt-subproc/adt-virt-qemu.1
@@ -97,6 +97,16 @@ Enable debugging output.
 .BI "--qemu-options=" arguments
 Pass through arguments to QEMU command; e. g. --qemu-options='-readconfig qemu.cfg'
 
+.TP
+.BI "--nested-qcow2-baseimage=" image
+Base image (in qcow2 format) that is passed through to the VM in read-only
+mode. It may then be used by the container to create an overlay qcow2 image on
+top of it and start a nested VM. If there is only one image specified to
+.BR adt-virt-qemu ,
+this option defaults to that image. If there is more one image specified, it
+doesn't have a default value, so the option should be specified if running
+tests that require nested VMs is to be supported.
+
 .SH CONFIGURATION FILES
 If you use lots of options or images, you can put parts of, or the whole
 command line into a text file, with one line per option. E. g. you can create a
-- 
2.1.4

From 11703001b3e9c4c4af87e838a8d30f523fdf9b39 Mon Sep 17 00:00:00 2001
From: Christian Seiler <[email protected]>
Date: Sun, 4 Oct 2015 13:11:06 +0200
Subject: [PATCH 2/2] adt-virt-qemu: emulate host-type CPU

In order to make nested KVM work, the emulated CPU needs to support
virtualization. The easiest way to do that that doesn't require lots of
compatibility checks is to tell QEMU to emulate the host CPU. This will
only work in KVM mode, so only enable it there.

This does not guarantee that nested KVM will work (the host's KVM
module has to have the appropriate option set), but it is required.
---
 virt-subproc/adt-virt-qemu | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/virt-subproc/adt-virt-qemu b/virt-subproc/adt-virt-qemu
index 2bed237..85e7bbd 100755
--- a/virt-subproc/adt-virt-qemu
+++ b/virt-subproc/adt-virt-qemu
@@ -495,6 +495,10 @@ def hook_open():
 
     if os.path.exists('/dev/kvm'):
         argv.append('-enable-kvm')
+        # emulate host CPU so that nested KVM might work (if it's
+        # enabled)
+        argv.append('-cpu')
+        argv.append('host')
 
     # pass through option to qemu
     if args.qemu_options:
-- 
2.1.4

Attachment: signature.asc
Description: OpenPGP digital signature


--- End Message ---
--- Begin Message ---
Source: autopkgtest
Source-Version: 3.20

We believe that the bug you reported is fixed in the latest version of
autopkgtest, which is due to be installed in the Debian FTP archive.

A summary of the changes between this version and the previous one is
attached.

Thank you for reporting the bug, which will now be closed.  If you
have further comments please address them to [email protected],
and the maintainer will reopen the bug report if appropriate.

Debian distribution maintenance software
pp.
Martin Pitt <[email protected]> (supplier of updated autopkgtest package)

(This message was generated automatically at their request; if you
believe that there is a problem with it please contact the archive
administrators by mailing [email protected])


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Format: 1.8
Date: Fri, 11 Mar 2016 10:05:08 +0100
Source: autopkgtest
Binary: autopkgtest
Architecture: source all
Version: 3.20
Distribution: unstable
Urgency: medium
Maintainer: Autopkgtest team <[email protected]>
Changed-By: Martin Pitt <[email protected]>
Description:
 autopkgtest - automatic as-installed testing for Debian packages
Closes: 800845 814115 817190
Changes:
 autopkgtest (3.20) unstable; urgency=medium
 .
   New features/behaviour changes:
 .
   [Martin Pitt]
   * adt-virt-lxd: Launch containers in ephemeral mode.
   * adt-virt-lxc: Use the new lxc-copy if available, as lxc-clone and
     lxc-start-ephemeral got deprecated by that. This now supports reboots in
     ephemeral mode.
   * adt-virt-lxc: Add --name option. This allows CI systems to use a more
     expressive name than the autogenerated adt-virt-lxc-XXXXXX, to make it
     easier to map a container to a running test.
   * Add CPU information to testinfo.json: "nproc" (#cpus), "cpu_model", and
     "cpu_flags". (LP: #1552129)
   * Add autopkgtest for adt-build-lxd and the lxd runner.
 .
   [ Christian Seiler ]
   * Support nested KVM by default by emulating a CPU with VMX/SVM support on
     x86_64. (Closes: #800845, part 1)
   * adt-virt-qemu: Provide read-only version of the VM image to the test as
     /dev/baseimage, for tests that want to run nested QEMU. (Closes: #800845)
 .
   Bug fixes:
 .
   [ Martin Pitt ]
   * setup-commands/setup-testbed: Ensure that removing cruft does not remove
     cloud-init. (LP: #1539126)
   * setup-commands/setup-testbed: Purge lxd and lxc.
   * adt-virt-lxc: Don't fail on deprecation warnings of lxc-clone and
     lxc-start-ephemeral. (LP: #1549995)
   * Run external commands with /dev/null as stdin. This has always been
     intended, but has not actually been done for a while.
   * Drop support for hook_forked_inchild() in virt-runners. This has never
     been used.
   * ssh-setup/nova: Try and prefer novaclient.v2 API first, and fall back to
     v1_1. (LP: #1552730)
   * Correctly ignore positive and negative build profiles with too old
     libdpkg-perl that does not support them yet.
   * tests/run-parallel: Don't run NullRunner and SchrootRunner tests in
     parallel, as they collide with a bind-mounted /tmp.
   * test_reboot_prepare testcase: Don't compare the host and guest kernel
     versions in the QemuRunner.
   * Keep and export $ADTTMP and $ADT_ARTIFACTS in debug shells.
     (Closes: #814115)
   * setup-commands/*: Add shebang headers to quiesce lintian.
   * Bump Standards-Version to 3.9.7 (no changes necessary).
   * Add debian/source/format (3.0 native).
   * debian/control: Use https Vcs-* links.
   * Bump debhelper compat level to 9.
   * adt-virt-qemu: Don't assert result of "runlevel" for connection test. This
     is a race condition under systemd as getty starts before default.target
     is fully finished.
   * tests/adt-run SchrootClickRunner: Ensure that the "click" system user
     exists in the schroot, so that it doesn't need to exist on the host.
   * Adjust SchrootRunner.test_apt_pocket_pkg_with_proposed_dep test case for
     apt 1.1.
   * Latest LXD now adds an "images" remote for images.linuxcontainers.org by
     default. Adjust adt-build-lxd.1 and adt-virt-lxd.1 accordingly.
   * Respect $TMPDIR when creating the downtmp and some other directory/files.
     (Closes: #817190)
   * tests/adt-run: Symlink real ~/.config/lxc into the temporary $HOME, to
     avoid regenerating the LXD client certificate for each test.
 .
   [ Christian Seiler ]
   * setup-testbed: reduce grub timeout on images that don't already configure
     this in /etc/default/grub.d (like vmdeboostrap).
   * adt-virt-qemu: Use correct qemu-system-i386 command on i[3456]86 systems.
   * Fix spelling errors in manpages.
Checksums-Sha1:
 fa6d1dcdc784fbc0a66564089380bcb7b8c761b7 1777 autopkgtest_3.20.dsc
 8dbf967a8ba76b3e686e441d961e10d73b46fc49 157504 autopkgtest_3.20.tar.xz
 d9613e2d68663c7a59304636eef9c49ff42d3408 167712 autopkgtest_3.20_all.deb
Checksums-Sha256:
 37cd91c1ce9a75b5b7faab4dfc034bd8e9a6cf6105c520b39c86d213b7badc1b 1777 
autopkgtest_3.20.dsc
 42103b3e135e9b7aae1951b2d6c9fe70e4aaae97ca1fde07d590d03797c6209d 157504 
autopkgtest_3.20.tar.xz
 67eebd80466f1051b5cc219231ed2fa696e3b797458e23da142269963d369a8b 167712 
autopkgtest_3.20_all.deb
Files:
 86974c2283a909da2bedf6340b76dd0a 1777 devel optional autopkgtest_3.20.dsc
 85a7a80ef6ab8e83cf2acffd57250800 157504 devel optional autopkgtest_3.20.tar.xz
 1fdfc6f83281f825e9552b3f77c69a36 167712 devel optional autopkgtest_3.20_all.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJW4ouWAAoJENFO8V2v4RNHKwEQAKpNKdm8pRGnuzsE/S9QTkWJ
4alA5n7e1Kt/8bufCpjQ0X/6GgHCq3AkBu7vtBwgL9QBAbV/EAYGRCPNTAzYva7D
M4diZtMOdUWXi9+tBCF9MCE1JrL3mI7u794wroqW1u1jlQJNFc0G+2l0FuSk+hZK
xGT6Zf6QbiQmfi0dq6kVx7cwUCKLXy5JVjbOYxdP+m2RAMHTZ6SFgZePFB/YW0Q0
nBWeoI4sOa668oS74LDOQdp2fGOn1ABvQWtiJjPk/yExfDuAWMJAoKQoYnG6CuDh
BFqznveE5ksd+MHqBRxtrQwNLm5gOgW5papSstSJOQ2V7EZOkQj9Il8de2jkvyVP
UGh+Xv6ZWsw4rDJURIo2FrlAQlKP8KdFVFtzPrEqOL4xqd7Duwl4FbTz2jM/sGQl
Kh0bLDJDOCvViIzHPsXsJ/28/37jyX24OoWIVW0CpPTjbA2v45kLmGNRHN4g+5rd
tYD7gy9Ju1cf1ZKbr8jLDMWsluLMSudYQa5RS/n3DK9zrGu+wwbb9KvK0dVo59EY
akIFbkKWi8qOWP8Pq44K8TzjlLWOuFKjJ/HTGUdDVeHT+5cTJhSE0NEfX+hWDFNU
xCl3LMq0UEg+Cc7wdgK3l8hSp+RILIDjxboprQBpVqxLcEV1z1Lq4mWAdUABIDpF
PX2Id2wAx5spcb7gpWnp
=kdAB
-----END PGP SIGNATURE-----

--- End Message ---

Reply via email to