Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | REMOTE_DEBUG=false |
| 3 | RERUN=false |
| 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" |
| 25 | help_usage |
| 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} |
| 35 | } |
| 36 | |
| 37 | #main |
| 38 | [ $# -lt 2 ] && help_usage |
| 39 | |
| 40 | JAR_FILE=$1 |
| 41 | SUITE_FILE=$2 |
| 42 | |
| 43 | while [ $# -ne 0 ]; do |
| 44 | case $1 in |
| 45 | -r|rerun) |
| 46 | RERUN=$2 |
| 47 | isBoolean $1 ${RERUN} |
| 48 | shift 1 |
| 49 | shift 1 |
| 50 | ;; |
| 51 | -d|debug) |
| 52 | REMOTE_DEBUG=$2 |
| 53 | isBoolean $1 ${REMOTE_DEBUG} |
| 54 | shift 1 |
| 55 | shift 1 |
| 56 | ;; |
| 57 | *) |
| 58 | shift 1 |
| 59 | ;; |
| 60 | esac |
| 61 | done |
| 62 | |
| 63 | CURRENT_DIR=`pwd` |
| 64 | BASEDIR=$(dirname $0) |
| 65 | |
| 66 | if [ ${BASEDIR:0:1} = "/" ] |
| 67 | then |
| 68 | FULL_PATH=$BASEDIR |
| 69 | else |
| 70 | FULL_PATH=$CURRENT_DIR/$BASEDIR |
| 71 | fi |
| 72 | LOGS_PROP_FILE=file:${FULL_PATH}/conf/log4j.properties |
| 73 | ############################################# |
| 74 | TARGET_DIR=${FULL_PATH}/target |
| 75 | CONF_FILE=${FULL_PATH}/conf/attsdc.yaml |
| 76 | |
| 77 | DEBUG=true |
| 78 | MainClass=org.openecomp.sdc.ci.tests.run.StartTest |
| 79 | |
| 80 | TESTS_DIR=/opt/app/sdc/ci/resources/tests |
| 81 | COMPONENTS_DIR=/opt/app/sdc/ci/resources/components |
| 82 | |
| 83 | |
| 84 | TARGET_LOG_DIR="${TARGET_DIR}/" |
| 85 | |
| 86 | ######ADD USERS################ |
| 87 | |
| 88 | BE_IP=`cat conf/attsdc.yaml | grep catalogBeHost| awk '{print $2}'` |
| 89 | |
| 90 | ADD_USERS_SCRIPT="addUsersFromList_new.sh" |
Tal Gitelman | 153a358 | 2017-07-03 20:16:55 +0300 | [diff] [blame] | 91 | USER_LIST="conf/userList.txt" |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 92 | chmod +x ${ADD_USERS_SCRIPT} |
| 93 | echo "add users..." |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 94 | ./${ADD_USERS_SCRIPT} -ip ${BE_IP} -f ${USER_LIST} |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 95 | |
| 96 | |
| 97 | |
| 98 | if [ ${REMOTE_DEBUG} == "true" ]; then |
| 99 | echo "Debug mode, Listen on port $debug_port"; |
| 100 | JAVA_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debug_port}" ; |
| 101 | fi |
| 102 | |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 103 | 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] | 104 | |
| 105 | |
| 106 | if [ $DEBUG == "true" ] |
| 107 | then |
| 108 | $cmd |
| 109 | else |
| 110 | $cmd >> /dev/null |
| 111 | fi |
| 112 | |
| 113 | if [ ${RERUN} == "true" ]; then |
| 114 | if [ -f ${TARGET_DIR}/${fileName} ]; then |
| 115 | echo "Prepare" ${TARGET_DIR}/${fileName} "file to rerun all failed tests ..."; |
| 116 | prepareFailedXmlFile ${TARGET_DIR}/${fileName} $SUITE_FILE; |
| 117 | SUITE_FILE=${fileName}; |
Michael Lando | 5b59349 | 2018-07-29 16:13:45 +0300 | [diff] [blame] | 118 | 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] | 119 | $cmd; |
| 120 | fi |
| 121 | fi |
| 122 | |
| 123 | status=`echo $?` |
| 124 | |
| 125 | source ExtentReport/versions.info |
| 126 | now=$(date +'%Y-%m-%d_%H_%M') |
| 127 | REPORT_NAME=${now} |
| 128 | VERSION=${osVersion} |
| 129 | |
| 130 | if [[ $env == *"DEV20"* ]] |
| 131 | then |
| 132 | MYENV="Nightly" |
| 133 | else |
| 134 | MYENV="" |
| 135 | fi |
| 136 | |
| 137 | COPY_REPORT_SCRIPT="copyToStorage.sh" |
| 138 | chmod +x ${COPY_REPORT_SCRIPT} |
| 139 | echo "copy report to storage..." |
Michael Lando | a544510 | 2018-03-04 14:53:33 +0200 | [diff] [blame] | 140 | ( ./${COPY_REPORT_SCRIPT} ${REPORT_NAME} ${VERSION} ${MYENV} ) |
Michael Lando | b3d4898 | 2017-06-11 14:22:02 +0300 | [diff] [blame] | 141 | |
| 142 | |
| 143 | MAILING_SCRIPT_NAME="sendMail.sh" |
| 144 | chmod +x ${MAILING_SCRIPT_NAME} |
| 145 | echo "Sending report via mail..." |
| 146 | `./${MAILING_SCRIPT_NAME} ${REPORT_NAME} ${VERSION} ${MYENV}` |
| 147 | |
| 148 | |
| 149 | echo "##################################################" |
| 150 | echo "################# status is ${status} #################" |
| 151 | echo "##################################################" |
| 152 | |
| 153 | exit $status |