Build sanity docker execute automation
[sdc.git] / sdc-os-chef / sdc-sanity / chef-repo / cookbooks / sdc-sanity / files / default / startTest.sh
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/sdc.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
91 if [ ${REMOTE_DEBUG} == "true" ]; then
92     echo "Debug mode, Listen on port $debug_port";
93     JAVA_OPTION="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${debug_port}" ;
94 fi
95
96 cmd="java $JAVA_OPTION -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 &"
97
98
99 if [ $DEBUG == "true" ]
100 then
101         $cmd
102 else
103         $cmd >> /dev/null
104 fi
105
106 if [ ${RERUN} == "true" ]; then
107     if [ -f ${TARGET_DIR}/${fileName} ]; then
108         echo "Prepare" ${TARGET_DIR}/${fileName} "file to rerun all failed tests ...";
109         prepareFailedXmlFile ${TARGET_DIR}/${fileName} $SUITE_FILE;
110         SUITE_FILE=${fileName};
111         cmd="java $JAVA_OPTION -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 &"
112         $cmd;
113     fi
114 fi
115
116 status=`echo $?`
117
118 source ExtentReport/versions.info
119 now=$(date +'%Y-%m-%d_%H_%M')
120 REPORT_NAME=${now}
121 VERSION=${osVersion}
122
123
124
125 echo "##################################################"
126 echo "################# status is ${status} #################"
127 echo "##################################################"
128
129 exit $status