Skip to content

Commit

Permalink
pkg/storagemigration: add integration test
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Günzler <robertg@balena.io>
  • Loading branch information
robertgzr committed Jan 25, 2021
1 parent dfa919e commit 369a091
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 0 deletions.
81 changes: 81 additions & 0 deletions integration/storagemigration/aufs_to_overlay2_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package storagemigration

import (
"context"
"os"
"os/exec"
"path/filepath"
"testing"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"

"github.com/docker/docker/internal/test/daemon"

"gotest.tools/assert"
"gotest.tools/fs"
"gotest.tools/skip"
)

func TestAufsToOverlay2Migration(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType != "linux")
skip.If(t, testEnv.DaemonInfo.Driver != "overlay2")
defer setupTest(t)()

var err error

root := fs.NewDir(t, t.Name())
defer root.Remove()

{
// aufs.tar.gz contains a snapshot of /var/lib/docker after
// building testdata/Dockerfile using dockerd which uses aufs
// as default storage driver
tar := exec.Command("tar", "-xzf", filepath.Join("testdata", "aufs.tar.gz"), "-C", root.Path())
tar.Stdout = os.Stdout
tar.Stderr = os.Stderr
assert.NilError(t, tar.Run())
}

// if testing.Verbose() {
// logrus.SetLevel(logrus.DebugLevel)
// }
// err = storagemigration.Migrate(root.Path())
// assert.NilError(t, err)

err = os.Setenv("BALENA_MIGRATE_OVERLAY", "1")
assert.NilError(t, err)

d := daemon.New(t)
d.Root = root.Path()
d.Start(t)
defer d.Stop(t)

ctx := context.Background()

cl := d.NewClientT(t)

ctr, err := cl.ContainerCreate(ctx,
&container.Config{
Image: "a2o-test",
},
nil,
nil,
"",
)
assert.NilError(t, err)

err = cl.ContainerStart(ctx, ctr.ID, types.ContainerStartOptions{})
assert.NilError(t, err)

// original f1 should be removed (.wh.)
_, err = cl.ContainerStatPath(ctx, ctr.ID, "/tmp/f1")
assert.ErrorContains(t, err, "No such container:path")
// original d1 should be opaque (.wh..wh.opq)
_, err = cl.ContainerStatPath(ctx, ctr.ID, "/tmp/d1/d1f2")
assert.NilError(t, err)
_, err = cl.ContainerStatPath(ctx, ctr.ID, "/tmp/hlkn")
assert.NilError(t, err)
_, err = cl.ContainerStatPath(ctx, ctr.ID, "/tmp/slkn")
assert.NilError(t, err)
}
33 changes: 33 additions & 0 deletions integration/storagemigration/main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package storagemigration

import (
"fmt"
"os"
"testing"

"github.com/docker/docker/internal/test/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())
}

func setupTest(t *testing.T) func() {
environment.ProtectAll(t, testEnv)
return func() { testEnv.Clean(t) }
}
5 changes: 5 additions & 0 deletions integration/storagemigration/testdata/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM busybox:1.33.0
RUN mkdir /tmp/d1 && touch /tmp/d1/d1f1 && touch /tmp/f1 && touch /tmp/f2
RUN rm -R /tmp/d1 && mkdir /tmp/d1 && touch /tmp/d1/d1f2 && rm /tmp/f1
RUN ln -s /tmp/d1/d1f2 /tmp/slkn
RUN ln /tmp/d1/d1f2 /tmp/hlkn
Binary file not shown.

0 comments on commit 369a091

Please sign in to comment.