summaryrefslogtreecommitdiffstats
path: root/test/csit
diff options
context:
space:
mode:
Diffstat (limited to 'test/csit')
-rwxr-xr-xtest/csit/plans/integration/functionality1/setup.sh34
-rwxr-xr-xtest/csit/plans/integration/functionality1/teardown.sh20
-rw-r--r--test/csit/plans/integration/functionality1/testplan.txt4
-rwxr-xr-xtest/csit/scripts/build-image.sh22
-rwxr-xr-xtest/csit/scripts/common_functions.sh235
-rwxr-xr-xtest/csit/scripts/get-instance-ip.sh17
-rwxr-xr-xtest/csit/scripts/integration/mock-hello.sh31
-rwxr-xr-xtest/csit/scripts/integration/script1.sh17
-rwxr-xr-xtest/csit/scripts/kill-instance.sh24
-rwxr-xr-xtest/csit/scripts/run-instance.sh22
-rw-r--r--test/csit/tests/integration/suite1/__init__.robot2
-rw-r--r--test/csit/tests/integration/suite1/test1.robot30
-rw-r--r--test/csit/tests/integration/suite2/__init__.robot2
-rw-r--r--test/csit/tests/integration/suite2/test1.robot35
14 files changed, 495 insertions, 0 deletions
diff --git a/test/csit/plans/integration/functionality1/setup.sh b/test/csit/plans/integration/functionality1/setup.sh
new file mode 100755
index 000000000..c18f62207
--- /dev/null
+++ b/test/csit/plans/integration/functionality1/setup.sh
@@ -0,0 +1,34 @@
+#!/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.
+#
+# Place the scripts in run order:
+source ${WORKSPACE}/test/csit/scripts/integration/script1.sh
+
+docker run --name i-mock -d jamesdbloom/mockserver
+MOCK_IP=`get-instance-ip.sh i-mock`
+
+# Wait for initialization
+for i in {1..10}; do
+ curl -sS ${MOCK_IP}:1080 && break
+ echo sleep $i
+ sleep $i
+done
+
+${WORKSPACE}/test/csit/scripts/integration/mock-hello.sh ${MOCK_IP}
+
+# Pass any variables required by Robot test suites in ROBOT_VARIABLES
+ROBOT_VARIABLES="-v MOCK_IP:${MOCK_IP}"
+
diff --git a/test/csit/plans/integration/functionality1/teardown.sh b/test/csit/plans/integration/functionality1/teardown.sh
new file mode 100755
index 000000000..acf2d0976
--- /dev/null
+++ b/test/csit/plans/integration/functionality1/teardown.sh
@@ -0,0 +1,20 @@
+#!/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.
+#
+
+kill-instance.sh i-mock
+
+
diff --git a/test/csit/plans/integration/functionality1/testplan.txt b/test/csit/plans/integration/functionality1/testplan.txt
new file mode 100644
index 000000000..7a29ca53d
--- /dev/null
+++ b/test/csit/plans/integration/functionality1/testplan.txt
@@ -0,0 +1,4 @@
+# Test suites are relative paths under [integration.git]/test/csit/tests/.
+# Place the suites in run order.
+integration/suite1
+integration/suite2
diff --git a/test/csit/scripts/build-image.sh b/test/csit/scripts/build-image.sh
new file mode 100755
index 000000000..87aac6ea6
--- /dev/null
+++ b/test/csit/scripts/build-image.sh
@@ -0,0 +1,22 @@
+#!/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.
+#
+# $1 docker image path under ${WORKSPACE}/test/csit/docker/
+
+# only rebuild if not already existing
+if [ "$(docker images -q $1 2> /dev/null)" == "" ]; then
+ docker build -t $1 $WORKSPACE/test/csit/docker/$1
+fi
diff --git a/test/csit/scripts/common_functions.sh b/test/csit/scripts/common_functions.sh
new file mode 100755
index 000000000..69856dab3
--- /dev/null
+++ b/test/csit/scripts/common_functions.sh
@@ -0,0 +1,235 @@
+#!/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}
+}
diff --git a/test/csit/scripts/get-instance-ip.sh b/test/csit/scripts/get-instance-ip.sh
new file mode 100755
index 000000000..c4ca82cfb
--- /dev/null
+++ b/test/csit/scripts/get-instance-ip.sh
@@ -0,0 +1,17 @@
+#!/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.
+#
+docker inspect --format '{{ .NetworkSettings.IPAddress }}' $1
diff --git a/test/csit/scripts/integration/mock-hello.sh b/test/csit/scripts/integration/mock-hello.sh
new file mode 100755
index 000000000..ac9551722
--- /dev/null
+++ b/test/csit/scripts/integration/mock-hello.sh
@@ -0,0 +1,31 @@
+#!/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.
+#
+# $1 ip address of the mock server
+
+curl -v -X PUT -d @- http://$1:1080/expectation <<EOF
+{
+ "httpRequest": {
+ "method": "GET",
+ "path": "/hello"
+ },
+ "httpResponse": {
+ "body": "Hello world!",
+ "statusCode": 200
+ }
+}
+EOF
+
diff --git a/test/csit/scripts/integration/script1.sh b/test/csit/scripts/integration/script1.sh
new file mode 100755
index 000000000..05d57e840
--- /dev/null
+++ b/test/csit/scripts/integration/script1.sh
@@ -0,0 +1,17 @@
+#!/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.
+#
+echo "This is ${WORKSPACE}/test/csit/scripts/integration/script1.sh"
diff --git a/test/csit/scripts/kill-instance.sh b/test/csit/scripts/kill-instance.sh
new file mode 100755
index 000000000..525f96e4f
--- /dev/null
+++ b/test/csit/scripts/kill-instance.sh
@@ -0,0 +1,24 @@
+#!/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.
+#
+# $1 nickname for the instance
+
+mkdir -p $WORKSPACE/archives
+
+docker logs $1 >> $WORKSPACE/archives/$1.log
+docker kill $1
+docker rm $1
+
diff --git a/test/csit/scripts/run-instance.sh b/test/csit/scripts/run-instance.sh
new file mode 100755
index 000000000..e68ecb3e0
--- /dev/null
+++ b/test/csit/scripts/run-instance.sh
@@ -0,0 +1,22 @@
+#!/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.
+#
+# $1 docker image path under ${WORKSPACE}/test/csit/docker/
+# $2 nickname for the instance
+# $3 docker run options, e.g. variables
+echo $@
+
+docker run --name $2 $3 -d $1
diff --git a/test/csit/tests/integration/suite1/__init__.robot b/test/csit/tests/integration/suite1/__init__.robot
new file mode 100644
index 000000000..f310a65b7
--- /dev/null
+++ b/test/csit/tests/integration/suite1/__init__.robot
@@ -0,0 +1,2 @@
+*** Settings ***
+Documentation Integration - Suite 1
diff --git a/test/csit/tests/integration/suite1/test1.robot b/test/csit/tests/integration/suite1/test1.robot
new file mode 100644
index 000000000..10e685213
--- /dev/null
+++ b/test/csit/tests/integration/suite1/test1.robot
@@ -0,0 +1,30 @@
+*** Settings ***
+Library OperatingSystem
+Library RequestsLibrary
+
+*** Variables ***
+${MESSAGE} Hello, world!
+
+*** Test Cases ***
+String Equality Test
+ Should Be Equal ${MESSAGE} Hello, world!
+
+Dir Test
+ [Documentation] Check if /tmp exists
+ Log ${MESSAGE}
+ CheckDir /tmp
+
+Url Test
+ [Documentation] Check if google.com can be reached
+ CheckUrl http://www.google.com
+
+*** Keywords ***
+CheckDir
+ [Arguments] ${path}
+ Directory Should Exist ${path}
+
+CheckUrl
+ [Arguments] ${url}
+ Create Session session ${url}
+ ${resp}= Get Request session /
+ Should Be Equal As Integers ${resp.status_code} 200
diff --git a/test/csit/tests/integration/suite2/__init__.robot b/test/csit/tests/integration/suite2/__init__.robot
new file mode 100644
index 000000000..f04a3af26
--- /dev/null
+++ b/test/csit/tests/integration/suite2/__init__.robot
@@ -0,0 +1,2 @@
+*** Settings ***
+Documentation Integration - Suite 2
diff --git a/test/csit/tests/integration/suite2/test1.robot b/test/csit/tests/integration/suite2/test1.robot
new file mode 100644
index 000000000..fd841861b
--- /dev/null
+++ b/test/csit/tests/integration/suite2/test1.robot
@@ -0,0 +1,35 @@
+*** Settings ***
+Library OperatingSystem
+Library RequestsLibrary
+
+*** Variables ***
+${MESSAGE} Hello, world!
+
+*** Test Cases ***
+String Equality Test
+ Should Be Equal ${MESSAGE} Hello, world!
+
+Dir Test
+ [Documentation] Check if /tmp exists
+ Log ${MESSAGE}
+ CheckDir /tmp
+
+Url Test
+ [Documentation] Check if www.open-o.org can be reached
+ Create Session openo http://www.open-o.org
+ CheckUrl openo /
+
+Mock Hello Server Test
+ [Documentation] Check /hello endpoint
+ Create Session hello http://${MOCK_IP}:1080
+ CheckUrl hello /hello
+
+*** Keywords ***
+CheckDir
+ [Arguments] ${path}
+ Directory Should Exist ${path}
+
+CheckUrl
+ [Arguments] ${session} ${path}
+ ${resp}= Get Request ${session} ${path}
+ Should Be Equal As Integers ${resp.status_code} 200