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