adding test directory
[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
22 start_server() {
23   pgrep -f "python DominoServer.py" && return 0  
24   python DominoServer.py --log "$LOGLEVEL" > server.log 2>&1 &
25 }
26
27 stop_server() {
28   pgrep -f "python DominoServer.py" || return 0  
29   kill $(pgrep -f "python DominoServer.py")
30   #cat server.log
31 }
32
33 start_client1() {
34   pgrep -f "python DominoClient.py" && return 0
35   python DominoClient.py -p $CLIENT1_PORT --cliport $CLIENT1_CLIPORT \
36         --log "$LOGLEVEL" > client1.log 2>&1 &
37 }
38
39 stop_client1() {
40   pgrep -f "python DominoClient.py" || return 0
41   kill $(pgrep -f "python DominoClient.py")
42   #cat client1.log
43 }
44
45 clean_directories() {
46   if [ -f dominoserver.db ]; then
47     rm dominoserver.db
48   fi
49
50   if [ -d toscafiles ]; then
51     rm rf toscafiles
52   fi
53 }
54
55 echo "domino/tests/run.sh has been executed."
56
57 echo "Cleaning residue files and folders from previous runs..."
58 clean_directories
59
60 echo "Launching Domino Server..."
61 start_server
62 sleep 1
63
64 echo "Launching Domino Client 1..."
65 start_client1
66 sleep 1
67
68 echo "Test Heartbeat"
69 python domino-cli.py $CLIENT1_CLIPORT heartbeat
70 sleep 1
71
72 echo "Test Subscribe API"
73 python domino-cli.py $CLIENT1_CLIPORT subscribe -t hot \
74         -l tosca.policies.Placement:properties:region:nova-1  
75 sleep 1
76 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top OVERWRITE
77 sleep 1
78 python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top DELETE
79 sleep 1
80 python domino-cli.py $CLIENT1_CLIPORT subscribe \
81         -l tosca.policies.Placement:properties:region:nova-2 \
82 sleep 1
83 python domino-cli.py $CLIENT1_CLIPORT subscribe \
84         -l tosca.policies.Placement:properties:region:nova-3 \
85         --lop OVERWRITE
86 sleep 1
87 python domino-cli.py $CLIENT1_CLIPORT subscribe \
88         -l tosca.policies.Placement:properties:region:nova-3 \
89         --lop DELETE
90 sleep 1
91
92 echo "Test Publish API"
93 python domino-cli.py $CLIENT1_CLIPORT publish -t "$toscafile_test1" 
94
95 sleep 5
96
97 echo "Stopping Domino Client 1..."
98 stop_client1
99
100 echo "Stopping Domino Server..."
101 stop_server
102
103 #will use the form below to declare success or failure
104 #diff -q file1 file2 1>/dev/null
105 #if [[ $? == "0" ]]
106 #then
107 #  echo "The same"
108 #else
109 #  echo "Not the same"
110 #fi
111
112
113 echo "done"