Update overlay snapshot driver to use metastore
Update tests to use boltdb. Update test suite to pass context. Signed-off-by: Derek McGowan <derek@mcgstyle.net> (github: dmcgowan)
This commit is contained in:
parent
63ea9908c0
commit
61b524aff2
4 changed files with 242 additions and 314 deletions
|
@ -11,20 +11,27 @@ import (
|
|||
|
||||
"github.com/docker/containerd"
|
||||
"github.com/docker/containerd/snapshot"
|
||||
"github.com/docker/containerd/snapshot/storage/boltdb"
|
||||
"github.com/docker/containerd/snapshot/testsuite"
|
||||
"github.com/docker/containerd/testutil"
|
||||
)
|
||||
|
||||
func boltSnapshotter(ctx context.Context, root string) (snapshot.Snapshotter, func(), error) {
|
||||
store, err := boltdb.NewMetaStore(ctx, filepath.Join(root, "metadata.db"))
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
snapshotter, err := NewSnapshotter(root, store)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return snapshotter, func() {}, nil
|
||||
}
|
||||
|
||||
func TestOverlay(t *testing.T) {
|
||||
testutil.RequiresRoot(t)
|
||||
testsuite.SnapshotterSuite(t, "Overlay", func(root string) (snapshot.Snapshotter, func(), error) {
|
||||
snapshotter, err := NewSnapshotter(root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
return snapshotter, func() {}, nil
|
||||
})
|
||||
testsuite.SnapshotterSuite(t, "Overlay", boltSnapshotter)
|
||||
}
|
||||
|
||||
func TestOverlayMounts(t *testing.T) {
|
||||
|
@ -34,7 +41,7 @@ func TestOverlayMounts(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(root)
|
||||
o, err := NewSnapshotter(root)
|
||||
o, _, err := boltSnapshotter(ctx, root)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -51,7 +58,7 @@ func TestOverlayMounts(t *testing.T) {
|
|||
if m.Type != "bind" {
|
||||
t.Errorf("mount type should be bind but received %q", m.Type)
|
||||
}
|
||||
expected := filepath.Join(root, "active", hash("/tmp/test"), "fs")
|
||||
expected := filepath.Join(root, "snapshots", "1", "fs")
|
||||
if m.Source != expected {
|
||||
t.Errorf("expected source %q but received %q", expected, m.Source)
|
||||
}
|
||||
|
@ -70,7 +77,7 @@ func TestOverlayCommit(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(root)
|
||||
o, err := NewSnapshotter(root)
|
||||
o, _, err := boltSnapshotter(ctx, root)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -99,7 +106,7 @@ func TestOverlayOverlayMount(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(root)
|
||||
o, err := NewSnapshotter(root)
|
||||
o, _, err := boltSnapshotter(ctx, root)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -129,11 +136,10 @@ func TestOverlayOverlayMount(t *testing.T) {
|
|||
t.Errorf("expected source %q but received %q", "overlay", m.Source)
|
||||
}
|
||||
var (
|
||||
ah = hash("/tmp/layer2")
|
||||
sh = hash("base")
|
||||
work = "workdir=" + filepath.Join(root, "active", ah, "work")
|
||||
upper = "upperdir=" + filepath.Join(root, "active", ah, "fs")
|
||||
lower = "lowerdir=" + filepath.Join(root, "committed", sh, "fs")
|
||||
bp = getBasePath(ctx, o, root, "/tmp/layer2")
|
||||
work = "workdir=" + filepath.Join(bp, "work")
|
||||
upper = "upperdir=" + filepath.Join(bp, "fs")
|
||||
lower = "lowerdir=" + getParents(ctx, o, root, "/tmp/layer2")[0]
|
||||
)
|
||||
for i, v := range []string{
|
||||
work,
|
||||
|
@ -146,6 +152,40 @@ func TestOverlayOverlayMount(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func getBasePath(ctx context.Context, sn snapshot.Snapshotter, root, key string) string {
|
||||
o := sn.(*Snapshotter)
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer t.Rollback()
|
||||
|
||||
active, err := o.ms.GetActive(ctx, key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return filepath.Join(root, "snapshots", active.ID)
|
||||
}
|
||||
|
||||
func getParents(ctx context.Context, sn snapshot.Snapshotter, root, key string) []string {
|
||||
o := sn.(*Snapshotter)
|
||||
ctx, t, err := o.ms.TransactionContext(ctx, false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer t.Rollback()
|
||||
active, err := o.ms.GetActive(ctx, key)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
parents := make([]string, len(active.ParentIDs))
|
||||
for i := range active.ParentIDs {
|
||||
parents[i] = filepath.Join(root, "snapshots", active.ParentIDs[i], "fs")
|
||||
}
|
||||
return parents
|
||||
}
|
||||
|
||||
func TestOverlayOverlayRead(t *testing.T) {
|
||||
testutil.RequiresRoot(t)
|
||||
ctx := context.TODO()
|
||||
|
@ -154,7 +194,7 @@ func TestOverlayOverlayRead(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(root)
|
||||
o, err := NewSnapshotter(root)
|
||||
o, _, err := boltSnapshotter(ctx, root)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
|
@ -206,7 +246,7 @@ func TestOverlayView(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(root)
|
||||
o, err := NewSnapshotter(root)
|
||||
o, _, err := boltSnapshotter(ctx, root)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -228,7 +268,7 @@ func TestOverlayView(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ioutil.WriteFile(filepath.Join(root, "active", hash(key), "fs", "foo"), []byte("hi, again"), 0660); err != nil {
|
||||
if err := ioutil.WriteFile(filepath.Join(getParents(ctx, o, root, "/tmp/top")[0], "foo"), []byte("hi, again"), 0660); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := o.Commit(ctx, "top", key); err != nil {
|
||||
|
@ -246,7 +286,7 @@ func TestOverlayView(t *testing.T) {
|
|||
if m.Type != "bind" {
|
||||
t.Errorf("mount type should be bind but received %q", m.Type)
|
||||
}
|
||||
expected := filepath.Join(root, "committed", hash("base"), "fs")
|
||||
expected := getParents(ctx, o, root, "/tmp/view1")[0]
|
||||
if m.Source != expected {
|
||||
t.Errorf("expected source %q but received %q", expected, m.Source)
|
||||
}
|
||||
|
@ -274,7 +314,8 @@ func TestOverlayView(t *testing.T) {
|
|||
if len(m.Options) != 1 {
|
||||
t.Errorf("expected 1 mount option but got %d", len(m.Options))
|
||||
}
|
||||
expected = fmt.Sprintf("lowerdir=%s:%s", filepath.Join(root, "committed", hash("top"), "fs"), filepath.Join(root, "committed", hash("base"), "fs"))
|
||||
lowers := getParents(ctx, o, root, "/tmp/view2")
|
||||
expected = fmt.Sprintf("lowerdir=%s:%s", lowers[0], lowers[1])
|
||||
if m.Options[0] != expected {
|
||||
t.Errorf("expected option %q but received %q", expected, m.Options[0])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue