Bug#854047: autopkgtest-buildvm-ubuntu-cloud: Support file:// for --mirror

Iain Lane laney at debian.org
Fri Feb 3 12:54:17 UTC 2017

Package: src:autopkgtest
Version: 4.3
Severity: wishlist
Tags: patch upstream

Hi there,

I wanted to work on an autopkgtest bug in the qemu runner on the train.
I've got a full mirror around which is available on my system. Currently
autopkgtest-buildvm-ubuntu-cloud doesn't support file:// for --mirror
though - the mirror isn't made available inside the VM.

Maybe I could already achieve this by manually passing qemu parameters,
but it's possible to support this OOTB. That's what the attached patch
does. It makes it so that "--mirror file://foo" is mounted as
/mirrors/ubuntu inside the VM.

When you run the actual tests ("-- qemu foo.img"), you also have to tell
the qemu runner where to find the mirror so that it can mount it. For
that I added a new "--localmirror" option. This isn't DRY as you've
already given that information when building the VM, but I don't know
how to avoid that. I hope it's acceptable.

Review / ideas for improvement appreciated!

Iain Lane                                  [ iain at orangesquash.org.uk ]
Debian Developer                                   [ laney at debian.org ]
Ubuntu Developer                                   [ laney at ubuntu.com ]
-------------- next part --------------
>From 872c7dfff9b0f883816a6c795068922c8037d397 Mon Sep 17 00:00:00 2001
From: Iain Lane <iain.lane at canonical.com>
Date: Fri, 3 Feb 2017 12:35:57 +0000
Subject: [PATCH] autopkgtest-buildvm-ubuntu-cloud: Support mounting file:///
 mirrors inside the VM

Mount the mirror inside the VM as /mirrors/ubuntu. For this to be
automounted at startup, we need to load the '9pnet_virtio' module in the

There's a corresponding new --localmirror option to
autopkgtest-virt-qemu, which mounts the directory when the image is used
for testing. It would be nice to not have to specify the same thing
again since you already gave it to autopkgtest-buildvm-ubuntu-cloud, but
I don't know how to avoid this.
 tools/autopkgtest-buildvm-ubuntu-cloud | 23 ++++++++++++++++++++---
 virt/autopkgtest-virt-qemu             | 10 ++++++++++
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/tools/autopkgtest-buildvm-ubuntu-cloud b/tools/autopkgtest-buildvm-ubuntu-cloud
index 34662b1..4a44b68 100755
--- a/tools/autopkgtest-buildvm-ubuntu-cloud
+++ b/tools/autopkgtest-buildvm-ubuntu-cloud
@@ -217,7 +217,10 @@ ssh_pwauth: True
 manage_etc_hosts: True
 apt_proxy: %(proxy)s
 apt_mirror: %(mirror)s
+ - %(mount)s
+ - echo "9pnet_virtio" | tee -a /etc/initramfs-tools/modules; update-initramfs -u
  - sed -i 's/deb-systemd-invoke/true/' /var/lib/dpkg/info/cloud-init.prerm
  - mount -r /dev/vdb /mnt
@@ -239,6 +242,13 @@ def build_seed(mirror, proxy, no_apt_upgrade, metadata_file=None,
     with open(os.path.join(workdir, 'meta-data'), 'w') as f:
+    # If this is a local mirror, mount it at /mirror
+    if mirror.startswith('file://'):
+        mirror = 'file:///mirror/ubuntu'
+        mounts = '[mirror, /mirror/ubuntu, 9p, "trans=virtio,version=9p2000.L"]'
+    else:
+        mounts = '[]'
     upgr = no_apt_upgrade and 'false' or 'true'
     if userdata_file:
         userdata = open(userdata_file).read()
@@ -246,7 +256,8 @@ def build_seed(mirror, proxy, no_apt_upgrade, metadata_file=None,
         userdata = DEFAULT_USERDATA % {'proxy': proxy or '', 'mirror': mirror,
                                        'upgr': upgr, 'tz': host_tz(),
                                        'postcmd': post_command or '',
-                                       'shopt': verbose and '-x' or ''}
+                                       'shopt': verbose and '-x' or '',
+                                       'mount': mounts}
     # preserve proxy from host
     for v in ['http_proxy', 'https_proxy', 'no_proxy']:
@@ -303,7 +314,7 @@ def host_tz():
     return 'Etc/UTC'
-def boot_image(image, seed, qemu_command, verbose, timeout):
+def boot_image(image, seed, qemu_command, verbose, timeout, mirror):
     print('Booting image to run cloud-init...')
     tty_sock = os.path.join(workdir, 'ttyS0')
@@ -317,6 +328,12 @@ def boot_image(image, seed, qemu_command, verbose, timeout):
             '-drive', 'file=%s,if=virtio' % image,
             '-drive', 'file=%s,if=virtio,readonly' % seed]
+    # if this is a local mirror, we need to mount it inside the VM
+    if mirror and mirror.startswith('file://'):
+        m = mirror[7:]
+        argv.append('-virtfs')
+        argv.append('local,id=mirror,path=%s,security_model=none,readonly,mount_tag=mirror' % m)
     if os.path.exists('/dev/kvm'):
@@ -360,7 +377,7 @@ image = download_image(args.cloud_image_url, args.release, args.arch)
 resize_image(image, args.disk_size)
 seed = build_seed(args.mirror, args.proxy, args.no_apt_upgrade,
                   args.metadata, args.userdata, args.post_command, args.verbose)
-boot_image(image, seed, args.qemu_command, args.verbose, args.timeout)
+boot_image(image, seed, args.qemu_command, args.verbose, args.timeout, args.mirror)
 if 'adt-buildvm' in sys.argv[0]:
     fname = 'adt-%s-%s-cloud.img' % (args.release, args.arch)
diff --git a/virt/autopkgtest-virt-qemu b/virt/autopkgtest-virt-qemu
index eb3b162..35c4990 100755
--- a/virt/autopkgtest-virt-qemu
+++ b/virt/autopkgtest-virt-qemu
@@ -84,6 +84,12 @@ def parse_args():
                         help='timeout for waiting for reboot (default: %(default)ss)')
     parser.add_argument('--show-boot', action='store_true',
                         help='Show boot messages from serial console')
+    parser.add_argument('--localmirror',
+                        help='Path to a directory containing a full archive '
+                        'mirror to use inside the VM. Will be mounted inside '
+                        'the VM, which must already be configured to use '
+                        'this directory for APT (e.g. by '
+                        'autopkgtest-buildvm-ubuntu-cloud --mirror).')
     parser.add_argument('-d', '--debug', action='store_true',
                         help='Enable debugging output')
@@ -544,6 +550,10 @@ def hook_open():
         argv.append('file=%s,if=virtio,index=%i,readonly' % (image, i + 1))
+    if args.localmirror:
+        argv.append('-virtfs')
+        argv.append('local,id=mirror,path=%s,security_model=none,mount_tag=mirror' % args.localmirror)
     if os.path.exists('/dev/kvm'):
         # Enable nested KVM by default on x86_64

More information about the autopkgtest-devel mailing list