3 # Copyright 2016-2017 Huawei Technologies Co., Ltd.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 function memory_details(){
18 #General memory details
19 echo "> top -bn1 | head -3"
27 #Memory details per Docker
32 echo "> docker stats --no-stream"
33 docker stats --no-stream
36 function fibonacci_number(){
47 for i in `eval echo {1..$Num}`;do
57 function wait_curl_driver(){
59 #CURL_COMMAND - the URL on which the curl command will be executed
60 #GREP_STRING - Desired string to be found inside the body response of the
61 # previous curl command
62 #EXCLUDE_STRING - If the filtered string (GREP_STRING) must not exist in
63 # the body response of the curl
64 #WAIT_MESSAGE - the message to be displayed for logging purpose. (optional)
65 #REPEAT_NUMBER - the maximum number of tries before abandoning the curl
66 # command (optional, by default = 15)
67 #MAX_TIME - Maximum time allowed for the transfer (in seconds)
68 #STATUS_CODE - A HTTP status code desired to be found by getting the link
69 # /!\ IMPORTANT NOTICE: the usage of STATUS_CODE option turn GREP_STRING/
70 # /!\ EXCLUDE_STRING/and the MAX_TIME options becomes obsolete with no
71 # /!\ execution impact
72 #MEMORY_USAGE - If Parameters exists shows the memory usage after curl
79 if [[ $parameters == *"WAIT_MESSAGE"* ]]
81 wait_message=`echo $parameters | sed -e "s/.*WAIT_MESSAGE=//g"`
82 wait_message=`echo $wait_message | sed -e "s/ .*//g"`
84 wait_message="wait ..."
88 if [[ $parameters == *"REPEAT_NUMBER"* ]]
90 repeat_max=`echo $parameters | sed -e "s/.*REPEAT_NUMBER=//g"`
91 repeat_max=`echo $repeat_max | sed -e "s/ .*//g"`
95 if [[ $parameters == *"CURL_COMMAND"* ]]
97 curl_command=`echo $parameters | sed -e 's/.*CURL_COMMAND=//g'`
98 curl_command=`echo $curl_command | sed -e 's/ .*//g'`
100 echo "-Curl is empty-" # Or no parameterseter passed.
105 if [[ $parameters == *"MAX_TIME"* ]]
107 max_time=`echo $parameters | sed -e 's/.*MAX_TIME=//g'`
108 max_time=`echo $max_time | sed -e 's/ .*//g'`
115 if [[ $parameters == *"EXCLUDE_STRING"* ]]
122 if [[ $parameters == *"STATUS_CODE"* ]]
124 status_code=`echo $parameters | sed -e 's/.*STATUS_CODE=//g'`
125 status_code=`echo $status_code | sed -e 's/ .*//g'`
128 for i in `eval echo {1..$repeat_max}`; do
129 response_code=`curl -o /dev/null --silent --head --write-out '%{http_code}' $curl_command`
131 if [[ ! -z $status_code ]] ; then
132 if [ "$status_code" -eq "$response_code" ]
134 echo "SUCCESS:Actual Status code <$response_code> match the expected code <$status_code>"
137 echo "WARNING:Expected <$status_code> but Actual <$response_code>"
141 if [[ $parameters == *"GREP_STRING"* ]]
143 grep_command=`echo $parameters | sed -e 's/.*GREP_STRING=//g'`
144 grep_command=`echo $grep_command | sed -e 's/ REPEAT_NUMBER=.*//g' | sed -e 's/ CURL_COMMAND=.*//g' | sed -e 's/ WAIT_MESSAGE=.*//g' | sed -e 's/ MAX_TIME=.*//g' | sed -e 's/ EXCLUDE_STRING.*//g'`
146 echo "-Grep_command is empty-" # Or no parameters passed.
150 str=`curl -sS -m$max_time $curl_command | grep "$grep_command"`
152 if [[ ! -z $exclude_string ]]
156 echo "SUCCESS: body response does not contains '$grep_command'";
159 echo "Fall_Short: Body response still contains '$grep_command'"
164 echo "SUCCESS: body response contains '$grep_command'";
167 echo "Fall_Short: Element '$grep_command' not found yet # "$i""
171 if [ "$?" = "7" ]; then
172 echo 'Connection refused or can not connect to server/proxy';
176 seconds2sleep=`fibonacci_number $i`
178 echo "Iteration::$i out of $repeat_max "
179 echo "Quiet time for $seconds2sleep seconds ..."
182 # if waiting for a long time, log system load
189 if [[ $parameters == *"MEMORY_USAGE"* ]]
191 echo "==========================MEMORY USAGE=================================="
193 echo "========================================================================"
198 function run_simulator ()
201 run_simulator_docker $1
204 function run_robottestlib ()
206 #Start the robottest REST library if not started
207 if ! pgrep -f robottest > /dev/null
209 #Download the latest robottest jar
210 wget -q -O ${SCRIPTS}/integration/mockserver/org.openo.robottest.jar "https://nexus.open-o.org/service/local/artifact/maven/redirect?r=snapshots&g=org.openo.integration&a=org.openo.robottest&e=jar&v=LATEST"
211 chmod +x ${SCRIPTS}/integration/mockserver/org.openo.robottest.jar
212 eval `java -cp ${SCRIPTS}/integration/mockserver/org.openo.robottest.jar org.openo.robot.test.robottest.MyRemoteLibrary` &
216 function run_simulator_docker ()
218 #Start the simulator docker if not started
219 SIMULATOR_IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' simulator`
220 if [[ -z $SIMULATOR_IP ]]
222 echo "Starting simulator docker..."
224 if [[ -z $SIMULATOR_JSON ]]
226 SIMULATOR_JSON=main.json
228 docker run -d -i -t --name simulator -e SIMULATOR_JSON=$SIMULATOR_JSON -p 18009:18009 -p 18008:18008 openoint/simulate-test-docker
229 SIMULATOR_IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' simulator`
232 #Set the simulator IP in robot variables
233 ROBOT_VARIABLES=${ROBOT_VARIABLES}" -v SIMULATOR_IP:${SIMULATOR_IP} -v SCRIPTS:${SCRIPTS}"
234 echo ${ROBOT_VARIABLES}
237 function get_docker_compose_service ()
240 local compose_file=${2:-docker-compose.yml}
242 echo $(docker-compose --file ./${compose_file} ps | grep $service | cut -d " " -f1 )
245 function bypass_ip_adress ()
249 if [[ $no_proxy && $no_proxy != *$ip_address* ]]; then
250 export no_proxy=$no_proxy,$ip_address
254 function wait_for_service_init ()
258 for delay in {1..50}; do
259 curl -sS ${service_url} && break
260 echo "$delay - Waiting for $service_url..."