2020-05-20 13:10:37 +02:00
package tests
import (
"fmt"
"github.com/stretchr/testify/require"
2020-08-31 16:04:00 +02:00
2020-05-20 13:10:37 +02:00
"github.com/zrepl/zrepl/platformtest"
2020-09-02 22:38:26 +02:00
"github.com/zrepl/zrepl/util/nodefault"
2020-05-20 13:10:37 +02:00
"github.com/zrepl/zrepl/zfs"
)
func ReceiveForceIntoEncryptedErr ( ctx * platformtest . Context ) {
2020-09-05 16:04:34 +02:00
supported , err := zfs . EncryptionCLISupported ( ctx )
require . NoError ( ctx , err , "encryption feature test failed" )
if ! supported {
ctx . SkipNow ( )
return
}
2020-05-20 13:10:37 +02:00
platformtest . Run ( ctx , platformtest . PanicErr , ctx . RootDataset , `
DESTROYROOT
CREATEROOT
+ "foo bar" encrypted
+ "sender" encrypted
+ "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 {
2020-09-07 01:20:57 +02:00
FS : sfs ,
From : nil ,
To : & sfsSnap1 ,
ZFSSendFlags : zfs . ZFSSendFlags {
Encrypted : & nodefault . Bool { B : false } ,
ResumeToken : "" ,
} ,
2020-05-20 13:10:37 +02:00
} . Validate ( ctx )
require . NoError ( ctx , err )
sendStream , err := zfs . ZFSSend ( ctx , sendArgs )
require . NoError ( ctx , err )
[#358] platformtest: ReceiveForceIntoEncryptedErr: fix `trace` panic caused by dangling open zfs send process
```
panic: end task: 1 active child tasks: end task: task still has active child tasks
goroutine 1 [running]:
github.com/zrepl/zrepl/daemon/logging/trace.WithTask.func1.1(0xc000020680, 0xc000080f00)
/home/cs/zrepl/zrepl/daemon/logging/trace/trace.go:221 +0x2f7
github.com/zrepl/zrepl/daemon/logging/trace.WithTask.func1()
/home/cs/zrepl/zrepl/daemon/logging/trace/trace.go:237 +0x38
main.HarnessRun(0x7ffe0b49ad3a, 0x11, 0x7ffe0b49acf2, 0x1a, 0xc800000, 0x7ffe0b49ad19, 0x16, 0x1, 0x0, 0x0, ...)
/home/cs/zrepl/zrepl/platformtest/harness/harness.go:168 +0xe54
main.main()
/home/cs/zrepl/zrepl/platformtest/harness/harness.go:41 +0x2ef
```
fixes #358
2020-08-23 19:54:48 +02:00
defer sendStream . Close ( )
2020-05-20 13:10:37 +02:00
recvOpts := zfs . RecvOptions {
RollbackAndForceRecv : true ,
SavePartialRecvState : false ,
}
err = zfs . ZFSRecv ( ctx , rfs , & zfs . ZFSSendArgVersion { RelName : "@1" , GUID : sfsSnap1 . GUID } , sendStream , recvOpts )
require . Error ( ctx , err )
re , ok := err . ( * zfs . RecvDestroyOrOverwriteEncryptedErr )
require . True ( ctx , ok )
require . Contains ( ctx , re . Error ( ) , "zfs receive -F cannot be used to destroy an encrypted filesystem or overwrite an unencrypted one with an encrypted on" )
}