|
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 |
|
13 | 10 | TIMEOUT=${TIMEOUT:-300} |
14 | 11 | FLOATING_IP=${FLOATING_IP:-""} |
15 | 12 | NAMESPACE="octavia-lb-test" |
| 13 | +GATEWAY_IP=${GATEWAY_IP:-""} |
| 14 | +OS_RC=${OS_RC:-"/home/zuul/devstack/openrc"} |
16 | 15 |
|
17 | 16 | delete_resources() { |
18 | 17 | ERROR_CODE="$?" |
@@ -62,7 +61,7 @@ function wait_for_loadbalancer { |
62 | 61 |
|
63 | 62 | end=$(($(date +%s) + ${TIMEOUT})) |
64 | 63 | while true; do |
65 | | - status=$(kubectl -n $NAMESPACE exec openstackcli -- openstack loadbalancer show $lbid -f value -c provisioning_status) |
| 64 | + status=$(openstack loadbalancer show $lbid -f value -c provisioning_status) |
66 | 65 | if [[ $status == "ACTIVE" ]]; then |
67 | 66 | if [[ $i == 2 ]]; then |
68 | 67 | printf "\n>>>>>>> Load balancer ${lbid} is ACTIVE\n" |
@@ -151,37 +150,6 @@ spec: |
151 | 150 | EOF |
152 | 151 | } |
153 | 152 |
|
154 | | -######################################################################## |
155 | | -## Name: create_openstackcli_pod |
156 | | -## Desc: Makes sure the openstackcli pod is running. |
157 | | -## Params: None |
158 | | -######################################################################## |
159 | | -function create_openstackcli_pod { |
160 | | - kubectl -n $NAMESPACE get pod | grep openstackcli | grep Running > /dev/null |
161 | | - if [[ $? -eq 1 ]]; then |
162 | | - printf "\n>>>>>>> Creating openstackcli pod\n" |
163 | | - cat <<EOF | kubectl apply -f - |
164 | | -apiVersion: v1 |
165 | | -kind: Pod |
166 | | -metadata: |
167 | | - name: openstackcli |
168 | | - namespace: $NAMESPACE |
169 | | -spec: |
170 | | - containers: |
171 | | - - name: openstackcli |
172 | | - image: lingxiankong/openstack-cli:1.0.0 |
173 | | - envFrom: |
174 | | - - secretRef: |
175 | | - name: openrc |
176 | | - command: |
177 | | - - sleep |
178 | | - - "3600" |
179 | | -EOF |
180 | | - kubectl -n $NAMESPACE wait --for=condition=Ready pod/openstackcli |
181 | | - printf "\n>>>>>>> Pod openstackcli created.\n" |
182 | | - fi |
183 | | -} |
184 | | - |
185 | 153 | ######################################################################## |
186 | 154 | ## Name: test_basic |
187 | 155 | ## Desc: Create a k8s service and send request to the service external |
|
259 | 227 | wait_for_service ${service} |
260 | 228 |
|
261 | 229 | printf "\n>>>>>>> Sending request to the Service ${service}\n" |
262 | | - orig_ip=$(curl -s http://${ipaddr} | grep x-forwarded-for | awk -F'=' '{print $2}') |
263 | | - if [[ "${orig_ip}" != "${local_ip}" && "${orig_ip}" != "${public_ip}" ]]; then |
264 | | - printf "\n>>>>>>> FAIL: Get incorrect response from Service ${service}, orig_ip: ${local_ip}, public_ip: ${public_ip}\n" |
| 230 | + ip_in_header=$(curl -s http://${ipaddr} | grep x-forwarded-for | awk -F'=' '{print $2}') |
| 231 | + if [[ "${ip_in_header}" != "${local_ip}" && "${ip_in_header}" != "${public_ip}" && "${ip_in_header}" != "${GATEWAY_IP}" ]]; then |
| 232 | + 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" |
265 | 233 | exit -1 |
266 | 234 | else |
267 | 235 | printf "\n>>>>>>> Expected: Get correct response from Service ${service}\n" |
@@ -307,12 +275,12 @@ EOF |
307 | 275 | wait_for_service ${service} |
308 | 276 |
|
309 | 277 | printf "\n>>>>>>> Validating openstack load balancer\n" |
310 | | - create_openstackcli_pod |
311 | | - lbid=$(kubectl -n $NAMESPACE exec openstackcli -- openstack loadbalancer list -c id -c name | grep "octavia-lb-test_${service}" | awk '{print $2}') |
312 | | - lb_info=$(kubectl -n $NAMESPACE exec openstackcli -- openstack loadbalancer status show $lbid) |
| 278 | + set +x; source $OS_RC demo demo; set -x |
| 279 | + lbid=$(openstack loadbalancer list -c id -c name | grep "octavia-lb-test_${service}" | awk '{print $2}') |
| 280 | + lb_info=$(openstack loadbalancer status show $lbid) |
313 | 281 | listener_count=$(echo $lb_info | jq '.loadbalancer.listeners | length') |
314 | 282 | member_ports=$(echo $lb_info | jq '.loadbalancer.listeners | .[].pools | .[].members | .[].protocol_port' | uniq) |
315 | | - service_nodeports=$(kubectl -n $NAMESPACE get svc $service -o json | jq '.spec.ports | .[].nodePort') |
| 283 | + service_nodeports=$(kubectl -n $NAMESPACE get svc $service -o json | jq '.spec.ports | .[].nodePort') |
316 | 284 |
|
317 | 285 | if [[ ${listener_count} != 2 ]]; then |
318 | 286 | printf "\n>>>>>>> FAIL: Unexpected number of listeners(${listener_count}) created for service ${service}\n" |
|
333 | 301 |
|
334 | 302 | printf "\n>>>>>>> Validating openstack load balancer after updating the service.\n" |
335 | 303 | create_openstackcli_pod |
336 | | - lb_info=$(kubectl -n $NAMESPACE exec openstackcli -- openstack loadbalancer status show $lbid) |
| 304 | + lb_info=$(openstack loadbalancer status show $lbid) |
337 | 305 | listener_count=$(echo $lb_info | jq '.loadbalancer.listeners | length') |
338 | 306 | member_port=$(echo $lb_info | jq '.loadbalancer.listeners | .[].pools | .[].members | .[].protocol_port' | uniq) |
339 | 307 | service_nodeport=$(kubectl -n $NAMESPACE get svc $service -o json | jq '.spec.ports | .[].nodePort') |
|
0 commit comments