Healing issue
[sdc.git] / test-apis-ci / sdc-api-tests / chef-repo / cookbooks / sdc-api-tests / files / default / startTest.sh
1 #!/bin/bash
2 REMOTE_DEBUG=false
3 RERUN=false
4 debug_port=8000
5 TEST_SUITES=testSuites
6 fileName=testng-failed.xml
7
8 function help_usage ()
9 {
10         echo
11         echo "$0 (<jar_file_name> <suite file name>) [-r/rerun <true/false> -d/debug <true/false>]"
12         echo "nohup ./startTest.sh ui-ci-1707.0.5-SNAPSHOT-jar-with-dependencies.jar extendedSanity.xml -r false -d true &"
13         echo "by default rerun is true and remote debug is false."
14         echo
15         exit 2
16 }
17
18 function isBoolean ()
19 {
20         PARAM_NAME=$1
21         VALUE=$2
22         if [[ ${VALUE} != "true" ]] && [[ ${VALUE} != "false" ]]; then
23                 echo "Valid parameter" ${PARAM_NAME} "values are: true/false"
24             help_usage
25         fi
26 }
27
28 function prepareFailedXmlFile ()
29 {
30         echo "1="$1 "2="$2 "fileName="${fileName}
31         PATTERN=`grep -w "test name=" ${FULL_PATH}/${TEST_SUITES}/$2 | awk -F'"' '{print $2}'`
32         sed '/<test name="'${PATTERN}'"/,/<!-- '${PATTERN}' --/d' $1 > ${FULL_PATH}/${TEST_SUITES}/${fileName}
33     sed -i 's/thread-count="[0-9]\+"/thread-count="1"/g' ${FULL_PATH}/${TEST_SUITES}/${fileName}
34     if [ -s "ExtentReport/ShortReport.csv" ]
35     then
36         SKIP_TESTS_LIST=$(cat ExtentReport/ShortReport.csv  |awk  -F, '{print  $2}' | sed 's/&.*//g' | uniq)
37         for SKIP_TEST in ${SKIP_TESTS_LIST}; do
38             sed -i "s/.*\"${SKIP_TEST}\".*//g" ${FULL_PATH}/${TEST_SUITES}/${fileName};
39         done;
40     fi
41 }
42
43 function setUpdatedTimeToReport ()
44 {
45         LINE_NUMBER_OF_START_REPORT_DATE=`grep -A1 -nw "Start" ExtentReport/SDC_UI_Extent_Report.html | tail -1 | awk '{print $1}' | tr -d -`
46     END_REPORT_DATE=`grep -A1 -nw "End" ExtentReport/SDC_UI_Extent_Report.html | tail -1 | awk -F'[>|<]' '{print $3}'`
47     EPOCH_START_REPORT_DATE=`date --date="${1}" +%s`
48     EPOCH_END_REPORT_DATE=`date --date="${END_REPORT_DATE}" +%s`
49     let DIFF_EPOCH_TIME=${EPOCH_END_REPORT_DATE}-${EPOCH_START_REPORT_DATE}
50     TAKEN_TIME_IN_MINUTES=`echo $((${DIFF_EPOCH_TIME}/60))`
51     LINE_NUMBER_OF_TAKEN_REPORT_TIME=`grep -A1 -nw "Time Taken" ExtentReport/SDC_UI_Extent_Report.html | tail -1 | awk '{print $1}' | tr -d -`
52     PATTERN="div class='panel-lead'>";
53     sed -i "${LINE_NUMBER_OF_START_REPORT_DATE}s/${PATTERN}.*\</${PATTERN}$1\<\//1" ExtentReport/SDC_UI_Extent_Report.html
54     sed -i "${LINE_NUMBER_OF_TAKEN_REPORT_TIME}s/${PATTERN}.*\</${PATTERN}${TAKEN_TIME_IN_MINUTES} min\<\//1" ExtentReport/SDC_UI_Extent_Report.html
55 }
56
57 #main
58 [ $# -lt 2 ] && help_usage
59
60 JAR_FILE=$1
61 SUITE_FILE=$2
62
63 while [ $# -ne 0 ]; do
64         case $1 in
65                 -r|rerun)
66                         RERUN=$2
67                         isBoolean $1 ${RERUN}
68                         shift 1
69                         shift 1
70                 ;;
71                 -d|debug)
72                         REMOTE_DEBUG=$2
73                         isBoolean $1 ${REMOTE_DEBUG}
74                         shift 1
75                         shift 1
76                 ;;
77                 *)
78                         shift 1
79                 ;;
80         esac
81 done
82
83 CURRENT_DIR=`pwd`
84 BASEDIR=$(dirname $0)
85
86 if [ ${BASEDIR:0:1} = "/" ]
87 then
88         FULL_PATH=$BASEDIR
89 else
90         FULL_PATH=$CURRENT_DIR/$BASEDIR
91 fi
92 LOGS_PROP_FILE=file:${FULL_PATH}/conf/log4j.properties
93 #############################################
94 TARGET_DIR=${FULL_PATH}/target
95 CONF_FILE=${FULL_PATH}/conf/sdc.yaml
96
97 DEBUG=true
98 MainClass=org.openecomp.sdc.ci.tests.run.StartTest
99
100 TESTS_DIR=/opt/app/sdc/ci/resources/tests
101 COMPONENTS_DIR=/opt/app/sdc/ci/resources/components
102
103
104 TARGET_LOG_DIR="${TARGET_DIR}/"
105
106
107 ######ADD USERS################
108
109 BE_IP=`cat conf/attsdc.yaml | grep catalogBeHost| awk '{print $2}'`
110
111
112
113
114
115
116 if [ ${REMOTE_DEBUG} == "true" ]; then
117     echo "Debug mode, Listen on port $debug_port";
118     JAVA_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debug_port}" ;
119 fi
120
121 cmd="java $JAVA_OPTIONS -DdisplayException=true -Dtargetlog=${TARGET_LOG_DIR} -DfilePath=${FILES_TEST} -Dconfig.resource=${CONF_FILE} -Ddebug=${DEBUG} -Dlog4j.configuration=${LOGS_PROP_FILE} -cp $JAR_FILE ${MainClass} $SUITE_FILE &"
122
123
124 if [ $DEBUG == "true" ]
125 then
126         $cmd
127 else
128         $cmd >> /dev/null
129 fi
130
131 if [ ${RERUN} == "true" ]; then
132     if [ -f ${TARGET_DIR}/${fileName} ]; then
133         echo "Prepare" ${TARGET_DIR}/${fileName} "file to rerun all failed tests ...";
134         prepareFailedXmlFile ${TARGET_DIR}/${fileName} $SUITE_FILE;
135         SUITE_FILE=${fileName};
136         cmd="java $JAVA_OPTIONS -DdisplayException=true -Dtargetlog=${TARGET_LOG_DIR} -DfilePath=${FILES_TEST} -Dconfig.resource=${CONF_FILE} -Ddebug=${DEBUG} -Dlog4j.configuration=${LOGS_PROP_FILE} -cp $JAR_FILE ${MainClass} $SUITE_FILE &"
137         $cmd;
138     fi
139 fi
140
141 status=`echo $?`
142
143 source ExtentReport/versions.info
144 now=$(date +'%Y-%m-%d_%H_%M')
145 REPORT_NAME=${now}
146 VERSION=${osVersion}
147
148
149
150 echo "##################################################"
151 echo "################# status is ${status} #################"
152 echo "##################################################"
153
154 exit $status