Fix sriov test in baremetal deploy
[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 © 2020 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 set -o errexit
13 set -o nounset
14 set -o pipefail
15 #set -o xtrace
16
17 source _common_test.sh
18 source _functions.sh
19 source _common.sh
20
21 if [ ${1:+1} ]; then
22     if [ "$1" == "--external" ]; then
23         master_ip=$(kubectl cluster-info | grep "Kubernetes master" | \
24             awk -F ":" '{print $2}' | awk -F "//" '{print $2}')
25         onap_svc_node_port=30498
26         base_url="http://$master_ip:$onap_svc_node_port/v1"
27     fi
28 fi
29
30 base_url=${base_url:-"http://localhost:9015/v1"}
31 kubeconfig_path="$HOME/.kube/config"
32 csar_id=cc009bfe-bbee-11e8-9766-525400435678
33 rb_name="vfw"
34 rb_version="plugin_test"
35 chart_name="firewall"
36 profile_name="test_profile"
37 release_name="test-release"
38 namespace="plugin-tests-namespace"
39 cloud_region_id="kud"
40 cloud_region_owner="localhost"
41
42 # Setup
43 install_deps
44 populate_CSAR_fw_rbdefinition "$csar_id"
45
46 print_msg "Registering resource bundle"
47 payload="$(cat <<EOF
48 {
49     "rb-name": "${rb_name}",
50     "rb-version": "${rb_version}",
51     "chart-name": "${chart_name}"
52 }
53 EOF
54 )"
55 call_api -d "${payload}" "${base_url}/rb/definition"
56
57 print_msg "Uploading resource bundle content"
58 call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_definition.tar.gz" \
59          "${base_url}/rb/definition/${rb_name}/${rb_version}/content"
60
61 print_msg "Registering rb's profile"
62 payload="$(cat <<EOF
63 {
64     "rb-name": "${rb_name}",
65     "rb-version": "${rb_version}",
66     "profile-name": "${profile_name}",
67     "release-name": "dummy",
68     "namespace": "${namespace}"
69 }
70 EOF
71 )"
72 call_api -d "${payload}" "${base_url}/rb/definition/${rb_name}/${rb_version}/profile"
73
74 print_msg "Uploading profile data"
75 call_api --data-binary "@${CSAR_DIR}/${csar_id}/rb_profile.tar.gz" \
76          "${base_url}/rb/definition/${rb_name}/${rb_version}/profile/${profile_name}/content"
77
78 print_msg "Setup cloud data"
79 payload="$(cat <<EOF
80 {
81     "cloud-region": "$cloud_region_id",
82     "cloud-owner": "$cloud_region_owner"
83 }
84 EOF
85 )"
86 call_api -F "metadata=$payload" \
87          -F "file=@$kubeconfig_path" \
88          "${base_url}/connectivity-info" >/dev/null #massive output
89
90 print_msg "Creating vFW VNF Instance"
91 payload="$(cat <<EOF
92 {
93     "rb-name": "${rb_name}",
94     "rb-version": "${rb_version}",
95     "profile-name": "${profile_name}",
96     "release-name": "${release_name}",
97     "cloud-region": "${cloud_region_id}",
98     "labels": {"testCaseName": "plugin_fw.sh"},
99     "override-values": {"global.onapPrivateNetworkName": "onap-private-net-test"}
100 }
101 EOF
102 )"
103 response="$(call_api -d "${payload}" "${base_url}/instance")"
104 echo "$response"
105 vnf_id="$(jq -r '.id' <<< "${response}")"
106
107 print_msg "[BEGIN] Basic checks for instantiated resource"
108 print_msg "Check if override value has been applied correctly"
109 kubectl get network -n "${namespace}" onap-private-net-test
110 print_msg "Wait for all pods to start"
111 wait_for_pod -n "${namespace}" -l app=sink
112 wait_for_pod -n "${namespace}" -l app=firewall
113 wait_for_pod -n "${namespace}" -l app=packetgen
114 # TODO: Provide some health check to verify vFW work
115 print_msg "Not waiting for vFW to fully install as no further checks are implemented in testcase"
116 #print_msg "Waiting 8minutes for vFW installation"
117 #sleep 8m
118 print_msg "[END] Basic checks for instantiated resource"
119
120 print_msg "Retrieving VNF status (this will result with long output)"
121 call_api "${base_url}/instance/${vnf_id}/status"
122
123 print_msg "Retrieving VNF details"
124 response="$(call_api "${base_url}/instance/${vnf_id}")"
125 echo "$response"
126 print_msg "Assert additional label has been assigned to rb instance"
127 test "$(jq -r '.request.labels.testCaseName' <<< "${response}")" == plugin_fw.sh
128 print_msg "Assert ReleaseName has been correctly overriden"
129 test "$(jq -r '.request."release-name"' <<< "${response}")" == "${release_name}"
130
131 #Teardown
132 print_msg "Deleting VNF Instance"
133 delete_resource "${base_url}/instance/${vnf_id}"
134
135 print_msg "Deleting Profile"
136 delete_resource "${base_url}/rb/definition/${rb_name}/${rb_version}/profile/${profile_name}"
137
138 print_msg "Deleting Resource Bundle"
139 delete_resource "${base_url}/rb/definition/${rb_name}/${rb_version}"
140
141 print_msg "Deleting ${cloud_region_id} cloud region connection"
142 delete_resource "${base_url}/connectivity-info/${cloud_region_id}"
143
144 print_msg "Test finished successfully"