Merge "Enable self-cleanup after testing vcFW deployment"
[multicloud/k8s.git] / kud / tests / integration_vcFW.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
10
11 set -o errexit
12 set -o nounset
13 set -o pipefail
14
15 #Default action
16 TEARDOWN_ACTION=preserve
17
18 for arg; do
19     case "$arg" in
20         --help|-h)
21             {
22                 echo "Usage: $0 [--cleanup]"
23                 echo "Run integration testcase on KUD deployment"
24                 echo "deploying vFW demo on hybrid container-VM"
25                 echo "setup. Script by default preserves environment."
26                 echo "If you want it to be cleaned, launch script"
27                 echo "with --cleanup flag"
28             } >&2
29             exit 0
30             ;;
31         --cleanup)
32             TEARDOWN_ACTION=cleanup
33             break
34             ;;
35         *)
36             #not implemented
37             break
38             ;;
39     esac
40 done
41
42 source _common.sh
43 source _common_test.sh
44 source _functions.sh
45
46 csar_id=aa443e7e-c8ba-11e8-8877-525400b164ff
47
48 # Setup
49 if [[ ! -f $HOME/.ssh/id_rsa.pub ]]; then
50     echo -e "\n\n\n" | ssh-keygen -t rsa -N ""
51 fi
52 populate_CSAR_vms_containers_vFW $csar_id
53 pushd ${CSAR_DIR}/${csar_id}
54
55 #Clean env
56 print_msg "Cleanup scenario leftovers"
57 teardown $packetgen_deployment_name $firewall_deployment_name $sink_deployment_name
58 for item in $unprotected_private_net $protected_private_net $onap_private_net sink-service sink_configmap; do
59     kubectl delete -f $item.yaml --ignore-not-found
60 done
61
62 #Spin up
63 print_msg "Instantiate vcFW"
64 for net in $unprotected_private_net $protected_private_net $onap_private_net; do
65     echo "Create OVN Network $net network"
66     kubectl apply -f $net.yaml
67 done
68 for resource in onap-ovn4nfvk8s-network sink-service sink_configmap; do
69     kubectl apply -f $resource.yaml
70 done
71 setup $packetgen_deployment_name $firewall_deployment_name $sink_deployment_name
72
73 # Test
74 print_msg "Verify integration functionality"
75 for deployment_name in $packetgen_deployment_name $firewall_deployment_name; do
76     pod_name=$(kubectl get pods | grep  $deployment_name | awk '{print $1}')
77     vm=$(kubectl virt virsh list | grep ".*$deployment_name"  | awk '{print $2}')
78     echo "Pod name: $pod_name Virsh domain: $vm"
79     echo "ssh -i ~/.ssh/id_rsa admin@$(kubectl get pods $pod_name -o jsonpath="{.status.podIP}")"
80     echo "kubectl attach -it $pod_name"
81     echo "=== Virtlet details ===="
82     echo "$(kubectl virt virsh dumpxml $vm | grep VIRTLET_)\n"
83 done
84
85 # Teardown
86 if [ "${TEARDOWN_ACTION}" == "cleanup" ]; then
87     print_msg "Teardown integration scenario"
88     teardown $packetgen_deployment_name $firewall_deployment_name $sink_deployment_name
89     for item in $unprotected_private_net $protected_private_net $onap_private_net sink-service sink_configmap; do
90         kubectl delete -f $item.yaml
91     done
92 else
93     print_msg "Integration scenario access"
94     echo "You can access darkstat service on your pc by (for example) port forwarding sink service"
95     echo '`kubectl port-forward svc/sink-service 667`'
96     echo "or by direct access to any k8s node under port $(kubectl get svc sink-service -o jsonpath='{.spec.ports[0].nodePort}')"
97     print_msg ""
98 fi
99 popd