testutil/daemon: daemon.Cleanup(): unmount daemon root-dir as part of cleanup

test-daemons remove their docker.pid when stopped, so the `.integration-daemon-stop`
script did not find the mounts for those daemons, and therefore was not unmounting
them.

As a result, cleaning up the bundles directory on consecutive runs of the tests would fail;

    rm: cannot remove 'bundles/test-integration/TestDockerSwarmSuite/TestSwarmInit/d1f188f3f5472/root': Device or resource busy

This patch unmounts the root directory of the daemon as part of the cleanup step.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2019-10-09 13:00:21 +02:00
parent 9407a57522
commit 1fe7a9552c
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
1 changed files with 11 additions and 0 deletions

View File

@ -19,6 +19,7 @@ import (
"github.com/docker/docker/client"
"github.com/docker/docker/opts"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/mount"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/testutil/request"
"github.com/docker/go-connections/sockets"
@ -213,6 +214,7 @@ func (d *Daemon) NewClient(extraOpts ...client.Opt) (*client.Client, error) {
// Cleanup cleans the daemon files : exec root (network namespaces, ...), swarmkit files
func (d *Daemon) Cleanup(t testing.TB) {
t.Helper()
cleanupMount(t, d)
// Cleanup swarmkit wal files if present
cleanupRaftDir(t, d.Root)
cleanupNetworkNamespace(t, d.execRoot)
@ -710,6 +712,15 @@ func (d *Daemon) Info(t testing.TB) types.Info {
return info
}
// cleanupMount unmounts the daemon root directory, or logs a message if
// unmounting failed.
func cleanupMount(t testing.TB, d *Daemon) {
t.Helper()
if err := mount.Unmount(d.Root); err != nil {
d.log.Logf("[%s] unable to unmount daemon root (%s): %v", d.id, d.Root, err)
}
}
func cleanupRaftDir(t testing.TB, rootPath string) {
t.Helper()
for _, p := range []string{"wal", "wal-v3-encrypted", "snap-v3-encrypted"} {