Merge "Sync to 1.16 k8"
[it/test.git] / ric_robot_suite / runTags.sh
1 #!/bin/bash
2
3 ################################################################################
4 #   Copyright (c) 2019 AT&T Intellectual Property.                             #
5 #   Copyright (c) 2019 Nokia.                                                  #
6 #                                                                              #
7 #   Licensed under the Apache License, Version 2.0 (the "License");            #
8 #   you may not use this file except in compliance with the License.           #
9 #   You may obtain a copy of the License at                                    #
10 #                                                                              #
11 #       http://www.apache.org/licenses/LICENSE-2.0                             #
12 #                                                                              #
13 #   Unless required by applicable law or agreed to in writing, software        #
14 #   distributed under the License is distributed on an "AS IS" BASIS,          #
15 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
16 #   See the License for the specific language governing permissions and        #
17 #   limitations under the License.                                             #
18 ################################################################################
19
20
21
22
23 # Set the defaults
24 DEFAULT_LOG_LEVEL="TRACE" # Available levels: TRACE, DEBUG, INFO (default), WARN, NONE (no logging)
25 DEFAULT_RES="1280x1024x24"
26 DEFAULT_DISPLAY=":99"
27 DEFAULT_ROBOT_TEST="-i health"
28 INSTALL_NAME="RIC"
29 DEFAULT_OUTPUT_FOLDER=./
30
31 # To mitigate the chromedriver hanging issue
32 export DBUS_SESSION_BUS_ADDRESS=/dev/null
33
34 # Use default if none specified as env var
35 LOG_LEVEL=${LOG_LEVEL:-$DEFAULT_LOG_LEVEL}
36 RES=${RES:-$DEFAULT_RES}
37 DISPLAY=${DISPLAY:-$DEFAULT_DISPLAY}
38
39 # OUTPUT_FOLDER env variable will be overridden by -d command line argument.
40 OUTPUT_FOLDER=${OUTPUT_FOLDER:-$DEFAULT_OUTPUT_FOLDER}
41
42 VARIABLEFILES=
43 LISTENERS=
44 VARIABLES="--removekeywords name:keystone_interface.*"
45
46 ## Single argument, it is an include tag
47 if [ $# -eq 1 ]; then
48     ROBOT_TAGS="-i $1"
49 fi
50
51 ##
52 ## if more than 1 tag is supplied, the must be provided with -i or -e
53 ##
54 while [ $# -gt 1 ]
55 do
56         key="$1"
57
58         case $key in
59         -i|--include)
60         ROBOT_TAGS="${ROBOT_TAGS} -i $2"
61         shift
62         ;;
63         -e|--exclude)
64         ROBOT_TAGS="${ROBOT_TAGS} -e $2"
65         shift
66         ;;
67         -d|--outputdir)
68         OUTPUT_FOLDER=$2
69         shift
70         ;;
71                 --display)
72         DISPLAY=:$2
73         shift
74         ;;
75                 --listener)
76         LISTENERS="${LISTENER} --listener $2 "
77         shift
78         ;;
79                 -V)
80         VARIABLEFILES="${VARIABLEFILES} -V $2 "
81         shift
82         ;;
83                 -v)
84         VARIABLES="${VARIABLES} -v $2 "
85         shift
86         ;;
87         esac
88         shift
89 done
90
91 if [ "${ROBOT_TAGS}" = "" ];then
92     ROBOT_TAGS=$DEFAULT_ROBOT_TEST
93 fi
94
95 # Start Xvfb
96 echo -e "Starting Xvfb on display ${DISPLAY} with res ${RES}"
97 Xvfb ${DISPLAY} -ac -screen 0 ${RES} +extension RANDR &
98 XVFBPID=$!
99 # Get pid of this spawned process to make sure we kill the correct process later
100
101 export DISPLAY=${DISPLAY}
102
103 # Execute tests
104 echo -e "Executing robot tests at log level ${LOG_LEVEL}"
105
106 ROBOT_LIBS=./robot/library:./robot/library/ricutils:./robot/library/eteutils:./robot/library/heatbridge
107
108 cd /var/opt/${INSTALL_NAME}
109 python -m robot.run -L ${LOG_LEVEL} -d ${OUTPUT_FOLDER} ${VARIABLEFILES} ${VARIABLES} ${LISTENERS} -P ${ROBOT_LIBS} ${ROBOT_TAGS} /var/opt/${INSTALL_NAME}/robot/testsuites/
110 RET_CODE=$?
111
112 # Stop Xvfb we started earlier
113 # select it from list of possible Xvfb pids running because
114 # a) there may be multiple Xvfbs running and
115 # b) the XVFBPID may not be the correct if the start did not actually work (unlikely and that may be)
116 PIDS=$(pgrep Xvfb)
117 for P in $PIDS
118 do
119         if [ $P == $XVFBPID ];then
120                 kill -9 $P
121         fi
122 done
123
124 exit $RET_CODE