mirror of
https://github.com/zrepl/zrepl.git
synced 2025-02-16 18:30:54 +01:00
platformtest: harness: -failure.stop-and-keep-pool mode, prettier logging
This commit is contained in:
parent
f8f9fd11cd
commit
18d2c350de
@ -19,12 +19,14 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
var args struct {
|
var args struct {
|
||||||
createArgs platformtest.ZpoolCreateArgs
|
createArgs platformtest.ZpoolCreateArgs
|
||||||
|
stopAndKeepPoolOnFail bool
|
||||||
}
|
}
|
||||||
flag.StringVar(&args.createArgs.PoolName, "poolname", "", "")
|
flag.StringVar(&args.createArgs.PoolName, "poolname", "", "")
|
||||||
flag.StringVar(&args.createArgs.ImagePath, "imagepath", "", "")
|
flag.StringVar(&args.createArgs.ImagePath, "imagepath", "", "")
|
||||||
flag.Int64Var(&args.createArgs.ImageSize, "imagesize", 100*(1<<20), "")
|
flag.Int64Var(&args.createArgs.ImageSize, "imagesize", 100*(1<<20), "")
|
||||||
flag.StringVar(&args.createArgs.Mountpoint, "mountpoint", "none", "")
|
flag.StringVar(&args.createArgs.Mountpoint, "mountpoint", "none", "")
|
||||||
|
flag.BoolVar(&args.stopAndKeepPoolOnFail, "failure.stop-and-keep-pool", false, "if a test case fails, stop test execution and keep pool as it was when the test failed")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
outlets := logger.NewOutlets()
|
outlets := logger.NewOutlets()
|
||||||
@ -52,13 +54,21 @@ func main() {
|
|||||||
boldGreen := color.New(color.Bold, color.FgHiGreen)
|
boldGreen := color.New(color.Bold, color.FgHiGreen)
|
||||||
for _, c := range tests.Cases {
|
for _, c := range tests.Cases {
|
||||||
// ATTENTION future parallelism must pass c by value into closure!
|
// ATTENTION future parallelism must pass c by value into closure!
|
||||||
err := func() error {
|
err := func() (err error) {
|
||||||
|
var oErr = &err
|
||||||
bold.Printf("BEGIN TEST CASE %s\n", c)
|
bold.Printf("BEGIN TEST CASE %s\n", c)
|
||||||
pool, err := platformtest.CreateOrReplaceZpool(ctx, ex, args.createArgs)
|
pool, err := platformtest.CreateOrReplaceZpool(ctx, ex, args.createArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "create test pool")
|
return errors.Wrap(err, "create test pool")
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
*oErr = errors.Errorf("panic while running test: %v", err) // shadow
|
||||||
|
if args.stopAndKeepPoolOnFail {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// fallthrough
|
||||||
|
}
|
||||||
if err := pool.Destroy(ctx, ex); err != nil {
|
if err := pool.Destroy(ctx, ex); err != nil {
|
||||||
fmt.Printf("error destroying test pool: %s", err)
|
fmt.Printf("error destroying test pool: %s", err)
|
||||||
}
|
}
|
||||||
@ -72,6 +82,11 @@ func main() {
|
|||||||
}()
|
}()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
boldRed.Printf("TEST CASE FAILED WITH ERROR:\n")
|
boldRed.Printf("TEST CASE FAILED WITH ERROR:\n")
|
||||||
|
fmt.Printf("%+v\n", err) // print with stack trace
|
||||||
|
if args.stopAndKeepPoolOnFail {
|
||||||
|
bold.Printf("STOPPING TEST RUN AT FAILING TEST PER USER REQUEST\n")
|
||||||
|
return
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
boldGreen.Printf("DONE TEST CASE %s\n", c)
|
boldGreen.Printf("DONE TEST CASE %s\n", c)
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ func CreateOrReplaceZpool(ctx context.Context, e Execer, args ZpoolCreateArgs) (
|
|||||||
image.Close()
|
image.Close()
|
||||||
|
|
||||||
// create the pool
|
// create the pool
|
||||||
err = e.RunExpectSuccessNoOutput(ctx, "zpool", "create", "-O", "mountpoint=none", args.PoolName, args.ImagePath)
|
err = e.RunExpectSuccessNoOutput(ctx, "zpool", "create", "-f", "-O", "mountpoint=none", args.PoolName, args.ImagePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "zpool create")
|
return nil, errors.Wrap(err, "zpool create")
|
||||||
}
|
}
|
||||||
|
@ -15,9 +15,6 @@ func GetNonexistent(ctx *platformtest.Context) {
|
|||||||
+ "foo bar"
|
+ "foo bar"
|
||||||
+ "foo bar@1"
|
+ "foo bar@1"
|
||||||
`)
|
`)
|
||||||
defer platformtest.Run(ctx, platformtest.PanicErr, ctx.RootDataset, `
|
|
||||||
DESTROYROOT
|
|
||||||
`)
|
|
||||||
|
|
||||||
// test raw
|
// test raw
|
||||||
_, err := zfs.ZFSGetRawAnySource(fmt.Sprintf("%s/foo bar", ctx.RootDataset), []string{"name"})
|
_, err := zfs.ZFSGetRawAnySource(fmt.Sprintf("%s/foo bar", ctx.RootDataset), []string{"name"})
|
||||||
|
@ -18,10 +18,6 @@ func UndestroyableSnapshotParsing(t *platformtest.Context) {
|
|||||||
+ "foo bar@7 8 9"
|
+ "foo bar@7 8 9"
|
||||||
R zfs hold zrepl_platformtest "${ROOTDS}/foo bar@4 5 6"
|
R zfs hold zrepl_platformtest "${ROOTDS}/foo bar@4 5 6"
|
||||||
`)
|
`)
|
||||||
defer platformtest.Run(t, platformtest.PanicErr, t.RootDataset, `
|
|
||||||
R zfs release zrepl_platformtest "${ROOTDS}/foo bar@4 5 6"
|
|
||||||
DESTROYROOT
|
|
||||||
`)
|
|
||||||
|
|
||||||
err := zfs.ZFSDestroy(fmt.Sprintf("%s/foo bar@1 2 3,4 5 6,7 8 9", t.RootDataset))
|
err := zfs.ZFSDestroy(fmt.Sprintf("%s/foo bar@1 2 3,4 5 6,7 8 9", t.RootDataset))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user