Skip to content

Commit 06aaaf7

Browse files
authored
[occm] Make sure we don't mask LB tests failures and fix what was failing (kubernetes#2360) (kubernetes#2367)
* Fix shared LBs tests PR kubernetes#2190 prohibited sharing an LB that is internal for security reasons. This commit fixes the shared LBs tests to not create internal LBs. * Make sure we don't mask LB tests failures In `test-lb-service.sh` we do `trap "delete_resources" EXIT` to make sure we cleanup resources on a test failure. In there, we only fetched the `$?` after making a check for `${AUTO_CLEAN_UP}`, which itself alters the code to 0, so function always returns success. This means tests can never really fail. This commit fixes it by making sure `$ERROR_CODE` is fetched at the very beginning of the cleanup function.
1 parent 74e30ac commit 06aaaf7

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

tests/e2e/cloudprovider/test-lb-service.sh

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ LB_SUBNET_NAME=${LB_SUBNET_NAME:-"private-subnet"}
2020
AUTO_CLEAN_UP=${AUTO_CLEAN_UP:-"true"}
2121

2222
function delete_resources() {
23+
ERROR_CODE="$?"
24+
2325
if [[ ${AUTO_CLEAN_UP} != "true" ]]; then
2426
exit ${ERROR_CODE}
2527
fi
2628

27-
ERROR_CODE="$?"
28-
2929
printf "\n>>>>>>> Deleting k8s services\n"
3030
kubectl -n ${NAMESPACE} get svc -o name | xargs -r kubectl -n $NAMESPACE delete
3131
printf "\n>>>>>>> Deleting k8s deployments\n"
@@ -34,6 +34,12 @@ function delete_resources() {
3434
printf "\n>>>>>>> Deleting openstack load balancer \n"
3535
openstack loadbalancer delete test_shared_user_lb --cascade
3636

37+
printf "\n>>>>>>> Deleting openstack FIPs \n"
38+
fips=$(openstack floating ip list --tag occm-test -f value -c ID)
39+
for fip in $fips; do
40+
openstack floating ip delete ${fip}
41+
done
42+
3743
if [[ "$ERROR_CODE" != "0" ]]; then
3844
printf "\n>>>>>>> Dump openstack-cloud-controller-manager logs \n"
3945
pod_name=$(kubectl -n kube-system get pod -l k8s-app=openstack-cloud-controller-manager -o name | awk 'NR==1 {print}')
@@ -438,7 +444,6 @@ metadata:
438444
name: ${service1}
439445
namespace: $NAMESPACE
440446
annotations:
441-
service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
442447
loadbalancer.openstack.org/enable-health-monitor: "false"
443448
spec:
444449
type: LoadBalancer
@@ -474,7 +479,6 @@ metadata:
474479
name: ${service2}
475480
namespace: $NAMESPACE
476481
annotations:
477-
service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
478482
loadbalancer.openstack.org/enable-health-monitor: "false"
479483
loadbalancer.openstack.org/load-balancer-id: "$lbID"
480484
spec:
@@ -521,7 +525,6 @@ metadata:
521525
name: ${service2}
522526
namespace: $NAMESPACE
523527
annotations:
524-
service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
525528
loadbalancer.openstack.org/enable-health-monitor: "false"
526529
loadbalancer.openstack.org/load-balancer-id: "$lbID"
527530
spec:
@@ -580,7 +583,6 @@ metadata:
580583
name: ${service3}
581584
namespace: $NAMESPACE
582585
annotations:
583-
service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
584586
loadbalancer.openstack.org/enable-health-monitor: "false"
585587
loadbalancer.openstack.org/load-balancer-id: "$lbID"
586588
spec:
@@ -614,7 +616,6 @@ metadata:
614616
name: ${service4}
615617
namespace: $NAMESPACE
616618
annotations:
617-
service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
618619
loadbalancer.openstack.org/enable-health-monitor: "false"
619620
loadbalancer.openstack.org/load-balancer-id: "$lbID"
620621
spec:
@@ -725,6 +726,20 @@ function test_shared_user_lb {
725726
printf "\n>>>>>>> Waiting for openstack load balancer $lbID ACTIVE after creating listener \n"
726727
wait_for_loadbalancer $lbID
727728

729+
printf "\n>>>>>>> Getting an external network \n"
730+
extNetID=$(openstack network list --external -f value -c ID | head -1)
731+
if [[ -z extNetID ]]; then
732+
printf "\n>>>>>>> FAIL: failed to find an external network\n"
733+
exit 1
734+
fi
735+
fip=$(openstack floating ip create --tag occm-test -f value -c id ${extNetID})
736+
if [ $? -ne 0 ]; then
737+
printf "\n>>>>>>> FAIL: failed to create FIP\n"
738+
exit 1
739+
fi
740+
vip=$(openstack loadbalancer show $lbID -f value -c vip_port_id)
741+
openstack floating ip set --port ${vip} ${fip}
742+
728743
local service1="test-shared-user-lb"
729744
printf "\n>>>>>>> Create Service ${service1}\n"
730745
cat <<EOF | kubectl apply -f -
@@ -735,7 +750,6 @@ metadata:
735750
namespace: $NAMESPACE
736751
annotations:
737752
loadbalancer.openstack.org/load-balancer-id: "$lbID"
738-
service.beta.kubernetes.io/openstack-internal-load-balancer: "true"
739753
loadbalancer.openstack.org/enable-health-monitor: "false"
740754
spec:
741755
type: LoadBalancer

0 commit comments

Comments
 (0)