From 1fe7a9552c5997d64a2180897923b52285eedfb7 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 9 Oct 2019 13:00:21 +0200 Subject: [PATCH] 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 --- testutil/daemon/daemon.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/testutil/daemon/daemon.go b/testutil/daemon/daemon.go index de948ecdc2..50a46958d4 100644 --- a/testutil/daemon/daemon.go +++ b/testutil/daemon/daemon.go @@ -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"} {