[PATCH 11/12] automation: stubdom test with boot from CDROM

Marek Marczykowski-Górecki posted 12 patches 6 months, 1 week ago
[PATCH 11/12] automation: stubdom test with boot from CDROM
Posted by Marek Marczykowski-Górecki 6 months, 1 week ago
Based on the initial stubdomain test add booting from CDOM. It's
significantly different in terms of emulated devices (contrary to PV
disk, the cdrom is backed by qemu), so test that path too.
Schedule it on the AMD runner, as it has less tests right now.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
---
 automation/build/alpine/3.19-arm64v8.dockerfile   |  1 +-
 automation/gitlab-ci/build.yaml                   |  2 +-
 automation/gitlab-ci/test.yaml                    |  8 ++-
 automation/scripts/qubes-x86-64.sh                | 58 +++++++++++-----
 automation/tests-artifacts/alpine/3.19.dockerfile |  3 +-
 5 files changed, 56 insertions(+), 16 deletions(-)

diff --git a/automation/build/alpine/3.19-arm64v8.dockerfile b/automation/build/alpine/3.19-arm64v8.dockerfile
index 12810f87ecc6..03a3f28ff686 100644
--- a/automation/build/alpine/3.19-arm64v8.dockerfile
+++ b/automation/build/alpine/3.19-arm64v8.dockerfile
@@ -49,3 +49,4 @@ RUN apk --no-cache add \
   fakeroot \
   sfdisk \
   e2fsprogs \
+  xorriso \
diff --git a/automation/gitlab-ci/build.yaml b/automation/gitlab-ci/build.yaml
index 134a01d03efa..f1e6a6144c90 100644
--- a/automation/gitlab-ci/build.yaml
+++ b/automation/gitlab-ci/build.yaml
@@ -324,10 +324,12 @@ alpine-3.19-rootfs-export:
   script:
     - mkdir binaries && cp /initrd.tar.gz binaries/initrd.tar.gz
     - cp /grub-core.img binaries/grub-core.img
+    - cp /grub-core-eltorito.img binaries/grub-core-eltorito.img
   artifacts:
     paths:
       - binaries/initrd.tar.gz
       - binaries/grub-core.img
+      - binaries/grub-core-eltorito.img
   tags:
     - x86_64
 
diff --git a/automation/gitlab-ci/test.yaml b/automation/gitlab-ci/test.yaml
index 76cc430ae00f..4e4dca91c26e 100644
--- a/automation/gitlab-ci/test.yaml
+++ b/automation/gitlab-ci/test.yaml
@@ -239,6 +239,14 @@ zen3p-pci-stubdom-x86-64-gcc-debug:
     - *x86-64-test-needs
     - alpine-3.19-gcc-debug
 
+zen3p-stubdom-hvm-cdboot-x86-64-gcc-debug:
+  extends: .zen3p-x86-64
+  script:
+    - ./automation/scripts/qubes-x86-64.sh stubdom-hvm-cdboot 2>&1 | tee ${LOGFILE}
+  needs:
+    - *x86-64-test-needs
+    - alpine-3.19-gcc-debug
+
 qemu-smoke-dom0-arm64-gcc:
   extends: .qemu-arm64
   script:
diff --git a/automation/scripts/qubes-x86-64.sh b/automation/scripts/qubes-x86-64.sh
index 816c16fbab3e..b4f5c846ffe3 100755
--- a/automation/scripts/qubes-x86-64.sh
+++ b/automation/scripts/qubes-x86-64.sh
@@ -19,6 +19,7 @@ vif = [ "bridge=xenbr0", ]
 disk = [ ]
 '
 domU_disk_path=
+domU_disk_type=disk
 
 ### helper functions
 
