From b9933f6cb2da666d30b09f02d62a599b326cab7f Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Mon, 14 Oct 2019 17:46:14 +0200 Subject: [PATCH] platformtest: add zfsGet bookmark handling & replicationCursor tests This encodes the observation made in issue #230 : In the ZFS version shipped in Ubuntu 16.04 where `zfs get someprop a#bookmark` does not work. --- platformtest/tests/getNonexistent.go | 13 ++++++ platformtest/tests/replicationCursor.go | 62 +++++++++++++++++++++++++ platformtest/tests/tests.go | 1 + zfs/zfs.go | 2 +- 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 platformtest/tests/replicationCursor.go diff --git a/platformtest/tests/getNonexistent.go b/platformtest/tests/getNonexistent.go index 496ec0b..2b961fd 100644 --- a/platformtest/tests/getNonexistent.go +++ b/platformtest/tests/getNonexistent.go @@ -48,4 +48,17 @@ func GetNonexistent(ctx *platformtest.Context) { panic(err) } + // test nonexistent bookmark + nonexistent = fmt.Sprintf("%s/foo bar#non existent", ctx.RootDataset) + props, err = zfs.ZFSGetRawAnySource(nonexistent, []string{"name"}) + if err == nil { + panic(props) + } + dsne, ok = err.(*zfs.DatasetDoesNotExist) + if !ok { + panic(err) + } else if dsne.Path != nonexistent { + panic(err) + } + } diff --git a/platformtest/tests/replicationCursor.go b/platformtest/tests/replicationCursor.go new file mode 100644 index 0000000..91fc75f --- /dev/null +++ b/platformtest/tests/replicationCursor.go @@ -0,0 +1,62 @@ +package tests + +import ( + "fmt" + + "github.com/zrepl/zrepl/platformtest" + "github.com/zrepl/zrepl/zfs" +) + +func ReplicationCursor(ctx *platformtest.Context) { + + platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, ` + CREATEROOT + + "foo bar" + + "foo bar@1 with space" + `) + + ds, err := zfs.NewDatasetPath(ctx.RootDataset + "/foo bar") + if err != nil { + panic(err) + } + guid, err := zfs.ZFSSetReplicationCursor(ds, "1 with space") + if err != nil { + panic(err) + } + snapProps, err := zfs.ZFSGetCreateTXGAndGuid(ds.ToString() + "@1 with space") + if err != nil { + panic(err) + } + if guid != snapProps.Guid { + panic(fmt.Sprintf("guids to not match: %v != %v", guid, snapProps.Guid)) + } + + bm, err := zfs.ZFSGetReplicationCursor(ds) + if err != nil { + panic(err) + } + if bm.CreateTXG != snapProps.CreateTXG { + panic(fmt.Sprintf("createtxgs do not match: %v != %v", bm.CreateTXG, snapProps.CreateTXG)) + } + if bm.Guid != snapProps.Guid { + panic(fmt.Sprintf("guids do not match: %v != %v", bm.Guid, snapProps.Guid)) + } + if bm.Guid != guid { + panic(fmt.Sprintf("guids do not match: %v != %v", bm.Guid, guid)) + } + + // test nonexistent + err = zfs.ZFSDestroyFilesystemVersion(ds, bm) + if err != nil { + panic(err) + } + bm2, err := zfs.ZFSGetReplicationCursor(ds) + if bm2 != nil { + panic(fmt.Sprintf("expecting no replication cursor after deleting it, got %v", bm)) + } + if err != nil { + panic(fmt.Sprintf("expecting no error for getting nonexistent replication cursor, bot %v", err)) + } + + // TODO test moving the replication cursor +} diff --git a/platformtest/tests/tests.go b/platformtest/tests/tests.go index 37d0e2f..0f7b945 100644 --- a/platformtest/tests/tests.go +++ b/platformtest/tests/tests.go @@ -17,4 +17,5 @@ var Cases = []Case{ BatchDestroy, UndestroyableSnapshotParsing, GetNonexistent, + ReplicationCursor, } diff --git a/zfs/zfs.go b/zfs/zfs.go index d555e4b..1cba141 100644 --- a/zfs/zfs.go +++ b/zfs/zfs.go @@ -929,7 +929,7 @@ func ZFSGetRawAnySource(path string, props []string) (*ZFSProperties, error) { return zfsGet(path, props, sourceAny) } -var zfsGetDatasetDoesNotExistRegexp = regexp.MustCompile(`^cannot open '([^)]+)': (dataset does not exist|no such pool or dataset)`) // TODO verify this works +var zfsGetDatasetDoesNotExistRegexp = regexp.MustCompile(`^cannot open '([^)]+)': (dataset does not exist|no such pool or dataset)`) // verified in platformtest type DatasetDoesNotExist struct { Path string