weldr: pin a real Arch object, rather than a string
weldr needs to know the host architecture. Rather than pinning a string, pin a real Arch object, and query its name when we need it. This verifies the validitiy of the architecture for the given distro before it is passed to weldr, rather than lazily on demand. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
bbd8dc338d
commit
f201fc84b7
4 changed files with 24 additions and 11 deletions
|
|
@ -100,6 +100,11 @@ func main() {
|
|||
log.Fatalf("Could not determine distro from host: " + err.Error())
|
||||
}
|
||||
|
||||
arch, err := distribution.GetArch(common.CurrentArch())
|
||||
if err != nil {
|
||||
log.Fatalf("Host distro does not support host architecture: " + err.Error())
|
||||
}
|
||||
|
||||
repoMap, err := rpmmd.LoadRepositories([]string{"/etc/osbuild-composer", "/usr/share/osbuild-composer"}, distribution.Name())
|
||||
if err != nil {
|
||||
log.Fatalf("Could not load repositories for %s: %v", distribution.Name(), err)
|
||||
|
|
@ -113,7 +118,7 @@ func main() {
|
|||
store := store.New(&stateDir)
|
||||
|
||||
jobAPI := jobqueue.New(logger, store)
|
||||
weldrAPI := weldr.New(rpm, common.CurrentArch(), distribution, repoMap[common.CurrentArch()], logger, store)
|
||||
weldrAPI := weldr.New(rpm, arch, distribution, repoMap[common.CurrentArch()], logger, store)
|
||||
|
||||
go func() {
|
||||
err := jobAPI.Serve(jobListener)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
test_distro "github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/fedoratest"
|
||||
rpmmd_mock "github.com/osbuild/osbuild-composer/internal/mocks/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/weldr"
|
||||
|
|
@ -209,10 +209,14 @@ func TestMain(m *testing.M) {
|
|||
// Create a mock API server listening on the temporary socket
|
||||
fixture := rpmmd_mock.BaseFixture()
|
||||
rpm := rpmmd_mock.NewRPMMDMock(fixture)
|
||||
distro := test_distro.New()
|
||||
distro := fedoratest.New()
|
||||
arch, err := distro.GetArch("x86_64")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
repos := []rpmmd.RepoConfig{{Id: "test-id", BaseURL: "http://example.com/test/os/test_arch"}}
|
||||
logger := log.New(os.Stdout, "", 0)
|
||||
api := weldr.New(rpm, "test_arch", distro, repos, logger, fixture.Store)
|
||||
api := weldr.New(rpm, arch, distro, repos, logger, fixture.Store)
|
||||
server := http.Server{Handler: api}
|
||||
defer server.Close()
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ type API struct {
|
|||
store *store.Store
|
||||
|
||||
rpmmd rpmmd.RPMMD
|
||||
arch string
|
||||
arch distro.Arch
|
||||
distro distro.Distro
|
||||
repos []rpmmd.RepoConfig
|
||||
|
||||
|
|
@ -39,7 +39,7 @@ type API struct {
|
|||
router *httprouter.Router
|
||||
}
|
||||
|
||||
func New(rpmmd rpmmd.RPMMD, arch string, distro distro.Distro, repos []rpmmd.RepoConfig, logger *log.Logger, store *store.Store) *API {
|
||||
func New(rpmmd rpmmd.RPMMD, arch distro.Arch, distro distro.Distro, repos []rpmmd.RepoConfig, logger *log.Logger, store *store.Store) *API {
|
||||
// This needs to be shared with the worker API so that they can communicate with each other
|
||||
// builds := make(chan queue.Build, 200)
|
||||
api := &API{
|
||||
|
|
@ -845,7 +845,7 @@ func (api *API) blueprintsDepsolveHandler(writer http.ResponseWriter, request *h
|
|||
continue
|
||||
}
|
||||
|
||||
dependencies, _, err := api.depsolveBlueprint(blueprint, "", api.arch)
|
||||
dependencies, _, err := api.depsolveBlueprint(blueprint, "", api.arch.Name())
|
||||
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
|
|
@ -941,7 +941,7 @@ func (api *API) blueprintsFreezeHandler(writer http.ResponseWriter, request *htt
|
|||
break
|
||||
}
|
||||
|
||||
dependencies, _, err := api.depsolveBlueprint(&blueprint, "", api.arch)
|
||||
dependencies, _, err := api.depsolveBlueprint(&blueprint, "", api.arch.Name())
|
||||
if err != nil {
|
||||
rerr := responseError{
|
||||
ID: "BlueprintsError",
|
||||
|
|
@ -1410,7 +1410,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
|
|||
|
||||
bp := api.store.GetBlueprintCommitted(cr.BlueprintName)
|
||||
if bp != nil {
|
||||
packages, buildPackages, err := api.depsolveBlueprint(bp, cr.ComposeType, api.arch)
|
||||
packages, buildPackages, err := api.depsolveBlueprint(bp, cr.ComposeType, api.arch.Name())
|
||||
if err != nil {
|
||||
errors := responseError{
|
||||
ID: "DepsolveError",
|
||||
|
|
@ -1420,7 +1420,7 @@ func (api *API) composeHandler(writer http.ResponseWriter, request *http.Request
|
|||
return
|
||||
}
|
||||
|
||||
err = api.store.PushCompose(api.distro, reply.BuildID, bp, api.repos, packages, buildPackages, api.arch, cr.ComposeType, cr.Size, uploadTarget)
|
||||
err = api.store.PushCompose(api.distro, reply.BuildID, bp, api.repos, packages, buildPackages, api.arch.Name(), cr.ComposeType, cr.Size, uploadTarget)
|
||||
|
||||
// TODO: we should probably do some kind of blueprint validation in future
|
||||
// for now, let's just 500 and bail out
|
||||
|
|
|
|||
|
|
@ -33,8 +33,12 @@ func createWeldrAPI(fixtureGenerator rpmmd_mock.FixtureGenerator) (*API, *store.
|
|||
rpm := rpmmd_mock.NewRPMMDMock(fixture)
|
||||
repos := []rpmmd.RepoConfig{{Id: "test-id", BaseURL: "http://example.com/test/os/x86_64"}}
|
||||
d := test_distro.New()
|
||||
arch, err := d.GetArch("x86_64")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return New(rpm, "x86_64", d, repos, nil, fixture.Store), fixture.Store
|
||||
return New(rpm, arch, d, repos, nil, fixture.Store), fixture.Store
|
||||
}
|
||||
|
||||
func TestBasic(t *testing.T) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue