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