Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | REMOTE_DEBUG=false |
| 3 | RERUN=true |
| 4 | JAVA_OPTION="" |
| 5 | debug_port=8000 |
| 6 | TEST_SUITES=testSuites |
| 7 | fileName=testng-failed.xml |
| 8 | |
| 9 | function 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 | |
| 19 | function 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 Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 25 | help_usage |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 26 | fi |
| 27 | } |
| 28 | |
| 29 | function 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 Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 35 | 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 | |
| 44 | function 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 Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | #main |
| 59 | [ $# -lt 2 ] && help_usage |
| 60 | |
| 61 | JAR_FILE=$1 |
| 62 | SUITE_FILE=$2 |
| 63 | |
| 64 | while [ $# -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 |
| 82 | done |
| 83 | |
| 84 | CURRENT_DIR=`pwd` |
| 85 | BASEDIR=$(dirname $0) |
| 86 | |
| 87 | if [ ${BASEDIR:0:1} = "/" ] |
| 88 | then |
| 89 | FULL_PATH=$BASEDIR |
| 90 | else |
| 91 | FULL_PATH=$CURRENT_DIR/$BASEDIR |
| 92 | fi |
amohamad | 9ee6094 | 2020-06-26 12:40:11 -0400 | [diff] [blame] | 93 | LOGS_PROP_FILE=file:${FULL_PATH}/conf/log4j2.properties |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 94 | ############################################# |
| 95 | TARGET_DIR=${FULL_PATH}/target |
| 96 | CONF_FILE=${FULL_PATH}/conf/attsdc.yaml |
| 97 | |
| 98 | DEBUG=true |
| 99 | MainClass=org.openecomp.sdc.ci.tests.run.StartTest |
| 100 | |
| 101 | TESTS_DIR=/opt/app/sdc/ci/resources/tests |
| 102 | COMPONENTS_DIR=/opt/app/sdc/ci/resources/components |
| 103 | |
| 104 | |
| 105 | TARGET_LOG_DIR="${TARGET_DIR}/" |
| 106 | |
| 107 | |
| 108 | ######ADD USERS################ |
| 109 | |
| 110 | BE_IP=`cat conf/attsdc.yaml | grep catalogBeHost| awk '{print $2}'` |
| 111 | |
| 112 | ADD_USERS_SCRIPT="addUsersFromList_new.sh" |
Tal Gitelman | 153a358 | 2017-07-03 20:16:55 +0300 | [diff] [blame] | 113 | USER_LIST="conf/userList.txt" |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 114 | chmod +x ${ADD_USERS_SCRIPT} |
| 115 | echo "add users..." |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 116 | ./${ADD_USERS_SCRIPT} -ip ${BE_IP} -f ${USER_LIST} |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | if [ ${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}" ; |
| 124 | fi |
| 125 | |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 126 | 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 Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 127 | |
| 128 | |
| 129 | if [ $DEBUG == "true" ] |
| 130 | then |
| 131 | $cmd |
| 132 | else |
| 133 | $cmd >> /dev/null |
| 134 | fi |
| 135 | |
| 136 | if [ ${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 Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 141 | 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 Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 142 | $cmd; |
| 143 | fi |
| 144 | fi |
| 145 | |
| 146 | status=`echo $?` |
| 147 | |
| 148 | source ExtentReport/versions.info |
| 149 | now=$(date +'%Y-%m-%d_%H_%M') |
| 150 | REPORT_NAME=${now} |
| 151 | VERSION=${osVersion} |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 152 | REPORT_START_DATE=${reportStartTime} |
| 153 | |
| 154 | if [ ${RERUN} == "true" ]; then |
| 155 | setUpdatedTimeToReport "${REPORT_START_DATE}"; |
| 156 | fi |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 157 | |
| 158 | if [[ $env == *"DEV20"* ]] |
| 159 | then |
| 160 | MYENV="Nightly" |
| 161 | else |
| 162 | MYENV="" |
| 163 | fi |
| 164 | |
| 165 | COPY_REPORT_SCRIPT="copyToStorage.sh" |
| 166 | chmod +x ${COPY_REPORT_SCRIPT} |
| 167 | echo "copy report to storage..." |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 168 | ( ./${COPY_REPORT_SCRIPT} ${REPORT_NAME} ${VERSION} ${MYENV} ) |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 169 | |
| 170 | |
| 171 | MAILING_SCRIPT_NAME="sendMail.sh" |
| 172 | chmod +x ${MAILING_SCRIPT_NAME} |
| 173 | echo "Sending report via mail..." |
| 174 | `./${MAILING_SCRIPT_NAME} ${REPORT_NAME} ${VERSION} ${MYENV}` |
| 175 | |
| 176 | |
| 177 | echo "##################################################" |
| 178 | echo "################# status is ${status} #################" |
| 179 | echo "##################################################" |
| 180 | |
| 181 | exit $status |