diff --git a/internal/distro/rhel7/distro.go b/internal/distro/rhel7/distro.go index 969e38ae9..8208536af 100644 --- a/internal/distro/rhel7/distro.go +++ b/internal/distro/rhel7/distro.go @@ -341,10 +341,11 @@ func (t *imageType) initializeManifest(bp *blueprint.Blueprint, repos []rpmmd.RepoConfig, packageSets map[string]rpmmd.PackageSet, containers []container.Spec, - seed int64) (*manifest.Manifest, error) { + seed int64) (*manifest.Manifest, []string, error) { - if err := t.checkOptions(bp.Customizations, options, containers); err != nil { - return nil, err + warnings, err := t.checkOptions(bp.Customizations, options, containers) + if err != nil { + return nil, nil, err } w := t.workload @@ -368,18 +369,18 @@ func (t *imageType) initializeManifest(bp *blueprint.Blueprint, rng := rand.New(source) if t.image == nil { - return nil, nil + return nil, nil, nil } img, err := t.image(w, t, bp.Customizations, options, packageSets, containers, rng) if err != nil { - return nil, err + return nil, nil, err } manifest := manifest.New() _, err = img.InstantiateManifest(&manifest, repos, t.arch.distro.runner, rng) if err != nil { - return nil, err + return nil, nil, err } - return &manifest, err + return &manifest, warnings, err } func (t *imageType) Manifest(customizations *blueprint.Customizations, @@ -387,7 +388,7 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations, repos []rpmmd.RepoConfig, packageSets map[string][]rpmmd.PackageSpec, containers []container.Spec, - seed int64) (distro.Manifest, error) { + seed int64) (distro.Manifest, []string, error) { bp := &blueprint.Blueprint{Name: "empty blueprint"} err := bp.Initialize() @@ -414,12 +415,16 @@ func (t *imageType) Manifest(customizations *blueprint.Customizations, mergedRepos = append(mergedRepos, repo) } - manifest, err := t.initializeManifest(bp, options, mergedRepos, nil, containers, seed) + manifest, warnings, err := t.initializeManifest(bp, options, mergedRepos, nil, containers, seed) if err != nil { - return distro.Manifest{}, err + return distro.Manifest{}, nil, err } - return manifest.Serialize(packageSets) + ret, err := manifest.Serialize(packageSets) + if err != nil { + return ret, nil, err + } + return ret, warnings, err } func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOptions, repos []rpmmd.RepoConfig) map[string][]rpmmd.PackageSet { @@ -460,7 +465,7 @@ func (t *imageType) PackageSets(bp blueprint.Blueprint, options distro.ImageOpti } // create a manifest object and instantiate it with the computed packageSetChains - manifest, err := t.initializeManifest(&bp, options, repos, packageSets, containers, 0) + manifest, _, err := t.initializeManifest(&bp, options, repos, packageSets, containers, 0) if err != nil { // TODO: handle manifest initialization errors more gracefully, we // refuse to initialize manifests with invalid config. @@ -504,8 +509,10 @@ func overridePackageNames(packages []string) []string { } // checkOptions checks the validity and compatibility of options and customizations for the image type. -func (t *imageType) checkOptions(customizations *blueprint.Customizations, options distro.ImageOptions, containers []container.Spec) error { - +// Returns ([]string, error) where []string, if non-nil, will hold any generated warnings (e.g. deprecation notices). +func (t *imageType) checkOptions(customizations *blueprint.Customizations, options distro.ImageOptions, containers []container.Spec) ([]string, error) { + // holds warnings (e.g. deprecation notices) + var warnings []string if t.workload != nil { // For now, if an image type defines its own workload, don't allow any // user customizations. @@ -513,23 +520,23 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio // set of customizations. The current set of customizations defined in // the blueprint spec corresponds to the Custom workflow. if customizations != nil { - return fmt.Errorf("image type %q does not support customizations", t.name) + return warnings, fmt.Errorf("image type %q does not support customizations", t.name) } } if len(containers) > 0 { - return fmt.Errorf("embedding containers is not supported for %s on %s", t.name, t.arch.distro.name) + return warnings, fmt.Errorf("embedding containers is not supported for %s on %s", t.name, t.arch.distro.name) } mountpoints := customizations.GetFilesystems() err := blueprint.CheckMountpointsPolicy(mountpoints, pathpolicy.MountpointPolicies) if err != nil { - return err + return warnings, err } if osc := customizations.GetOpenSCAP(); osc != nil { - return fmt.Errorf(fmt.Sprintf("OpenSCAP unsupported os version: %s", t.arch.distro.osVersion)) + return warnings, fmt.Errorf(fmt.Sprintf("OpenSCAP unsupported os version: %s", t.arch.distro.osVersion)) } // Check Directory/File Customizations are valid @@ -538,20 +545,20 @@ func (t *imageType) checkOptions(customizations *blueprint.Customizations, optio err = blueprint.ValidateDirFileCustomizations(dc, fc) if err != nil { - return err + return warnings, err } err = blueprint.CheckDirectoryCustomizationsPolicy(dc, pathpolicy.CustomDirectoriesPolicies) if err != nil { - return err + return warnings, err } err = blueprint.CheckFileCustomizationsPolicy(fc, pathpolicy.CustomFilesPolicies) if err != nil { - return err + return warnings, err } - return nil + return warnings, nil } // New creates a new distro object, defining the supported architectures and image types diff --git a/internal/distro/rhel7/distro_test.go b/internal/distro/rhel7/distro_test.go index 24bc87f8e..b4e1b2dc4 100644 --- a/internal/distro/rhel7/distro_test.go +++ b/internal/distro/rhel7/distro_test.go @@ -178,7 +178,7 @@ func TestDistro_ManifestError(t *testing.T) { Size: imgType.Size(0), } testPackageSpecSets := distro_test_common.GetTestingImagePackageSpecSets("kernel", imgType) - _, err := imgType.Manifest(bp.Customizations, imgOpts, nil, testPackageSpecSets, nil, 0) + _, _, err := imgType.Manifest(bp.Customizations, imgOpts, nil, testPackageSpecSets, nil, 0) assert.NoError(t, err) } } @@ -284,7 +284,7 @@ func TestDistro_CustomFileSystemManifestError(t *testing.T) { arch, _ := r7distro.GetArch(archName) for _, imgTypeName := range arch.ListImageTypes() { imgType, _ := arch.GetImageType(imgTypeName) - _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, nil, nil, 0) + _, _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, nil, nil, 0) assert.EqualError(t, err, "The following custom mountpoints are not supported [\"/etc\"]") } } @@ -307,7 +307,7 @@ func TestDistro_TestRootMountPoint(t *testing.T) { for _, imgTypeName := range arch.ListImageTypes() { imgType, _ := arch.GetImageType(imgTypeName) testPackageSpecSets := distro_test_common.GetTestingImagePackageSpecSets("kernel", imgType) - _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, testPackageSpecSets, nil, 0) + _, _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, testPackageSpecSets, nil, 0) assert.NoError(t, err) } } @@ -334,7 +334,7 @@ func TestDistro_CustomFileSystemSubDirectories(t *testing.T) { for _, imgTypeName := range arch.ListImageTypes() { imgType, _ := arch.GetImageType(imgTypeName) testPackageSpecSets := distro_test_common.GetTestingImagePackageSpecSets("kernel", imgType) - _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, testPackageSpecSets, nil, 0) + _, _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, testPackageSpecSets, nil, 0) assert.NoError(t, err) } } @@ -369,7 +369,7 @@ func TestDistro_MountpointsWithArbitraryDepthAllowed(t *testing.T) { for _, imgTypeName := range arch.ListImageTypes() { imgType, _ := arch.GetImageType(imgTypeName) testPackageSpecSets := distro_test_common.GetTestingImagePackageSpecSets("kernel", imgType) - _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, testPackageSpecSets, nil, 0) + _, _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, testPackageSpecSets, nil, 0) assert.NoError(t, err) } } @@ -399,7 +399,7 @@ func TestDistro_DirtyMountpointsNotAllowed(t *testing.T) { arch, _ := r7distro.GetArch(archName) for _, imgTypeName := range arch.ListImageTypes() { imgType, _ := arch.GetImageType(imgTypeName) - _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, nil, nil, 0) + _, _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, nil, nil, 0) assert.EqualError(t, err, "The following custom mountpoints are not supported [\"//\" \"/var//\" \"/var//log/audit/\"]") } } @@ -425,7 +425,7 @@ func TestDistro_CustomFileSystemPatternMatching(t *testing.T) { arch, _ := r7distro.GetArch(archName) for _, imgTypeName := range arch.ListImageTypes() { imgType, _ := arch.GetImageType(imgTypeName) - _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, nil, nil, 0) + _, _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, nil, nil, 0) assert.EqualError(t, err, "The following custom mountpoints are not supported [\"/variable\" \"/variable/log/audit\"]") } } @@ -448,7 +448,7 @@ func TestDistro_CustomUsrPartitionNotLargeEnough(t *testing.T) { for _, imgTypeName := range arch.ListImageTypes() { imgType, _ := arch.GetImageType(imgTypeName) testPackageSpecSets := distro_test_common.GetTestingImagePackageSpecSets("kernel", imgType) - _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, testPackageSpecSets, nil, 0) + _, _, err := imgType.Manifest(bp.Customizations, distro.ImageOptions{}, nil, testPackageSpecSets, nil, 0) assert.NoError(t, err) } }