/
test_ingress.py
358 lines (307 loc) · 15.7 KB
/
test_ingress.py
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
import time
import test
from common.k8s.base import BaseK8sTest
from k8s.ingress import IngressFixture
from tcutils.wrappers import preposttest_wrapper
from tcutils.contrail_status_check import ContrailStatusChecker
from tcutils.util import skip_because
class TestIngress(BaseK8sTest):
@classmethod
def setUpClass(cls):
super(TestIngress, cls).setUpClass()
@classmethod
def tearDownClass(cls):
super(TestIngress, cls).tearDownClass()
@test.attr(type=['k8s_sanity'])
@skip_because(mx_gw = False)
@preposttest_wrapper
def test_ingress_with_kube_manager_restart(self):
''' Create a service with 2 pods running nginx
Create an ingress out of this service
From the local node, do a wget on the ingress public ip
Validate that service and its loadbalancing works
Restart kube-manager
Validate that service and its loadbalancing works after
restart
For now, do this test only in default project
'''
app = 'http_test'
labels = {'app':app}
namespace = self.setup_namespace(name='default')
assert namespace.verify_on_setup()
service = self.setup_http_service(namespace=namespace.name,
labels=labels)
pod1 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels)
pod2 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels)
ingress = self.setup_simple_nginx_ingress(service.name,
namespace=namespace.name)
assert ingress.verify_on_setup()
pod3 = self.setup_busybox_pod(namespace=namespace.name)
self.verify_nginx_pod(pod1)
self.verify_nginx_pod(pod2)
assert pod3.verify_on_setup()
# Now validate ingress from within the cluster network
assert self.validate_nginx_lb([pod1, pod2], ingress.cluster_ip,
test_pod=pod3)
# Now validate ingress from public network
assert self.validate_nginx_lb([pod1, pod2], ingress.external_ips[0])
self.restart_kube_manager()
# Now validate ingress from within the cluster network
assert self.validate_nginx_lb([pod1, pod2], ingress.cluster_ip,
test_pod=pod3)
# Now validate ingress from public network
assert self.validate_nginx_lb([pod1, pod2], ingress.external_ips[0])
# end test_ingress_with_kube_manager_restart
@test.attr(type=['k8s_sanity'])
@skip_because(mx_gw = False)
@preposttest_wrapper
def test_ingress_with_kube_apiserver_restart(self):
'''
Verifies that Kube APIs are correctly recieved and processed by Kube
API server post kube-apiserver restart.
Steps:
1. Before creating any k8s object, restart the Kube API service
2. Create a service with 2 pods running nginx
Create an ingress out of this service
3. From the local node, do a wget on the ingress public ip
Validate that service and its loadbalancing works
'''
self.inputs.restart_service("kube-apiserver",
[self.inputs.k8s_master_ip],
container = "kube-apiserver",
verify_service = False)
time.sleep(20) # Kube-apiserver being non contrail service, skipping the verification and putting a sleep
app = 'http_test'
labels = {'app':app}
namespace = self.setup_namespace(name='default')
assert namespace.verify_on_setup()
service = self.setup_http_service(namespace=namespace.name,
labels=labels)
pod1 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels)
pod2 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels)
ingress = self.setup_simple_nginx_ingress(service.name,
namespace=namespace.name)
assert ingress.verify_on_setup()
pod3 = self.setup_busybox_pod(namespace=namespace.name)
self.verify_nginx_pod(pod1)
self.verify_nginx_pod(pod2)
assert pod3.verify_on_setup()
# Now validate ingress from within the cluster network
assert self.validate_nginx_lb([pod1, pod2], ingress.cluster_ip,
test_pod=pod3)
# Now validate ingress from public network
assert self.validate_nginx_lb([pod1, pod2], ingress.external_ips[0])
# end test_ingress_with_kube_apiserver_restart
@test.attr(type=['k8s_sanity'])
@skip_because(mx_gw = False)
@preposttest_wrapper
def test_ingress_with_contrail_apiserver_restart(self):
'''
Verifies that Kube APIs are correctly recieved and processed by Contrail
API server post contrail-api restart.
Steps:
1. Before creating any k8s object, restart the contrail API server
2. Create a service with 2 pods running nginx
Create an ingress out of this service
3. From the local node, do a wget on the ingress public ip
Validate that service and its loadbalancing works
'''
self.inputs.restart_service("contrail-api",
self.inputs.cfgm_ips,
container = "api-server")
app = 'http_test'
labels = {'app':app}
namespace = self.setup_namespace(name='default')
assert namespace.verify_on_setup()
service = self.setup_http_service(namespace=namespace.name,
labels=labels)
pod1 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels)
pod2 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels)
ingress = self.setup_simple_nginx_ingress(service.name,
namespace=namespace.name)
assert ingress.verify_on_setup()
pod3 = self.setup_busybox_pod(namespace=namespace.name)
self.verify_nginx_pod(pod1)
self.verify_nginx_pod(pod2)
assert pod3.verify_on_setup()
# Now validate ingress from within the cluster network
assert self.validate_nginx_lb([pod1, pod2], ingress.cluster_ip,
test_pod=pod3)
# Now validate ingress from public network
assert self.validate_nginx_lb([pod1, pod2], ingress.external_ips[0])
# end test_ingress_with_contrail_apiserver_restart
@test.attr(type=['k8s_sanity'])
@skip_because(mx_gw = False)
@preposttest_wrapper
def test_ingress_fanout_with_vrouter_agent_restart(self):
'''Creating a fanout ingress with 2 different host having 2 different path along with a default backend
This host are supported by repective service. Service has required backend pod with required path
mentioned in ingress rule. From the local node, do a wget on the ingress public ip
Validate that service and its loadbalancing works.
Restart the Kube manager
Re verify the loadbalancing works after the kubemanager restart
'''
app1 = 'http_test1'
app2 = 'http_test2'
labels1 = {'app':app1}
labels2 = {'app':app2}
service_name1 = 's1'
service_name2 = 's2'
path1 = 'foo'
path2 = 'bar'
host1 = 'foo.bar.com'
host2 = 'bar.foo.com'
ingress_name = 'testingress'
namespace = self.setup_namespace(name='default')
assert namespace.verify_on_setup()
service1 = self.setup_http_service(namespace=namespace.name,
labels=labels1,
name=service_name1)
service2 = self.setup_http_service(namespace=namespace.name,
labels=labels2,
name=service_name2)
pod1 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels1)
pod2 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels1)
pod3 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels2)
pod4 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels2)
rules = [{'host': host1,
'http': {'paths': [{
'path':'/'+path1,
'backend': { 'service_name': service_name1,
'service_port': 80
}
}]
}
},
{'host': host2,
'http': {'paths': [{
'path': '/'+path2,
'backend': { 'service_name': service_name2,
'service_port': 80
}
}]
}
}]
default_backend = {'service_name': service_name1,
'service_port': 80}
ingress = self.setup_ingress(name=ingress_name,
namespace=namespace.name,
rules=rules,
default_backend=default_backend)
assert ingress.verify_on_setup()
pod5 = self.setup_busybox_pod(namespace=namespace.name)
self.verify_nginx_pod(pod1,path=path1)
self.verify_nginx_pod(pod2,path=path1)
self.verify_nginx_pod(pod3,path=path2)
self.verify_nginx_pod(pod4,path=path2)
assert pod5.verify_on_setup()
# Now validate ingress from within the cluster network
assert self.validate_nginx_lb([pod1, pod2], ingress.cluster_ip,
test_pod=pod5, path=path1, host=host1)
assert self.validate_nginx_lb([pod3, pod4], ingress.cluster_ip,
test_pod=pod5, path=path2, host=host2)
# Now validate ingress from public network
assert self.validate_nginx_lb([pod1, pod2], ingress.external_ips[0], path=path1, host=host1)
assert self.validate_nginx_lb([pod3, pod4], ingress.external_ips[0], path=path2, host=host2)
for compute_ip in self.inputs.compute_ips:
self.inputs.restart_service('contrail-vrouter-agent',[compute_ip],
container='agent')
cluster_status, error_nodes = ContrailStatusChecker(self.inputs).wait_till_contrail_cluster_stable(
nodes=self.inputs.compute_ips, roles="vrouter")
assert cluster_status, 'Cluster is not stable after restart'
assert self.validate_nginx_lb([pod1, pod2], ingress.cluster_ip,
test_pod=pod5, path=path1, host=host1)
assert self.validate_nginx_lb([pod3, pod4], ingress.cluster_ip,
test_pod=pod5, path=path2, host=host2)
@test.attr(type=['k8s_sanity'])
@skip_because(mx_gw = False)
@preposttest_wrapper
def test_ingress_fanout_with_node_reboot(self):
'''Creating a fanout ingress with 2 different host having 2 different path along with a default backend
This host are supported by repective service. Service has required backend pod with required path
mentioned in ingress rule. From the local node, do a wget on the ingress public ip
Validate that service and its loadbalancing works.
Reboot the nodes
Re verify the loadbalancing works after the nodes reboot
'''
app1 = 'http_test1'
app2 = 'http_test2'
labels1 = {'app':app1}
labels2 = {'app':app2}
service_name1 = 's1'
service_name2 = 's2'
path1 = 'foo'
path2 = 'bar'
host1 = 'foo.bar.com'
host2 = 'bar.foo.com'
ingress_name = 'testingress'
namespace = self.setup_namespace(name='default')
assert namespace.verify_on_setup()
service1 = self.setup_http_service(namespace=namespace.name,
labels=labels1,
name=service_name1)
service2 = self.setup_http_service(namespace=namespace.name,
labels=labels2,
name=service_name2)
pod1 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels1)
pod2 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels1)
pod3 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels2)
pod4 = self.setup_nginx_pod(namespace=namespace.name,
labels=labels2)
rules = [{'host': host1,
'http': {'paths': [{
'path':'/'+path1,
'backend': { 'service_name': service_name1,
'service_port': 80
}
}]
}
},
{'host': host2,
'http': {'paths': [{
'path': '/'+path2,
'backend': { 'service_name': service_name2,
'service_port': 80
}
}]
}
}]
default_backend = {'service_name': service_name1,
'service_port': 80}
ingress = self.setup_ingress(name=ingress_name,
namespace=namespace.name,
rules=rules,
default_backend=default_backend)
assert ingress.verify_on_setup()
pod5 = self.setup_busybox_pod(namespace=namespace.name)
self.verify_nginx_pod(pod1,path=path1)
self.verify_nginx_pod(pod2,path=path1)
self.verify_nginx_pod(pod3,path=path2)
self.verify_nginx_pod(pod4,path=path2)
assert pod5.verify_on_setup()
# Now validate ingress from within the cluster network
assert self.validate_nginx_lb([pod1, pod2], ingress.cluster_ip,
test_pod=pod5, path=path1, host=host1)
assert self.validate_nginx_lb([pod3, pod4], ingress.cluster_ip,
test_pod=pod5, path=path2, host=host2)
# Now validate ingress from public network
assert self.validate_nginx_lb([pod1, pod2], ingress.external_ips[0], path=path1, host=host1)
assert self.validate_nginx_lb([pod3, pod4], ingress.external_ips[0], path=path2, host=host2)
self.restart_vrouter_agent()
assert self.validate_nginx_lb([pod1, pod2], ingress.cluster_ip,
test_pod=pod5, path=path1, host=host1)
assert self.validate_nginx_lb([pod3, pod4], ingress.cluster_ip,
test_pod=pod5, path=path2, host=host2)