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:
parent
051ac5dd63
commit
a8c5ff57e5
@ -20,16 +20,18 @@ func testSupportsDType(t *testing.T, expected bool, mkfs ...string) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(mnt)
|
defer os.RemoveAll(mnt)
|
||||||
|
|
||||||
deviceName, cleanupDevice, err := testutil.NewLoopback(150 << 20) // 150 MB
|
deviceName, cleanupDevice, err := testutil.NewLoopback(100 << 20) // 100 MB
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if out, err := exec.Command(mkfs[0], append(mkfs[1:], deviceName)...).CombinedOutput(); err != nil {
|
if out, err := exec.Command(mkfs[0], append(mkfs[1:], deviceName)...).CombinedOutput(); err != nil {
|
||||||
// not fatal
|
// not fatal
|
||||||
|
cleanupDevice()
|
||||||
t.Skipf("could not mkfs (%v) %s: %v (out: %q)", mkfs, deviceName, err, string(out))
|
t.Skipf("could not mkfs (%v) %s: %v (out: %q)", mkfs, deviceName, err, string(out))
|
||||||
}
|
}
|
||||||
if out, err := exec.Command("mount", deviceName, mnt).CombinedOutput(); err != nil {
|
if out, err := exec.Command("mount", deviceName, mnt).CombinedOutput(); err != nil {
|
||||||
// not fatal
|
// not fatal
|
||||||
|
cleanupDevice()
|
||||||
t.Skipf("could not mount %s: %v (out: %q)", deviceName, err, string(out))
|
t.Skipf("could not mount %s: %v (out: %q)", deviceName, err, string(out))
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
|
@ -39,7 +39,7 @@ func testLookup(t *testing.T, fsType string) {
|
|||||||
}
|
}
|
||||||
defer os.RemoveAll(mnt)
|
defer os.RemoveAll(mnt)
|
||||||
|
|
||||||
deviceName, cleanupDevice, err := testutil.NewLoopback(150 << 20) // 150 MB
|
deviceName, cleanupDevice, err := testutil.NewLoopback(100 << 20) // 100 MB
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# Downloads and installs protobuf
|
# Downloads and installs protobuf
|
||||||
#
|
#
|
||||||
set -eux -o pipefail
|
set -eu -o pipefail
|
||||||
|
|
||||||
PROTOBUF_VERSION=3.5.1
|
PROTOBUF_VERSION=3.5.1
|
||||||
GOARCH=$(go env GOARCH)
|
GOARCH=$(go env GOARCH)
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# Builds and installs runc to /usr/local/go/bin based off
|
# Builds and installs runc to /usr/local/go/bin based off
|
||||||
# the commit defined in vendor.conf
|
# the commit defined in vendor.conf
|
||||||
#
|
#
|
||||||
set -eux -o pipefail
|
set -eu -o pipefail
|
||||||
|
|
||||||
RUNC_COMMIT=$(grep opencontainers/runc ${GOPATH}/src/github.com/containerd/containerd/vendor.conf | cut -d " " -f 2)
|
RUNC_COMMIT=$(grep opencontainers/runc ${GOPATH}/src/github.com/containerd/containerd/vendor.conf | cut -d " " -f 2)
|
||||||
|
|
||||||
|
@ -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) {
|
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 {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if out, err := exec.Command(mkbtrfs, deviceName).CombinedOutput(); err != nil {
|
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)
|
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 {
|
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)
|
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", deviceName, out)
|
||||||
}
|
}
|
||||||
|
|
||||||
snapshotter, err := NewSnapshotter(root)
|
snapshotter, err := NewSnapshotter(root)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
cleanupDevice()
|
||||||
return nil, nil, errors.Wrap(err, "failed to create new snapshotter")
|
return nil, nil, errors.Wrap(err, "failed to create new snapshotter")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,6 +21,8 @@ func NewLoopback(size int64) (string, func() error, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err := file.Truncate(size); err != nil {
|
if err := file.Truncate(size); err != nil {
|
||||||
|
file.Close()
|
||||||
|
os.Remove(file.Name())
|
||||||
return "", nil, errors.Wrap(err, "failed to resize temp file")
|
return "", nil, errors.Wrap(err, "failed to resize temp file")
|
||||||
}
|
}
|
||||||
file.Close()
|
file.Close()
|
||||||
@ -29,6 +31,7 @@ func NewLoopback(size int64) (string, func() error, error) {
|
|||||||
losetup := exec.Command("losetup", "--find", "--show", file.Name())
|
losetup := exec.Command("losetup", "--find", "--show", file.Name())
|
||||||
p, err := losetup.Output()
|
p, err := losetup.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
os.Remove(file.Name())
|
||||||
return "", nil, errors.Wrap(err, "loopback setup failed")
|
return "", nil, errors.Wrap(err, "loopback setup failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user