@@ -27,27 +28,47 @@ build_domU_disk() {
     local initrd="$2"
     local rootfs="$3"
     local output="$4"
+    local img_type="$5"
     local grubcfg="$rootfs/boot/grub2/grub.cfg"
-    local kernel_cmdline="root=/dev/xvda1 console=hvc0 earlyprintk=xen"
+    local kernel_cmdline
 
     mkdir -p "$rootfs/boot/grub2"
     cp "$kernel" "$rootfs/boot/vmlinuz"
+    if [ "$img_type" = "disk" ]; then
+        kernel_cmdline="root=/dev/xvda1 console=hvc0 earlyprintk=xen"
+    elif [ "$img_type" = "cdrom" ]; then
+        kernel_cmdline="root=/dev/sr0 console=hvc0 earlyprintk=xen"
+    fi
     echo "linux /boot/vmlinuz $kernel_cmdline" >> "$grubcfg"
     if [ -n "$initrd" ]; then
         cp "$initrd" "$rootfs/boot/initrd.img"
         echo "initrd /boot/initrd.img" >> "$grubcfg"
     fi
     echo "boot" >> "$grubcfg"
-    size=$(du -sm "$rootfs")
-    size=${size%%	*}
-    # add 5M margin
-    size=$(( size + 5 ))
-    mke2fs -d "$rootfs" "$output.part1" ${size}m
-    cat "$rootfs/usr/lib/grub/i386-pc/boot_hybrid.img" binaries/grub-core.img > "$output"
-    # align for the partition 1 start (2048 sectors)
-    truncate -s $((2048 * 512)) "$output"
-    cat "$output.part1" >> "$output"
-    echo ",,linux,*" | sfdisk "$output"
+    if [ "$img_type" = "disk" ]; then
+        size=$(du -sm "$rootfs")
+        size=${size%%	*}
+        # add 5M margin
+        size=$(( size + 5 ))
+        mke2fs -d "$rootfs" "$output.part1" ${size}m
+        cat "$rootfs/usr/lib/grub/i386-pc/boot_hybrid.img" binaries/grub-core.img > "$output"
+        # align for the partition 1 start (2048 sectors)
+        truncate -s $((2048 * 512)) "$output"
+        cat "$output.part1" >> "$output"
+        echo ",,linux,*" | sfdisk "$output"
+    elif [ "$img_type" = "cdrom" ]; then
+        cp binaries/grub-core-eltorito.img "$rootfs/boot/"
+        xorriso -as mkisofs \
+            -o "$output" \
+            -b boot/grub-core-eltorito.img \
+            -no-emul-boot \
+            -boot-load-size 4 \
+            -boot-info-table \
+            "$rootfs"
+    else
+        echo "Invalid img_type: $img_type" >&2
+        return 1
+    fi
 }
 
 ### test: smoke test & smoke test PVH
@@ -168,16 +189,22 @@ until grep -q \"^domU Welcome to Alpine Linux\" /var/log/xen/console/guest-domU.
 done
 "
 
-### test: stubdom-hvm
-elif [ "${test_variant}" = "stubdom-hvm" ]; then
+### test: stubdom-hvm, stubdom-hvm-cdboot
+elif [ "${test_variant}" = "stubdom-hvm" ] || [ "${test_variant}" = "stubdom-hvm-cdboot" ] ; then
     passed="ping test passed"
 
+    disk_opts=
+    if [ "${test_variant}" = "stubdom-hvm-cdboot" ]; then
+        disk_opts=",devtype=cdrom"
+        domU_disk_type="cdrom"
+    fi
+
     domU_config='
 type = "hvm"
 name = "domU"
 memory = 512
 vif = [ "bridge=xenbr0", ]
-disk = [ "/srv/disk.img,format=raw,vdev=xvda" ]
+disk = [ "/srv/disk.img,format=raw,vdev=xvda'"$disk_opts"'" ]
 device_model_version = "qemu-xen"
 device_model_stubdomain_override = 1
 on_reboot = "destroy"
@@ -229,7 +256,8 @@ if [ -n "$domU_disk_path" ]; then
         "binaries/bzImage" \
         "" \
         "rootfs" \
-        "binaries/disk.img"
+        "binaries/disk.img" \
+        "$domU_disk_type"
 else
     (cd rootfs; find . | fakeroot -i ../fakeroot-save cpio -H newc -o | gzip > ../binaries/domU-rootfs.cpio.gz)
 fi
diff --git a/automation/tests-artifacts/alpine/3.19.dockerfile b/automation/tests-artifacts/alpine/3.19.dockerfile
index cfb2cb30fb30..7632b694c3da 100644
--- a/automation/tests-artifacts/alpine/3.19.dockerfile
+++ b/automation/tests-artifacts/alpine/3.19.dockerfile
@@ -68,4 +68,5 @@ RUN \
   cd / && \
   tar cvzf /initrd.tar.gz bin dev etc home init lib mnt opt root sbin usr var && \
   # Prepare boot sector for HVM disk
-  grub-mkimage -o /grub-core.img -O i386-pc -p '(hd0,msdos1)/boot/grub2' boot part_msdos ext2 linux biosdisk configfile normal
+  grub-mkimage -o /grub-core.img -O i386-pc -p '(hd0,msdos1)/boot/grub2' boot part_msdos ext2 linux biosdisk configfile normal && \
+  grub-mkimage -o /grub-core-eltorito.img -O i386-pc-eltorito -p '(cd)/boot/grub2' boot part_msdos ext2 linux biosdisk configfile normal iso9660
-- 
git-series 0.9.1