blob: 20afd86414f54fe780b7b52e4eedfa50e727dd36 [file] [log] [blame]
Michael Landob3d48982017-06-11 14:22:02 +03001#!/bin/bash
2REMOTE_DEBUG=false
3RERUN=true
4JAVA_OPTION=""
5debug_port=8000
6TEST_SUITES=testSuites
7fileName=testng-failed.xml
8
9function help_usage ()
10{
11 echo
12 echo "$0 (<jar_file_name> <suite file name>) [-r/rerun <true/false> -d/debug <true/false>]"
13 echo "nohup ./startTest.sh ui-ci-1707.0.5-SNAPSHOT-jar-with-dependencies.jar extendedSanity.xml -r false -d true &"
14 echo "by default rerun is true and remote debug is false."
15 echo
16 exit 2
17}
18
19function isBoolean ()
20{
21 PARAM_NAME=$1
22 VALUE=$2
23 if [[ ${VALUE} != "true" ]] && [[ ${VALUE} != "false" ]]; then
24 echo "Valid parameter" ${PARAM_NAME} "values are: true/false"
Michael Landoa5445102018-03-04 14:53:33 +020025 help_usage
Michael Landob3d48982017-06-11 14:22:02 +030026 fi
27}
28
29function prepareFailedXmlFile ()
30{
31 echo "1="$1 "2="$2 "fileName="${fileName}
32 PATTERN=`grep -w "test name=" ${FULL_PATH}/${TEST_SUITES}/$2 | awk -F'"' '{print $2}'`
33 sed '/<test name="'${PATTERN}'"/,/<!-- '${PATTERN}' --/d' $1 > ${FULL_PATH}/${TEST_SUITES}/${fileName}
34 sed -i 's/thread-count="[0-9]\+"/thread-count="1"/g' ${FULL_PATH}/${TEST_SUITES}/${fileName}
Michael Landoa5445102018-03-04 14:53:33 +020035 if [ -s "ExtentReport/ShortReport.csv" ]
36 then
37 SKIP_TESTS_LIST=$(cat ExtentReport/ShortReport.csv |awk -F, '{print $2}' | sed 's/&.*//g' | uniq)
38 for SKIP_TEST in ${SKIP_TESTS_LIST}; do
39 sed -i "s/.*\"${SKIP_TEST}\".*//g" ${FULL_PATH}/${TEST_SUITES}/${fileName};
40 done;
41 fi
42}
43
44function setUpdatedTimeToReport ()
45{
46 LINE_NUMBER_OF_START_REPORT_DATE=`grep -A1 -nw "Start" ExtentReport/SDC_UI_Extent_Report.html | tail -1 | awk '{print $1}' | tr -d -`
47 END_REPORT_DATE=`grep -A1 -nw "End" ExtentReport/SDC_UI_Extent_Report.html | tail -1 | awk -F'[>|<]' '{print $3}'`
48 EPOCH_START_REPORT_DATE=`date --date="${1}" +%s`
49 EPOCH_END_REPORT_DATE=`date --date="${END_REPORT_DATE}" +%s`
50 let DIFF_EPOCH_TIME=${EPOCH_END_REPORT_DATE}-${EPOCH_START_REPORT_DATE}
51 TAKEN_TIME_IN_MINUTES=`echo $((${DIFF_EPOCH_TIME}/60))`
52 LINE_NUMBER_OF_TAKEN_REPORT_TIME=`grep -A1 -nw "Time Taken" ExtentReport/SDC_UI_Extent_Report.html | tail -1 | awk '{print $1}' | tr -d -`
53 PATTERN="div class='panel-lead'>";
54 sed -i "${LINE_NUMBER_OF_START_REPORT_DATE}s/${PATTERN}.*\</${PATTERN}$1\<\//1" ExtentReport/SDC_UI_Extent_Report.html
55 sed -i "${LINE_NUMBER_OF_TAKEN_REPORT_TIME}s/${PATTERN}.*\</${PATTERN}${TAKEN_TIME_IN_MINUTES} min\<\//1" ExtentReport/SDC_UI_Extent_Report.html
Michael Landob3d48982017-06-11 14:22:02 +030056}
57
58#main
59[ $# -lt 2 ] && help_usage
60
61JAR_FILE=$1
62SUITE_FILE=$2
63
64while [ $# -ne 0 ]; do
65 case $1 in
66 -r|rerun)
67 RERUN=$2
68 isBoolean $1 ${RERUN}
69 shift 1
70 shift 1
71 ;;
72 -d|debug)
73 REMOTE_DEBUG=$2
74 isBoolean $1 ${REMOTE_DEBUG}
75 shift 1
76 shift 1
77 ;;
78 *)
79 shift 1
80 ;;
81 esac
82done
83
84CURRENT_DIR=`pwd`
85BASEDIR=$(dirname $0)
86
87if [ ${BASEDIR:0:1} = "/" ]
88then
89 FULL_PATH=$BASEDIR
90else
91 FULL_PATH=$CURRENT_DIR/$BASEDIR
92fi
amohamad9ee60942020-06-26 12:40:11 -040093LOGS_PROP_FILE=file:${FULL_PATH}/conf/log4j2.properties
Michael Landob3d48982017-06-11 14:22:02 +030094#############################################
95TARGET_DIR=${FULL_PATH}/target
96CONF_FILE=${FULL_PATH}/conf/attsdc.yaml
97
98DEBUG=true
99MainClass=org.openecomp.sdc.ci.tests.run.StartTest
100
101TESTS_DIR=/opt/app/sdc/ci/resources/tests
102COMPONENTS_DIR=/opt/app/sdc/ci/resources/components
103
104
105TARGET_LOG_DIR="${TARGET_DIR}/"
106
107
108######ADD USERS################
109
110BE_IP=`cat conf/attsdc.yaml | grep catalogBeHost| awk '{print $2}'`
111
112ADD_USERS_SCRIPT="addUsersFromList_new.sh"
Tal Gitelman153a3582017-07-03 20:16:55 +0300113USER_LIST="conf/userList.txt"
Michael Landob3d48982017-06-11 14:22:02 +0300114chmod +x ${ADD_USERS_SCRIPT}
115echo "add users..."
Michael Landoa5445102018-03-04 14:53:33 +0200116./${ADD_USERS_SCRIPT} -ip ${BE_IP} -f ${USER_LIST}
Michael Landob3d48982017-06-11 14:22:02 +0300117
118
119
120
121if [ ${REMOTE_DEBUG} == "true" ]; then
122 echo "Debug mode, Listen on port $debug_port";
123 JAVA_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debug_port}" ;
124fi
125
Michael Lando5b593492018-07-29 16:13:45 +0300126cmd="java -Xmx2048m -Xms1024m $JAVA_OPTION -DdisplayException=true -Dtargetlog=${TARGET_LOG_DIR} -DfilePath=${FILES_TEST} -Dconfig.resource=${CONF_FILE} -Ddebug=${DEBUG} -Dlog4j.configuration=${LOGS_PROP_FILE} -Dorg.freemarker.loggerLibrary=none -cp $JAR_FILE ${MainClass} $SUITE_FILE &"
Michael Landob3d48982017-06-11 14:22:02 +0300127
128
129if [ $DEBUG == "true" ]
130then
131 $cmd
132else
133 $cmd >> /dev/null
134fi
135
136if [ ${RERUN} == "true" ]; then
137 if [ -f ${TARGET_DIR}/${fileName} ]; then
138 echo "Prepare" ${TARGET_DIR}/${fileName} "file to rerun all failed tests ...";
139 prepareFailedXmlFile ${TARGET_DIR}/${fileName} $SUITE_FILE;
140 SUITE_FILE=${fileName};
Michael Lando5b593492018-07-29 16:13:45 +0300141 cmd="java -Xmx2048m -Xms1024m $JAVA_OPTION -DdisplayException=true -Dtargetlog=${TARGET_LOG_DIR} -DfilePath=${FILES_TEST} -Dconfig.resource=${CONF_FILE} -Ddebug=${DEBUG} -Dlog4j.configuration=${LOGS_PROP_FILE} -Dorg.freemarker.loggerLibrary=none -cp $JAR_FILE ${MainClass} $SUITE_FILE &"
Michael Landob3d48982017-06-11 14:22:02 +0300142 $cmd;
143 fi
144fi
145
146status=`echo $?`
147
148source ExtentReport/versions.info
149now=$(date +'%Y-%m-%d_%H_%M')
150REPORT_NAME=${now}
151VERSION=${osVersion}
Michael Landoa5445102018-03-04 14:53:33 +0200152REPORT_START_DATE=${reportStartTime}
153
154if [ ${RERUN} == "true" ]; then
155 setUpdatedTimeToReport "${REPORT_START_DATE}";
156fi
Michael Landob3d48982017-06-11 14:22:02 +0300157
158if [[ $env == *"DEV20"* ]]
159then
160 MYENV="Nightly"
161else
162 MYENV=""
163fi
164
165COPY_REPORT_SCRIPT="copyToStorage.sh"
166chmod +x ${COPY_REPORT_SCRIPT}
167echo "copy report to storage..."
Michael Landoa5445102018-03-04 14:53:33 +0200168( ./${COPY_REPORT_SCRIPT} ${REPORT_NAME} ${VERSION} ${MYENV} )
Michael Landob3d48982017-06-11 14:22:02 +0300169
170
171MAILING_SCRIPT_NAME="sendMail.sh"
172chmod +x ${MAILING_SCRIPT_NAME}
173echo "Sending report via mail..."
174`./${MAILING_SCRIPT_NAME} ${REPORT_NAME} ${VERSION} ${MYENV}`
175
176
177echo "##################################################"
178echo "################# status is ${status} #################"
179echo "##################################################"
180
181exit $status