blob: 623870b9f309e1196ccf67ca13228f71b2532641 [file] [log] [blame]
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +01001#!/bin/bash
Guillaume Lambert134188d2021-03-11 13:42:23 +01002
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +01003# Copyright 2019 AT&T Intellectual Property. All rights reserved.
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
Guillaume Lambert134188d2021-03-11 13:42:23 +010017THIS_DIR="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )"
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +010018
19NAMESPACE=
20FOLDER=
21POLL=0
22
Guillaume Lambert785bc382021-03-09 21:41:30 +010023check_required_parameter () {
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +010024 # arg1 = parameter
25 # arg2 = parameter name
26 if [ -z "$1" ]; then
27 echo "$2 was not was provided. This parameter is required."
28 exit 1
29 fi
30}
31
Guillaume Lambert785bc382021-03-09 21:41:30 +010032check_optional_paramater () {
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +010033 # arg1 = parameter
34 # arg2 = parameter name
35 if [ -z $1 ]; then
36 echo "$2"
37 else
38 echo "$1"
39 fi
40}
41
42while test $# -gt 0; do
43 case "$1" in
44 -h|--help)
45 echo "./instantiate-k8s.sh [options]"
46 echo " "
47 echo "required:"
48 echo "-n, --namespace <namespace> namespace that robot pod is running under."
49 echo "-f, --folder <folder> path to folder containing heat templates, preloads, and vnf-details.json."
50 echo " "
51 echo "additional options:"
52 echo "-p, --poll some cloud environments (like azure) have a short time out value when executing"
53 echo " kubectl. If your shell exits before the testsuite finishes, using this option"
54 echo " will poll the testsuite logs every 30 seconds until the test finishes."
55 echo " "
56 echo "This script executes the VNF instantiation robot testsuite."
57 echo "- It copies the VNF folder to the robot container that is part of the ONAP deployment."
58 echo "- It models, distributes, and instantiates a heat-based VNF."
59 echo "- It copies the logs to an output directory, and creates a tarball for upload to the OVP portal."
60 echo ""
61 exit 0
62 ;;
63 -n|--namespace)
64 shift
65 NAMESPACE=$1
66 shift
67 ;;
68 -f|--folder)
69 shift
70 FOLDER=$1
71 shift
72 ;;
73 -p|--poll)
74 shift
75 POLL=1
76 ;;
77 *)
78 echo "Unknown Argument $1. Try running with --help."
79 exit 0
80 ;;
81 esac
82done
83
84check_required_parameter "$NAMESPACE" "--namespace"
85check_required_parameter "$FOLDER" "--folder"
86
87TAG="instantiate_vnf_ovp"
88
89if [ ! -d "$FOLDER" ]; then
90 echo "VNF folder $FOLDER does not exist, exiting."
91 exit 1
92fi
93
94BUILDNUM="$$"
95OUTPUT_DIRECTORY=/tmp/vnfdata.${BUILDNUM}
96
97set -x
98
99POD=$(kubectl --namespace $NAMESPACE get pods | sed 's/ .*//'| grep robot)
100export GLOBAL_BUILD_NUMBER=$(kubectl --namespace $NAMESPACE exec ${POD} -- bash -c "ls -1q /share/logs/ | wc -l")
101TAGS="-i $TAG"
102ETEHOME=/var/opt/ONAP
103OUTPUT_FOLDER=$(printf %04d $GLOBAL_BUILD_NUMBER)_ete_instantiate_vnf
104DISPLAY_NUM=$(($GLOBAL_BUILD_NUMBER + 90))
105VARIABLEFILES="-V /share/config/robot_properties.py"
106VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:${BUILDNUM}"
107
108echo "Copying the VNF folder into robot pod..."
109kubectl --namespace $NAMESPACE cp $FOLDER ${POD}:/tmp/vnfdata.${BUILDNUM}
110
111
112echo "Executing instantiation..."
113
114if [ $POLL = 1 ]; then
Guillaume Lambert9a4593b2021-03-12 21:21:54 +0100115 kubectl --namespace $NAMESPACE exec ${POD} -- bash -c "${ETEHOME}/runTags.sh ${VARIABLEFILES} ${VARIABLES} -d /share/logs/${OUTPUT_FOLDER} ${TAGS} --listener ${ETEHOME}/testsuite/eteutils/robotframework-onap/listeners/OVPListener.py --display $DISPLAY_NUM > /tmp/vnf_instantiation.$BUILDNUM.log 2>&1 &"
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +0100116
Guillaume Lambert9a4593b2021-03-12 21:21:54 +0100117 pid=`kubectl --namespace $NAMESPACE exec ${POD} -- bash -c "pgrep runTags.sh -n"`
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +0100118
119 if [ -z "$pid" ]; then
120 echo "robot testsuite unable to start"
121 exit 1
122 fi
123
124 kubectl --namespace $NAMESPACE exec ${POD} -- bash -c "while ps -p \"$pid\" --no-headers | grep -v defunct; do echo \$'\n\n'; echo \"Testsuite still running \"\`date\`; echo \"LOG FILE: \"; tail -10 /tmp/vnf_instantiation.$BUILDNUM.log; sleep 30; done"
125
126else
Guillaume Lambert9a4593b2021-03-12 21:21:54 +0100127 kubectl --namespace $NAMESPACE exec ${POD} -- bash -c "${ETEHOME}/runTags.sh ${VARIABLEFILES} ${VARIABLES} -d /share/logs/${OUTPUT_FOLDER} ${TAGS} --listener ${ETEHOME}/testsuite/eteutils/robotframework-onap/listeners/OVPListener.py --display $DISPLAY_NUM"
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +0100128fi
129
Guillaume Lambert9a4593b2021-03-12 21:21:54 +0100130set +x
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +0100131
132echo "testsuite has finished"
133
134mkdir -p "$OUTPUT_DIRECTORY"
135echo "Copying Results from pod..."
136
137kubectl --namespace $NAMESPACE cp ${POD}:share/logs/$OUTPUT_FOLDER/summary/report.json "$OUTPUT_DIRECTORY"/report.json
138kubectl --namespace $NAMESPACE cp ${POD}:share/logs/$OUTPUT_FOLDER/summary/stack_report.json "$OUTPUT_DIRECTORY"/stack_report.json
139kubectl --namespace $NAMESPACE cp ${POD}:share/logs/$OUTPUT_FOLDER/summary/results.json "$OUTPUT_DIRECTORY"/results.json
140kubectl --namespace $NAMESPACE cp ${POD}:share/logs/$OUTPUT_FOLDER/log.html "$OUTPUT_DIRECTORY"/log.html
141
Guillaume Lambert134188d2021-03-11 13:42:23 +0100142initdir=$(pwd)
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +0100143
144# echo -e "import hashlib\nwith open(\"README.md\", \"r\") as f: bytes = f.read()\nreadable_hash = hashlib.sha256(bytes).hexdigest()\nprint(readable_hash)" | python
145
146cd "$OUTPUT_DIRECTORY"
147tar -czvf vnf_heat_results.tar.gz *
148
Guillaume Lambert134188d2021-03-11 13:42:23 +0100149cd $initdir
Sylvain Desbureaux16bdf242020-12-07 10:28:24 +0100150
151echo "VNF test results: $OUTPUT_DIRECTORY/vnf_heat_results.tar.gz"