blob: 684c418417e918d4f5b0e9a227444fa19f4ef08c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cp#!/bin/bash
# Copyright 2016-2017 Huawei Technologies Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
function memory_details(){
#General memory details
echo "> top -bn1 | head -3"
top -bn1 | head -3
echo
echo "> free -h"
free -h
echo
#Memory details per Docker
echo "> docker ps"
docker ps
echo
echo "> docker stats --no-stream"
docker stats --no-stream
echo
}
function fibonacci_number(){
set +x
if [ $1 -le 1 ]
then
echo "1"
elif [ $1 -le 10 ]
then
Num=$1
f1=0
f2=1
fn=-1
for i in `eval echo {1..$Num}`;do
fn=$((f1+f2))
f1=$f2
f2=$fn
done
echo $fn
else
echo "30"
fi
}
function wait_curl_driver(){
#Parameters:
#CURL_COMMAND - the URL on which the curl command will be executed
#GREP_STRING - Desired string to be found inside the body response of the
# previous curl command
#EXCLUDE_STRING - If the filtered string (GREP_STRING) must not exist in
# the body response of the curl
#WAIT_MESSAGE - the message to be displayed for logging purpose. (optional)
#REPEAT_NUMBER - the maximum number of tries before abandoning the curl
# command (optional, by default = 15)
#MAX_TIME - Maximum time allowed for the transfer (in seconds)
#STATUS_CODE - A HTTP status code desired to be found by getting the link
# /!\ IMPORTANT NOTICE: the usage of STATUS_CODE option turn GREP_STRING/
# /!\ EXCLUDE_STRING/and the MAX_TIME options becomes obsolete with no
# /!\ execution impact
#MEMORY_USAGE - If Parameters exists shows the memory usage after curl
# execution(s)
repeat_max=15
parameters="$@"
#WAIT_MESSAGE
if [[ $parameters == *"WAIT_MESSAGE"* ]]
then
wait_message=`echo $parameters | sed -e "s/.*WAIT_MESSAGE=//g"`
wait_message=`echo $wait_message | sed -e "s/ .*//g"`
else
wait_message="wait ..."
fi
#REPEAT_NUMBER
if [[ $parameters == *"REPEAT_NUMBER"* ]]
then
repeat_max=`echo $parameters | sed -e "s/.*REPEAT_NUMBER=//g"`
repeat_max=`echo $repeat_max | sed -e "s/ .*//g"`
fi
#CURL_COMMAND
if [[ $parameters == *"CURL_COMMAND"* ]]
then
curl_command=`echo $parameters | sed -e 's/.*CURL_COMMAND=//g'`
curl_command=`echo $curl_command | sed -e 's/ .*//g'`
else
echo "-Curl is empty-" # Or no parameterseter passed.
return 0
fi
#MAX_TIME
if [[ $parameters == *"MAX_TIME"* ]]
then
max_time=`echo $parameters | sed -e 's/.*MAX_TIME=//g'`
max_time=`echo $max_time | sed -e 's/ .*//g'`
else
max_time="5"
fi
exclude_string=""
#EXCLUDE_STRING
if [[ $parameters == *"EXCLUDE_STRING"* ]]
then
exclude_string="-v"
fi
status_code=""
#STATUS_CODE
if [[ $parameters == *"STATUS_CODE"* ]]
then
status_code=`echo $parameters | sed -e 's/.*STATUS_CODE=//g'`
status_code=`echo $status_code | sed -e 's/ .*//g'`
fi
for i in `eval echo {1..$repeat_max}`; do
response_code=`curl -o /dev/null --silent --head --write-out '%{http_code}' $curl_command`
echo "..."
if [[ ! -z $status_code ]] ; then
if [ "$status_code" -eq "$response_code" ]
then
echo "SUCCESS:Actual Status code <$response_code> match the expected code <$status_code>"
return 0
else
echo "WARNING:Expected <$status_code> but Actual <$response_code>"
fi
else
#GREP_STRING
if [[ $parameters == *"GREP_STRING"* ]]
then
grep_command=`echo $parameters | sed -e 's/.*GREP_STRING=//g'`
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'`
else
echo "-Grep_command is empty-" # Or no parameters passed.
return 0
fi
str=`curl -sS -m$max_time $curl_command | grep "$grep_command"`
echo "BODY::$str"
if [[ ! -z $exclude_string ]]
then
if [[ -z $str ]]
then
echo "SUCCESS: body response does not contains '$grep_command'";
break;
else
echo "Fall_Short: Body response still contains '$grep_command'"
fi
else
if [[ ! -z $str ]]
then
echo "SUCCESS: body response contains '$grep_command'";
break;
else
echo "Fall_Short: Element '$grep_command' not found yet # "$i""
fi
fi
if [ "$?" = "7" ]; then
echo 'Connection refused or can not connect to server/proxy';
str=''
fi
fi
seconds2sleep=`fibonacci_number $i`
echo $wait_message
echo "Iteration::$i out of $repeat_max "
echo "Quiet time for $seconds2sleep seconds ..."
sleep $seconds2sleep
# if waiting for a long time, log system load
if [ $i -gt 45 ]
then
memory_details
fi
done
#MEMORY_USAGE
if [[ $parameters == *"MEMORY_USAGE"* ]]
then
echo "==========================MEMORY USAGE=================================="
memory_details
echo "========================================================================"
fi
return 0
}
function run_simulator ()
{
run_robottestlib
run_simulator_docker $1
}
function run_robottestlib ()
{
#Start the robottest REST library if not started
if ! pgrep -f robottest > /dev/null
then
#Download the latest robottest jar
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"
chmod +x ${SCRIPTS}/integration/mockserver/org.openo.robottest.jar
eval `java -cp ${SCRIPTS}/integration/mockserver/org.openo.robottest.jar org.openo.robot.test.robottest.MyRemoteLibrary` &
fi
}
function run_simulator_docker ()
{
#Start the simulator docker if not started
SIMULATOR_IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' simulator`
if [[ -z $SIMULATOR_IP ]]
then
echo "Starting simulator docker..."
SIMULATOR_JSON=$1
if [[ -z $SIMULATOR_JSON ]]
then
SIMULATOR_JSON=main.json
fi
docker run -d -i -t --name simulator -e SIMULATOR_JSON=$SIMULATOR_JSON -p 18009:18009 -p 18008:18008 openoint/simulate-test-docker
SIMULATOR_IP=`docker inspect --format '{{ .NetworkSettings.IPAddress }}' simulator`
fi
#Set the simulator IP in robot variables
ROBOT_VARIABLES=${ROBOT_VARIABLES}" -v SIMULATOR_IP:${SIMULATOR_IP} -v SCRIPTS:${SCRIPTS}"
echo ${ROBOT_VARIABLES}
}
function get_docker_compose_service ()
{
local service=$1
local compose_file=${2:-docker-compose.yml}
echo $(docker-compose --file ./${compose_file} ps | grep $service | cut -d " " -f1 )
}
function bypass_ip_adress ()
{
local ip_address=$1
if [[ $no_proxy && $no_proxy != *$ip_address* ]]; then
export no_proxy=$no_proxy,$ip_address
fi
}
function wait_for_service_init ()
{
local service_url=$1
for delay in {1..50}; do
curl -sS ${service_url} && break
echo "$delay - Waiting for $service_url..."
sleep $delay
done
}
|