Cleanup loop devices after test failure

Cleans up loop devices if part of the test or mount process fails.

Also increases btrfs default file size to 650MB to accommodate
minimum btrfs size on ppc64le and s390x

Signed-off-by: Christopher Jones <tophj@linux.vnet.ibm.com>
This commit is contained in:
Christopher Jones
2018-01-23 15:27:16 -05:00
parent 051ac5dd63
commit a8c5ff57e5
6 changed files with 13 additions and 5 deletions

View File

@@ -29,20 +29,23 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
return func(ctx context.Context, root string) (snapshots.Snapshotter, func() error, error) {
deviceName, cleanupDevice, err := testutil.NewLoopback(150 << 20) // 150 MB
deviceName, cleanupDevice, err := testutil.NewLoopback(650 << 20) // 650 MB
if err != nil {
return nil, nil, err
}
if out, err := exec.Command(mkbtrfs, deviceName).CombinedOutput(); err != nil {
cleanupDevice()
return nil, nil, errors.Wrapf(err, "failed to make btrfs filesystem (out: %q)", out)
}
if out, err := exec.Command("mount", deviceName, root).CombinedOutput(); err != nil {
cleanupDevice()
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", deviceName, out)
}
snapshotter, err := NewSnapshotter(root)
if err != nil {
cleanupDevice()
return nil, nil, errors.Wrap(err, "failed to create new snapshotter")
}