@@ -12,6 +12,8 @@ import (
1212 "github.com/docker/docker/pkg/stringid"
1313 "github.com/docker/docker/pkg/truncindex"
1414 "github.com/docker/docker/volume"
15+ "github.com/docker/docker/volume/drivers"
16+ "github.com/docker/docker/volume/local"
1517)
1618
1719//
@@ -178,10 +180,11 @@ func TestLoadWithVolume(t *testing.T) {
178180 t .Fatal (err )
179181 }
180182
181- daemon := & Daemon {
182- repository : tmp ,
183- root : tmp ,
183+ daemon , err := initDaemonForVolumesTest ( tmp )
184+ if err != nil {
185+ t . Fatal ( err )
184186 }
187+ defer volumedrivers .Unregister (volume .DefaultDriverName )
185188
186189 c , err := daemon .load (containerId )
187190 if err != nil {
@@ -214,7 +217,7 @@ func TestLoadWithVolume(t *testing.T) {
214217 t .Fatalf ("Expected mount driver local, was %s\n " , m .Driver )
215218 }
216219
217- newVolumeContent := filepath .Join (volumePath , "helo" )
220+ newVolumeContent := filepath .Join (volumePath , local . VolumeDataPathName , "helo" )
218221 b , err := ioutil .ReadFile (newVolumeContent )
219222 if err != nil {
220223 t .Fatal (err )
@@ -265,10 +268,11 @@ func TestLoadWithBindMount(t *testing.T) {
265268 t .Fatal (err )
266269 }
267270
268- daemon := & Daemon {
269- repository : tmp ,
270- root : tmp ,
271+ daemon , err := initDaemonForVolumesTest ( tmp )
272+ if err != nil {
273+ t . Fatal ( err )
271274 }
275+ defer volumedrivers .Unregister (volume .DefaultDriverName )
272276
273277 c , err := daemon .load (containerId )
274278 if err != nil {
@@ -301,3 +305,212 @@ func TestLoadWithBindMount(t *testing.T) {
301305 t .Fatalf ("Expected mount point to be RW but it was not\n " )
302306 }
303307}
308+
309+ func TestLoadWithVolume17RC (t * testing.T ) {
310+ tmp , err := ioutil .TempDir ("" , "docker-daemon-test-" )
311+ if err != nil {
312+ t .Fatal (err )
313+ }
314+ defer os .RemoveAll (tmp )
315+
316+ containerId := "d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e"
317+ containerPath := filepath .Join (tmp , containerId )
318+ if err := os .MkdirAll (containerPath , 0755 ); err != nil {
319+ t .Fatal (err )
320+ }
321+
322+ hostVolumeId := "6a3c03fc4a4e588561a543cc3bdd50089e27bd11bbb0e551e19bf735e2514101"
323+ volumePath := filepath .Join (tmp , "volumes" , hostVolumeId )
324+
325+ if err := os .MkdirAll (volumePath , 0755 ); err != nil {
326+ t .Fatal (err )
327+ }
328+
329+ content := filepath .Join (volumePath , "helo" )
330+ if err := ioutil .WriteFile (content , []byte ("HELO" ), 0644 ); err != nil {
331+ t .Fatal (err )
332+ }
333+
334+ config := `{"State":{"Running":true,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":2464,"ExitCode":0,
335+ "Error":"","StartedAt":"2015-05-26T16:48:53.869308965Z","FinishedAt":"0001-01-01T00:00:00Z"},
336+ "ID":"d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e","Created":"2015-05-26T16:48:53.7987917Z","Path":"top",
337+ "Args":[],"Config":{"Hostname":"d59df5276e7b","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"Cpuset":"",
338+ "AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":null,"Tty":true,"OpenStdin":true,
339+ "StdinOnce":false,"Env":null,"Cmd":["top"],"Image":"ubuntu:latest","Volumes":null,"WorkingDir":"","Entrypoint":null,
340+ "NetworkDisabled":false,"MacAddress":"","OnBuild":null,"Labels":{}},"Image":"07f8e8c5e66084bef8f848877857537ffe1c47edd01a93af27e7161672ad0e95",
341+ "NetworkSettings":{"IPAddress":"172.17.0.1","IPPrefixLen":16,"MacAddress":"02:42:ac:11:00:01","LinkLocalIPv6Address":"fe80::42:acff:fe11:1",
342+ "LinkLocalIPv6PrefixLen":64,"GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"Gateway":"172.17.42.1","IPv6Gateway":"","Bridge":"docker0","PortMapping":null,"Ports":{}},
343+ "ResolvConfPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/resolv.conf",
344+ "HostnamePath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/hostname",
345+ "HostsPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/hosts",
346+ "LogPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e-json.log",
347+ "Name":"/ubuntu","Driver":"aufs","ExecDriver":"native-0.2","MountLabel":"","ProcessLabel":"","AppArmorProfile":"","RestartCount":0,
348+ "UpdateDns":false,"MountPoints":{"/vol1":{"Name":"6a3c03fc4a4e588561a543cc3bdd50089e27bd11bbb0e551e19bf735e2514101","Destination":"/vol1","Driver":"local","RW":true,"Source":"","Relabel":""}},"AppliedVolumesFrom":null}`
349+
350+ if err = ioutil .WriteFile (filepath .Join (containerPath , "config.json" ), []byte (config ), 0644 ); err != nil {
351+ t .Fatal (err )
352+ }
353+
354+ hostConfig := `{"Binds":[],"ContainerIDFile":"","LxcConf":[],"Memory":0,"MemorySwap":0,"CpuShares":0,"CpusetCpus":"",
355+ "Privileged":false,"PortBindings":{},"Links":null,"PublishAllPorts":false,"Dns":null,"DnsSearch":null,"ExtraHosts":null,"VolumesFrom":null,
356+ "Devices":[],"NetworkMode":"bridge","IpcMode":"","PidMode":"","CapAdd":null,"CapDrop":null,"RestartPolicy":{"Name":"no","MaximumRetryCount":0},
357+ "SecurityOpt":null,"ReadonlyRootfs":false,"Ulimits":null,"LogConfig":{"Type":"","Config":null},"CgroupParent":""}`
358+ if err = ioutil .WriteFile (filepath .Join (containerPath , "hostconfig.json" ), []byte (hostConfig ), 0644 ); err != nil {
359+ t .Fatal (err )
360+ }
361+
362+ daemon , err := initDaemonForVolumesTest (tmp )
363+ if err != nil {
364+ t .Fatal (err )
365+ }
366+ defer volumedrivers .Unregister (volume .DefaultDriverName )
367+
368+ c , err := daemon .load (containerId )
369+ if err != nil {
370+ t .Fatal (err )
371+ }
372+
373+ err = daemon .verifyVolumesInfo (c )
374+ if err != nil {
375+ t .Fatal (err )
376+ }
377+
378+ if len (c .MountPoints ) != 1 {
379+ t .Fatalf ("Expected 1 volume mounted, was 0\n " )
380+ }
381+
382+ m := c .MountPoints ["/vol1" ]
383+ if m .Name != hostVolumeId {
384+ t .Fatalf ("Expected mount name to be %s, was %s\n " , hostVolumeId , m .Name )
385+ }
386+
387+ if m .Destination != "/vol1" {
388+ t .Fatalf ("Expected mount destination /vol1, was %s\n " , m .Destination )
389+ }
390+
391+ if ! m .RW {
392+ t .Fatalf ("Expected mount point to be RW but it was not\n " )
393+ }
394+
395+ if m .Driver != volume .DefaultDriverName {
396+ t .Fatalf ("Expected mount driver local, was %s\n " , m .Driver )
397+ }
398+
399+ newVolumeContent := filepath .Join (volumePath , local .VolumeDataPathName , "helo" )
400+ b , err := ioutil .ReadFile (newVolumeContent )
401+ if err != nil {
402+ t .Fatal (err )
403+ }
404+ if string (b ) != "HELO" {
405+ t .Fatalf ("Expected HELO, was %s\n " , string (b ))
406+ }
407+ }
408+
409+ func TestRemoveLocalVolumesFollowingSymlinks (t * testing.T ) {
410+ tmp , err := ioutil .TempDir ("" , "docker-daemon-test-" )
411+ if err != nil {
412+ t .Fatal (err )
413+ }
414+ defer os .RemoveAll (tmp )
415+
416+ containerId := "d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e"
417+ containerPath := filepath .Join (tmp , containerId )
418+ if err := os .MkdirAll (containerPath , 0755 ); err != nil {
419+ t .Fatal (err )
420+ }
421+
422+ hostVolumeId := stringid .GenerateRandomID ()
423+ vfsPath := filepath .Join (tmp , "vfs" , "dir" , hostVolumeId )
424+ volumePath := filepath .Join (tmp , "volumes" , hostVolumeId )
425+
426+ if err := os .MkdirAll (vfsPath , 0755 ); err != nil {
427+ t .Fatal (err )
428+ }
429+ if err := os .MkdirAll (volumePath , 0755 ); err != nil {
430+ t .Fatal (err )
431+ }
432+
433+ content := filepath .Join (vfsPath , "helo" )
434+ if err := ioutil .WriteFile (content , []byte ("HELO" ), 0644 ); err != nil {
435+ t .Fatal (err )
436+ }
437+
438+ config := `{"State":{"Running":true,"Paused":false,"Restarting":false,"OOMKilled":false,"Dead":false,"Pid":2464,"ExitCode":0,
439+ "Error":"","StartedAt":"2015-05-26T16:48:53.869308965Z","FinishedAt":"0001-01-01T00:00:00Z"},
440+ "ID":"d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e","Created":"2015-05-26T16:48:53.7987917Z","Path":"top",
441+ "Args":[],"Config":{"Hostname":"d59df5276e7b","Domainname":"","User":"","Memory":0,"MemorySwap":0,"CpuShares":0,"Cpuset":"",
442+ "AttachStdin":false,"AttachStdout":false,"AttachStderr":false,"PortSpecs":null,"ExposedPorts":null,"Tty":true,"OpenStdin":true,
443+ "StdinOnce":false,"Env":null,"Cmd":["top"],"Image":"ubuntu:latest","Volumes":null,"WorkingDir":"","Entrypoint":null,
444+ "NetworkDisabled":false,"MacAddress":"","OnBuild":null,"Labels":{}},"Image":"07f8e8c5e66084bef8f848877857537ffe1c47edd01a93af27e7161672ad0e95",
445+ "NetworkSettings":{"IPAddress":"172.17.0.1","IPPrefixLen":16,"MacAddress":"02:42:ac:11:00:01","LinkLocalIPv6Address":"fe80::42:acff:fe11:1",
446+ "LinkLocalIPv6PrefixLen":64,"GlobalIPv6Address":"","GlobalIPv6PrefixLen":0,"Gateway":"172.17.42.1","IPv6Gateway":"","Bridge":"docker0","PortMapping":null,"Ports":{}},
447+ "ResolvConfPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/resolv.conf",
448+ "HostnamePath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/hostname",
449+ "HostsPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/hosts",
450+ "LogPath":"/var/lib/docker/containers/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e/d59df5276e7b219d510fe70565e0404bc06350e0d4b43fe961f22f339980170e-json.log",
451+ "Name":"/ubuntu","Driver":"aufs","ExecDriver":"native-0.2","MountLabel":"","ProcessLabel":"","AppArmorProfile":"","RestartCount":0,
452+ "UpdateDns":false,"Volumes":{"/vol1":"%s"},"VolumesRW":{"/vol1":true},"AppliedVolumesFrom":null}`
453+
454+ cfg := fmt .Sprintf (config , vfsPath )
455+ if err = ioutil .WriteFile (filepath .Join (containerPath , "config.json" ), []byte (cfg ), 0644 ); err != nil {
456+ t .Fatal (err )
457+ }
458+
459+ hostConfig := `{"Binds":[],"ContainerIDFile":"","LxcConf":[],"Memory":0,"MemorySwap":0,"CpuShares":0,"CpusetCpus":"",
460+ "Privileged":false,"PortBindings":{},"Links":null,"PublishAllPorts":false,"Dns":null,"DnsSearch":null,"ExtraHosts":null,"VolumesFrom":null,
461+ "Devices":[],"NetworkMode":"bridge","IpcMode":"","PidMode":"","CapAdd":null,"CapDrop":null,"RestartPolicy":{"Name":"no","MaximumRetryCount":0},
462+ "SecurityOpt":null,"ReadonlyRootfs":false,"Ulimits":null,"LogConfig":{"Type":"","Config":null},"CgroupParent":""}`
463+ if err = ioutil .WriteFile (filepath .Join (containerPath , "hostconfig.json" ), []byte (hostConfig ), 0644 ); err != nil {
464+ t .Fatal (err )
465+ }
466+
467+ daemon , err := initDaemonForVolumesTest (tmp )
468+ if err != nil {
469+ t .Fatal (err )
470+ }
471+ defer volumedrivers .Unregister (volume .DefaultDriverName )
472+
473+ c , err := daemon .load (containerId )
474+ if err != nil {
475+ t .Fatal (err )
476+ }
477+
478+ err = daemon .verifyVolumesInfo (c )
479+ if err != nil {
480+ t .Fatal (err )
481+ }
482+
483+ if len (c .MountPoints ) != 1 {
484+ t .Fatalf ("Expected 1 volume mounted, was 0\n " )
485+ }
486+
487+ m := c .MountPoints ["/vol1" ]
488+ v , err := createVolume (m .Name , m .Driver )
489+ if err != nil {
490+ t .Fatal (err )
491+ }
492+
493+ if err := removeVolume (v ); err != nil {
494+ t .Fatal (err )
495+ }
496+
497+ fi , err := os .Stat (vfsPath )
498+ if err == nil || ! os .IsNotExist (err ) {
499+ t .Fatalf ("Expected vfs path to not exist: %v - %v\n " , fi , err )
500+ }
501+ }
502+
503+ func initDaemonForVolumesTest (tmp string ) (* Daemon , error ) {
504+ daemon := & Daemon {
505+ repository : tmp ,
506+ root : tmp ,
507+ }
508+
509+ volumesDriver , err := local .New (tmp )
510+ if err != nil {
511+ return nil , err
512+ }
513+ volumedrivers .Register (volumesDriver , volumesDriver .Name ())
514+
515+ return daemon , nil
516+ }
0 commit comments