store/json: log on dropping composes on unmarshal
If an invalid compose is encountered, then we drop it. Make sure to log if a logger object is provided. Signed-off-by: Tom Gundersen <teg@jklm.no>
This commit is contained in:
parent
f8db2e28e1
commit
a22cd78eb3
6 changed files with 15 additions and 12 deletions
|
|
@ -117,7 +117,7 @@ func main() {
|
|||
logger = log.New(os.Stdout, "", 0)
|
||||
}
|
||||
|
||||
store := store.New(&stateDir, arch)
|
||||
store := store.New(&stateDir, arch, logger)
|
||||
|
||||
queueDir := path.Join(stateDir, "jobs")
|
||||
err = os.Mkdir(queueDir, 0700)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func FixtureBase() *Store {
|
|||
if err != nil {
|
||||
panic("invalid image type qcow2 for x86_64 @ fedoratest")
|
||||
}
|
||||
s := New(nil, arch)
|
||||
s := New(nil, arch, nil)
|
||||
|
||||
s.blueprints[bName] = b
|
||||
s.composes = map[uuid.UUID]Compose{
|
||||
|
|
@ -206,7 +206,7 @@ func FixtureEmpty() *Store {
|
|||
if err != nil {
|
||||
panic("invalid architecture x86_64 for fedoratest")
|
||||
}
|
||||
s := New(nil, arch)
|
||||
s := New(nil, arch, nil)
|
||||
|
||||
s.blueprints[bName] = b
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package store
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
|
|
@ -92,13 +93,15 @@ func newWorkspaceFromV0(workspaceStruct workspaceV0) map[string]blueprint.Bluepr
|
|||
return workspace
|
||||
}
|
||||
|
||||
func newComposesFromV0(composesStruct composesV0, arch distro.Arch) map[uuid.UUID]Compose {
|
||||
func newComposesFromV0(composesStruct composesV0, arch distro.Arch, log *log.Logger) map[uuid.UUID]Compose {
|
||||
composes := make(map[uuid.UUID]Compose)
|
||||
|
||||
for composeID, composeStruct := range composesStruct {
|
||||
c, err := newComposeFromV0(composeStruct, arch)
|
||||
if err != nil {
|
||||
// Ignore invalid composes.
|
||||
if log != nil {
|
||||
log.Printf("ignoring compose: %v", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
composes[composeID] = c
|
||||
|
|
@ -223,11 +226,11 @@ func newCommitsFromV0(commitsMapStruct commitsV0, changesMapStruct changesV0) ma
|
|||
return commitsMap
|
||||
}
|
||||
|
||||
func newStoreFromV0(storeStruct storeV0, arch distro.Arch) *Store {
|
||||
func newStoreFromV0(storeStruct storeV0, arch distro.Arch, log *log.Logger) *Store {
|
||||
return &Store{
|
||||
blueprints: newBlueprintsFromV0(storeStruct.Blueprints),
|
||||
workspace: newWorkspaceFromV0(storeStruct.Workspace),
|
||||
composes: newComposesFromV0(storeStruct.Composes, arch),
|
||||
composes: newComposesFromV0(storeStruct.Composes, arch, log),
|
||||
sources: newSourceConfigsFromV0(storeStruct.Sources),
|
||||
blueprintsChanges: newChangesFromV0(storeStruct.Changes),
|
||||
blueprintsCommits: newCommitsFromV0(storeStruct.Commits, storeStruct.Changes),
|
||||
|
|
|
|||
|
|
@ -171,12 +171,12 @@ func Test_newStoreFromV0(t *testing.T) {
|
|||
storeStruct: storeV0{},
|
||||
arch: &test_distro.TestArch{},
|
||||
},
|
||||
want: New(nil, &test_distro.TestArch{}),
|
||||
want: New(nil, &test_distro.TestArch{}, nil),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := newStoreFromV0(tt.args.storeStruct, tt.args.arch); !reflect.DeepEqual(got, tt.want) {
|
||||
if got := newStoreFromV0(tt.args.storeStruct, tt.args.arch, nil); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("newStoreFromV0() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ func (e *NoLocalTargetError) Error() string {
|
|||
return e.message
|
||||
}
|
||||
|
||||
func New(stateDir *string, arch distro.Arch) *Store {
|
||||
func New(stateDir *string, arch distro.Arch, log *log.Logger) *Store {
|
||||
var storeStruct storeV0
|
||||
var db *jsondb.JSONDatabase
|
||||
|
||||
|
|
@ -90,7 +90,7 @@ func New(stateDir *string, arch distro.Arch) *Store {
|
|||
}
|
||||
}
|
||||
|
||||
store := newStoreFromV0(storeStruct, arch)
|
||||
store := newStoreFromV0(storeStruct, arch, log)
|
||||
|
||||
store.stateDir = stateDir
|
||||
store.db = db
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ func (suite *storeTest) SetupTest() {
|
|||
arch, err := distro.GetArch("test_arch")
|
||||
suite.NoError(err)
|
||||
suite.dir = tmpDir
|
||||
suite.myStore = New(&suite.dir, arch)
|
||||
suite.myStore = New(&suite.dir, arch, nil)
|
||||
}
|
||||
|
||||
//teardown after each test
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue