-
Notifications
You must be signed in to change notification settings - Fork 175
/
Copy path10-01-VCH-Restart.robot
282 lines (235 loc) · 13.9 KB
/
10-01-VCH-Restart.robot
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# Copyright 2016-2018 VMware, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License
*** Settings ***
Documentation Test 10-01 - VCH Restart
Resource ../../resources/Util.robot
Test Setup Install VIC Appliance To Test Server
Test Teardown Cleanup VIC Appliance On Test Server
Default Tags
*** Keywords ***
Get Container IP
[Arguments] ${id} ${network}=default
${rc} ${ip}= Run And Return Rc And Output docker %{VCH-PARAMS} network inspect ${network} | jq '.[0].Containers."${id}".IPv4Address'
Should Be Equal As Integers ${rc} 0
[Return] ${ip}
Launch Container
[Arguments] ${name} ${network}=default ${command}=sh
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} run --name ${name} --net ${network} -itd ${busybox} ${command}
Should Be Equal As Integers ${rc} 0
${id}= Get Line ${output} -1
[Return] ${id}
Launch Container With Port Forwarding
[Arguments] ${name} ${port1} ${port2} ${network}=default
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -p ${port1}:80 -p ${port2}:80 --name ${name} --net ${network} ${nginx}
Should Be Equal As Integers ${rc} 0
Should Not Contain ${output} Error
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start ${name}
Should Be Equal As Integers ${rc} 0
Should Not Contain ${output} Error
Check Nginx Port Forwarding
[Arguments] ${port1} ${port2}
Wait Until Keyword Succeeds 20x 5 seconds Hit Nginx Endpoint %{VCH-IP} ${port1}
Wait Until Keyword Succeeds 20x 5 seconds Hit Nginx Endpoint %{VCH-IP} ${port2}
*** Test Cases ***
Created Network And Images Persists As Well As Containers Are Discovered With Correct IPs
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull ${nginx}
Should Be Equal As Integers ${rc} 0
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} network create foo
Should Be Equal As Integers ${rc} 0
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} network create bar
Should Be Equal As Integers ${rc} 0
${bridge-exited}= Launch Container vch-restart-bridge-exited bridge ls
${bridge-running}= Launch Container vch-restart-bridge-running bridge
${bridge-running-ip}= Get Container IP ${bridge-running} bridge
${bar-exited}= Launch Container vch-restart-bar-exited bar ls
${bar-running}= Launch Container vch-restart-bar-running bar
${bar-running-ip}= Get Container IP ${bar-running} bar
Launch Container foo-c1 foo
Launch Container foo-c2 foo
Launch Container bar-c1 bar
Launch Container bar-c2 bar
# name resolution should work on the foo and bar networks
${rc}= Run And Return Rc docker %{VCH-PARAMS} exec foo-c1 ping -c3 foo-c2
Should Be Equal As Integers ${rc} 0
${rc}= Run And Return Rc docker %{VCH-PARAMS} exec foo-c2 ping -c3 foo-c1
Should Be Equal As Integers ${rc} 0
${rc}= Run And Return Rc docker %{VCH-PARAMS} exec bar-c1 ping -c3 bar-c2
Should Be Equal As Integers ${rc} 0
${rc}= Run And Return Rc docker %{VCH-PARAMS} exec bar-c2 ping -c3 bar-c1
Should Be Equal As Integers ${rc} 0
Launch Container With Port Forwarding webserver 10000 10001
Check Nginx Port Forwarding 10000 10001
# Gather logs before rebooting
Run Keyword And Continue On Failure Gather Logs From Test Server -before-reboot-1
Reboot VM %{VCH-NAME}
Wait For VCH Initialization 20x 10 seconds
# name resolution should work on the foo and bar networks
${rc}= Run And Return Rc docker %{VCH-PARAMS} exec foo-c1 ping -c3 foo-c2
Should Be Equal As Integers ${rc} 0
${rc}= Run And Return Rc docker %{VCH-PARAMS} exec foo-c2 ping -c3 foo-c1
Should Be Equal As Integers ${rc} 0
${rc}= Run And Return Rc docker %{VCH-PARAMS} exec bar-c1 ping -c3 bar-c2
Should Be Equal As Integers ${rc} 0
${rc}= Run And Return Rc docker %{VCH-PARAMS} exec bar-c2 ping -c3 bar-c1
Should Be Equal As Integers ${rc} 0
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} images
Should Be Equal As Integers ${rc} 0
Should Contain ${output} nginx
Should Contain ${output} busybox
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} network ls
Should Be Equal As Integers ${rc} 0
Should Contain ${output} foo
Should Contain ${output} bar
Should Contain ${output} bridge
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} network inspect bridge
Should Be Equal As Integers ${rc} 0
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} network inspect bar
Should Be Equal As Integers ${rc} 0
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} network inspect foo
Should Be Equal As Integers ${rc} 0
${ip}= Get Container IP ${bridge-running} bridge
Should Be Equal ${ip} ${bridge-running-ip}
${ip}= Get Container IP ${bar-running} bar
Should Be Equal ${ip} ${bar-running-ip}
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect ${bridge-running} | jq '.[0].State.Status'
Should Be Equal As Integers ${rc} 0
Should Be Equal ${output} \"running\"
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect ${bar-running} | jq '.[0].State.Status'
Should Be Equal As Integers ${rc} 0
Should Be Equal ${output} \"running\"
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect ${bridge-exited} | jq '.[0].State.Status'
Should Be Equal As Integers ${rc} 0
Should Be Equal ${output} \"exited\"
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect ${bar-exited} | jq '.[0].State.Status'
Should Be Equal As Integers ${rc} 0
Should Be Equal ${output} \"exited\"
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start ${bar-exited}
Should Be Equal As Integers ${rc} 0
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start ${bridge-exited}
Should Be Equal As Integers ${rc} 0
Check Nginx Port Forwarding 10000 10001
# one of the ports collides
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} create -it -p 10001:80 -p 10002:80 --name webserver1 ${nginx}
Should Be Equal As Integers ${rc} 0
Should Not Contain ${output} Error
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start webserver1
Should Be Equal As Integers ${rc} 1
Should Contain ${output} port 10001 is not available
# docker pull should work after restart
# if this fails, very likely the default gateway on the VCH is not set
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull ${alpine}
Should Be Equal As Integers ${rc} 0
Container on Open Network And Port Forwarding Persist After Reboot
[Setup] NONE
Log To Console Create Port Groups For Container network
${out}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.portgroup.remove open-net
Run Keyword If '%{HOST_TYPE}' == 'VC' Remove VC Distributed Portgroup open-net
${vlan}= Get Public Network VLAN ID
${vswitch}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.vswitch.info -json | jq -r ".Vswitch[0].Name"
${out}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.portgroup.add -vlan=${vlan} -vswitch ${vswitch} open-net
${dvs}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run govc find -type DistributedVirtualSwitch | head -n1
${rc} ${output}= Run Keyword If '%{HOST_TYPE}' == 'VC' Run And Return Rc And Output govc dvs.portgroup.add -vlan=${vlan} -dvs ${dvs} open-net
Log ${out}
Install VIC Appliance To Test Server additional-args=--container-network=open-net --container-network-firewall=open-net:open
# Create a container on the open network
${open-running}= Launch Container vch-restart-open-running open-net
${open-exited}= Launch Container vch-restart-open-exited open-net ls
# Create nginx on the open network and bridge network
Launch Container With Port Forwarding webserver-open 10000 10001 open-net
Launch Container with Port Forwarding webserver-bridge 10002 10003 bridge
Check Nginx Port Forwarding 10002 10003
# Gather logs before rebooting
Run Keyword And Continue On Failure Gather Logs From Test Server -open-network
# Reboot VCH
Reboot VM %{VCH-NAME}
Wait For VCH Initialization 20x 10 seconds
# Check if the open container is persisted
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect ${open-running} | jq '.[0].State.Status'
Should Be Equal As Integers ${rc} 0
Should Be Equal ${output} \"running\"
# ensure that there isn't a mapping entry for unspecified ports - they are all open but we are not listing them as bindings
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect ${open-running} | jq '.[0].HostConfig.PortBindings'
Should Be Equal As Integers ${rc} 0
Should Not Contain $[output} \"0/tcp\":
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect ${open-exited} | jq -r '.[0].State.Status'
Should Be Equal As Integers ${rc} 0
Should Be Equal ${output} exited
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} start ${open-exited}
Should Be Equal As Integers ${rc} 0
# Check port forwarding on bridge container after reboot
Check Nginx Port Forwarding 10002 10003
# Check port forwarding on open container not reachable from endpoint VM
${rc1} ${output1}= Run And Return Rc And Output wget %{VCH-IP}:10000
${rc2} ${output2}= Run And Return Rc And Output wget %{VCH-IP}:10001
Should Not Be Equal As Integers ${rc1} 0
Should Not Be Equal As Integers ${rc2} 0
Log To Console Cleanup Port Groups For Container network
${out}= Run Keyword If '%{HOST_TYPE}' == 'ESXi' Run govc host.portgroup.remove open-net
${out}= Run Keyword If '%{HOST_TYPE}' == 'VC' Remove VC Distributed Portgroup open-net
Log ${out}
Create VCH attach disk and reboot
${rc}= Run And Return Rc govc vm.disk.create -vm=%{VCH-NAME} -name=%{VCH-NAME}/deleteme -size "16M"
Should Be Equal As Integers ${rc} 0
# Gather logs before rebooting
Run Keyword And Continue On Failure Gather Logs From Test Server -before-reboot-2
Reboot VM %{VCH-NAME}
# wait for docker info to succeed
Wait Until Keyword Succeeds 20x 5 seconds Run Docker Info %{VCH-PARAMS}
${rc}= Run And Return Rc govc device.ls -vm=%{VCH-NAME} | grep disk
Should Be Equal As Integers ${rc} 1
Docker inspect mount and cmd data after reboot
${rc} ${container}= Run And Return Rc And Output docker %{VCH-PARAMS} volume create --name=named-volume
Should Be Equal As Integers ${rc} 0
${rc} ${container}= Run And Return Rc And Output docker %{VCH-PARAMS} create --name=mount-data-test -v /mnt/test -v named-volume:/mnt/named busybox /bin/ls -la /
Should Be Equal As Integers ${rc} 0
${rc} ${out}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect -f '{{.Mounts}}' mount-data-test
Should Be Equal As Integers ${rc} 0
Should Contain ${out} /mnt/test
Should Contain ${out} /mnt/named
${rc} ${out}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect -f '{{.Config.Cmd}}' mount-data-test
Should Be Equal As Integers ${rc} 0
Should Contain X Times ${out} /bin/ls 1
Should Contain X Times ${out} -la 1
Should Contain X Times ${out} ${SPACE}/ 1
# Gather logs before rebooting
Run Keyword And Continue On Failure Gather Logs From Test Server -before-reboot-3
Reboot VM %{VCH-NAME}
# wait for docker info to succeed
Wait Until Keyword Succeeds 20x 5 seconds Run Docker Info %{VCH-PARAMS}
${rc} ${out}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect -f '{{.Mounts}}' mount-data-test
Should Be Equal As Integers ${rc} 0
Should Contain ${out} /mnt/test
Should Contain ${out} /mnt/named
${rc} ${out}= Run And Return Rc And Output docker %{VCH-PARAMS} inspect -f '{{.Config.Cmd}}' mount-data-test
Should Be Equal As Integers ${rc} 0
Should Contain X Times ${out} /bin/ls 1
Should Contain X Times ${out} -la 1
Should Contain X Times ${out} ${SPACE}/ 1
Docker pull interrupted by reboot should be restartable
${interrupt-image}= Set Variable tomcat
# delete image so we can be sure it's not already present for when we pull after restart
# image may not exist
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} rmi -f ${interrupt-image}
Log To Console \nPull ${interrupt-image} in background
${pid}= Start Process docker %{VCH-PARAMS} pull ${interrupt-image} shell=True
# Gather logs before rebooting - this acts as a sleep
# There is some uncertainty as to where we interrupt the download which means failures in this test
# are inherently likely to be intermittent
Run Keyword And Continue On Failure Gather Logs From Test Server -interrupted-pull
# Reboot VCH
Reboot VM %{VCH-NAME}
Wait For VCH Initialization 20x 10 seconds
# docker pull should work after restart
${rc} ${output}= Run And Return Rc And Output docker %{VCH-PARAMS} pull ${interrupt-image}
Should Be Equal As Integers ${rc} 0