[Libguestfs] [PATCH 1/3] test-data/phony-guests: Add Fedora LUKS phony image for testing.

Richard W.M. Jones rjones at redhat.com
Wed Jul 18 13:37:23 UTC 2018


This is not added to guests-all-good since it cannot be used in
automated tests -- a password must be supplied.
---
 .gitignore                                |  1 +
 test-data/phony-guests/Makefile.am        |  8 ++++
 test-data/phony-guests/guests.xml.in      | 49 +++++++++++++++--------
 test-data/phony-guests/make-fedora-img.pl | 29 ++++++++++++++
 4 files changed, 71 insertions(+), 16 deletions(-)

diff --git a/.gitignore b/.gitignore
index d855459f3..bb4f45e0a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -650,6 +650,7 @@ Makefile.in
 /test-data/phony-guests/debian.img
 /test-data/phony-guests/fedora.img
 /test-data/phony-guests/fedora-btrfs.img
+/test-data/phony-guests/fedora-luks.img
 /test-data/phony-guests/fedora-md1.img
 /test-data/phony-guests/fedora-md2.img
 /test-data/phony-guests/fedora-name.db
diff --git a/test-data/phony-guests/Makefile.am b/test-data/phony-guests/Makefile.am
index 4e978f654..6a0d23e04 100644
--- a/test-data/phony-guests/Makefile.am
+++ b/test-data/phony-guests/Makefile.am
@@ -51,6 +51,7 @@ disk_images = \
 	fedora-md1.img \
 	fedora-md2.img \
 	fedora-btrfs.img \
+	fedora-luks.img \
 	ubuntu.img \
 	archlinux.img \
 	coreos.img \
@@ -100,6 +101,13 @@ fedora-btrfs.img: make-fedora-img.pl \
 		fedora-packages.db
 	SRCDIR=$(srcdir) LAYOUT=btrfs $(top_builddir)/run --test ./$<
 
+# Make a (dummy) Fedora image with LVM encrypted with LUKS.
+fedora-luks.img: make-fedora-img.pl \
+		fedora-journal.tar.xz \
+		fedora-name.db \
+		fedora-packages.db
+	SRCDIR=$(srcdir) LAYOUT=lvm-luks $(top_builddir)/run --test ./$<
+
 # Make a (dummy) Debian image.
 debian.img: make-debian-img.sh
 	SRCDIR=$(srcdir) $(top_builddir)/run --test ./$<
diff --git a/test-data/phony-guests/guests.xml.in b/test-data/phony-guests/guests.xml.in
index 9c7c989dc..4139d04f6 100644
--- a/test-data/phony-guests/guests.xml.in
+++ b/test-data/phony-guests/guests.xml.in
@@ -151,22 +151,6 @@
     </devices>
   </domain>
 
-  <domain type='test'>
-    <name>fedora-btrfs</name>
-    <memory>1048576</memory>
-    <os>
-      <type>hvm</type>
-      <boot dev='hd'/>
-    </os>
-    <devices>
-      <disk type='file' device='disk'>
-        <driver name='qemu' type='raw'/>
-        <source file='@abs_builddir@/fedora-btrfs.img'/>
-        <target dev='vda' bus='virtio'/>
-      </disk>
-    </devices>
-  </domain>
-
   <domain type='test'>
     <name>fedora</name>
     <memory>1048576</memory>
@@ -183,6 +167,39 @@
     </devices>
   </domain>
 
+  <domain type='test'>
+    <name>fedora-btrfs</name>
+    <memory>1048576</memory>
+    <os>
+      <type>hvm</type>
+      <boot dev='hd'/>
+    </os>
+    <devices>
+      <disk type='file' device='disk'>
+        <driver name='qemu' type='raw'/>
+        <source file='@abs_builddir@/fedora-btrfs.img'/>
+        <target dev='vda' bus='virtio'/>
+      </disk>
+    </devices>
+  </domain>
+
+  <!-- LUKS password is 'FEDORA' -->
+  <domain type='test'>
+    <name>fedora-luks</name>
+    <memory>1048576</memory>
+    <os>
+      <type>hvm</type>
+      <boot dev='hd'/>
+    </os>
+    <devices>
+      <disk type='file' device='disk'>
+        <driver name='qemu' type='raw'/>
+        <source file='@abs_builddir@/fedora-luks.img'/>
+        <target dev='vda' bus='virtio'/>
+      </disk>
+    </devices>
+  </domain>
+
   <domain type='test'>
     <name>fedora-md1</name>
     <memory>1048576</memory>
diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl
index cd1c4a48c..c665f0d19 100755
--- a/test-data/phony-guests/make-fedora-img.pl
+++ b/test-data/phony-guests/make-fedora-img.pl
@@ -153,6 +153,35 @@ EOF
   $g->mount ('btrfsvol:/dev/sda2/root', '/');
 }
 
+elsif ($ENV{LAYOUT} eq 'lvm-luks') {
+  push (@images, "fedora-luks.img-t");
+
+  open (my $fstab, '>', "fedora.fstab") or die;
+  print $fstab <<EOF;
+LABEL=BOOT /boot ext2 default 0 0
+LABEL=ROOT / ext2 default 0 0
+EOF
+  close ($fstab) or die;
+
+  $bootdev = '/dev/sda1';
+
+  $g->disk_create ("fedora-luks.img-t", "raw", $IMAGE_SIZE);
+
+  $g->add_drive ("fedora-luks.img-t", format => "raw");
+  $g->launch ();
+
+  $g->part_init ('/dev/sda', 'mbr');
+  foreach my $p (@PARTITIONS) {
+    $g->part_add('/dev/sda', @$p);
+  }
+
+  # Put LUKS on the second partition.
+  $g->luks_format ('/dev/sda2', 'FEDORA', 0);
+  $g->luks_open ('/dev/sda2', 'FEDORA', 'luks');
+
+  init_lvm_root ('/dev/mapper/luks');
+}
+
 else {
   print STDERR "$0: Unknown LAYOUT: ",$ENV{LAYOUT},"\n";
   exit 1;
-- 
2.18.0




More information about the Libguestfs mailing list