Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/core/metastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,14 @@ func MetaStore(conf *config.Config) (meta.Store, error) {
if conf.MetaBackend == "" {
log.WithFunc("core.MetaStore").Info(ctx, "legacy json meta store in use; `cocoon meta convert` upgrades it to sqlite")
}
if s, err := metajson.Open(MetaJSONNamespaces(conf)...); err != nil {
nss := MetaJSONNamespaces(conf)
for _, ns := range nss {
if err := utils.EnsureDirs(filepath.Dir(ns.LockPath)); err != nil {
metaErr = err
return
}
}
if s, err := metajson.Open(nss...); err != nil {
metaErr = err
} else {
metaStore = s
Expand Down
19 changes: 19 additions & 0 deletions cmd/core/metastore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"testing"

"github.com/cocoonstack/cocoon/config"
"github.com/cocoonstack/cocoon/hypervisor"
"github.com/cocoonstack/cocoon/meta"
"github.com/cocoonstack/cocoon/utils"
)

Expand Down Expand Up @@ -39,6 +41,23 @@ func TestMetaStoreBootstrapsFreshRoot(t *testing.T) {
resetMetaStore()
}

func TestMetaStoreJSONFreshRootLocksPeerNamespace(t *testing.T) {
resetMetaStore()
conf := testConf(t)
conf.MetaBackend = config.MetaBackendJSON
s, err := MetaStore(conf)
if err != nil {
t.Fatalf("open fresh json root: %v", err)
}
ch := hypervisor.VMNamespaceName(string(config.HypervisorCloudHypervisor))
fc := hypervisor.VMNamespaceName(string(config.HypervisorFirecracker))
if err := s.Update(t.Context(), meta.Scope{Write: ch, Read: []string{fc}}, meta.CommitDurable, func(meta.Writer) error { return nil }); err != nil {
t.Fatalf("placement-shaped update on a fresh json root: %v", err)
}
CloseMetaStore(t.Context())
resetMetaStore()
}

func TestMetaStoreKeepsLegacyJSON(t *testing.T) {
resetMetaStore()
conf := testConf(t)
Expand Down
Loading