From a5c9450b2de6ebfe32243be2e50562182def00ab Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sun, 24 May 2020 17:49:16 +0200 Subject: [PATCH] [#321] platformtest: add test for zfs.ZFSHolds --- platformtest/tests/generated_cases.go | 2 + platformtest/tests/holds.go | 32 ++++++++++++++++ platformtest/tests/recvRollback.go | 54 +++++++++++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 platformtest/tests/holds.go create mode 100644 platformtest/tests/recvRollback.go diff --git a/platformtest/tests/generated_cases.go b/platformtest/tests/generated_cases.go index 01ed559..311944d 100644 --- a/platformtest/tests/generated_cases.go +++ b/platformtest/tests/generated_cases.go @@ -5,6 +5,7 @@ package tests var Cases = []Case{BatchDestroy, CreateReplicationCursor, GetNonexistent, + HoldsWork, IdempotentBookmark, IdempotentDestroy, IdempotentHold, @@ -14,6 +15,7 @@ var Cases = []Case{BatchDestroy, ListFilesystemVersionsZeroExistIsNotAnError, ListFilesystemsNoFilter, ReceiveForceIntoEncryptedErr, + ReceiveForceRollbackWorksUnencrypted, ReplicationIncrementalCleansUpStaleAbstractionsWithCacheOnSecondReplication, ReplicationIncrementalCleansUpStaleAbstractionsWithoutCacheOnSecondReplication, ReplicationIncrementalIsPossibleIfCommonSnapshotIsDestroyed, diff --git a/platformtest/tests/holds.go b/platformtest/tests/holds.go new file mode 100644 index 0000000..e0b09e6 --- /dev/null +++ b/platformtest/tests/holds.go @@ -0,0 +1,32 @@ +package tests + +import ( + "path" + + "github.com/stretchr/testify/require" + "github.com/zrepl/zrepl/platformtest" + "github.com/zrepl/zrepl/zfs" +) + +func HoldsWork(ctx *platformtest.Context) { + platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, ` + DESTROYROOT + CREATEROOT + + "foo bar" + + "foo bar@snap name" + `) + + fs := path.Join(ctx.RootDataset, "foo bar") + + err := zfs.ZFSHold(ctx, fs, fsversion(ctx, fs, "@snap name"), "tag 1") + require.NoError(ctx, err) + + err = zfs.ZFSHold(ctx, fs, fsversion(ctx, fs, "@snap name"), "tag 2") + require.NoError(ctx, err) + + holds, err := zfs.ZFSHolds(ctx, fs, "snap name") + require.NoError(ctx, err) + require.Len(ctx, holds, 2) + require.Contains(ctx, holds, "tag 1") + require.Contains(ctx, holds, "tag 2") +} diff --git a/platformtest/tests/recvRollback.go b/platformtest/tests/recvRollback.go new file mode 100644 index 0000000..149e694 --- /dev/null +++ b/platformtest/tests/recvRollback.go @@ -0,0 +1,54 @@ +package tests + +import ( + "fmt" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/zrepl/zrepl/platformtest" + "github.com/zrepl/zrepl/zfs" +) + +func ReceiveForceRollbackWorksUnencrypted(ctx *platformtest.Context) { + platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, ` + DESTROYROOT + CREATEROOT + + "foo bar" + + "foo bar@a snap" + + "foo bar@another snap" + + "foo bar@snap3" + + "sender" + + "sender@1" + `) + + rfs := fmt.Sprintf("%s/foo bar", ctx.RootDataset) + sfs := fmt.Sprintf("%s/sender", ctx.RootDataset) + sfsSnap1 := sendArgVersion(ctx, sfs, "@1") + + sendArgs, err := zfs.ZFSSendArgsUnvalidated{ + FS: sfs, + Encrypted: &zfs.NilBool{B: false}, + From: nil, + To: &sfsSnap1, + ResumeToken: "", + }.Validate(ctx) + require.NoError(ctx, err) + + sendStream, err := zfs.ZFSSend(ctx, sendArgs) + require.NoError(ctx, err) + + recvOpts := zfs.RecvOptions{ + RollbackAndForceRecv: true, + SavePartialRecvState: false, + } + err = zfs.ZFSRecv(ctx, rfs, &zfs.ZFSSendArgVersion{RelName: "@1", GUID: sfsSnap1.GUID}, sendStream, recvOpts) + require.NoError(ctx, err) + + // assert exists on receiver + rfsSnap1 := fsversion(ctx, rfs, "@1") + // assert it's the only one (rollback and force-recv should be blowing away the other filesystems) + rfsVersions, err := zfs.ZFSListFilesystemVersions(ctx, mustDatasetPath(rfs), zfs.ListFilesystemVersionsOptions{}) + require.NoError(ctx, err) + assert.Len(ctx, rfsVersions, 1) + assert.Equal(ctx, rfsVersions[0], rfsSnap1) +}