From 0c189265e82e5ec61ea05782bd2ccc9bef2c7c5c Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 5 Sep 2020 16:04:34 +0200 Subject: [PATCH] platformtests: fix skipping encryption-only tests on systems that don't support encryption (Or split the test into two tests of which one is skipped depending on encryption support) --- platformtest/tests/generated_cases.go | 3 +- .../tests/recvForceIntoEncryptedErr.go | 8 +++++ platformtest/tests/sendArgsValidation.go | 29 ++++++++++++------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/platformtest/tests/generated_cases.go b/platformtest/tests/generated_cases.go index 593a06d..da1cc74 100644 --- a/platformtest/tests/generated_cases.go +++ b/platformtest/tests/generated_cases.go @@ -29,7 +29,8 @@ var Cases = []Case{BatchDestroy, ReplicationStepCompletedLostBehavior__GuaranteeResumability, ResumableRecvAndTokenHandling, ResumeTokenParsing, - SendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden, + SendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden__EncryptionSupported_false, + SendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden__EncryptionSupported_true, SendArgsValidationResumeTokenDifferentFilesystemForbidden, SendArgsValidationResumeTokenEncryptionMismatchForbidden, UndestroyableSnapshotParsing, diff --git a/platformtest/tests/recvForceIntoEncryptedErr.go b/platformtest/tests/recvForceIntoEncryptedErr.go index 37677e7..3134a3c 100644 --- a/platformtest/tests/recvForceIntoEncryptedErr.go +++ b/platformtest/tests/recvForceIntoEncryptedErr.go @@ -10,6 +10,14 @@ import ( ) func ReceiveForceIntoEncryptedErr(ctx *platformtest.Context) { + + supported, err := zfs.EncryptionCLISupported(ctx) + require.NoError(ctx, err, "encryption feature test failed") + if !supported { + ctx.SkipNow() + return + } + platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, ` DESTROYROOT CREATEROOT diff --git a/platformtest/tests/sendArgsValidation.go b/platformtest/tests/sendArgsValidation.go index 416c046..4d2d409 100644 --- a/platformtest/tests/sendArgsValidation.go +++ b/platformtest/tests/sendArgsValidation.go @@ -9,11 +9,22 @@ import ( "github.com/zrepl/zrepl/zfs" ) -func SendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden(ctx *platformtest.Context) { +func SendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden__EncryptionSupported_true(ctx *platformtest.Context) { + sendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden_impl(ctx, true) +} + +func SendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden__EncryptionSupported_false(ctx *platformtest.Context) { + sendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden_impl(ctx, false) +} + +func sendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden_impl(ctx *platformtest.Context, testForEncryptionSupported bool) { supported, err := zfs.EncryptionCLISupported(ctx) check(err) - expectNotSupportedErr := !supported + if supported != testForEncryptionSupported { + ctx.SkipNow() + } + noEncryptionCLISupport := !supported platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, ` DESTROYROOT @@ -44,9 +55,11 @@ func SendArgsValidationEncryptedSendOfUnencryptedDatasetForbidden(ctx *platformt // fallthrough } - if expectNotSupportedErr { + if noEncryptionCLISupport { require.Error(ctx, err) - require.Equal(ctx, zfs.ErrEncryptedSendNotSupported, err) + saverr, ok := err.(*zfs.ZFSSendArgsValidationError) + require.True(ctx, ok, "%T", err) + require.Equal(ctx, zfs.ZFSSendArgsEncryptedSendRequestedButFSUnencrypted, saverr.What) return } require.Error(ctx, err) @@ -138,13 +151,7 @@ func SendArgsValidationResumeTokenEncryptionMismatchForbidden(ctx *platformtest. } func SendArgsValidationResumeTokenDifferentFilesystemForbidden(ctx *platformtest.Context) { - - supported, err := zfs.EncryptionCLISupported(ctx) - check(err) - if !supported { - ctx.SkipNow() - } - supported, err = zfs.ResumeSendSupported(ctx) + supported, err := zfs.ResumeSendSupported(ctx) check(err) if !supported { ctx.SkipNow()