Upgrade run.sh to two-client case
[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_reffile1=./tests/refdata/test1_client1.ref
22 test1_reffile2=./tests/refdata/test1_client2.ref
23 test1_reffile3=./tests/refdata/test1_server.ref
24 client1_log=./tests/logdata/client1.log
25 client2_log=./tests/logdata/client2.log
26
27 start_server() {
28   pgrep -f "python DominoServer.py" && return 0  
29   python DominoServer.py --log "$LOGLEVEL" > "$server_log" 2>&1 &
30 }
31
32 stop_server() {
33   pgrep -f "python DominoServer.py" || return 0  
34   kill $(pgrep -f "python DominoServer.py")
35   #cat server.log
36 }
37
38 start_client1() {
39   #pgrep -f "python DominoClient.py -p $CLIENT1_PORT" && return 0
40   python DominoClient.py -p $CLIENT1_PORT --cliport $CLIENT1_CLIPORT \
41         --log "$LOGLEVEL" > "$client1_log" 2>&1 &
42 }
43
44 start_client2() {
45   #pgrep -f "python DominoClient.py -p $CLIENT2_PORT" && return 0
46   python DominoClient.py -p $CLIENT2_PORT --cliport $CLIENT2_CLIPORT \
47         --log "$LOGLEVEL" > "$client2_log" 2>&1 &
48 }
49
50 stop_clients() {
51   pgrep -f "python DominoClient.py" || return 0
52   kill $(pgrep -f "python DominoClient.py")
53   #cat client1.log
54 }
55
56 clean_directories() {
57   if [ -f dominoserver.db ]; then
58     rm dominoserver.db
59   fi
60
61   if [ -d toscafiles ]; then
62     rm -rf toscafiles
63   fi
64 }
65
66 cleanup() {
67   set +e
68   echo "cleanup..."
69   
70   echo "Stopping Domino Clients..."
71   stop_clients
72
73   echo "Stopping Domino Server..."
74   stop_server
75
76 #  if [ -f file1 ]; then
77 #    rm file1
78 #  fi
79
80 #  if [ -f file2 ]; then
81 #    rm file2
82 #  fi
83 }
84
85 echo "domino/tests/run.sh has been executed."
86
87 trap cleanup EXIT
88
89 echo "Terminating any running Domino Clients..."
90 stop_clients
91
92 echo "Terminating any running Domino Servers..."
93 stop_server
94 sleep 1
95
96 echo "Cleaning residue files and folders from previous runs..."
97 clean_directories
98 sleep 1
99
100 echo "Launching Domino Server..."
101 start_server
102 sleep 1
103
104 echo "Launching Domino Client 1..."
105 start_client1
106 sleep 1
107
108 echo "Launching Domino Client 2..."
109 start_client2
110 sleep 1
111
112 echo "Test Heartbeat"
113 python domino-cli.py $CLIENT1_CLIPORT heartbeat
114 sleep 1
115
116 echo "Test Subscribe API"
117 python domino-cli.py $CLIENT1_CLIPORT subscribe -t hot \
118         -l tosca.policies.Placement:properties:region:nova-1  
119 sleep 1
120 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top OVERWRITE
121 sleep 1
122 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top DELETE
123 sleep 1
124 python domino-cli.py $CLIENT1_CLIPORT subscribe \
125         -l tosca.policies.Placement:properties:region:nova-2
126 sleep 1
127 python domino-cli.py $CLIENT1_CLIPORT subscribe \
128         -l tosca.policies.Placement:properties:region:nova-3 \
129         --lop OVERWRITE
130 sleep 1
131 python domino-cli.py $CLIENT1_CLIPORT subscribe \
132         -l tosca.policies.Placement:properties:region:nova-3 \
133         --lop DELETE
134 sleep 1
135
136 echo "Test Publish API"
137 python domino-cli.py $CLIENT1_CLIPORT publish -t "$toscafile_test1" 
138
139 sleep 1
140 python domino-cli.py $CLIENT1_CLIPORT subscribe \
141         -l tosca.policies.Placement.Geolocation:properties:region:us-west-1
142 sleep 1
143 python domino-cli.py $CLIENT2_CLIPORT publish -t "$toscafile_test1"
144
145 #echo "Stopping Domino Client 1..."
146 #stop_client1
147
148 #echo "Stopping Domino Server..."
149 #stop_server
150
151 cut -d " " -f 4- "$client1_log" > file1
152 cut -d " " -f 4- "$client2_log" > file2
153 #will use the form below to declare success or failure
154 set +e
155
156 diff -q file1 "$test1_reffile1" 1>/dev/null
157 if [[ $? == "0" ]]
158 then
159   echo "Log1 PASS"
160 else
161   echo "Log1 FAIL"
162 fi
163
164 diff -q file2 "$test1_reffile2" 1>/dev/null
165 if [[ $? == "0" ]]
166 then
167   echo "Log2 PASS"
168 else
169   echo "Log2 FAIL"
170 fi
171
172 set -e
173
174 echo "done"
175