refactored run.sh and changed its execution mode
[domino.git] / tests / run.sh
1 #!/bin/bash -ex
2
3 #Copyright 2016 Open Platform for NFV Project, Inc. and its contributors
4 #   Licensed under the Apache License, Version 2.0 (the "License");
5 #   you may not use this file except in compliance with the License.
6 #   You may obtain a copy of the License at
7 #       http://www.apache.org/licenses/LICENSE-2.0
8 #   Unless required by applicable law or agreed to in writing, software
9 #   distributed under the License is distributed on an "AS IS" BASIS,
10 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 #   See the License for the specific language governing permissions and
12 #   limitations under the License.
13
14 CLIENT1_PORT=9091
15 CLIENT2_PORT=9092
16 CLIENT1_CLIPORT=9100
17 CLIENT2_CLIPORT=9200
18 LOGLEVEL=DEBUG
19
20 toscafile_test1=./tosca-templates/tosca_helloworld_nfv.yaml
21 test1_reffile=./tests/refdata/test1.ref
22 client1_log=./tests/logdata/client1.log
23 server_log=./tests/logdata/server.log
24
25 start_server() {
26   pgrep -f "python DominoServer.py" && return 0  
27   python DominoServer.py --log "$LOGLEVEL" > "$server_log" 2>&1 &
28 }
29
30 stop_server() {
31   pgrep -f "python DominoServer.py" || return 0  
32   kill $(pgrep -f "python DominoServer.py")
33   #cat server.log
34 }
35
36 start_client1() {
37   pgrep -f "python DominoClient.py" && return 0
38   python DominoClient.py -p $CLIENT1_PORT --cliport $CLIENT1_CLIPORT \
39         --log "$LOGLEVEL" > "$client1_log" 2>&1 &
40 }
41
42 stop_client1() {
43   pgrep -f "python DominoClient.py" || return 0
44   kill $(pgrep -f "python DominoClient.py")
45   #cat client1.log
46 }
47
48 clean_directories() {
49   if [ -f dominoserver.db ]; then
50     rm dominoserver.db
51   fi
52
53   if [ -d toscafiles ]; then
54     rm -rf toscafiles
55   fi
56 }
57
58 cleanup() {
59   set +e
60   echo "cleanup..."
61   
62   echo "Stopping Domino Client 1..."
63   stop_client1
64
65   echo "Stopping Domino Server..."
66   stop_server
67 }
68
69 echo "domino/tests/run.sh has been executed."
70
71 trap cleanup EXIT
72
73 echo "Cleaning residue files and folders from previous runs..."
74 clean_directories
75
76 echo "Launching Domino Server..."
77 start_server
78 sleep 1
79
80 echo "Launching Domino Client 1..."
81 start_client1
82 sleep 1
83
84 echo "Test Heartbeat"
85 python domino-cli.py $CLIENT1_CLIPORT heartbeat
86 sleep 1
87
88 echo "Test Subscribe API"
89 python domino-cli.py $CLIENT1_CLIPORT subscribe -t hot \
90         -l tosca.policies.Placement:properties:region:nova-1  
91 sleep 1
92 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top OVERWRITE
93 sleep 1
94 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top DELETE
95 sleep 1
96 python domino-cli.py $CLIENT1_CLIPORT subscribe \
97         -l tosca.policies.Placement:properties:region:nova-2 \
98 sleep 1
99 python domino-cli.py $CLIENT1_CLIPORT subscribe \
100         -l tosca.policies.Placement:properties:region:nova-3 \
101         --lop OVERWRITE
102 sleep 1
103 python domino-cli.py $CLIENT1_CLIPORT subscribe \
104         -l tosca.policies.Placement:properties:region:nova-3 \
105         --lop DELETE
106 sleep 1
107
108 echo "Test Publish API"
109 python domino-cli.py $CLIENT1_CLIPORT publish -t "$toscafile_test1" 
110
111 sleep 5
112
113 #echo "Stopping Domino Client 1..."
114 #stop_client1
115
116 #echo "Stopping Domino Server..."
117 #stop_server
118
119 cut -d " " -f 4- "$client1_log" > file1
120 #will use the form below to declare success or failure
121 diff -q file1 "$test1_reffile" 1>/dev/null
122 if [[ $? == "0" ]]
123 then
124   echo "SUCCESS"
125 else
126   echo "FAILURE"
127 fi
128
129
130 echo "done"