summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Rose <dr695h@att.com>2019-09-13 18:40:17 +0000
committerGerrit Code Review <gerrit@onap.org>2019-09-13 18:40:17 +0000
commite319430e199814608529493c30579e15a481a070 (patch)
tree029da9d96131e0fbfa4833c7912605b8b6dab29b
parentdb5b5ffbd1e2281664a42ea128cde83f3dd6c8ff (diff)
parent3406ff40e825280517a9548a42a6476a3f27115b (diff)
Merge "[INT] Add driver script for vnf lifecycle validation"
-rwxr-xr-xinstantiate-k8s.sh150
1 files changed, 150 insertions, 0 deletions
diff --git a/instantiate-k8s.sh b/instantiate-k8s.sh
new file mode 100755
index 0000000..ff730c9
--- /dev/null
+++ b/instantiate-k8s.sh
@@ -0,0 +1,150 @@
+#!/bin/bash
+# Copyright 2019 AT&T Intellectual Property. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
+
+NAMESPACE=
+FOLDER=
+POLL=0
+
+function check_required_parameter() {
+ # arg1 = parameter
+ # arg2 = parameter name
+ if [ -z "$1" ]; then
+ echo "$2 was not was provided. This parameter is required."
+ exit 1
+ fi
+}
+
+function check_optional_paramater() {
+ # arg1 = parameter
+ # arg2 = parameter name
+ if [ -z $1 ]; then
+ echo "$2"
+ else
+ echo "$1"
+ fi
+}
+
+while test $# -gt 0; do
+ case "$1" in
+ -h|--help)
+ echo "./instantiate-k8s.sh [options]"
+ echo " "
+ echo "required:"
+ echo "-n, --namespace <namespace> namespace that robot pod is running under."
+ echo "-f, --folder <folder> path to folder containing heat templates, preloads, and vnf-details.json."
+ echo " "
+ echo "additional options:"
+ echo "-p, --poll some cloud environments (like azure) have a short time out value when executing"
+ echo " kubectl. If your shell exits before the testsuite finishes, using this option"
+ echo " will poll the testsuite logs every 30 seconds until the test finishes."
+ echo " "
+ echo "This script executes the VNF instantiation robot testsuite."
+ echo "- It copies the VNF folder to the robot container that is part of the ONAP deployment."
+ echo "- It models, distributes, and instantiates a heat-based VNF."
+ echo "- It copies the logs to an output directory, and creates a tarball for upload to the OVP portal."
+ echo ""
+ exit 0
+ ;;
+ -n|--namespace)
+ shift
+ NAMESPACE=$1
+ shift
+ ;;
+ -f|--folder)
+ shift
+ FOLDER=$1
+ shift
+ ;;
+ -p|--poll)
+ shift
+ POLL=1
+ ;;
+ *)
+ echo "Unknown Argument $1. Try running with --help."
+ exit 0
+ ;;
+ esac
+done
+
+check_required_parameter "$NAMESPACE" "--namespace"
+check_required_parameter "$FOLDER" "--folder"
+
+TAG="instantiate_vnf_ovp"
+
+if [ ! -d "$FOLDER" ]; then
+ echo "VNF folder $FOLDER does not exist, exiting."
+ exit 1
+fi
+
+BUILDNUM="$$"
+OUTPUT_DIRECTORY=/tmp/vnfdata.${BUILDNUM}
+
+set -x
+
+POD=$(kubectl --namespace $NAMESPACE get pods | sed 's/ .*//'| grep robot)
+export GLOBAL_BUILD_NUMBER=$(kubectl --namespace $NAMESPACE exec ${POD} -- bash -c "ls -1q /share/logs/ | wc -l")
+TAGS="-i $TAG"
+ETEHOME=/var/opt/ONAP
+OUTPUT_FOLDER=$(printf %04d $GLOBAL_BUILD_NUMBER)_ete_instantiate_vnf
+DISPLAY_NUM=$(($GLOBAL_BUILD_NUMBER + 90))
+VARIABLEFILES="-V /share/config/robot_properties.py"
+VARIABLES="$VARIABLES -v GLOBAL_BUILD_NUMBER:${BUILDNUM}"
+
+echo "Copying the VNF folder into robot pod..."
+kubectl --namespace $NAMESPACE cp $FOLDER ${POD}:/tmp/vnfdata.${BUILDNUM}
+
+
+echo "Executing instantiation..."
+
+if [ $POLL = 1 ]; then
+ 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 &"
+
+ pid=`kubectl --namespace $NAMESPACE exec ${POD} -- bash -c "pgrep runTags.sh -n"`
+
+ if [ -z "$pid" ]; then
+ echo "robot testsuite unable to start"
+ exit 1
+ fi
+
+ 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"
+
+else
+ 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"
+fi
+
+set +x
+
+echo "testsuite has finished"
+
+mkdir -p "$OUTPUT_DIRECTORY"
+echo "Copying Results from pod..."
+
+kubectl --namespace $NAMESPACE cp ${POD}:share/logs/$OUTPUT_FOLDER/summary/report.json "$OUTPUT_DIRECTORY"/report.json
+kubectl --namespace $NAMESPACE cp ${POD}:share/logs/$OUTPUT_FOLDER/summary/stack_report.json "$OUTPUT_DIRECTORY"/stack_report.json
+kubectl --namespace $NAMESPACE cp ${POD}:share/logs/$OUTPUT_FOLDER/summary/results.json "$OUTPUT_DIRECTORY"/results.json
+kubectl --namespace $NAMESPACE cp ${POD}:share/logs/$OUTPUT_FOLDER/log.html "$OUTPUT_DIRECTORY"/log.html
+
+pushd .
+
+# echo -e "import hashlib\nwith open(\"README.md\", \"r\") as f: bytes = f.read()\nreadable_hash = hashlib.sha256(bytes).hexdigest()\nprint(readable_hash)" | python
+
+cd "$OUTPUT_DIRECTORY"
+tar -czvf vnf_heat_results.tar.gz *
+
+popd
+
+echo "VNF test results: $OUTPUT_DIRECTORY/vnf_heat_results.tar.gz"