2 # SPDX-license-identifier: Apache-2.0
3 ##############################################################################
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 ##############################################################################
15 source _common_test.sh
19 # TODO KUBECONFIG may be a list of paths
20 kubeconfig_path="${KUBECONFIG:-$HOME/.kube/config}"
22 clusters="${KUD_PLUGIN_FW_CLUSTERS:-$(cat <<EOF
27 "description": "description of edge01",
28 "userData1": "edge01 user data 1",
29 "userData2": "edge01 user data 2"
31 "file": "$kubeconfig_path"
37 function cluster_names {
38 echo $clusters | jq -e -r '.[].metadata.name'
41 function cluster_metadata {
44 "metadata": $(echo $clusters | jq -e -r --arg name "$1" '.[]|select(.metadata.name==$name)|.metadata')
49 function cluster_file {
50 echo $clusters | jq -e -r --arg name "$1" '.[]|select(.metadata.name==$name)|.file'
54 while [[ $# -gt 0 ]]; do
59 service_host=$(kubectl cluster-info | grep "Kubernetes master" | \
60 awk -F ":" '{print $2}' | awk -F "//" '{print $2}')
69 set -- "${ARGS[@]}" # restore positional parameters
71 service_host=${service_host:-"localhost"}
74 csar_id="4bf66240-a0be-4ce2-aebd-a01df7725f16"
76 demo_folder=$test_folder/../demo
78 function populate_CSAR_compositevfw_helm {
80 pushd "${CSAR_DIR}/$1"
81 print_msg "Create Helm Chart Archives for compositevfw"
83 tar -czf packetgen.tar.gz -C $demo_folder/composite-firewall packetgen
84 tar -czf firewall.tar.gz -C $demo_folder/composite-firewall firewall
85 tar -czf sink.tar.gz -C $demo_folder/composite-firewall sink
86 tar -czf profile.tar.gz -C $demo_folder/composite-firewall manifest.yaml override_values.yaml
91 composite_app="compositevfw"
93 deployment_intent_group="vfw_deployment_intent_group"
97 populate_CSAR_compositevfw_helm "$csar_id"
98 cat <<EOF >plugin_fw_v2_config.yaml
100 host: ${service_host}
103 host: ${service_host}
106 host: ${service_host}
109 host: ${service_host}
112 host: ${service_host}
115 host: ${service_host}
118 host: ${service_host}
121 cat <<EOF >plugin_fw_v2_values.yaml
122 ClusterProvider: vfw-cluster-provider
126 echo $clusters | jq -r '.[] | "- Name: \(.metadata.name)\n KubeConfig: \(.file)"' >>plugin_fw_v2_values.yaml
127 cat <<EOF >>plugin_fw_v2_values.yaml
128 EmcoProviderNetwork: emco-private-net
129 UnprotectedProviderNetwork: unprotected-private-net
130 ProtectedNetwork: protected-private-net
132 LogicalCloud: lcadmin
133 CompositeApp: ${composite_app}
135 PackagesPath: ${CSAR_DIR}/${csar_id}
136 CompositeProfile: vfw_composite-profile
137 DeploymentIntentGroup: ${deployment_intent_group}
139 DeploymentIntentsInGroup: vfw_deploy_intents
140 GenericPlacementIntent: generic-placement-intent
141 OvnActionIntent: vfw_ovnaction_intent
145 function call_emcoctl {
148 # retry due to known issue with emcoctl and instantiating/terminating multiple resources
150 until [[ $(emcoctl $@ | awk '/Response Code:/ {code=$3} END{print code}') =~ $rc ]]; do
151 if [[ $try -lt 10 ]]; then
161 function createData {
162 call_emcoctl 2.. --config plugin_fw_v2_config.yaml apply -f plugin_fw_v2.yaml -v plugin_fw_v2_values.yaml
166 emcoctl --config plugin_fw_v2_config.yaml get -f plugin_fw_v2.yaml -v plugin_fw_v2_values.yaml
169 function deleteData {
170 call_emcoctl 4.. --config plugin_fw_v2_config.yaml delete -f plugin_fw_v2.yaml -v plugin_fw_v2_values.yaml
174 emcoctl --config plugin_fw_v2_config.yaml get projects/${project}/composite-apps/${composite_app}/${version}/deployment-intent-groups/${deployment_intent_group}/status
177 function waitForVfw {
178 for try in {0..59}; do
180 new_phase="$(emcoctl --config plugin_fw_v2_config.yaml get projects/${project}/composite-apps/${composite_app}/${version}/deployment-intent-groups/${deployment_intent_group}/status | awk '/Response: / {print $2}' | jq -r .status)"
181 echo "$(date +%H:%M:%S) - Filter=[$*] : $new_phase"
182 if [[ "$new_phase" == "$1" ]]; then
189 echo "Usage: $0 setup|create|get|destroy|status"
190 echo " setup - creates the emcoctl files and packages needed for vfw"
191 echo " create - creates all ncm, ovnaction, clm resources needed for vfw"
192 echo " get - queries all resources in ncm, ovnaction, clm resources created for vfw"
193 echo " destroy - deletes all resources in ncm, ovnaction, clm resources created for vfw"
194 echo " status - get status of deployed resources"
196 echo " a reasonable test sequence:"
204 if [[ "$#" -gt 0 ]] ; then
207 "create" ) createData ;;
209 "status" ) statusVfw ;;
210 "wait" ) waitForVfw "Instantiated" ;;
211 "delete" ) deleteData ;;
218 print_msg "[BEGIN] Basic checks for instantiated resource"
219 print_msg "Wait for deployment to be instantiated"
220 waitForVfw "Instantiated"
221 for name in $(cluster_names); do
222 print_msg "Check that networks were created on cluster $name"
223 file=$(cluster_file "$name")
224 KUBECONFIG=$file kubectl get network protected-private-net -o name
225 KUBECONFIG=$file kubectl get providernetwork emco-private-net -o name
226 KUBECONFIG=$file kubectl get providernetwork unprotected-private-net -o name
228 for name in $(cluster_names); do
229 print_msg "Wait for all pods to start on cluster $name"
230 file=$(cluster_file "$name")
231 KUBECONFIG=$file kubectl wait pod -l release=fw0 --for=condition=Ready
233 # TODO: Provide some health check to verify vFW work
234 print_msg "Not waiting for vFW to fully install as no further checks are implemented in testcase"
235 #print_msg "Waiting 8minutes for vFW installation"
237 print_msg "[END] Basic checks for instantiated resource"
239 print_msg "Delete deployment"