From 121d3377134a61be8250aa64cae5b6d702968371 Mon Sep 17 00:00:00 2001 From: Kunal Kushwaha Date: Thu, 7 Sep 2017 13:31:04 +0900 Subject: [PATCH 1/2] Added testcase Removal of intermediate snapshot Removal of intermediate snapshot layer must fail. Signed-off-by: Kunal Kushwaha --- snapshot/testsuite/testsuite.go | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/snapshot/testsuite/testsuite.go b/snapshot/testsuite/testsuite.go index b7bae12aa..3b2c0c474 100644 --- a/snapshot/testsuite/testsuite.go +++ b/snapshot/testsuite/testsuite.go @@ -35,6 +35,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context. t.Run("RemoveDirectoryInLowerLayer", makeTest(name, snapshotterFn, checkRemoveDirectoryInLowerLayer)) t.Run("Chown", makeTest(name, snapshotterFn, checkChown)) t.Run("DirectoryPermissionOnCommit", makeTest(name, snapshotterFn, checkDirectoryPermissionOnCommit)) + t.Run("RemoveIntermediateSnapshot", makeTest(name, snapshotterFn, checkRemoveIntermediateSnapshot)) // Rename test still fails on some kernels with overlay //t.Run("Rename", makeTest(name, snapshotterFn, checkRename)) @@ -437,6 +438,58 @@ func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter } +//Create three layers. Deleting intermediate layer must fail. +func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) { + + base, err := snapshotterPrepareMount(ctx, snapshotter, "base", "", work) + if err != nil { + t.Fatal(err) + } + defer testutil.Unmount(t, base) + + committedBase := filepath.Join(work, "committed-base") + if err = snapshotter.Commit(ctx, committedBase, base); err != nil { + t.Fatal(err) + } + + // Create intermediate layer + intermediate := filepath.Join(work, "intermediate") + if _, err = snapshotter.Prepare(ctx, intermediate, committedBase); err != nil { + t.Fatal(err) + } + + committedInter := filepath.Join(work, "committed-inter") + if err = snapshotter.Commit(ctx, committedInter, intermediate); err != nil { + t.Fatal(err) + } + + // Create top layer + topLayer := filepath.Join(work, "toplayer") + if _, err = snapshotter.Prepare(ctx, topLayer, committedInter); err != nil { + t.Fatal(err) + } + + // Deletion of intermediate layer must fail. + err = snapshotter.Remove(ctx, committedInter) + if err == nil { + t.Fatal("intermediate layer removal should fail.") + } + + //Removal from toplayer to base should not fail. + err = snapshotter.Remove(ctx, topLayer) + if err != nil { + t.Fatal(err) + } + err = snapshotter.Remove(ctx, committedInter) + if err != nil { + t.Fatal(err) + } + err = snapshotter.Remove(ctx, committedBase) + if err != nil { + t.Fatal(err) + } +} + // baseTestSnapshots creates a base set of snapshots for tests, each snapshot is empty // Tests snapshots: // c1 - committed snapshot, no parent From b6fb234142c4c2f896d8b5b8b7120e6b0f718c0d Mon Sep 17 00:00:00 2001 From: Kunal Kushwaha Date: Thu, 7 Sep 2017 13:34:33 +0900 Subject: [PATCH 2/2] Testcase added for deletion of files in lower layer Files/folders deleted in lower layer and commited, it should not reflect on upper layer Signed-off-by: Kunal Kushwaha --- snapshot/testsuite/testsuite.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/snapshot/testsuite/testsuite.go b/snapshot/testsuite/testsuite.go index 3b2c0c474..67e35b5a0 100644 --- a/snapshot/testsuite/testsuite.go +++ b/snapshot/testsuite/testsuite.go @@ -36,7 +36,7 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn func(ctx context. t.Run("Chown", makeTest(name, snapshotterFn, checkChown)) t.Run("DirectoryPermissionOnCommit", makeTest(name, snapshotterFn, checkDirectoryPermissionOnCommit)) t.Run("RemoveIntermediateSnapshot", makeTest(name, snapshotterFn, checkRemoveIntermediateSnapshot)) - + t.Run("DeletedFilesInChildSnapshot", makeTest(name, snapshotterFn, checkDeletedFilesInChildSnapshot)) // Rename test still fails on some kernels with overlay //t.Run("Rename", makeTest(name, snapshotterFn, checkRename)) @@ -438,6 +438,24 @@ func checkSnapshotterPrepareView(ctx context.Context, t *testing.T, snapshotter } +// Deletion of files/folder of base layer in new layer, On Commit, those files should not be visible. +func checkDeletedFilesInChildSnapshot(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) { + + l1Init := fstest.Apply( + fstest.CreateFile("/foo", []byte("foo\n"), 0777), + fstest.CreateFile("/foobar", []byte("foobar\n"), 0777), + ) + l2Init := fstest.Apply( + fstest.RemoveAll("/foobar"), + ) + l3Init := fstest.Apply() + + if err := checkSnapshots(ctx, snapshotter, work, l1Init, l2Init, l3Init); err != nil { + t.Fatalf("Check snapshots failed: %+v", err) + } + +} + //Create three layers. Deleting intermediate layer must fail. func checkRemoveIntermediateSnapshot(ctx context.Context, t *testing.T, snapshotter snapshot.Snapshotter, work string) {