@@ -2,8 +2,10 @@ package com.eficode.devstack.container.impl
2
2
3
3
import com.eficode.devstack.DevStackSpec
4
4
import com.eficode.devstack.util.DirectorySyncer
5
+ import com.eficode.devstack.util.ImageSummaryDS
5
6
import de.gesellix.docker.remote.api.ContainerInspectResponse
6
7
import de.gesellix.docker.remote.api.MountPoint
8
+ import de.gesellix.docker.remote.api.Volume
7
9
import org.slf4j.LoggerFactory
8
10
9
11
@@ -42,13 +44,13 @@ class DirectorySyncerTest extends DevStackSpec {
42
44
! volumeExists(uniqueVolumeName) ?: dockerClient. rmVolume(uniqueVolumeName)
43
45
log. debug(" \t Will use sync to Docker volume:" + uniqueVolumeName)
44
46
45
- DirectorySyncer firstSyncer = DirectorySyncer . createSyncToVolume([srcDir1. canonicalPath, srcDir2. canonicalPath], uniqueVolumeName, " -avh --delete" , dockerRemoteHost, dockerCertPath )
47
+ DirectorySyncer firstSyncer = DirectorySyncer . createSyncToVolume([srcDir1. canonicalPath, srcDir2. canonicalPath], uniqueVolumeName, " DirSyncer " , " -avh --delete" , dockerRemoteHost, dockerCertPath )
46
48
log. info(" \t Created first sync container: ${ firstSyncer.containerName} (${ firstSyncer.shortId} )" )
47
49
Integer containersAfterFirst = firstSyncer. dockerClient. ps(true ). content. size()
48
50
log. info(" \t\t Docker engine now has a total of ${ containersAfterFirst} contianers" )
49
51
50
52
when : " Creating second sync container"
51
- DirectorySyncer secondSyncer = DirectorySyncer . createSyncToVolume([srcDir1. canonicalPath, srcDir2. canonicalPath], uniqueVolumeName, " -avh --delete" , dockerRemoteHost, dockerCertPath )
53
+ DirectorySyncer secondSyncer = DirectorySyncer . createSyncToVolume([srcDir1. canonicalPath, srcDir2. canonicalPath], uniqueVolumeName, " DirSyncer " , " -avh --delete" , dockerRemoteHost, dockerCertPath )
52
54
log. info(" \t Created second sync container: ${ secondSyncer.containerName} (${ secondSyncer.shortId} )" )
53
55
54
56
then : " They should have the same ID"
@@ -60,7 +62,7 @@ class DirectorySyncerTest extends DevStackSpec {
60
62
when : " Stopping the sync container, and creating another duplicate"
61
63
firstSyncer. stopContainer()
62
64
assert ! firstSyncer. running
63
- secondSyncer = DirectorySyncer . createSyncToVolume([srcDir1. canonicalPath, srcDir2. canonicalPath], uniqueVolumeName, " -avh --delete" , dockerRemoteHost, dockerCertPath )
65
+ secondSyncer = DirectorySyncer . createSyncToVolume([srcDir1. canonicalPath, srcDir2. canonicalPath], uniqueVolumeName, " DirSyncer " , " -avh --delete" , dockerRemoteHost, dockerCertPath )
64
66
65
67
then :" The duplicate should have been automatically started"
66
68
secondSyncer. running
@@ -74,6 +76,62 @@ class DirectorySyncerTest extends DevStackSpec {
74
76
75
77
76
78
79
+ }
80
+
81
+
82
+ def " Test create createSyncVolumeToVolume" () {
83
+
84
+ setup :
85
+ log. info(" Testing createSyncVolumeToVolume" )
86
+ Volume srcVolume = dockerClient. getOrCreateVolume(" srcVolume" + System . nanoTime(). toString(). takeRight(3 ))
87
+ Volume destVolume = dockerClient. getOrCreateVolume(" destVolume" + System . nanoTime(). toString(). takeRight(3 ))
88
+ log. info(" \t Will use src volume:" + srcVolume)
89
+ log. info(" \t Will use dest volume:" + destVolume)
90
+
91
+
92
+ when : " Creating two containers with two different default users"
93
+ UbuntuContainer srcContainer = new UbuntuContainer ()
94
+ srcContainer. containerName = " SrcContainer"
95
+ srcContainer. prepareVolumeMount(srcVolume. name, " /mnt/volume" , false )
96
+ srcContainer. user = " 1001:1001"
97
+ srcContainer. createSleepyContainer()
98
+ srcContainer. startContainer()
99
+ srcContainer. runBashCommandInContainer(ImageSummaryDS . getReplaceUserScriptBody(" ubuntu" , " 1000" , " ubuntu" , " 1000" , " ubuntusrc" , " 1001" , " ubuntusrc" , " 1001" ),10 , " root" )
100
+ srcContainer. runBashCommandInContainer(" chown 1001:1001 -R /mnt/volume" , 5 , " root" )
101
+
102
+
103
+ UbuntuContainer destContainer = new UbuntuContainer ()
104
+ destContainer. containerName = " DestContainer"
105
+ destContainer. prepareVolumeMount(destVolume. name, " /mnt/volume" , false )
106
+ destContainer. user = " 1002:1002"
107
+ destContainer. createSleepyContainer()
108
+ destContainer. startContainer()
109
+ destContainer. runBashCommandInContainer(ImageSummaryDS . getReplaceUserScriptBody(" ubuntu" , " 1000" , " ubuntu" , " 1000" , " ubuntudest" , " 1002" , " ubuntudest" , " 1002" ),10 , " root" )
110
+ destContainer. runBashCommandInContainer(" chown 1002:1002 -R /mnt/volume" , 5 , " root" )
111
+
112
+ then : " When checking user id, they should be different"
113
+ srcContainer. runBashCommandInContainer(" id -u" ). contains(" 1001" )
114
+ destContainer. runBashCommandInContainer(" id -u" ). contains(" 1002" )
115
+
116
+
117
+ when : " Creating the syncer"
118
+
119
+ DirectorySyncer syncer = DirectorySyncer . syncBetweenVolumesAndUsers(srcVolume. name, destVolume. name, " 1002:1002" )
120
+ srcContainer. runBashCommandInContainer(" touch /mnt/volume/createdInSource" )
121
+ sleep(1000 )
122
+ then :
123
+ destContainer. runBashCommandInContainer(" ls -l /mnt/volume/createdInSource && echo Status: \$ ?" ). contains(" Status: 0" )
124
+ destContainer. runBashCommandInContainer(" echo edited >> /mnt/volume/createdInSource && echo Status: \$ ?" ). contains(" Status: 0" )
125
+ destContainer. runBashCommandInContainer(" rm /mnt/volume/createdInSource && echo Status: \$ ?" ). contains(" Status: 0" )
126
+
127
+
128
+ cleanup :
129
+ srcContainer. stopAndRemoveContainer()
130
+ destContainer. stopAndRemoveContainer()
131
+ syncer. stopAndRemoveContainer()
132
+ dockerClient. manageVolume. rmVolume(srcVolume. name)
133
+ dockerClient. manageVolume. rmVolume(destVolume. name)
134
+
77
135
}
78
136
79
137
def " Test createSyncToVolume" () {
@@ -93,7 +151,7 @@ class DirectorySyncerTest extends DevStackSpec {
93
151
when : " When creating syncer"
94
152
95
153
assert ! volumeExists(uniqueVolumeName): " Destination volume already exists"
96
- DirectorySyncer syncer = DirectorySyncer . createSyncToVolume([srcDir1. canonicalPath, srcDir2. canonicalPath], uniqueVolumeName, " -avh --delete" , dockerRemoteHost, dockerCertPath )
154
+ DirectorySyncer syncer = DirectorySyncer . createSyncToVolume([srcDir1. canonicalPath, srcDir2. canonicalPath], uniqueVolumeName, " DirSyncer " , " -avh --delete" , dockerRemoteHost, dockerCertPath )
97
155
log. info(" \t Created sync container: ${ syncer.containerName} (${ syncer.shortId} )" )
98
156
ContainerInspectResponse containerInspect = syncer. inspectContainer()
99
157
0 commit comments