Repository: osbuild/osbuild-composer
Pull request #117 (2019-11-22 12:33:43)

targets: add dummy azure and aws targets
These are not currently implemented in the backend, but shows how
the API will look like.

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/internal/jobqueue/job.go b/internal/jobqueue/job.go
index 4b3d53e5a..339106af7 100644
--- a/internal/jobqueue/job.go
+++ b/internal/jobqueue/job.go
@@ -74,6 +74,8 @@ func (job *Job) Run() error {
 			if err != nil {
 				panic(err)
 			}
+		case *target.AWSTargetOptions:
+		case *target.AzureTargetOptions:
 		default:
 			panic("foo")
 		}
diff --git a/internal/store/store.go b/internal/store/store.go
index 1b4c01c82..bae7aecda 100644
--- a/internal/store/store.go
+++ b/internal/store/store.go
@@ -444,7 +444,11 @@ func (s *Store) DeleteBlueprintFromWorkspace(name string) {
 
 func (s *Store) PushCompose(composeID uuid.UUID, bp *blueprint.Blueprint, composeType string) error {
 	targets := []*target.Target{
-		target.NewLocalTarget(target.NewLocalTargetOptions("/var/lib/osbuild-composer/outputs/" + composeID.String())),
+		target.NewLocalTarget(
+			&target.LocalTargetOptions{
+				Location: "/var/lib/osbuild-composer/outputs/" + composeID.String(),
+			},
+		),
 	}
 	d := distro.New("")
 	pipeline, err := d.Pipeline(bp, composeType)
diff --git a/internal/target/aws_target.go b/internal/target/aws_target.go
new file mode 100644
index 000000000..5048c3aba
--- /dev/null
+++ b/internal/target/aws_target.go
@@ -0,0 +1,18 @@
+package target
+
+type AWSTargetOptions struct {
+	Region          string `json:"region"`
+	AccessKeyID     string `json:"accessKeyID"`
+	SecretAccessKey string `json:"secretAccessKey"`
+	Bucket          string `json:"bucket"`
+	Key             string `json:"key"`
+}
+
+func (AWSTargetOptions) isTargetOptions() {}
+
+func NewAWSTarget(options *AWSTargetOptions) *Target {
+	return &Target{
+		Name:    "org.osbuild.aws",
+		Options: options,
+	}
+}
diff --git a/internal/target/azure_target.go b/internal/target/azure_target.go
new file mode 100644
index 000000000..10ad8434c
--- /dev/null
+++ b/internal/target/azure_target.go
@@ -0,0 +1,16 @@
+package target
+
+type AzureTargetOptions struct {
+	Account   string `json:"account"`
+	AccessKey string `json:"accessKey"`
+	Container string `json:"container"`
+}
+
+func (AzureTargetOptions) isTargetOptions() {}
+
+func NewAzureTarget(options *AzureTargetOptions) *Target {
+	return &Target{
+		Name:    "org.osbuild.azure",
+		Options: options,
+	}
+}
diff --git a/internal/target/local_target.go b/internal/target/local_target.go
index a13b4a226..816354bba 100644
--- a/internal/target/local_target.go
+++ b/internal/target/local_target.go
@@ -6,12 +6,6 @@ type LocalTargetOptions struct {
 
 func (LocalTargetOptions) isTargetOptions() {}
 
-func NewLocalTargetOptions(location string) *LocalTargetOptions {
-	return &LocalTargetOptions{
-		Location: location,
-	}
-}
-
 func NewLocalTarget(options *LocalTargetOptions) *Target {
 	return &Target{
 		Name:    "org.osbuild.local",
diff --git a/internal/target/target.go b/internal/target/target.go
index 6b546295a..65f727a41 100644
--- a/internal/target/target.go
+++ b/internal/target/target.go
@@ -27,6 +27,10 @@ func (target *Target) UnmarshalJSON(data []byte) error {
 	}
 	var options TargetOptions
 	switch rawTarget.Name {
+	case "org.osbuild.azure":
+		options = new(AzureTargetOptions)
+	case "org.osbuild.aws":
+		options = new(AWSTargetOptions)
 	case "org.osbuild.local":
 		options = new(LocalTargetOptions)
 	default:
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
+}