updated test script and folders
[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 echo "domino/tests/run.sh has been executed."
59
60 echo "Cleaning residue files and folders from previous runs..."
61 clean_directories
62
63 echo "Launching Domino Server..."
64 start_server
65 sleep 1
66
67 echo "Launching Domino Client 1..."
68 start_client1
69 sleep 1
70
71 echo "Test Heartbeat"
72 python domino-cli.py $CLIENT1_CLIPORT heartbeat
73 sleep 1
74
75 echo "Test Subscribe API"
76 python domino-cli.py $CLIENT1_CLIPORT subscribe -t hot \
77         -l tosca.policies.Placement:properties:region:nova-1  
78 sleep 1
79 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top OVERWRITE
80 sleep 1
81 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top DELETE
82 sleep 1
83 python domino-cli.py $CLIENT1_CLIPORT subscribe \
84         -l tosca.policies.Placement:properties:region:nova-2 \
85 sleep 1
86 python domino-cli.py $CLIENT1_CLIPORT subscribe \
87         -l tosca.policies.Placement:properties:region:nova-3 \
88         --lop OVERWRITE
89 sleep 1
90 python domino-cli.py $CLIENT1_CLIPORT subscribe \
91         -l tosca.policies.Placement:properties:region:nova-3 \
92         --lop DELETE
93 sleep 1
94
95 echo "Test Publish API"
96 python domino-cli.py $CLIENT1_CLIPORT publish -t "$toscafile_test1" 
97
98 sleep 5
99
100 echo "Stopping Domino Client 1..."
101 stop_client1
102
103 echo "Stopping Domino Server..."
104 stop_server
105
106 cut -d " " -f 4- "$client1_log" > file1
107 #will use the form below to declare success or failure
108 diff -q file1 "$test1_reffile" 1>/dev/null
109 if [[ $? == "0" ]]
110 then
111   echo "SUCCESS"
112 else
113   echo "FAILURE"
114 fi
115
116
117 echo "done"