forked from smartsdk/mongo-rs-controller-swarm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-locally.sh
executable file
·212 lines (174 loc) · 7.12 KB
/
test-locally.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/sh
oneTimeSetUp(){
miniswarm delete
miniswarm start 3
eval $(docker-machine env ms-manager0)
docker network create --attachable --opt encrypted -d overlay backend
docker secret create mongo-keyfile ./mongo-keyfile
docker stack deploy -c docker-compose.yml mongo
docker run --name client --network=backend -d mongo:3.2 tail -f /dev/null
echo "Created MongoDB Client"
}
# Start a new MongoDB cluster with persistence data and checks that the controller configure it correctly.
testSetUpMongoIsRunning(){
sleep 120
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Mode}}")
assertEquals "mongo_mongo:global" "${result}"
}
testSetUpControllerIsRunning(){
result=$(docker service ls -f name=mongo_controller --format "{{.Name}}:{{.Mode}}")
assertEquals "mongo_controller:replicated" "${result}"
}
testSetUpMongoReplicas(){
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:3/3" "${result}"
}
testSetUpControllerReplicas(){
result=$(docker service ls -f name=mongo_controller --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_controller:1/1" "${result}"
}
testSetUpMongoClusterStatus(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['ok']")
assertEquals "1" "${result}"
}
testSetUpMongoClusterSize(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['members'].length")
assertEquals "3" "${result}"
}
# Kill container
testKillMongo(){
container=$(docker ps -f name=mongo_mongo --format {{.ID}})
docker kill ${container}
sleep 10 #time needed to kill container
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:2/3" "${result}"
}
testKillMongoReplicas(){
sleep 60 #time needed to download mongo image and start it
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:3/3" "${result}"
}
testSetUpMongoClusterStatus(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['ok']")
assertEquals "1" "${result}"
}
testKillMongoClusterSize(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['members'].length")
assertEquals "3" "${result}"
}
# Stop Swarm-2 node
testStopSwarm(){
docker node update ms-worker0 --availability drain
docker node update ms-worker0 --availability pause
sleep 10 #time needed to kill container
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:2/2" "${result}"
}
testStopSwarmReplicas(){
sleep 60 #time needed to download mongo image and start it
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:2/2" "${result}"
}
testStopSwarmClusterStatus(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['ok']")
assertEquals "1" "${result}"
}
testStopSwarmClusterSize(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['members'].length")
assertEquals "2" "${result}"
}
# Re-Start Swarm-2 node
testStartSwarm(){
docker node update ms-worker0 --availability active
sleep 120 #time needed to kill container
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:3/3" "${result}"
}
testStartSwarmReplicas(){
sleep 10 #time needed to download mongo image and start it
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:3/3" "${result}"
}
testStartSwarmClusterStatus(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['ok']")
assertEquals "1" "${result}"
}
testStartSwarmClusterSize(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['members'].length")
assertEquals "3" "${result}"
}
# Stop Swarm-Manager node
testStopSwarmManager(){
docker node promote ms-worker0
docker rm -fv client
eval $(docker-machine env ms-worker0)
docker run --name client --network=backend -d mongo:3.2 tail -f /dev/null
docker node update ms-manager0 --availability drain
docker node update ms-manager0 --availability pause
sleep 120 #time needed to kill container
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:2/2" "${result}"
}
testStopSwarmManagerControllerMoved(){
result=$(docker service ls -f name=mongo_controller --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_controller:1/1" "${result}"
}
testStopSwarmManagerReplicas(){
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:2/2" "${result}"
}
testStopSwarmManagerClusterStatus(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['ok']")
assertEquals "1" "${result}"
}
testStopSwarmManagerClusterSize(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['members'].length")
assertEquals "2" "${result}"
}
testStopSwarmManagerRestore(){
docker node update ms-manager0 --availability active
docker rm -fv client
eval $(docker-machine env ms-manager0)
docker run --name client --network=backend -d mongo:3.2 tail -f /dev/null
docker node demote ms-worker0
sleep 120 #time needed to kill container
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:3/3" "${result}"
}
# Restart MongoDB cluster
testRestartMongoIsRunning(){
docker stack rm mongo
docker stack deploy -c docker-compose.yml mongo
sleep 120 #time needed to restart
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Mode}}")
assertEquals "mongo_mongo:global" "${result}"
}
testRestartControllerIsRunning(){
result=$(docker service ls -f name=mongo_controller --format "{{.Name}}:{{.Mode}}")
assertEquals "mongo_controller:replicated" "${result}"
}
testRestartMongoReplicas(){
result=$(docker service ls -f name=mongo_mongo --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_mongo:3/3" "${result}"
}
testRestartControllerReplicas(){
result=$(docker service ls -f name=mongo_controller --format "{{.Name}}:{{.Replicas}}")
assertEquals "mongo_controller:1/1" "${result}"
}
testRestartMongoClusterStatus(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['ok']")
assertEquals "1" "${result}"
}
testRestartMongoClusterSize(){
result=$(docker exec client mongo --quiet mongo_mongo/admin --eval "db.runCommand( { replSetGetStatus : 1 } )['members'].length")
assertEquals "3" "${result}"
}
oneTimeTearDown(){
docker rm -fv client
docker stack remove mongo
sleep 50
docker network rm backend
miniswarm delete
}
# load shunit2
. shunit2