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