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