Attempt to make device mapper snapshotter tests less flaky

Signed-off-by: Maksym Pavlenko <makpav@amazon.com>
This commit is contained in:
Maksym Pavlenko 2019-12-13 13:20:23 -08:00
parent f0c6684ef1
commit 75efbaf678

View File

@ -22,9 +22,11 @@ import (
"context" "context"
"path/filepath" "path/filepath"
"strconv" "strconv"
"time"
"github.com/hashicorp/go-multierror" "github.com/hashicorp/go-multierror"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/sys/unix"
"github.com/containerd/containerd/log" "github.com/containerd/containerd/log"
"github.com/containerd/containerd/snapshots/devmapper/dmsetup" "github.com/containerd/containerd/snapshots/devmapper/dmsetup"
@ -360,7 +362,30 @@ func (p *PoolDevice) DeactivateDevice(ctx context.Context, deviceName string, de
} }
if err := p.transition(ctx, deviceName, Deactivating, Deactivated, func() error { if err := p.transition(ctx, deviceName, Deactivating, Deactivated, func() error {
return dmsetup.RemoveDevice(deviceName, opts...) var (
maxRetries = 100
retryDelay = 100 * time.Millisecond
retryErr error
)
for attempt := 1; attempt <= maxRetries; attempt++ {
retryErr = dmsetup.RemoveDevice(deviceName, opts...)
if retryErr == nil {
return nil
} else if retryErr != unix.EBUSY {
return retryErr
}
// Don't spam logs
if attempt%10 == 0 {
log.G(ctx).WithError(retryErr).Warnf("failed to deactivate device, retrying... (%d of %d)", attempt, maxRetries)
}
// Devmapper device is busy, give it a bit of time and retry removal
time.Sleep(retryDelay)
}
return retryErr
}); err != nil { }); err != nil {
return errors.Wrapf(err, "failed to deactivate device %q", deviceName) return errors.Wrapf(err, "failed to deactivate device %q", deviceName)
} }