From 9c91b12076bd443fa94a311bcaed85fb788a01cc Mon Sep 17 00:00:00 2001 From: Martin Sehnoutka Date: Mon, 10 Feb 2020 09:23:26 +0100 Subject: [PATCH] common: compose request should include full bp and repositories we want to move to a state where composer is a stateless service, therefore we cannot take blueprints by name (and fetch them from a storage) or assume repositories by the distribution. This commit introduces both of these parameters as part of the structure. --- internal/common/types.go | 13 ++++--- internal/common/types_test.go | 68 +++++++++++++++++++++++++---------- 2 files changed, 58 insertions(+), 23 deletions(-) diff --git a/internal/common/types.go b/internal/common/types.go index e93ede8b8..292e9d35a 100644 --- a/internal/common/types.go +++ b/internal/common/types.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "github.com/google/uuid" + "github.com/osbuild/osbuild-composer/internal/blueprint" + "github.com/osbuild/osbuild-composer/internal/rpmmd" ) // CustomJsonConversionError is thrown when parsing strings into enumerations @@ -316,9 +318,10 @@ type ImageRequest struct { // ComposeRequest is used to submit a new compose to the store type ComposeRequest struct { - BlueprintName string `json:"blueprint_name"` - ComposeID uuid.UUID `json:"uuid"` - Distro Distribution `json:"distro"` - Arch Architecture `json:"arch"` - RequestedImages []ImageRequest `json:"requested_images"` + Blueprint blueprint.Blueprint `json:"blueprint"` + ComposeID uuid.UUID `json:"uuid"` + Distro Distribution `json:"distro"` + Arch Architecture `json:"arch"` + Repositories []rpmmd.RepoConfig `json:"repositories"` + RequestedImages []ImageRequest `json:"requested_images"` } diff --git a/internal/common/types_test.go b/internal/common/types_test.go index fb9da27ab..20a8b67e8 100644 --- a/internal/common/types_test.go +++ b/internal/common/types_test.go @@ -3,23 +3,32 @@ package common import ( "encoding/json" "github.com/google/uuid" + "github.com/osbuild/osbuild-composer/internal/blueprint" + "github.com/osbuild/osbuild-composer/internal/rpmmd" "reflect" "testing" ) func TestJSONConversionsComposeRequest(t *testing.T) { - cases := []struct{ - input string + cases := []struct { + input string expectedConversionResult ComposeRequest }{ // 1st case { ` { - "blueprint_name": "foo", + "blueprint": { + "name": "", + "description": "", + "packages": [], + "modules": [], + "groups": [] + }, "uuid": "789b4d42-da1a-49c9-a20c-054da3bb6c82", "distro": "fedora-31", "arch": "x86_64", + "repositories": [], "requested_images": [ { "image_type": "AWS", @@ -29,10 +38,19 @@ func TestJSONConversionsComposeRequest(t *testing.T) { } `, ComposeRequest{ - BlueprintName: "foo", - ComposeID: uuid.UUID{}, - Distro: Fedora31, - Arch: X86_64, + Blueprint: blueprint.Blueprint{ + Name: "", + Description: "", + Version: "", + Packages: nil, + Modules: nil, + Groups: nil, + Customizations: nil, + }, + ComposeID: uuid.UUID{}, + Distro: Fedora31, + Arch: X86_64, + Repositories: []rpmmd.RepoConfig{}, RequestedImages: []ImageRequest{{ ImgType: Aws, UpTarget: []UploadTarget{EC2}, @@ -43,10 +61,17 @@ func TestJSONConversionsComposeRequest(t *testing.T) { { ` { - "blueprint_name": "bar", + "blueprint": { + "name": "", + "description": "", + "packages": [], + "modules": [], + "groups": [] + }, "uuid": "789b4d42-da1a-49c9-a20c-054da3bb6c82", "distro": "rhel-8.2", "arch": "aarch64", + "repositories": [], "requested_images": [ { "image_type": "Azure", @@ -56,10 +81,19 @@ func TestJSONConversionsComposeRequest(t *testing.T) { } `, ComposeRequest{ - BlueprintName: "bar", - ComposeID: uuid.UUID{}, - Distro: RHEL82, - Arch: Aarch64, + Blueprint: blueprint.Blueprint{ + Name: "", + Description: "", + Version: "", + Packages: nil, + Modules: nil, + Groups: nil, + Customizations: nil, + }, + ComposeID: uuid.UUID{}, + Distro: RHEL82, + Arch: Aarch64, + Repositories: []rpmmd.RepoConfig{}, RequestedImages: []ImageRequest{{ ImgType: Azure, UpTarget: []UploadTarget{AzureStorage, EC2}, @@ -68,12 +102,12 @@ func TestJSONConversionsComposeRequest(t *testing.T) { }, } - for _, c := range cases { + for n, c := range cases { // Test unmashaling the JSON from the string above var inputStringAsStruct *ComposeRequest err := json.Unmarshal([]byte(c.input), &inputStringAsStruct) if err != nil { - t.Fatal("Failed ot unmarshal ComposeRequest:", err) + t.Fatal("Failed to unmarshal ComposeRequest (", n, "):", err) } if reflect.DeepEqual(inputStringAsStruct, c.expectedConversionResult) { t.Error("Unmarshaled compose request is not the one expected") @@ -84,12 +118,12 @@ func TestJSONConversionsComposeRequest(t *testing.T) { // compare the resulting structure with the input one data, err := json.Marshal(c.expectedConversionResult) if err != nil { - t.Fatal("Failed ot marshal ComposeRequest:", err) + t.Fatal("Failed to marshal ComposeRequest:", err) } var expectedResultAfterMarshaling *ComposeRequest err = json.Unmarshal(data, &expectedResultAfterMarshaling) if err != nil { - t.Fatal("Failed ot unmarshal ComposeRequest:", err, ", input:", string(data)) + t.Fatal("Failed to unmarshal ComposeRequest:", err, ", input:", string(data)) } if reflect.DeepEqual(expectedResultAfterMarshaling, c.expectedConversionResult) { t.Error("Marshaled compose request is not the one expected") @@ -97,5 +131,3 @@ func TestJSONConversionsComposeRequest(t *testing.T) { } } - -