-
Notifications
You must be signed in to change notification settings - Fork 704
Expand file tree
/
Copy pathservice_configuration_test.yml
More file actions
276 lines (256 loc) · 9.28 KB
/
service_configuration_test.yml
File metadata and controls
276 lines (256 loc) · 9.28 KB
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
---
# Service Configuration Test Suite
# Tests for different service types and configurations
- name: Test ClusterIP service (default)
block:
- name: Apply AWX with ClusterIP service
k8s:
state: present
definition:
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: test-clusterip-awx
namespace: "{{ namespace }}"
spec:
service_type: ClusterIP
service_labels: |
test-type: clusterip
service_annotations: |
test.annotation/type: clusterip
- name: Wait for AWX ClusterIP service to be created
k8s_info:
namespace: "{{ namespace }}"
api_version: v1
kind: Service
name: test-clusterip-awx-service
wait: true
wait_condition:
type: Ready
status: "True"
wait_timeout: 300
register: clusterip_service
- name: Validate ClusterIP service configuration
ansible.builtin.assert:
that:
- clusterip_service.resources[0].spec.type == "ClusterIP"
- clusterip_service.resources[0].spec.ports[0].port == 80
- clusterip_service.resources[0].spec.ports[0].targetPort == 8052
- clusterip_service.resources[0].spec.ports[0].name == "http"
- "'test-type: clusterip' in clusterip_service.resources[0].metadata.labels"
- "'test.annotation/type: clusterip' in clusterip_service.resources[0].metadata.annotations"
fail_msg: "ClusterIP service validation failed"
- name: Test NodePort service
block:
- name: Apply AWX with NodePort service
k8s:
state: present
definition:
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: test-nodeport-awx
namespace: "{{ namespace }}"
spec:
service_type: NodePort
nodeport_port: 30080
service_labels: |
test-type: nodeport
- name: Wait for AWX NodePort service to be created
k8s_info:
namespace: "{{ namespace }}"
api_version: v1
kind: Service
name: test-nodeport-awx-service
wait: true
wait_condition:
type: Ready
status: "True"
wait_timeout: 300
register: nodeport_service
- name: Validate NodePort service configuration
ansible.builtin.assert:
that:
- nodeport_service.resources[0].spec.type == "NodePort"
- nodeport_service.resources[0].spec.ports[0].port == 80
- nodeport_service.resources[0].spec.ports[0].targetPort == 8052
- nodeport_service.resources[0].spec.ports[0].nodePort == 30080
- nodeport_service.resources[0].spec.ports[0].name == "http"
- "'test-type: nodeport' in nodeport_service.resources[0].metadata.labels"
fail_msg: "NodePort service validation failed"
- name: Test LoadBalancer service with HTTP
block:
- name: Apply AWX with LoadBalancer service (HTTP)
k8s:
state: present
definition:
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: test-lb-http-awx
namespace: "{{ namespace }}"
spec:
service_type: LoadBalancer
loadbalancer_port: 8080
loadbalancer_protocol: http
loadbalancer_class: "nginx"
service_labels: |
test-type: loadbalancer-http
- name: Wait for AWX LoadBalancer HTTP service to be created
k8s_info:
namespace: "{{ namespace }}"
api_version: v1
kind: Service
name: test-lb-http-awx-service
wait: true
wait_condition:
type: Ready
status: "True"
wait_timeout: 300
register: lb_http_service
- name: Validate LoadBalancer HTTP service configuration
ansible.builtin.assert:
that:
- lb_http_service.resources[0].spec.type == "LoadBalancer"
- lb_http_service.resources[0].spec.ports[0].port == 8080
- lb_http_service.resources[0].spec.ports[0].targetPort == 8052
- lb_http_service.resources[0].spec.ports[0].name == "http"
- lb_http_service.resources[0].spec.loadBalancerClass == "nginx"
- "'test-type: loadbalancer-http' in lb_http_service.resources[0].metadata.labels"
fail_msg: "LoadBalancer HTTP service validation failed"
- name: Test LoadBalancer service with HTTPS
block:
- name: Apply AWX with LoadBalancer service (HTTPS)
k8s:
state: present
definition:
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: test-lb-https-awx
namespace: "{{ namespace }}"
spec:
service_type: LoadBalancer
loadbalancer_port: 8443
loadbalancer_protocol: https
loadbalancer_ip: "192.168.1.100"
service_labels: |
test-type: loadbalancer-https
- name: Wait for AWX LoadBalancer HTTPS service to be created
k8s_info:
namespace: "{{ namespace }}"
api_version: v1
kind: Service
name: test-lb-https-awx-service
wait: true
wait_condition:
type: Ready
status: "True"
wait_timeout: 300
register: lb_https_service
- name: Validate LoadBalancer HTTPS service configuration
ansible.builtin.assert:
that:
- lb_https_service.resources[0].spec.type == "LoadBalancer"
- lb_https_service.resources[0].spec.ports[0].port == 8443
- lb_https_service.resources[0].spec.ports[0].targetPort == 8052
- lb_https_service.resources[0].spec.ports[0].name == "https"
- lb_https_service.resources[0].spec.loadBalancerIP == "192.168.1.100"
- "'test-type: loadbalancer-https' in lb_https_service.resources[0].metadata.labels"
fail_msg: "LoadBalancer HTTPS service validation failed"
- name: Test Route passthrough HTTPS configuration
block:
- name: Apply AWX with Route passthrough
k8s:
state: present
definition:
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: test-route-passthrough-awx
namespace: "{{ namespace }}"
spec:
service_type: ClusterIP
ingress_type: route
route_tls_termination_mechanism: passthrough
service_labels: |
test-type: route-passthrough
- name: Wait for AWX Route passthrough service to be created
k8s_info:
namespace: "{{ namespace }}"
api_version: v1
kind: Service
name: test-route-passthrough-awx-service
wait: true
wait_condition:
type: Ready
status: "True"
wait_timeout: 300
register: route_passthrough_service
- name: Validate Route passthrough service has HTTPS port
ansible.builtin.assert:
that:
- route_passthrough_service.resources[0].spec.type == "ClusterIP"
# Should have both HTTP and HTTPS ports for passthrough
- route_passthrough_service.resources[0].spec.ports | length >= 1
# Check if HTTPS port (443 -> 8053) exists for passthrough
- route_passthrough_service.resources[0].spec.ports | selectattr('port', 'equalto', 443) | list | length == 1
- (route_passthrough_service.resources[0].spec.ports | selectattr('port', 'equalto', 443) | first).targetPort == 8053
- (route_passthrough_service.resources[0].spec.ports | selectattr('port', 'equalto', 443) | first).name == "https"
fail_msg: "Route passthrough service validation failed"
- name: Test service template field validation (negative tests)
block:
# Test invalid NodePort range
- name: Test invalid NodePort (should fail)
k8s:
state: present
definition:
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: test-invalid-nodeport-awx
namespace: "{{ namespace }}"
spec:
service_type: NodePort
nodeport_port: 25000 # Below valid range
register: invalid_nodeport_result
failed_when: false
- name: Verify invalid NodePort was rejected
ansible.builtin.assert:
that:
- invalid_nodeport_result is failed
fail_msg: "Invalid NodePort should have been rejected"
rescue:
- name: Clean up test resources on failure
k8s:
state: absent
api_version: awx.ansible.com/v1beta1
kind: AWX
name: "{{ item }}"
namespace: "{{ namespace }}"
loop:
- test-clusterip-awx
- test-nodeport-awx
- test-lb-http-awx
- test-lb-https-awx
- test-route-passthrough-awx
- test-invalid-nodeport-awx
ignore_errors: yes
- name: Re-emit failure
fail:
msg: "Service configuration tests failed: {{ ansible_failed_result }}"
- name: Clean up test resources
k8s:
state: absent
api_version: awx.ansible.com/v1beta1
kind: AWX
name: "{{ item }}"
namespace: "{{ namespace }}"
loop:
- test-clusterip-awx
- test-nodeport-awx
- test-lb-http-awx
- test-lb-https-awx
- test-route-passthrough-awx
- test-invalid-nodeport-awx
ignore_errors: yes