Merge "Remove warning displayed from ssh commands in baremetal test"
[multicloud/k8s.git] / kud / tests / plugin_fw.sh
1 #!/bin/bash
2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
4 # Copyright (c) 2018
5 # Copyright © 2021 Samsung Electronics
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Apache License, Version 2.0
8 # which accompanies this distribution, and is available at
9 # http://www.apache.org/licenses/LICENSE-2.0
10 ##############################################################################
11
12 # Script respects environment variable SKIP_CNF_TEARDOWN
13 # If set to "yes", it will preserve CNF for manual handling
14
15 set -o errexit
16 set -o nounset
17 set -o pipefail
18 #set -o xtrace
19
20 source _common_test.sh
21 source _functions.sh
22 source _common.sh
23
24 if [ ${1:+1} ]; then
25     if [ "$1" == "--external" ]; then
26         master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \
27             awk -F ":" '{print $2}' | awk -F "//" '{print $2}')
28         onap_svc_node_port=30498
29         base_url="http://$master_ip:$onap_svc_node_port/v1"
30     fi
31 fi
32
33 base_url=${base_url:-"http://localhost:9015/v1"}
34 kubeconfig_path="$HOME/.kube/config"
35 csar_id=cc009bfe-bbee-11e8-9766-525400435678
36 rb_name="vfw"
37 rb_version="plugin_test"
38 chart_name="firewall"
39 profile_name="test_profile"
40 release_name="test-release"
41 namespace="plugin-tests-namespace"
42 cloud_region_id="kud"
43 cloud_region_owner="localhost"
44
45 # Setup
46 install_deps
47 populate_CSAR_fw_rbdefinition "$csar_id"
48
49 print_msg "Registering resource bundle"
50 payload="$(cat <<EOF
51 {
52     "rb-name": "${rb_name}",
53     "rb-version": "${rb_version}",
54     "chart-name": "${chart_name}"
55 }
56 EOF
57 )"
58 call_api -d "${payload}" "${base_url}/rb/definition"
59
60 print_msg "Uploading resource bundle content"
61 call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_definition.tar.gz" \
62          "${base_url}/rb/definition/${rb_name}/${rb_version}/content"
63
64 print_msg "Registering rb's profile"
65 payload="$(cat <<EOF
66 {
67     "rb-name": "${rb_name}",
68     "rb-version": "${rb_version}",
69     "profile-name": "${profile_name}",
70     "release-name": "dummy",
71     "namespace": "${namespace}"
72 }
73 EOF
74 )"
75 call_api -d "${payload}" "${base_url}/rb/definition/${rb_name}/${rb_version}/profile"
76
77 print_msg "Uploading profile data"
78 call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_profile.tar.gz" \
79          "${base_url}/rb/definition/${rb_name}/${rb_version}/profile/${profile_name}/content"
80
81 print_msg "Setup cloud data"
82 payload="$(cat <<EOF
83 {
84     "cloud-region": "$cloud_region_id",
85     "cloud-owner": "$cloud_region_owner"
86 }
87 EOF
88 )"
89 call_api -F "metadata=$payload" \
90          -F "file=@$kubeconfig_path" \
91          "${base_url}/connectivity-info" >/dev/null #massive output
92
93 print_msg "Creating vFW VNF Instance"
94 payload="$(cat <<EOF
95 {
96     "rb-name": "${rb_name}",
97     "rb-version": "${rb_version}",
98     "profile-name": "${profile_name}",
99     "release-name": "${release_name}",
100     "cloud-region": "${cloud_region_id}",
101     "labels": {"testCaseName": "plugin_fw.sh"},
102     "override-values": {"global.onapPrivateNetworkName": "onap-private-net-test"}
103 }
104 EOF
105 )"
106 response="$(call_api -d "${payload}" "${base_url}/instance")"
107 echo "$response"
108 vnf_id="$(jq -r '.id' <<< "${response}")"
109
110 print_msg "[BEGIN] Basic checks for instantiated resource"
111 print_msg "Check if override value has been applied correctly"
112 kubectl get network -n "${namespace}" onap-private-net-test
113 print_msg "Wait for all pods to start"
114 wait_for_pod -n "${namespace}" -l app=sink
115 wait_for_pod -n "${namespace}" -l app=firewall
116 wait_for_pod -n "${namespace}" -l app=packetgen
117 # TODO: Provide some health check to verify vFW work
118 print_msg "Not waiting for vFW to fully install as no further checks are implemented in testcase"
119 #print_msg "Waiting 8minutes for vFW installation"
120 #sleep 8m
121 print_msg "[END] Basic checks for instantiated resource"
122
123 print_msg "Retrieving VNF status (this will result with long output)"
124 call_api "${base_url}/instance/${vnf_id}/status"
125
126 print_msg "Retrieving VNF details"
127 response="$(call_api "${base_url}/instance/${vnf_id}")"
128 echo "$response"
129 print_msg "Assert additional label has been assigned to rb instance"
130 test "$(jq -r '.request.labels.testCaseName' <<< "${response}")" == plugin_fw.sh
131 print_msg "Assert ReleaseName has been correctly overriden"
132 test "$(jq -r '.request."release-name"' <<< "${response}")" == "${release_name}"
133
134 #Teardown
135 if [ "${SKIP_CNF_TEARDOWN:-}" == "yes" ]; then
136     print_msg "Leaving CNF running for further debugging"
137     echo "Remember to later issue following DELETE calls to clean environment"
138     cat <<EOF
139     curl -X DELETE "${base_url}/instance/${vnf_id}"
140     curl -X DELETE "${base_url}/rb/definition/${rb_name}/${rb_version}/profile/${profile_name}"
141     curl -X DELETE "${base_url}/rb/definition/${rb_name}/${rb_version}"
142     curl -X DELETE "${base_url}/connectivity-info/${cloud_region_id}"
143 EOF
144 else
145     print_msg "Deleting VNF Instance"
146     delete_resource "${base_url}/instance/${vnf_id}"
147
148     print_msg "Deleting Profile"
149     delete_resource "${base_url}/rb/definition/${rb_name}/${rb_version}/profile/${profile_name}"
150
151     print_msg "Deleting Resource Bundle"
152     delete_resource "${base_url}/rb/definition/${rb_name}/${rb_version}"
153
154     print_msg "Deleting ${cloud_region_id} cloud region connection"
155     delete_resource "${base_url}/connectivity-info/${cloud_region_id}"
156 fi
157 print_msg "Test finished successfully"