summaryrefslogtreecommitdiff
path: root/daemon/daemon_unix_test.go
diff options
context:
space:
mode:
authorBrian Goff <cpuguy83@gmail.com>2016-09-06 09:49:10 -0400
committerBrian Goff <cpuguy83@gmail.com>2016-09-06 17:17:47 -0400
commitdc712b92495d12d789f45c84d45c3de3292089a8 (patch)
treec67d0dee127dfc55f494873be4cc0fac9ad30f1a /daemon/daemon_unix_test.go
parentd8e151535017b4bb4ee5aa8281f1b9bb7bffa397 (diff)
downloaddocker-dc712b92495d12d789f45c84d45c3de3292089a8.tar.gz
restore migrating pre-1.7.0 volumes
This was removed in a clean-up (060f4ae6179b10aeafa883670826159fdae8204a) but should not have been. Fixes issues with volumes when upgrading from pre-1.7.0 daemons. Signed-off-by: Brian Goff <cpuguy83@gmail.com>
Diffstat (limited to 'daemon/daemon_unix_test.go')
-rw-r--r--daemon/daemon_unix_test.go84
1 files changed, 84 insertions, 0 deletions
diff --git a/daemon/daemon_unix_test.go b/daemon/daemon_unix_test.go
index fae84bab6a..98d94ff23d 100644
--- a/daemon/daemon_unix_test.go
+++ b/daemon/daemon_unix_test.go
@@ -5,9 +5,14 @@ package daemon
import (
"io/ioutil"
"os"
+ "path/filepath"
"testing"
"github.com/docker/docker/container"
+ "github.com/docker/docker/volume"
+ "github.com/docker/docker/volume/drivers"
+ "github.com/docker/docker/volume/local"
+ "github.com/docker/docker/volume/store"
containertypes "github.com/docker/engine-api/types/container"
)
@@ -197,3 +202,82 @@ func TestNetworkOptions(t *testing.T) {
t.Fatalf("Expected networkOptions error, got nil")
}
}
+
+func TestMigratePre17Volumes(t *testing.T) {
+ rootDir, err := ioutil.TempDir("", "test-daemon-volumes")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer os.RemoveAll(rootDir)
+
+ volumeRoot := filepath.Join(rootDir, "volumes")
+ err = os.MkdirAll(volumeRoot, 0755)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ containerRoot := filepath.Join(rootDir, "containers")
+ cid := "1234"
+ err = os.MkdirAll(filepath.Join(containerRoot, cid), 0755)
+
+ vid := "5678"
+ vfsPath := filepath.Join(rootDir, "vfs", "dir", vid)
+ err = os.MkdirAll(vfsPath, 0755)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ config := []byte(`
+ {
+ "ID": "` + cid + `",
+ "Volumes": {
+ "/foo": "` + vfsPath + `",
+ "/bar": "/foo",
+ "/quux": "/quux"
+ },
+ "VolumesRW": {
+ "/foo": true,
+ "/bar": true,
+ "/quux": false
+ }
+ }
+ `)
+
+ volStore, err := store.New(volumeRoot)
+ if err != nil {
+ t.Fatal(err)
+ }
+ drv, err := local.New(volumeRoot, 0, 0)
+ if err != nil {
+ t.Fatal(err)
+ }
+ volumedrivers.Register(drv, volume.DefaultDriverName)
+
+ daemon := &Daemon{root: rootDir, repository: containerRoot, volumes: volStore}
+ err = ioutil.WriteFile(filepath.Join(containerRoot, cid, "config.v2.json"), config, 600)
+ if err != nil {
+ t.Fatal(err)
+ }
+ c, err := daemon.load(cid)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if err := daemon.verifyVolumesInfo(c); err != nil {
+ t.Fatal(err)
+ }
+
+ expected := map[string]volume.MountPoint{
+ "/foo": {Destination: "/foo", RW: true, Name: vid},
+ "/bar": {Source: "/foo", Destination: "/bar", RW: true},
+ "/quux": {Source: "/quux", Destination: "/quux", RW: false},
+ }
+ for id, mp := range c.MountPoints {
+ x, exists := expected[id]
+ if !exists {
+ t.Fatal("volume not migrated")
+ }
+ if mp.Source != x.Source || mp.Destination != x.Destination || mp.RW != x.RW || mp.Name != x.Name {
+ t.Fatalf("got unexpected mountpoint, expected: %+v, got: %+v", x, mp)
+ }
+ }
+}