Repository: osbuild/osbuild-composer
Pull request #118 (2019-11-24 15:42:52)

image-info: support images with empty partitions
Official RHEL EC2 images come with an empty partition, simply ignore
it rather than fail.

Signed-off-by: Tom Gundersen <teg@jklm.no>


Patch:
diff --git a/internal/distro/fedora30/ami.go b/internal/distro/fedora30/ami.go
index ccd7266eb..1dd34a45d 100644
--- a/internal/distro/fedora30/ami.go
+++ b/internal/distro/fedora30/ami.go
@@ -30,7 +30,7 @@ func (t *amiOutput) translate(b *blueprint.Blueprint) (*pipeline.Pipeline, error
 	addF30FSTabStage(p)
 	addF30GRUB2Stage(p, nil)
 	addF30SELinuxStage(p)
-	addF30QemuAssembler(p, "qcow2", t.getName())
+	addF30QemuAssembler(p, "raw", t.getName())
 
 	if b.Customizations != nil {
 		err := customizeAll(p, b.Customizations)
@@ -46,5 +46,5 @@ func (t *amiOutput) getName() string {
 }
 
 func (t *amiOutput) getMime() string {
-	return "application/x-qemu-disk"
+	return "application/octet-stream"
 }
diff --git a/tools/image-info b/tools/image-info
index ee773283a..89e205397 100755
--- a/tools/image-info
+++ b/tools/image-info
@@ -64,8 +64,9 @@ def read_partition(device, bootable, typ=None, start=0, size=0, type=None):
    return {
        "label": blkid.get("LABEL"), # doesn't exist for mbr
        "type": typ,
-       "uuid": blkid["UUID"],
-       "fstype": blkid["TYPE"],
+       "uuid": blkid.get("UUID"),
+       "partuuid": blkid.get("PARTUUID"),
+       "fstype": blkid.get("TYPE"),
        "bootable": bootable,
        "start": start,
        "size": size
@@ -167,9 +168,10 @@ with nbd_connect(image) as device:
 
     if report["partition-table"]:
         n_partitions = len(report["partitions"])
-        for n in range(1, n_partitions + 1):
-            with mount(device + f"p{n}") as tree:
-                append_filesystem(report, tree)
+        for n in range(n_partitions):
+            if report["partitions"][n]["fstype"]:
+                with mount(device + f"p{n + 1}") as tree:
+                    append_filesystem(report, tree)
     else:
         with mount(device) as tree:
             append_filesystem(report, tree)


Test patch:
diff --git a/internal/distro/fedora30/os_test.go b/internal/distro/fedora30/os_test.go
index e19576dc6..f74a95678 100644
--- a/internal/distro/fedora30/os_test.go
+++ b/internal/distro/fedora30/os_test.go
@@ -42,7 +42,7 @@ func TestFilenameFromType(t *testing.T) {
 			name:  "ami",
 			args:  args{"ami"},
 			want:  "image.ami",
-			want1: "application/x-qemu-disk",
+			want1: "application/octet-stream",
 		},
 		{
 			name:  "ext4",
diff --git a/test/cases/ami_empty_blueprint.json b/test/cases/ami_empty_blueprint.json
index 1f6c46154..0a716f829 100644
--- a/test/cases/ami_empty_blueprint.json
+++ b/test/cases/ami_empty_blueprint.json
@@ -107,7 +107,7 @@
     "assembler": {
       "name": "org.osbuild.qemu",
       "options": {
-        "format": "qcow2",
+        "format": "raw",
         "filename": "image.ami",
         "ptuuid": "0x14fc63d2",
         "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac",
@@ -182,7 +182,7 @@
       "video:x:39:",
       "wheel:x:10:"
     ],
-    "image-format": "qcow2",
+    "image-format": "raw",
     "os-release": {
       "ANSI_COLOR": "0;34",
       "BUG_REPORT_URL": "https://bugzilla.redhat.com/",
@@ -556,6 +556,7 @@
         "bootable": true,
         "fstype": "ext4",
         "label": null,
+        "partuuid": "14fc63d2-01",
         "size": 3220176896,
         "start": 1048576,
         "type": "83",
diff --git a/test/cases/ami_local_boot.json b/test/cases/ami_local_boot.json
index 67b41964e..2d984e3fe 100644
--- a/test/cases/ami_local_boot.json
+++ b/test/cases/ami_local_boot.json
@@ -161,7 +161,7 @@
     "assembler": {
       "name": "org.osbuild.qemu",
       "options": {
-        "format": "qcow2",
+        "format": "raw",
         "filename": "image.ami",
         "ptuuid": "0x14fc63d2",
         "root_fs_uuid": "76a22bf4-f153-4541-b6c7-0332c0dfaeac",
@@ -169,4 +169,4 @@
       }
     }
   }
-}
\ No newline at end of file
+}
diff --git a/test/cases/disk_empty_blueprint.json b/test/cases/disk_empty_blueprint.json
index 9cc82c68e..2e74ceecc 100644
--- a/test/cases/disk_empty_blueprint.json
+++ b/test/cases/disk_empty_blueprint.json
@@ -517,6 +517,7 @@
         "bootable": true,
         "fstype": "ext4",
         "label": null,
+        "partuuid": "14fc63d2-01",
         "size": 3220176896,
         "start": 1048576,
         "type": "83",
diff --git a/test/cases/ext4_empty_blueprint.json b/test/cases/ext4_empty_blueprint.json
index a4b14df13..a400227cf 100644
--- a/test/cases/ext4_empty_blueprint.json
+++ b/test/cases/ext4_empty_blueprint.json
@@ -381,6 +381,7 @@
         "bootable": false,
         "fstype": "ext4",
         "label": null,
+        "partuuid": null,
         "size": 0,
         "start": 0,
         "type": null,
diff --git a/test/cases/fedora-30-cloud-base.json b/test/cases/fedora-30-cloud-base.json
index ea40a6834..e4d3f6e81 100644
--- a/test/cases/fedora-30-cloud-base.json
+++ b/test/cases/fedora-30-cloud-base.json
@@ -436,6 +436,7 @@
         "bootable": true,
         "fstype": "ext4",
         "label": null,
+        "partuuid": "14fc63d2-01",
         "size": 4293918720,
         "start": 1048576,
         "type": "83",
diff --git a/test/cases/openstack_empty_blueprint.json b/test/cases/openstack_empty_blueprint.json
index 2aadc8078..61fad3e27 100644
--- a/test/cases/openstack_empty_blueprint.json
+++ b/test/cases/openstack_empty_blueprint.json
@@ -573,6 +573,7 @@
         "bootable": true,
         "fstype": "ext4",
         "label": null,
+        "partuuid": "14fc63d2-01",
         "size": 3220176896,
         "start": 1048576,
         "type": "83",
diff --git a/test/cases/qcow2_empty_blueprint.json b/test/cases/qcow2_empty_blueprint.json
index fc5b518f5..e4481cc5c 100644
--- a/test/cases/qcow2_empty_blueprint.json
+++ b/test/cases/qcow2_empty_blueprint.json
@@ -554,6 +554,7 @@
         "bootable": true,
         "fstype": "ext4",
         "label": null,
+        "partuuid": "14fc63d2-01",
         "size": 3220176896,
         "start": 1048576,
         "type": "83",
diff --git a/test/cases/vhd_empty_blueprint.json b/test/cases/vhd_empty_blueprint.json
index f068221b8..6b22809ef 100644
--- a/test/cases/vhd_empty_blueprint.json
+++ b/test/cases/vhd_empty_blueprint.json
@@ -527,6 +527,7 @@
         "bootable": true,
         "fstype": "ext4",
         "label": null,
+        "partuuid": "14fc63d2-01",
         "size": 3220176896,
         "start": 1048576,
         "type": "83",
diff --git a/test/cases/vhd_local_boot.json b/test/cases/vhd_local_boot.json
index 33dfce2f9..9d3cad836 100644
--- a/test/cases/vhd_local_boot.json
+++ b/test/cases/vhd_local_boot.json
@@ -164,4 +164,4 @@
       }
     }
   }
-}
\ No newline at end of file
+}
diff --git a/test/cases/vmdk_empty_blueprint.json b/test/cases/vmdk_empty_blueprint.json
index 84e923924..6321f73eb 100644
--- a/test/cases/vmdk_empty_blueprint.json
+++ b/test/cases/vmdk_empty_blueprint.json
@@ -534,6 +534,7 @@
         "bootable": true,
         "fstype": "ext4",
         "label": null,
+        "partuuid": "14fc63d2-01",
         "size": 3220176896,
         "start": 1048576,
         "type": "83",
diff --git a/test/cases/vmdk_local_boot.json b/test/cases/vmdk_local_boot.json
index cc31a7b25..b8ced1c4c 100644
--- a/test/cases/vmdk_local_boot.json
+++ b/test/cases/vmdk_local_boot.json
@@ -162,4 +162,4 @@
       }
     }
   }
-}
\ No newline at end of file
+}