store: move adding the local target to weldr

The automatic local target is only needed when accessing the API via
weldr.

In the store, the target was only added when `stateDir` was not `nil`.
This is only used for testing which doesn't exercise the branch in
weldr. Thus, the same check is not needed there.
This commit is contained in:
Lars Karlitski 2020-03-23 18:07:46 +01:00
parent 7594cb262e
commit 3544590036
3 changed files with 30 additions and 16 deletions

View file

@ -554,8 +554,10 @@ func (s *Store) getImageBuildDirectory(composeID uuid.UUID, imageBuildID int) st
return fmt.Sprintf("%s/%d", s.getComposeDirectory(composeID), imageBuildID)
}
func (s *Store) PushCompose(distro distro.Distro, arch distro.Arch, imageType distro.ImageType, composeID uuid.UUID, bp *blueprint.Blueprint, repos []rpmmd.RepoConfig, packages, buildPackages []rpmmd.PackageSpec, size uint64, uploadTarget *target.Target) error {
targets := []*target.Target{}
func (s *Store) PushCompose(distro distro.Distro, arch distro.Arch, imageType distro.ImageType, composeID uuid.UUID, bp *blueprint.Blueprint, repos []rpmmd.RepoConfig, packages, buildPackages []rpmmd.PackageSpec, size uint64, targets []*target.Target) error {
if targets == nil {
targets = []*target.Target{}
}
// Compatibility layer for image types in Weldr API v0
imageTypeCommon, exists := common.ImageTypeFromCompatString(imageType.Name())
@ -570,16 +572,6 @@ func (s *Store) PushCompose(distro distro.Distro, arch distro.Arch, imageType di
if err != nil {
return fmt.Errorf("cannot create output directory for job %v: %#v", composeID, err)
}
targets = append(targets, target.NewLocalTarget(
&target.LocalTargetOptions{
Filename: imageType.Filename(),
},
))
}
if uploadTarget != nil {
targets = append(targets, uploadTarget)
}
allRepos := append([]rpmmd.RepoConfig{}, repos...)

View file

@ -1407,11 +1407,18 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
return
}
var uploadTarget *target.Target
var targets []*target.Target
if isRequestVersionAtLeast(params, 1) && cr.Upload != nil {
uploadTarget = uploadRequestToTarget(*cr.Upload, imageType)
t := uploadRequestToTarget(*cr.Upload, imageType)
targets = append(targets, t)
}
targets = append(targets, target.NewLocalTarget(
&target.LocalTargetOptions{
Filename: imageType.Filename(),
},
))
bp := api.store.GetBlueprintCommitted(cr.BlueprintName)
if bp == nil {
errors := responseError{
@ -1437,7 +1444,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
Status: true,
}
err = api.store.PushCompose(api.distro, api.arch, imageType, reply.BuildID, bp, api.repos, packages, buildPackages, cr.Size, uploadTarget)
err = api.store.PushCompose(api.distro, api.arch, imageType, reply.BuildID, bp, api.repos, packages, buildPackages, cr.Size, targets)
// TODO: we should probably do some kind of blueprint validation in future
// for now, let's just 500 and bail out

View file

@ -476,7 +476,15 @@ func TestCompose(t *testing.T) {
{
QueueStatus: common.IBWaiting,
ImageType: common.Qcow2Generic,
Targets: []*target.Target{},
Targets: []*target.Target{
{
// skip Uuid and Created fields - they are ignored
Name: "org.osbuild.local",
Options: &target.LocalTargetOptions{
Filename: "test.img",
},
},
},
},
},
}
@ -507,6 +515,13 @@ func TestCompose(t *testing.T) {
Key: "imagekey",
},
},
{
// skip Uuid and Created fields - they are ignored
Name: "org.osbuild.local",
Options: &target.LocalTargetOptions{
Filename: "test.img",
},
},
},
},
},