Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix live-restore w/ restart policies + volume refs #44231

Merged
merged 1 commit into from Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions daemon/daemon.go
Expand Up @@ -519,6 +519,9 @@ func (daemon *Daemon) restore() error {
}
}

if err := daemon.prepareMountPoints(c); err != nil {
log.WithError(err).Error("failed to prepare mount points for container")
}
if err := daemon.containerStart(c, "", "", true); err != nil {
log.WithError(err).Error("failed to start container")
}
Expand Down
57 changes: 57 additions & 0 deletions integration/daemon/daemon_test.go
Expand Up @@ -14,7 +14,10 @@ import (
"testing"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/daemon/config"
"github.com/docker/docker/integration/internal/container"
"github.com/docker/docker/testutil/daemon"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
Expand Down Expand Up @@ -378,3 +381,57 @@ func TestDaemonProxy(t *testing.T) {
assert.Assert(t, !strings.Contains(string(logs), userPass), "logs should not contain the non-sanitized proxy URL: %s", string(logs))
})
}

func TestLiveRestore(t *testing.T) {
skip.If(t, runtime.GOOS == "windows", "cannot start multiple daemons on windows")

t.Run("volume references", testLiveRestoreVolumeReferences)
}

func testLiveRestoreVolumeReferences(t *testing.T) {
Comment on lines +388 to +391
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was there a specific reason for splitting this into two functions? (I can see the reason for the subtests inside testLiveRestoreVolumeReferences(), but was a bit confused about the split here 馃槄 馃

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential other live restore tests.
Just namespacing.

t.Parallel()

d := daemon.New(t)
d.StartWithBusybox(t, "--live-restore", "--iptables=false")
defer func() {
d.Stop(t)
d.Cleanup(t)
}()

c := d.NewClientT(t)
ctx := context.Background()

runTest := func(t *testing.T, policy string) {
t.Run(policy, func(t *testing.T) {
volName := "test-live-restore-volume-references-" + policy
_, err := c.VolumeCreate(ctx, volume.CreateOptions{Name: volName})
assert.NilError(t, err)

// Create a container that uses the volume
m := mount.Mount{
Type: mount.TypeVolume,
Source: volName,
Target: "/foo",
}
cID := container.Run(ctx, t, c, container.WithMount(m), container.WithCmd("top"), container.WithRestartPolicy(policy))
defer c.ContainerRemove(ctx, cID, types.ContainerRemoveOptions{Force: true})

// Stop the daemon
d.Restart(t, "--live-restore", "--iptables=false")

// Try to remove the volume
err = c.VolumeRemove(ctx, volName, false)
assert.ErrorContains(t, err, "volume is in use")

_, err = c.VolumeInspect(ctx, volName)
assert.NilError(t, err)
})
}

t.Run("restartPolicy", func(t *testing.T) {
runTest(t, "always")
runTest(t, "unless-stopped")
runTest(t, "on-failure")
runTest(t, "no")
})
}
18 changes: 18 additions & 0 deletions integration/daemon/main_test.go
@@ -1,10 +1,28 @@
package daemon // import "github.com/docker/docker/integration/daemon"

import (
"fmt"
"os"
"testing"

"github.com/docker/docker/testutil/environment"
)

var testEnv *environment.Execution

func TestMain(m *testing.M) {
var err error
testEnv, err = environment.New()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
err = environment.EnsureFrozenImagesLinux(testEnv)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

testEnv.Print()
os.Exit(m.Run())
}