Merge pull request #7081 from kzys/old-kernel

Enable checkRename test
This commit is contained in:
Derek McGowan 2022-12-20 13:43:22 -08:00 committed by GitHub
commit bd61843a25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 21 deletions

View File

@ -47,5 +47,5 @@ func TestSnapshotterClient(t *testing.T) {
if runtime.GOOS == "windows" { if runtime.GOOS == "windows" {
t.Skip("snapshots not yet supported on Windows") t.Skip("snapshots not yet supported on Windows")
} }
testsuite.SnapshotterSuite(t, "SnapshotterClient", newSnapshotter) testsuite.SnapshotterSuite(t, DefaultSnapshotter, newSnapshotter)
} }

View File

@ -57,7 +57,7 @@ func TestOverlay(t *testing.T) {
for optsName, opts := range optTestCases { for optsName, opts := range optTestCases {
t.Run(optsName, func(t *testing.T) { t.Run(optsName, func(t *testing.T) {
newSnapshotter := newSnapshotterWithOpts(opts...) newSnapshotter := newSnapshotterWithOpts(opts...)
testsuite.SnapshotterSuite(t, "Overlay", newSnapshotter) testsuite.SnapshotterSuite(t, "overlayfs", newSnapshotter)
t.Run("TestOverlayMounts", func(t *testing.T) { t.Run("TestOverlayMounts", func(t *testing.T) {
testOverlayMounts(t, newSnapshotter) testOverlayMounts(t, newSnapshotter)
}) })

View File

@ -114,23 +114,33 @@ func checkChown(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, wor
// checkRename // checkRename
// https://github.com/docker/docker/issues/25409 // https://github.com/docker/docker/issues/25409
func checkRename(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) { func checkRename(ss string) func(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) {
t.Skip("rename test still fails on some kernels with overlay") return func(ctx context.Context, t *testing.T, sn snapshots.Snapshotter, work string) {
l1Init := fstest.Apply( l1Init := fstest.Apply(
fstest.CreateDir("/dir1", 0700), fstest.CreateDir("/dir1", 0700),
fstest.CreateDir("/somefiles", 0700), fstest.CreateDir("/somefiles", 0700),
fstest.CreateFile("/somefiles/f1", []byte("was here first!"), 0644), fstest.CreateFile("/somefiles/f1", []byte("was here first!"), 0644),
fstest.CreateFile("/somefiles/f2", []byte("nothing interesting"), 0644), fstest.CreateFile("/somefiles/f2", []byte("nothing interesting"), 0644),
) )
l2Init := fstest.Apply(
fstest.Rename("/dir1", "/dir2"),
fstest.CreateFile("/somefiles/f1-overwrite", []byte("new content 1"), 0644),
fstest.Rename("/somefiles/f1-overwrite", "/somefiles/f1"),
fstest.Rename("/somefiles/f2", "/somefiles/f3"),
)
if err := checkSnapshots(ctx, sn, work, l1Init, l2Init); err != nil { var applier []fstest.Applier
t.Fatalf("Check snapshots failed: %+v", err) if ss != "overlayfs" {
// With neither OVERLAY_FS_REDIRECT_DIR nor redirect_dir,
// renaming the directory on the lower directory doesn't work on overlayfs.
// https://github.com/torvalds/linux/blob/v5.18/Documentation/filesystems/overlayfs.rst#renaming-directories
applier = append(applier, fstest.Rename("/dir1", "/dir2"))
}
applier = append(
applier,
fstest.CreateFile("/somefiles/f1-overwrite", []byte("new content 1"), 0644),
fstest.Rename("/somefiles/f1-overwrite", "/somefiles/f1"),
fstest.Rename("/somefiles/f2", "/somefiles/f3"),
)
l2Init := fstest.Apply(applier...)
if err := checkSnapshots(ctx, sn, work, l1Init, l2Init); err != nil {
t.Fatalf("Check snapshots failed: %+v", err)
}
} }
} }

View File

@ -62,7 +62,6 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn SnapshotterFunc)
t.Run("RemoveIntermediateSnapshot", makeTest(name, snapshotterFn, checkRemoveIntermediateSnapshot)) t.Run("RemoveIntermediateSnapshot", makeTest(name, snapshotterFn, checkRemoveIntermediateSnapshot))
t.Run("DeletedFilesInChildSnapshot", makeTest(name, snapshotterFn, checkDeletedFilesInChildSnapshot)) t.Run("DeletedFilesInChildSnapshot", makeTest(name, snapshotterFn, checkDeletedFilesInChildSnapshot))
t.Run("MoveFileFromLowerLayer", makeTest(name, snapshotterFn, checkFileFromLowerLayer)) t.Run("MoveFileFromLowerLayer", makeTest(name, snapshotterFn, checkFileFromLowerLayer))
t.Run("Rename", makeTest(name, snapshotterFn, checkRename))
t.Run("ViewReadonly", makeTest(name, snapshotterFn, checkSnapshotterViewReadonly)) t.Run("ViewReadonly", makeTest(name, snapshotterFn, checkSnapshotterViewReadonly))
@ -70,10 +69,16 @@ func SnapshotterSuite(t *testing.T, name string, snapshotterFn SnapshotterFunc)
t.Run("CloseTwice", makeTest(name, snapshotterFn, closeTwice)) t.Run("CloseTwice", makeTest(name, snapshotterFn, closeTwice))
t.Run("RootPermission", makeTest(name, snapshotterFn, checkRootPermission)) t.Run("RootPermission", makeTest(name, snapshotterFn, checkRootPermission))
// Different snapshotters behave slightly differently in the tests below.
t.Run("Rename", makeTest(name, snapshotterFn, checkRename(name)))
t.Run("128LayersMount", makeTest(name, snapshotterFn, check128LayersMount(name))) t.Run("128LayersMount", makeTest(name, snapshotterFn, check128LayersMount(name)))
} }
func makeTest(name string, snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error), fn func(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string)) func(t *testing.T) { func makeTest(
snapshotter string,
snapshotterFn func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error),
fn func(ctx context.Context, t *testing.T, snapshotter snapshots.Snapshotter, work string),
) func(t *testing.T) {
return func(t *testing.T) { return func(t *testing.T) {
t.Parallel() t.Parallel()
@ -85,7 +90,7 @@ func makeTest(name string, snapshotterFn func(ctx context.Context, root string)
// work/ -> passed to test functions // work/ -> passed to test functions
// root/ -> passed to snapshotter // root/ -> passed to snapshotter
// //
tmpDir, err := os.MkdirTemp("", "snapshot-suite-"+name+"-") tmpDir, err := os.MkdirTemp("", "snapshot-suite-"+snapshotter+"-")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }