store: don't keep a "default" distro
Only the weldr API has the concept of a default distro. Pass that distro explicitly to `PushCompose()` and fetch the distro from the compose in all other functions that accessed Store.Distro.
This commit is contained in:
parent
15033faa81
commit
0f1a014aca
6 changed files with 38 additions and 27 deletions
|
|
@ -99,7 +99,7 @@ func main() {
|
|||
logger = log.New(os.Stdout, "", 0)
|
||||
}
|
||||
|
||||
store := store.New(&stateDir, distribution, *distros)
|
||||
store := store.New(&stateDir, *distros)
|
||||
|
||||
jobAPI := jobqueue.New(logger, store)
|
||||
weldrAPI := weldr.New(rpm, common.CurrentArch(), distribution, logger, store)
|
||||
|
|
|
|||
|
|
@ -34,12 +34,11 @@ func TestBasic(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, c := range cases {
|
||||
distroStruct := test_distro.New()
|
||||
registry, err := distro_mock.NewDefaultRegistry()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
api := jobqueue.New(nil, store.New(nil, distroStruct, *registry))
|
||||
api := jobqueue.New(nil, store.New(nil, *registry))
|
||||
|
||||
test.TestNonJsonRoute(t, api, false, c.Method, c.Path, c.Body, c.ExpectedStatus, c.ExpectedResponse)
|
||||
}
|
||||
|
|
@ -52,10 +51,10 @@ func TestCreate(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := store.New(nil, distroStruct, *registry)
|
||||
store := store.New(nil, *registry)
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
err = store.PushCompose(id, &blueprint.Blueprint{}, nil, nil, "x86_64", "qcow2", 0, nil)
|
||||
err = store.PushCompose(distroStruct, id, &blueprint.Blueprint{}, nil, nil, "x86_64", "qcow2", 0, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("error pushing compose: %v", err)
|
||||
}
|
||||
|
|
@ -71,11 +70,11 @@ func testUpdateTransition(t *testing.T, from, to string, expectedStatus int, exp
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
store := store.New(nil, distroStruct, *registry)
|
||||
store := store.New(nil, *registry)
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
if from != "VOID" {
|
||||
err := store.PushCompose(id, &blueprint.Blueprint{}, nil, nil, "x86_64", "qcow2", 0, nil)
|
||||
err := store.PushCompose(distroStruct, id, &blueprint.Blueprint{}, nil, nil, "x86_64", "qcow2", 0, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("error pushing compose: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@ import (
|
|||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
test_distro "github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
"github.com/osbuild/osbuild-composer/internal/target"
|
||||
|
|
@ -93,9 +92,8 @@ func createBaseStoreFixture() *store.Store {
|
|||
},
|
||||
}
|
||||
|
||||
d := test_distro.New()
|
||||
r, _ := distro_mock.NewDefaultRegistry()
|
||||
s := store.New(nil, d, *r)
|
||||
s := store.New(nil, *r)
|
||||
|
||||
s.Blueprints[bName] = b
|
||||
s.Composes = map[uuid.UUID]compose.Compose{
|
||||
|
|
@ -190,9 +188,8 @@ func createStoreWithoutComposesFixture() *store.Store {
|
|||
Customizations: nil,
|
||||
}
|
||||
|
||||
d := test_distro.New()
|
||||
r, _ := distro_mock.NewDefaultRegistry()
|
||||
s := store.New(nil, d, *r)
|
||||
s := store.New(nil, *r)
|
||||
|
||||
s.Blueprints[bName] = b
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import (
|
|||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
|
||||
distro_mock "github.com/osbuild/osbuild-composer/internal/mocks/distro"
|
||||
rpmmd_mock "github.com/osbuild/osbuild-composer/internal/mocks/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/rcm"
|
||||
|
|
@ -53,8 +52,7 @@ func TestBasicRcmAPI(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
distroStruct := fedoratest.New()
|
||||
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()), registry)
|
||||
api := rcm.New(nil, store.New(nil, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()), registry)
|
||||
|
||||
for _, c := range cases {
|
||||
resp := internalRequest(api, c.Method, c.Path, c.Body, c.ContentType)
|
||||
|
|
@ -76,12 +74,11 @@ func TestBasicRcmAPI(t *testing.T) {
|
|||
|
||||
func TestSubmitCompose(t *testing.T) {
|
||||
// Test the most basic use case: Submit a new job and get its status.
|
||||
distroStruct := fedoratest.New()
|
||||
registry, err := distro_mock.NewDefaultRegistry()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
api := rcm.New(nil, store.New(nil, distroStruct, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()), registry)
|
||||
api := rcm.New(nil, store.New(nil, *registry), rpmmd_mock.NewRPMMDMock(rpmmd_mock.BaseFixture()), registry)
|
||||
|
||||
var submit_reply struct {
|
||||
UUID uuid.UUID `json:"compose_id"`
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ type Store struct {
|
|||
mu sync.RWMutex // protects all fields
|
||||
pendingJobs chan Job
|
||||
stateChannel chan []byte
|
||||
distro distro.Distro
|
||||
distroRegistry distro.Registry
|
||||
stateDir *string
|
||||
}
|
||||
|
|
@ -121,7 +120,7 @@ func (e *NoLocalTargetError) Error() string {
|
|||
return e.message
|
||||
}
|
||||
|
||||
func New(stateDir *string, distroArg distro.Distro, distroRegistryArg distro.Registry) *Store {
|
||||
func New(stateDir *string, distroRegistryArg distro.Registry) *Store {
|
||||
var s Store
|
||||
|
||||
if stateDir != nil {
|
||||
|
|
@ -155,7 +154,6 @@ func New(stateDir *string, distroArg distro.Distro, distroRegistryArg distro.Reg
|
|||
}
|
||||
|
||||
s.pendingJobs = make(chan Job, 200)
|
||||
s.distro = distroArg
|
||||
s.distroRegistry = distroRegistryArg
|
||||
s.stateDir = stateDir
|
||||
|
||||
|
|
@ -556,8 +554,18 @@ func (s *Store) GetImageBuildImage(composeId uuid.UUID, imageBuildId int) (io.Re
|
|||
return nil, 0, &NoLocalTargetError{"compose does not have local target"}
|
||||
}
|
||||
|
||||
name, ok := imageBuild.Distro.ToString()
|
||||
if !ok {
|
||||
panic("distro name was validated earlier")
|
||||
}
|
||||
|
||||
distro := s.distroRegistry.GetDistro(name)
|
||||
if distro == nil {
|
||||
panic("distro was validated earlier")
|
||||
}
|
||||
|
||||
compatString, _ := imageBuild.ImageType.ToCompatString()
|
||||
filename, _, err := s.distro.FilenameFromType(compatString)
|
||||
filename, _, err := distro.FilenameFromType(compatString)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
@ -588,7 +596,7 @@ func (s *Store) getImageBuildDirectory(composeID uuid.UUID, imageBuildID int) st
|
|||
return fmt.Sprintf("%s/%d", s.getComposeDirectory(composeID), imageBuildID)
|
||||
}
|
||||
|
||||
func (s *Store) PushCompose(composeID uuid.UUID, bp *blueprint.Blueprint, packages, buildPackages []rpmmd.PackageSpec, arch, composeType string, size uint64, uploadTarget *target.Target) error {
|
||||
func (s *Store) PushCompose(distro distro.Distro, composeID uuid.UUID, bp *blueprint.Blueprint, packages, buildPackages []rpmmd.PackageSpec, arch, composeType string, size uint64, uploadTarget *target.Target) error {
|
||||
targets := []*target.Target{}
|
||||
|
||||
// Compatibility layer for image types in Weldr API v0
|
||||
|
|
@ -610,7 +618,7 @@ func (s *Store) PushCompose(composeID uuid.UUID, bp *blueprint.Blueprint, packag
|
|||
))
|
||||
}
|
||||
|
||||
size = s.distro.GetSizeForOutputType(composeType, size)
|
||||
size = distro.GetSizeForOutputType(composeType, size)
|
||||
|
||||
if uploadTarget != nil {
|
||||
targets = append(targets, uploadTarget)
|
||||
|
|
@ -621,7 +629,7 @@ func (s *Store) PushCompose(composeID uuid.UUID, bp *blueprint.Blueprint, packag
|
|||
repos = append(repos, source.RepoConfig())
|
||||
}
|
||||
|
||||
manifestStruct, err := s.distro.Manifest(bp.Customizations, repos, packages, buildPackages, arch, composeType, size)
|
||||
manifestStruct, err := distro.Manifest(bp.Customizations, repos, packages, buildPackages, arch, composeType, size)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -645,7 +653,7 @@ func (s *Store) PushCompose(composeID uuid.UUID, bp *blueprint.Blueprint, packag
|
|||
s.pendingJobs <- Job{
|
||||
ComposeID: composeID,
|
||||
ImageBuildID: 0,
|
||||
Distro: s.distro.Name(),
|
||||
Distro: distro.Name(),
|
||||
Manifest: manifestStruct,
|
||||
Targets: targets,
|
||||
ImageType: composeType,
|
||||
|
|
@ -863,8 +871,18 @@ func (s *Store) AddImageToImageUpload(composeID uuid.UUID, imageBuildID int, rea
|
|||
return &NoLocalTargetError{fmt.Sprintf("image upload requested for compse %s and image build %d but it has no local target", composeID.String(), imageBuildID)}
|
||||
}
|
||||
|
||||
name, ok := imageBuild.Distro.ToString()
|
||||
if !ok {
|
||||
panic("distro name was validated earlier")
|
||||
}
|
||||
|
||||
distro := s.distroRegistry.GetDistro(name)
|
||||
if distro == nil {
|
||||
panic("distro was validated earlier")
|
||||
}
|
||||
|
||||
imageType, _ := imageBuild.ImageType.ToCompatString()
|
||||
filename, _, err := s.distro.FilenameFromType(imageType)
|
||||
filename, _, err := distro.FilenameFromType(imageType)
|
||||
|
||||
if err != nil {
|
||||
return &InvalidRequestError{err.Error()}
|
||||
|
|
|
|||
|
|
@ -1428,7 +1428,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
err = api.store.PushCompose(reply.BuildID, bp, packages, buildPackages, api.arch, cr.ComposeType, size, uploadTarget)
|
||||
err = api.store.PushCompose(api.distro, reply.BuildID, bp, packages, buildPackages, api.arch, cr.ComposeType, size, uploadTarget)
|
||||
|
||||
// TODO: we should probably do some kind of blueprint validation in future
|
||||
// for now, let's just 500 and bail out
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue