Merge pull request #3720 from dmcgowan/fix-flaky-btrfs
Fix flaky btrfs test
This commit is contained in:
commit
635dbf251a
@ -77,7 +77,7 @@ func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if mnt.FSType != "btrfs" {
|
if mnt.FSType != "btrfs" {
|
||||||
return nil, errors.Wrapf(plugin.ErrSkipPlugin, "path %s must be a btrfs filesystem to be used with the btrfs snapshotter", root)
|
return nil, errors.Wrapf(plugin.ErrSkipPlugin, "path %s (%s) must be a btrfs filesystem to be used with the btrfs snapshotter", root, mnt.FSType)
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
active = filepath.Join(root, "active")
|
active = filepath.Join(root, "active")
|
||||||
|
@ -30,6 +30,7 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/containerd/mount"
|
"github.com/containerd/containerd/mount"
|
||||||
"github.com/containerd/containerd/pkg/testutil"
|
"github.com/containerd/containerd/pkg/testutil"
|
||||||
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/snapshots"
|
"github.com/containerd/containerd/snapshots"
|
||||||
"github.com/containerd/containerd/snapshots/testsuite"
|
"github.com/containerd/containerd/snapshots/testsuite"
|
||||||
"github.com/containerd/continuity/testutil/loopback"
|
"github.com/containerd/continuity/testutil/loopback"
|
||||||
@ -66,27 +67,31 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
|
|||||||
// sync after a mkfs on the loopback before trying to mount the device
|
// sync after a mkfs on the loopback before trying to mount the device
|
||||||
unix.Sync()
|
unix.Sync()
|
||||||
|
|
||||||
|
var snapshotter snapshots.Snapshotter
|
||||||
for i := 0; i < 5; i++ {
|
for i := 0; i < 5; i++ {
|
||||||
if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil {
|
if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil {
|
||||||
loop.Close()
|
loop.Close()
|
||||||
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out)
|
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out)
|
||||||
}
|
}
|
||||||
var stat unix.Statfs_t
|
|
||||||
if err := unix.Statfs(root, &stat); err != nil {
|
if i > 0 {
|
||||||
unix.Unmount(root, 0)
|
time.Sleep(10 * time.Duration(i) * time.Millisecond)
|
||||||
return nil, nil, errors.Wrapf(err, "unable to statfs btrfs mount %s", root)
|
|
||||||
}
|
}
|
||||||
if stat.Type == unix.BTRFS_SUPER_MAGIC {
|
|
||||||
|
snapshotter, err = NewSnapshotter(root)
|
||||||
|
if err == nil {
|
||||||
break
|
break
|
||||||
|
} else if errors.Cause(err) != plugin.ErrSkipPlugin {
|
||||||
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t.Logf("Attempt %d to create btrfs snapshotter failed: %#v", i+1, err)
|
||||||
|
|
||||||
// unmount and try again
|
// unmount and try again
|
||||||
unix.Unmount(root, 0)
|
unix.Unmount(root, 0)
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
snapshotter, err := NewSnapshotter(root)
|
if snapshotter == nil {
|
||||||
if err != nil {
|
return nil, nil, errors.Wrap(err, "failed to successfully create snapshotter after 5 attempts")
|
||||||
loop.Close()
|
|
||||||
return nil, nil, errors.Wrap(err, "failed to create new snapshotter")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return snapshotter, func() error {
|
return snapshotter, func() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user