From 8022c227ba2971a77867dab7b1d706da6c167f13 Mon Sep 17 00:00:00 2001 From: Irene Diez Date: Wed, 8 Mar 2023 13:10:08 +0100 Subject: [PATCH] distro: allow to return warnings in the Manifest function This changes the `Manifest` function of the `ImageType` interface so that any warnings detected during the `checkOptions` step of the manifest initialization can be propagated back to the Weldr-API (see next commit). Signed-off-by: Irene Diez --- internal/cloudapi/v2/server.go | 2 +- internal/distro/distro.go | 7 ++++--- internal/distro/distro_test.go | 2 +- .../distro_test_common/distro_test_common.go | 2 +- internal/distro/test_distro/distro.go | 10 +++++----- internal/store/fixtures.go | 4 ++-- internal/store/store_test.go | 2 +- internal/worker/server_test.go | 14 +++++++------- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/internal/cloudapi/v2/server.go b/internal/cloudapi/v2/server.go index fdae5eeae..7c863c36d 100644 --- a/internal/cloudapi/v2/server.go +++ b/internal/cloudapi/v2/server.go @@ -458,7 +458,7 @@ func generateManifest(ctx context.Context, workers *worker.Server, depsolveJobID options.OSTree.URL = result.Specs[0].URL } - manifest, err := imageType.Manifest(b, options, repos, depsolveResults.PackageSpecs, containerSpecs, seed) + manifest, _, err := imageType.Manifest(b, options, repos, depsolveResults.PackageSpecs, containerSpecs, seed) if err != nil { reason := "Error generating manifest" jobResult.JobError = clienterrors.WorkerClientError(clienterrors.ErrorManifestGeneration, reason, nil) diff --git a/internal/distro/distro.go b/internal/distro/distro.go index c40c55186..e81489c99 100644 --- a/internal/distro/distro.go +++ b/internal/distro/distro.go @@ -118,9 +118,10 @@ type ImageType interface { // Returns an osbuild manifest, containing the sources and pipeline necessary // to build an image, given output format with all packages and customizations - // specified in the given blueprint. The packageSpecSets must be labelled in - // the same way as the originating PackageSets. - Manifest(b *blueprint.Customizations, options ImageOptions, repos []rpmmd.RepoConfig, packageSpecSets map[string][]rpmmd.PackageSpec, containers []container.Spec, seed int64) (Manifest, error) + // specified in the given blueprint; it also returns any warnings (e.g. + // deprecation notices) generated by the manifest. + // The packageSpecSets must be labelled in the same way as the originating PackageSets. + Manifest(b *blueprint.Customizations, options ImageOptions, repos []rpmmd.RepoConfig, packageSpecSets map[string][]rpmmd.PackageSpec, containers []container.Spec, seed int64) (Manifest, []string, error) } // The ImageOptions specify options for a specific image build diff --git a/internal/distro/distro_test.go b/internal/distro/distro_test.go index aebb07729..db71b4a2e 100644 --- a/internal/distro/distro_test.go +++ b/internal/distro/distro_test.go @@ -231,7 +231,7 @@ func TestImageTypePipelineNames(t *testing.T) { packageSets[plName] = minimalPackageSet } - m, err := imageType.Manifest(bp.Customizations, options, repos, packageSets, containers, seed) + m, _, err := imageType.Manifest(bp.Customizations, options, repos, packageSets, containers, seed) require.NoError(err) pm := new(manifest) err = json.Unmarshal(m, pm) diff --git a/internal/distro/distro_test_common/distro_test_common.go b/internal/distro/distro_test_common/distro_test_common.go index b29e1279b..7a458abdc 100644 --- a/internal/distro/distro_test_common/distro_test_common.go +++ b/internal/distro/distro_test_common/distro_test_common.go @@ -136,7 +136,7 @@ func TestDistro_Manifest(t *testing.T, pipelinePath string, prefix string, regis imgPackageSpecSets = tt.PackageSpecSets } - got, err := imageType.Manifest(tt.ComposeRequest.Blueprint.Customizations, + got, _, err := imageType.Manifest(tt.ComposeRequest.Blueprint.Customizations, options, repos, imgPackageSpecSets, diff --git a/internal/distro/test_distro/distro.go b/internal/distro/test_distro/distro.go index cdc22bdbd..c4b232c33 100644 --- a/internal/distro/test_distro/distro.go +++ b/internal/distro/test_distro/distro.go @@ -239,7 +239,7 @@ func (t *TestImageType) Exports() []string { return distro.ExportsFallback() } -func (t *TestImageType) Manifest(b *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSpecSets map[string][]rpmmd.PackageSpec, containers []container.Spec, seed int64) (distro.Manifest, error) { +func (t *TestImageType) Manifest(b *blueprint.Customizations, options distro.ImageOptions, repos []rpmmd.RepoConfig, packageSpecSets map[string][]rpmmd.PackageSpec, containers []container.Spec, seed int64) (distro.Manifest, []string, error) { mountpoints := b.GetFilesystems() invalidMountpoints := []string{} @@ -250,15 +250,15 @@ func (t *TestImageType) Manifest(b *blueprint.Customizations, options distro.Ima } if len(invalidMountpoints) > 0 { - return nil, fmt.Errorf("The following custom mountpoints are not supported %+q", invalidMountpoints) + return nil, nil, fmt.Errorf("The following custom mountpoints are not supported %+q", invalidMountpoints) } - return json.Marshal( + ret, err := json.Marshal( osbuild.Manifest{ Sources: osbuild.Sources{}, Pipelines: []osbuild.Pipeline{}, - }, - ) + }) + return ret, nil, err } // newTestDistro returns a new instance of TestDistro with the diff --git a/internal/store/fixtures.go b/internal/store/fixtures.go index 93d936a66..15ddc69ab 100644 --- a/internal/store/fixtures.go +++ b/internal/store/fixtures.go @@ -51,7 +51,7 @@ func FixtureBase() *Store { if err != nil { panic(fmt.Sprintf("failed to get image type %s for a test distro architecture: %v", test_distro.TestImageTypeName, err)) } - manifest, err := imgType.Manifest(nil, distro.ImageOptions{}, nil, nil, nil, 0) + manifest, _, err := imgType.Manifest(nil, distro.ImageOptions{}, nil, nil, nil, 0) if err != nil { panic(fmt.Sprintf("failed to create a manifest: %v", err)) } @@ -188,7 +188,7 @@ func FixtureFinished() *Store { if err != nil { panic(fmt.Sprintf("failed to get image type %s for a test distro architecture: %v", test_distro.TestImageTypeName, err)) } - manifest, err := imgType.Manifest(nil, distro.ImageOptions{}, nil, nil, nil, 0) + manifest, _, err := imgType.Manifest(nil, distro.ImageOptions{}, nil, nil, nil, 0) if err != nil { panic(fmt.Sprintf("failed to create a manifest: %v", err)) } diff --git a/internal/store/store_test.go b/internal/store/store_test.go index 2cb0e6b65..7cd2b4127 100644 --- a/internal/store/store_test.go +++ b/internal/store/store_test.go @@ -51,7 +51,7 @@ func (suite *storeTest) SetupSuite() { suite.myDistro = test_distro.New() suite.myArch, _ = suite.myDistro.GetArch(test_distro.TestArchName) suite.myImageType, _ = suite.myArch.GetImageType(test_distro.TestImageTypeName) - suite.myManifest, _ = suite.myImageType.Manifest(&suite.myCustomizations, suite.myImageOptions, suite.myRepoConfig, nil, nil, 0) + suite.myManifest, _, _ = suite.myImageType.Manifest(&suite.myCustomizations, suite.myImageOptions, suite.myRepoConfig, nil, nil, 0) suite.mySourceConfig = SourceConfig{ Name: "testSourceConfig", } diff --git a/internal/worker/server_test.go b/internal/worker/server_test.go index 54ba8f1c3..9505b51c1 100644 --- a/internal/worker/server_test.go +++ b/internal/worker/server_test.go @@ -129,7 +129,7 @@ func TestCreate(t *testing.T) { if err != nil { t.Fatalf("error getting image type from arch: %v", err) } - manifest, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) + manifest, _, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) if err != nil { t.Fatalf("error creating osbuild manifest: %v", err) } @@ -154,7 +154,7 @@ func TestCancel(t *testing.T) { if err != nil { t.Fatalf("error getting image type from arch: %v", err) } - manifest, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) + manifest, _, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) if err != nil { t.Fatalf("error creating osbuild manifest: %v", err) } @@ -191,7 +191,7 @@ func TestUpdate(t *testing.T) { if err != nil { t.Fatalf("error getting image type from arch: %v", err) } - manifest, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) + manifest, _, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) if err != nil { t.Fatalf("error creating osbuild manifest: %v", err) } @@ -221,7 +221,7 @@ func TestArgs(t *testing.T) { require.NoError(t, err) imageType, err := arch.GetImageType(test_distro.TestImageTypeName) require.NoError(t, err) - manifest, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) + manifest, _, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) require.NoError(t, err) server := newTestServer(t, t.TempDir(), time.Duration(0), "/api/worker/v1", false) @@ -267,7 +267,7 @@ func TestUpload(t *testing.T) { if err != nil { t.Fatalf("error getting image type from arch: %v", err) } - manifest, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) + manifest, _, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) if err != nil { t.Fatalf("error creating osbuild manifest: %v", err) } @@ -297,7 +297,7 @@ func TestUploadNotAcceptingArtifacts(t *testing.T) { if err != nil { t.Fatalf("error getting image type from arch: %v", err) } - manifest, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) + manifest, _, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) if err != nil { t.Fatalf("error creating osbuild manifest: %v", err) } @@ -327,7 +327,7 @@ func TestUploadAlteredBasePath(t *testing.T) { if err != nil { t.Fatalf("error getting image type from arch: %v", err) } - manifest, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) + manifest, _, err := imageType.Manifest(nil, distro.ImageOptions{Size: imageType.Size(0)}, nil, nil, nil, 0) if err != nil { t.Fatalf("error creating osbuild manifest: %v", err) }