distro: don't fall back to fedora-30
Make osbuild-composer use FromHost() directly. Everywhere else needs to specify the distro explicitly. Also don't panic when a distro doesn't exist. Instead, return nil. Make sure all callers check for that.
This commit is contained in:
parent
70857963bb
commit
85e6182bdc
7 changed files with 34 additions and 33 deletions
|
|
@ -34,14 +34,18 @@ func main() {
|
|||
jobListener := listeners[1]
|
||||
|
||||
rpm := rpmmd.NewRPMMD()
|
||||
distribution := distro.New("")
|
||||
|
||||
distribution, err := distro.FromHost()
|
||||
if err != nil {
|
||||
panic("cannot detect distro from host: " + err.Error())
|
||||
}
|
||||
|
||||
var logger *log.Logger
|
||||
if verbose {
|
||||
logger = log.New(os.Stdout, "", 0)
|
||||
}
|
||||
|
||||
store := store.New(&stateFile)
|
||||
store := store.New(&stateFile, distribution)
|
||||
|
||||
jobAPI := jobqueue.New(logger, store)
|
||||
weldrAPI := weldr.New(rpm, distribution, logger, store)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,10 @@ func main() {
|
|||
}
|
||||
|
||||
d := distro.New(distroArg)
|
||||
if d == nil {
|
||||
panic("unknown distro: " + distroArg)
|
||||
}
|
||||
|
||||
pipeline, err := d.Pipeline(blueprint, format)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bufio"
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
|
|
@ -44,20 +43,9 @@ func init() {
|
|||
}
|
||||
|
||||
func New(name string) Distro {
|
||||
if name == "" {
|
||||
distro, err := FromHost()
|
||||
if err == nil {
|
||||
return distro
|
||||
} else {
|
||||
log.Println("cannot detect distro from host: " + err.Error())
|
||||
log.Println("falling back to 'fedora-30'")
|
||||
return New("fedora-30")
|
||||
}
|
||||
}
|
||||
|
||||
distro, ok := registered[name]
|
||||
if !ok {
|
||||
panic("unknown distro: " + name)
|
||||
return nil
|
||||
}
|
||||
|
||||
return distro
|
||||
|
|
@ -77,11 +65,12 @@ func FromHost() (Distro, error) {
|
|||
|
||||
name := osrelease["ID"] + "-" + osrelease["VERSION_ID"]
|
||||
|
||||
distro, ok := registered[name]
|
||||
if !ok {
|
||||
d := New(name)
|
||||
if d == nil {
|
||||
return nil, errors.New("unknown distro: " + name)
|
||||
}
|
||||
return distro, nil
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func Register(name string, distro Distro) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/jobqueue"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
"github.com/osbuild/osbuild-composer/internal/test"
|
||||
|
|
@ -31,7 +32,7 @@ func TestBasic(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, c := range cases {
|
||||
api := jobqueue.New(nil, store.New(nil))
|
||||
api := jobqueue.New(nil, store.New(nil, distro.New("fedora-30")))
|
||||
|
||||
test.TestRoute(t, api, false, c.Method, c.Path, c.Body, c.ExpectedStatus, c.ExpectedJSON)
|
||||
}
|
||||
|
|
@ -39,7 +40,7 @@ func TestBasic(t *testing.T) {
|
|||
|
||||
func TestCreate(t *testing.T) {
|
||||
id, _ := uuid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff")
|
||||
store := store.New(nil)
|
||||
store := store.New(nil, distro.New("fedora-30"))
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
err := store.PushCompose(id, &blueprint.Blueprint{}, "tar")
|
||||
|
|
@ -53,7 +54,7 @@ func TestCreate(t *testing.T) {
|
|||
|
||||
func testUpdateTransition(t *testing.T, from, to string, expectedStatus int) {
|
||||
id, _ := uuid.Parse("ffffffff-ffff-ffff-ffff-ffffffffffff")
|
||||
store := store.New(nil)
|
||||
store := store.New(nil, distro.New("fedora-30"))
|
||||
api := jobqueue.New(nil, store)
|
||||
|
||||
if from != "VOID" {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,14 @@ package rpmmd_mock
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/osbuild/osbuild-composer/internal/blueprint"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/rpmmd"
|
||||
"github.com/osbuild/osbuild-composer/internal/store"
|
||||
)
|
||||
|
||||
type FixtureGenerator func() Fixture
|
||||
|
|
@ -56,7 +58,8 @@ func createBaseStoreFixture() *store.Store {
|
|||
|
||||
var date = time.Date(2019, 11, 27, 13, 19, 0, 0, time.FixedZone("UTC+1", 60*60))
|
||||
|
||||
s := store.New(nil)
|
||||
d := distro.New("fedora-30")
|
||||
s := store.New(nil, d)
|
||||
|
||||
s.Blueprints[bName] = b
|
||||
s.Composes = map[uuid.UUID]store.Compose{
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ type Store struct {
|
|||
mu sync.RWMutex // protects all fields
|
||||
pendingJobs chan Job
|
||||
stateChannel chan []byte
|
||||
distro distro.Distro
|
||||
}
|
||||
|
||||
// A Compose represent the task of building one image. It contains all the information
|
||||
|
|
@ -105,7 +106,7 @@ func (e *InvalidRequestError) Error() string {
|
|||
return e.message
|
||||
}
|
||||
|
||||
func New(stateFile *string) *Store {
|
||||
func New(stateFile *string, distro distro.Distro) *Store {
|
||||
var s Store
|
||||
|
||||
if stateFile != nil {
|
||||
|
|
@ -149,6 +150,8 @@ func New(stateFile *string) *Store {
|
|||
}
|
||||
s.pendingJobs = make(chan Job, 200)
|
||||
|
||||
s.distro = distro
|
||||
|
||||
return &s
|
||||
}
|
||||
|
||||
|
|
@ -448,8 +451,7 @@ func (s *Store) PushCompose(composeID uuid.UUID, bp *blueprint.Blueprint, compos
|
|||
},
|
||||
),
|
||||
}
|
||||
d := distro.New("")
|
||||
pipeline, err := d.Pipeline(bp, composeType)
|
||||
pipeline, err := s.distro.Pipeline(bp, composeType)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -527,8 +529,7 @@ func (s *Store) GetImage(composeID uuid.UUID) (*Image, error) {
|
|||
if compose.QueueStatus != "FINISHED" {
|
||||
return nil, &InvalidRequestError{"compose was not finished"}
|
||||
}
|
||||
d := distro.New("")
|
||||
name, mime, err := d.FilenameFromType(compose.OutputType)
|
||||
name, mime, err := s.distro.FilenameFromType(compose.OutputType)
|
||||
if err != nil {
|
||||
panic("invalid output type")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1195,8 +1195,7 @@ func (api *API) composeTypesHandler(writer http.ResponseWriter, request *http.Re
|
|||
Types []composeType `json:"types"`
|
||||
}
|
||||
|
||||
d := distro.New("")
|
||||
for _, format := range d.ListOutputFormats() {
|
||||
for _, format := range api.distro.ListOutputFormats() {
|
||||
reply.Types = append(reply.Types, composeType{format, true})
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue