return FAILED status when no file is generated for distribution
[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   if [ -f file1 ]; then
69     rm file1
70   fi
71 }
72
73 echo "domino/tests/run.sh has been executed."
74
75 trap cleanup EXIT
76
77 echo "Cleaning residue files and folders from previous runs..."
78 clean_directories
79
80 echo "Launching Domino Server..."
81 start_server
82 sleep 1
83
84 echo "Launching Domino Client 1..."
85 start_client1
86 sleep 1
87
88 echo "Test Heartbeat"
89 python domino-cli.py $CLIENT1_CLIPORT heartbeat
90 sleep 1
91
92 echo "Test Subscribe API"
93 python domino-cli.py $CLIENT1_CLIPORT subscribe -t hot \
94         -l tosca.policies.Placement:properties:region:nova-1  
95 sleep 1
96 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top OVERWRITE
97 sleep 1
98 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top DELETE
99 sleep 1
100 python domino-cli.py $CLIENT1_CLIPORT subscribe \
101         -l tosca.policies.Placement:properties:region:nova-2 \
102 sleep 1
103 python domino-cli.py $CLIENT1_CLIPORT subscribe \
104         -l tosca.policies.Placement:properties:region:nova-3 \
105         --lop OVERWRITE
106 sleep 1
107 python domino-cli.py $CLIENT1_CLIPORT subscribe \
108         -l tosca.policies.Placement:properties:region:nova-3 \
109         --lop DELETE
110 sleep 1
111
112 echo "Test Publish API"
113 python domino-cli.py $CLIENT1_CLIPORT publish -t "$toscafile_test1" 
114
115 sleep 1
116
117 #echo "Stopping Domino Client 1..."
118 #stop_client1
119
120 #echo "Stopping Domino Server..."
121 #stop_server
122
123 cut -d " " -f 4- "$client1_log" > file1
124 #will use the form below to declare success or failure
125 set +e
126 diff -q file1 "$test1_reffile" 1>/dev/null
127 if [[ $? == "0" ]]
128 then
129   echo "SUCCESS"
130 else
131   echo "FAILURE"
132 fi
133 set -e
134
135 echo "done"
136