|
1 | 1 | #!/usr/bin/env bash |
2 | 2 |
|
3 | | -# This script is used for the openlab CI job cloud-provider-openstack-acceptance-test-lb-octavia. |
4 | | -# See https://github.com/theopenlab/openlab-zuul-jobs/blob/master/playbooks/cloud-provider-openstack-acceptance-test-lb-octavia/run.yaml#L104 |
| 3 | +# This script is used for the openlab CI job cloud-provider-openstack-test-occm. |
5 | 4 | # |
6 | 5 | # Prerequisites: |
7 | | -# - This script is supposed to be running on a host has access to kubernetes cluster. |
| 6 | +# - This script is supposed to be running on the CI host which is running devstack. |
8 | 7 | # - kubectl is ready to talk with the kubernetes cluster. |
9 | | -# - It's recommended to run the script on a host with as less proxies to the public as possible, otherwise the |
10 | | -# x-forwarded-for test will probably fail. |
11 | 8 | # - This script is not responsible for resource clean up if there is test case fails. |
12 | 9 | set -x |
13 | 10 |
|
14 | 11 | TIMEOUT=${TIMEOUT:-300} |
15 | 12 | FLOATING_IP=${FLOATING_IP:-""} |
16 | 13 | NAMESPACE="octavia-lb-test" |
| 14 | +GATEWAY_IP=${GATEWAY_IP:-""} |
| 15 | +OS_RC=${OS_RC:-"/home/zuul/devstack/openrc"} |
17 | 16 |
|
18 | 17 | delete_resources() { |
19 | 18 | ERROR_CODE="$?" |
@@ -63,7 +62,7 @@ function wait_for_loadbalancer { |
63 | 62 |
|
64 | 63 | end=$(($(date +%s) + ${TIMEOUT})) |
65 | 64 | while true; do |
66 | | - status=$(kubectl -n $NAMESPACE exec openstackcli -- openstack loadbalancer show $lbid -f value -c provisioning_status) |
| 65 | + status=$(openstack loadbalancer show $lbid -f value -c provisioning_status) |
67 | 66 | if [[ $status == "ACTIVE" ]]; then |
68 | 67 | if [[ $i == 2 ]]; then |
69 | 68 | printf "\n>>>>>>> Load balancer ${lbid} is ACTIVE\n" |
@@ -152,37 +151,6 @@ spec: |
152 | 151 | EOF |
153 | 152 | } |
154 | 153 |
|
155 | | -######################################################################## |
156 | | -## Name: create_openstackcli_pod |
157 | | -## Desc: Makes sure the openstackcli pod is running. |
158 | | -## Params: None |
159 | | -######################################################################## |
160 | | -function create_openstackcli_pod { |
161 | | - kubectl -n $NAMESPACE get pod | grep openstackcli | grep Running > /dev/null |
162 | | - if [[ $? -eq 1 ]]; then |
163 | | - printf "\n>>>>>>> Creating openstackcli pod\n" |
164 | | - cat <<EOF | kubectl apply -f - |
165 | | -apiVersion: v1 |
166 | | -kind: Pod |
167 | | -metadata: |
168 | | - name: openstackcli |
169 | | - namespace: $NAMESPACE |
170 | | -spec: |
171 | | - containers: |
172 | | - - name: openstackcli |
173 | | - image: lingxiankong/openstack-cli:1.0.0 |
174 | | - envFrom: |
175 | | - - secretRef: |
176 | | - name: openrc |
177 | | - command: |
178 | | - - sleep |
179 | | - - "3600" |
180 | | -EOF |
181 | | - kubectl -n $NAMESPACE wait --for=condition=Ready pod/openstackcli |
182 | | - printf "\n>>>>>>> Pod openstackcli created.\n" |
183 | | - fi |
184 | | -} |
185 | | - |
186 | 154 | ######################################################################## |
187 | 155 | ## Name: test_basic |
188 | 156 | ## Desc: Create a k8s service and send request to the service external |
|
260 | 228 | wait_for_service ${service} |
261 | 229 |
|
262 | 230 | printf "\n>>>>>>> Sending request to the Service ${service}\n" |
263 | | - orig_ip=$(curl -s http://${ipaddr} | grep x-forwarded-for | awk -F'=' '{print $2}') |
264 | | - if [[ "${orig_ip}" != "${local_ip}" && "${orig_ip}" != "${public_ip}" ]]; then |
265 | | - printf "\n>>>>>>> FAIL: Get incorrect response from Service ${service}, orig_ip: ${local_ip}, public_ip: ${public_ip}\n" |
| 231 | + ip_in_header=$(curl -s http://${ipaddr} | grep x-forwarded-for | awk -F'=' '{print $2}') |
| 232 | + if [[ "${ip_in_header}" != "${local_ip}" && "${ip_in_header}" != "${public_ip}" && "${ip_in_header}" != "${GATEWAY_IP}" ]]; then |
| 233 | + printf "\n>>>>>>> FAIL: Get incorrect response from Service ${service}, ip_in_header: ${ip_in_header}, local_ip: ${local_ip}, gateway_ip: ${GATEWAY_IP}, public_ip: ${public_ip}\n" |
266 | 234 | exit -1 |
267 | 235 | else |
268 | 236 | printf "\n>>>>>>> Expected: Get correct response from Service ${service}\n" |
@@ -308,12 +276,12 @@ EOF |
308 | 276 | wait_for_service ${service} |
309 | 277 |
|
310 | 278 | printf "\n>>>>>>> Validating openstack load balancer\n" |
311 | | - create_openstackcli_pod |
312 | | - lbid=$(kubectl -n $NAMESPACE exec openstackcli -- openstack loadbalancer list -c id -c name | grep "octavia-lb-test_${service}" | awk '{print $2}') |
313 | | - lb_info=$(kubectl -n $NAMESPACE exec openstackcli -- openstack loadbalancer status show $lbid) |
| 279 | + set +x; source $OS_RC demo demo; set -x |
| 280 | + lbid=$(openstack loadbalancer list -c id -c name | grep "octavia-lb-test_${service}" | awk '{print $2}') |
| 281 | + lb_info=$(openstack loadbalancer status show $lbid) |
314 | 282 | listener_count=$(echo $lb_info | jq '.loadbalancer.listeners | length') |
315 | 283 | member_ports=$(echo $lb_info | jq '.loadbalancer.listeners | .[].pools | .[].members | .[].protocol_port' | uniq) |
316 | | - service_nodeports=$(kubectl -n $NAMESPACE get svc $service -o json | jq '.spec.ports | .[].nodePort') |
| 284 | + service_nodeports=$(kubectl -n $NAMESPACE get svc $service -o json | jq '.spec.ports | .[].nodePort') |
317 | 285 |
|
318 | 286 | if [[ ${listener_count} != 2 ]]; then |
319 | 287 | printf "\n>>>>>>> FAIL: Unexpected number of listeners(${listener_count}) created for service ${service}\n" |
|
334 | 302 |
|
335 | 303 | printf "\n>>>>>>> Validating openstack load balancer after updating the service.\n" |
336 | 304 | create_openstackcli_pod |
337 | | - lb_info=$(kubectl -n $NAMESPACE exec openstackcli -- openstack loadbalancer status show $lbid) |
| 305 | + lb_info=$(openstack loadbalancer status show $lbid) |
338 | 306 | listener_count=$(echo $lb_info | jq '.loadbalancer.listeners | length') |
339 | 307 | member_port=$(echo $lb_info | jq '.loadbalancer.listeners | .[].pools | .[].members | .[].protocol_port' | uniq) |
340 | 308 | service_nodeport=$(kubectl -n $NAMESPACE get svc $service -o json | jq '.spec.ports | .[].nodePort') |
|
0 commit comments