Skip to content

Commit

Permalink
cloudapi: Add architecture support to the optional Blueprint
Browse files Browse the repository at this point in the history
If included it overrides the architecture in the compose image request.
  • Loading branch information
bcl committed Oct 9, 2024
1 parent 905df41 commit d98f127
Show file tree
Hide file tree
Showing 4 changed files with 230 additions and 184 deletions.
10 changes: 9 additions & 1 deletion internal/cloudapi/v2/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ func (request *ComposeRequest) GetBlueprintFromCompose() (blueprint.Blueprint, e
if rbp.Distro != nil {
bp.Distro = *rbp.Distro
}
if rbp.Architecture != nil {
bp.Arch = *rbp.Architecture
}

if rbp.Packages != nil {
for _, pkg := range *rbp.Packages {
Expand Down Expand Up @@ -1144,7 +1147,12 @@ func (request *ComposeRequest) GetImageRequests(distroFactory *distrofactory.Fac
}
var irs []imageRequest
for _, ir := range *request.ImageRequests {
arch, err := distribution.GetArch(ir.Architecture)
reqArch := ir.Architecture
// If there is an architecture in the blueprint it overrides the request's arch
if len(bp.Arch) > 0 {
reqArch = bp.Arch
}
arch, err := distribution.GetArch(reqArch)
if err != nil {
return nil, HTTPError(ErrorUnsupportedArchitecture)
}
Expand Down
27 changes: 27 additions & 0 deletions internal/cloudapi/v2/compose_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,33 @@ func TestGetImageRequests_BlueprintDistro(t *testing.T) {
assert.Equal(t, got[0].blueprint.Distro, "fedora-39")
}

// TestGetImageRequests_BlueprintArch test to make sure blueprint architecture overrides
// the request arch
func TestGetImageRequests_BlueprintArch(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: "arch-test",
Architecture: common.ToPtr("aarch64"),
},
}
// 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.Equal(t, got[0].blueprint.Arch, "aarch64")
}

func TestOpenSCAPTailoringOptions(t *testing.T) {
cr := ComposeRequest{
Customizations: &Customizations{
Expand Down
Loading

0 comments on commit d98f127

Please sign in to comment.