From 620536fd61abcb92a63ca91ab092f4d506eaeaad Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Thu, 20 Oct 2022 14:47:04 +0200 Subject: [PATCH] internal/cloudapi: add ostree options for all otree image types b01792d9dd8db737369dce28addb083391d192e6 broke this behaviour. All ostree image types should have an ostree resolve job. --- internal/cloudapi/v2/handler.go | 21 ++++++++-------- internal/cloudapi/v2/v2_test.go | 2 +- internal/distro/test_distro/distro.go | 16 +++++++++--- internal/weldr/api_test.go | 35 +++++++++++++++------------ 4 files changed, 44 insertions(+), 30 deletions(-) diff --git a/internal/cloudapi/v2/handler.go b/internal/cloudapi/v2/handler.go index 449817a01..c8d2543c1 100644 --- a/internal/cloudapi/v2/handler.go +++ b/internal/cloudapi/v2/handler.go @@ -289,18 +289,19 @@ func (h *apiHandlers) PostCompose(ctx echo.Context) error { var ostreeOptions *ostree.RequestParams // assume it's an ostree image if the type has a default ostree ref - if imageType.OSTreeRef() != "" && ir.Ostree != nil { + if imageType.OSTreeRef() != "" { ostreeOptions = &ostree.RequestParams{} - if ir.Ostree.Ref != nil { - ostreeOptions.Ref = *ir.Ostree.Ref + if ir.Ostree != nil { + if ir.Ostree.Ref != nil { + ostreeOptions.Ref = *ir.Ostree.Ref + } + if ir.Ostree.Url != nil { + ostreeOptions.URL = *ir.Ostree.Url + } + if ir.Ostree.Parent != nil { + ostreeOptions.Parent = *ir.Ostree.Parent + } } - if ir.Ostree.Url != nil { - ostreeOptions.URL = *ir.Ostree.Url - } - if ir.Ostree.Parent != nil { - ostreeOptions.Parent = *ir.Ostree.Parent - } - if ostreeOptions.Ref == "" { ostreeOptions.Ref = imageType.OSTreeRef() } diff --git a/internal/cloudapi/v2/v2_test.go b/internal/cloudapi/v2/v2_test.go index 7209bd825..21d44f916 100644 --- a/internal/cloudapi/v2/v2_test.go +++ b/internal/cloudapi/v2/v2_test.go @@ -713,7 +713,7 @@ func TestComposeDependencyError(t *testing.T) { "distribution": "%s", "image_request":{ "architecture": "%s", - "image_type": "aws", + "image_type": "edge-commit", "ostree": { "url": "somerepo.org", "ref": "test" diff --git a/internal/distro/test_distro/distro.go b/internal/distro/test_distro/distro.go index 6b1bedb3e..3fbc35db0 100644 --- a/internal/distro/test_distro/distro.go +++ b/internal/distro/test_distro/distro.go @@ -57,8 +57,9 @@ const ( TestArch2Name = "test_arch2" TestArch3Name = "test_arch3" - TestImageTypeName = "test_type" - TestImageType2Name = "test_type2" + TestImageTypeName = "test_type" + TestImageType2Name = "test_type2" + TestImageTypeOSTree = "test_ostree_type" // added for cloudapi tests TestImageTypeAmi = "ami" @@ -175,7 +176,10 @@ func (t *TestImageType) MIMEType() string { } func (t *TestImageType) OSTreeRef() string { - return t.architecture.distribution.OSTreeRef() + if t.name == TestImageTypeEdgeCommit || t.name == TestImageTypeEdgeInstaller || t.name == TestImageTypeOSTree { + return t.architecture.distribution.OSTreeRef() + } + return "" } func (t *TestImageType) Size(size uint64) uint64 { @@ -322,7 +326,11 @@ func newTestDistro(name, modulePlatformID, releasever string) *TestDistro { name: TestImageTypeGce, } - ta1.addImageTypes(it1) + it11 := TestImageType{ + name: TestImageTypeOSTree, + } + + ta1.addImageTypes(it1, it11) ta2.addImageTypes(it1, it2) ta3.addImageTypes(it3, it4, it5, it6, it7, it8, it9, it10) diff --git a/internal/weldr/api_test.go b/internal/weldr/api_test.go index 483d9a452..d69f7442e 100644 --- a/internal/weldr/api_test.go +++ b/internal/weldr/api_test.go @@ -167,8 +167,8 @@ func TestBasic(t *testing.T) { {"/api/v0/blueprints/info/", http.StatusNotFound, `{"errors":[{"code":404,"id":"HTTPError","msg":"Not Found"}],"status":false}`}, {"/api/v0/blueprints/info/foo", http.StatusOK, `{"blueprints":[],"changes":[],"errors":[{"id":"UnknownBlueprint","msg":"foo: "}]}`}, {"/api/v1/distros/list", http.StatusOK, `{"distros": ["test-distro", "test-distro-2"]}`}, - {"/api/v1/compose/types", http.StatusOK, `{"types": [{"enabled":true, "name":"test_type"}]}`}, - {"/api/v1/compose/types?distro=test-distro-2", http.StatusOK, `{"types": [{"enabled":true, "name":"test_type"}]}`}, + {"/api/v1/compose/types", http.StatusOK, `{"types": [{"enabled":true, "name":"test_ostree_type"},{"enabled":true, "name":"test_type"}]}`}, + {"/api/v1/compose/types?distro=test-distro-2", http.StatusOK, `{"types": [{"enabled":true, "name":"test_ostree_type"},{"enabled":true, "name":"test_type"}]}`}, {"/api/v1/compose/types?distro=fedora-1", http.StatusBadRequest, `{"status":false,"errors":[{"id":"DistroError","msg":"Invalid distro: fedora-1"}]}`}, } @@ -679,6 +679,11 @@ func TestCompose(t *testing.T) { manifest, err := imgType.Manifest(nil, distro.ImageOptions{}, nil, nil, nil, 0) require.NoError(t, err) + ostreeImgType, err := arch.GetImageType(test_distro.TestImageTypeOSTree) + require.NoError(t, err) + ostreeManifest, err := ostreeImgType.Manifest(nil, distro.ImageOptions{}, nil, nil, nil, 0) + require.NoError(t, err) + expectedComposeLocal := &store.Compose{ Blueprint: &blueprint.Blueprint{ Name: "test", @@ -760,14 +765,14 @@ func TestCompose(t *testing.T) { }, ImageBuild: store.ImageBuild{ QueueStatus: common.IBWaiting, - ImageType: imgType, - Manifest: manifest, + ImageType: ostreeImgType, + Manifest: ostreeManifest, Targets: []*target.Target{ { - ImageName: imgType.Filename(), + ImageName: ostreeImgType.Filename(), OsbuildArtifact: target.OsbuildArtifact{ - ExportFilename: imgType.Filename(), - ExportName: imgType.Exports()[0], + ExportFilename: ostreeImgType.Filename(), + ExportName: ostreeImgType.Exports()[0], }, Name: target.TargetNameWorkerServer, Options: &target.WorkerServerTargetOptions{}, @@ -897,7 +902,7 @@ func TestCompose(t *testing.T) { false, "POST", "/api/v1/compose", - fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"parentid","url":""}}`, test_distro.TestImageTypeName), + fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"refid","parent":"parentid","url":""}}`, test_distro.TestImageTypeOSTree), http.StatusBadRequest, `{"status": false, "errors":[{"id":"OSTreeOptionsError","msg":"ostree parent ref specified, but no URL to retrieve it"}]}`, expectedComposeOSTree, @@ -908,7 +913,7 @@ func TestCompose(t *testing.T) { false, "POST", "/api/v1/compose", - fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"%s","parent":"","url":"%s"}}`, test_distro.TestImageTypeName, ostreeRepoOther.OSTreeRef, ostreeRepoOther.Server.URL), + fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"%s","parent":"","url":"%s"}}`, test_distro.TestImageTypeOSTree, ostreeRepoOther.OSTreeRef, ostreeRepoOther.Server.URL), http.StatusOK, `{"status": true}`, expectedComposeOSTree, @@ -919,7 +924,7 @@ func TestCompose(t *testing.T) { false, "POST", "/api/v1/compose", - fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"whatever","parent":"","url":"invalid-url"}}`, test_distro.TestImageTypeName), + fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"whatever","parent":"","url":"invalid-url"}}`, test_distro.TestImageTypeOSTree), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Get \"invalid-url/refs/heads/whatever\": unsupported protocol scheme \"\""}]}`, nil, @@ -930,7 +935,7 @@ func TestCompose(t *testing.T) { false, "POST", "/api/v1/compose", - fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"/bad/ref","parent":"","url":"http://ostree/"}}`, test_distro.TestImageTypeName), + fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"/bad/ref","parent":"","url":"http://ostree/"}}`, test_distro.TestImageTypeOSTree), http.StatusBadRequest, `{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"Invalid ostree ref \"/bad/ref\""}]}`, expectedComposeOSTree, @@ -941,7 +946,7 @@ func TestCompose(t *testing.T) { false, "POST", "/api/v1/compose", - fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"%s","parent":"","url":"%s"}}`, test_distro.TestImageTypeName, "the/wrong/ref", ostreeRepoDefault.Server.URL), + fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"%s","parent":"","url":"%s"}}`, test_distro.TestImageTypeOSTree, "the/wrong/ref", ostreeRepoDefault.Server.URL), http.StatusBadRequest, fmt.Sprintf(`{"status":false,"errors":[{"id":"OSTreeOptionsError","msg":"ostree repository \"%s/refs/heads/the/wrong/ref\" returned status: 404 Not Found"}]}`, ostreeRepoDefault.Server.URL), expectedComposeOSTree, @@ -952,7 +957,7 @@ func TestCompose(t *testing.T) { false, "POST", "/api/v1/compose", - fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"%s","parent":"%s","url":"%s"}}`, test_distro.TestImageTypeName, "the/new/ref", ostreeRepoOther.OSTreeRef, ostreeRepoOther.Server.URL), + fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"%s","parent":"%s","url":"%s"}}`, test_distro.TestImageTypeOSTree, "the/new/ref", ostreeRepoOther.OSTreeRef, ostreeRepoOther.Server.URL), http.StatusOK, `{"status":true}`, expectedComposeOSTree, @@ -963,7 +968,7 @@ func TestCompose(t *testing.T) { false, "POST", "/api/v1/compose", - fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"","parent":"%s","url":"%s"}}`, test_distro.TestImageTypeName, ostreeRepoDefault.OSTreeRef, ostreeRepoDefault.Server.URL), + fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"","parent":"%s","url":"%s"}}`, test_distro.TestImageTypeOSTree, ostreeRepoDefault.OSTreeRef, ostreeRepoDefault.Server.URL), http.StatusOK, `{"status":true}`, expectedComposeOSTree, @@ -974,7 +979,7 @@ func TestCompose(t *testing.T) { false, "POST", "/api/v1/compose", - fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"","parent":"","url":"%s"}}`, test_distro.TestImageTypeName, ostreeRepoDefault.Server.URL), + fmt.Sprintf(`{"blueprint_name": "test","compose_type":"%s","branch":"master","ostree":{"ref":"","parent":"","url":"%s"}}`, test_distro.TestImageTypeOSTree, ostreeRepoDefault.Server.URL), http.StatusOK, `{"status":true}`, expectedComposeOSTree,