Fix flaky btrfs test
Add logging and move the creation of the snapshotter inside the attempt loop to catch cases where the mountinfo may not be updated yet. When all attempts are reached there is no reason to create the snapshotter as the unmount has already occurred. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
2a6d13b2ca
commit
772032598a
@ -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