Hi Martin,

On 03/06/2016 04:29 PM, Christian Seiler wrote:
> What you _could_ do is create a flag file in /run and update the reboot
> script to update the initramfs before rebooting if that flag file is
> set - that way only if a reboot is needed will the initramfs be updated
> and hence you optimize for the common case where that's not needed.

So this took me longer than I hoped, because a kernel update on my host
screwed up QEMU's support for rebooting VMs in general - and it was a
real pain to figure that out.

Now that that works again:

I've implemented this in the following way:

 - touch /run/autopkgtest-update-initramfs-at-reboot in setup_baseimage()
 - /sbin/autopkgtest-reboot{,-prepare}:
      - if /run/autopkgtest-update-initramfs-at-reboot exists AND 
           update-initramfs is present, update the initramfs
 - /usr/share/initramfs-tools/hooks/autopkgtest (created in
   setup_baseimage()):
      - unconditionally remove /run/autopkgtest-update-initramfs-at-reboot
        Because a initramfs-tools hook will only be called if an initramfs
        is generated - but if it's generated anyway, we might as well
        remove the flag file, because then we can save ourselves a lot of
        work.

So basically, IF a reboot is requested AND no initramfs was generated
since, THEN and ONLY THEN will update-initramfs be called. So we minimize
how often it's required to actually generate it.

Tested it against my update open-iscsi package tests (see my RFC mail),
and it works without a hitch.

Patch is attached.

Hopefully that satisfies your performance requirements?

Regards,
Christian
From f4652b649883e2d11aeb7354e3dcf4e52135e5e1 Mon Sep 17 00:00:00 2001
From: Christian Seiler <christ...@iwakd.de>
Date: Sun, 6 Mar 2016 17:04:24 +0100
Subject: [PATCH] adt-virt-qemu: regenerate initramfs only on reboots

The initramfs needs to be regenerated due to UUID collisions with the
baseimage drive, but we only need to do that if the testbed is
rebooted. So in turn just set a flag file and only regenerate the
initramfs when a reboot is requested.
---
 lib/adt_testbed.py         |  6 ++++++
 virt-subproc/adt-virt-qemu | 14 ++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/lib/adt_testbed.py b/lib/adt_testbed.py
index 2e6dffd..30ee075 100644
--- a/lib/adt_testbed.py
+++ b/lib/adt_testbed.py
@@ -142,6 +142,9 @@ class Testbed:
             self.execute(['sh', '-ecC', '''[ ! -e /tmp/autopkgtest-reboot ] || exit 0; '''
                           '''/bin/echo -e '#!/bin/sh -e\\n'''
                           '''[ -n "$1" ] || { echo "Usage: $0 <mark>" >&2; exit 1; }\\n'''
+                          '''[ ! -e "/run/autopkgtest-update-initramfs-at-reboot" ] || {'''
+                          '''  if type update-initramfs >/dev/null 2>&1; then '''
+                          '''    update-initramfs -k all -u; fi; }\\n'''
                           '''echo "$1" > /run/autopkgtest-reboot-mark\\n'''
                           '''test_script_pid=$(cat /tmp/adt_test_script_pid)\\n'''
                           '''p=$PPID; while true; do read _ c _ pp _ < /proc/$p/stat;'''
@@ -154,6 +157,9 @@ class Testbed:
             self.execute(['sh', '-ecC', '''[ ! -e /tmp/autopkgtest-reboot-prepare ] || exit 0; '''
                           '''/bin/echo -e '#!/bin/sh -e\\n'''
                           '''[ -n "$1" ] || { echo "Usage: $0 <mark>" >&2; exit 1; }\\n'''
+                          '''[ ! -e "/run/autopkgtest-update-initramfs-at-reboot" ] || {'''
+                          '''  if type update-initramfs >/dev/null 2>&1; then '''
+                          '''    update-initramfs -k all -u; fi; }\\n'''
                           '''echo "$1" > /run/autopkgtest-reboot-prepare-mark\\n'''
                           '''test_script_pid=$(cat /tmp/adt_test_script_pid)\\n'''
                           '''kill -KILL $test_script_pid\\n'''
diff --git a/virt-subproc/adt-virt-qemu b/virt-subproc/adt-virt-qemu
index 2116be1..a0f1339 100755
--- a/virt-subproc/adt-virt-qemu
+++ b/virt-subproc/adt-virt-qemu
@@ -208,6 +208,20 @@ def setup_baseimage():
     term.send(b'udevadm settle --exit-if-exists=/dev/baseimage\n')
     VirtSubproc.expect(term, b'#', 10)
 
+    # The initramfs needs to be regenerated to include the new udev
+    # rules, but this is only necesssary if the testbed is rebooted, so
+    # just touch a flag file.
+    term.send(b'touch /run/autopkgtest-update-initramfs-at-reboot\n')
+    VirtSubproc.expect(term, b'#', 10)
+
+    # Add an update-initramfs hook that removes the flag file, because
+    # if the test case calls update-initramfs anyway, we don't need to
+    # do so ourselves.
+    term.send(b'''if [ -d /usr/share/initramfs-tools/hooks ] ; then '''
+              b'''printf '#!/bin/sh\\nrm -f %s\\nexit 0\\n' "/run/autopkgtest-update-initramfs-at-reboot" '''
+              b'''> /usr/share/initramfs-tools/hooks/autopkgtest; '''
+              b'''chmod +x /usr/share/initramfs-tools/hooks/autopkgtest; fi\n''')
+    VirtSubproc.expect(term, b'#', 10)
 
 def setup_shared(shared_dir):
     '''Set up shared dir'''
-- 
2.1.4

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to