cloudapi: Override the request distro with the blueprint distro
When the blueprint sets a specific distribution it should be used instead of the distribution from the compose request. Includes a test to make sure it uses repositories from the blueprint, not the request.
This commit is contained in:
parent
f311adf35d
commit
d3fc53bdec
2 changed files with 45 additions and 8 deletions
|
|
@ -967,11 +967,6 @@ func (request *ComposeRequest) GetPartitioningMode() (disk.PartitioningMode, err
|
|||
// GetImageRequests converts a composeRequest structure from the API to an intermediate imageRequest structure
|
||||
// that's used for generating manifests and orchestrating worker jobs.
|
||||
func (request *ComposeRequest) GetImageRequests(distroFactory *distrofactory.Factory, repoRegistry *reporegistry.RepoRegistry) ([]imageRequest, error) {
|
||||
distribution := distroFactory.GetDistro(request.Distribution)
|
||||
if distribution == nil {
|
||||
return nil, HTTPError(ErrorUnsupportedDistribution)
|
||||
}
|
||||
|
||||
// OpenAPI enforces blueprint or customization, not both
|
||||
// but check anyway
|
||||
if request.Customizations != nil && request.Blueprint != nil {
|
||||
|
|
@ -984,6 +979,19 @@ func (request *ComposeRequest) GetImageRequests(distroFactory *distrofactory.Fac
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// Used when no repositories are included. Must be the original name because it may
|
||||
// be an alias and you cannot map back from the distrofactory to the original string.
|
||||
originalDistroName := request.Distribution
|
||||
|
||||
// If there is a distribution in the blueprint it overrides the request's distro
|
||||
if len(bp.Distro) > 0 {
|
||||
originalDistroName = bp.Distro
|
||||
}
|
||||
distribution := distroFactory.GetDistro(originalDistroName)
|
||||
if distribution == nil {
|
||||
return nil, HTTPError(ErrorUnsupportedDistribution)
|
||||
}
|
||||
|
||||
// add the user-defined repositories only to the depsolve job for the
|
||||
// payload (the packages for the final image)
|
||||
payloadRepositories := request.GetPayloadRepositories()
|
||||
|
|
@ -1024,9 +1032,10 @@ func (request *ComposeRequest) GetImageRequests(distroFactory *distrofactory.Fac
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// If no repositories are included with the imageRequest use the defaults for the distro
|
||||
// If no repositories are included with the imageRequest use the defaults for
|
||||
// the distro selected by the blueprint, or the compose request.
|
||||
if len(ir.Repositories) == 0 {
|
||||
dr, err := repoRegistry.ReposByImageTypeName(request.Distribution, arch.Name(), imageType.Name())
|
||||
dr, err := repoRegistry.ReposByImageTypeName(originalDistroName, arch.Name(), imageType.Name())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -708,5 +708,33 @@ func TestGetImageRequests_NoRepositories(t *testing.T) {
|
|||
got, err := request.GetImageRequests(distrofactory.NewDefault(), rr)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
assert.Greater(t, len(got[0].repositories), 0)
|
||||
require.Greater(t, len(got[0].repositories), 0)
|
||||
assert.Contains(t, got[0].repositories[0].Metalink, "40")
|
||||
}
|
||||
|
||||
// TestGetImageRequests_BlueprintDistro test to make sure blueprint distro overrides request distro
|
||||
func TestGetImageRequests_BlueprintDistro(t *testing.T) {
|
||||
uo := UploadOptions(struct{}{})
|
||||
request := &ComposeRequest{
|
||||
Distribution: "fedora-40",
|
||||
ImageRequest: &ImageRequest{
|
||||
Architecture: "x86_64",
|
||||
ImageType: ImageTypesAws,
|
||||
UploadOptions: &uo,
|
||||
Repositories: []Repository{},
|
||||
},
|
||||
Blueprint: &Blueprint{
|
||||
Name: "distro-test",
|
||||
Distro: common.ToPtr("fedora-38"),
|
||||
},
|
||||
}
|
||||
// NOTE: current directory is the location of this file, back up so it can use ./repositories/
|
||||
rr, err := reporegistry.New([]string{"../../../"})
|
||||
require.NoError(t, err)
|
||||
got, err := request.GetImageRequests(distrofactory.NewDefault(), rr)
|
||||
assert.NoError(t, err)
|
||||
require.Len(t, got, 1)
|
||||
require.Greater(t, len(got[0].repositories), 0)
|
||||
assert.Contains(t, got[0].repositories[0].Metalink, "38")
|
||||
assert.Equal(t, got[0].blueprint.Distro, "fedora-38")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue