aboutsummaryrefslogtreecommitdiffstats
path: root/tests/run.sh
blob: 7da8f36614ed17b84b1e8140bb58af5c9fff3b45 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/bin/bash -ex

#Copyright 2016 Open Platform for NFV Project, Inc. and its contributors
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#       http://www.apache.org/licenses/LICENSE-2.0
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

CLIENT1_PORT=9091
CLIENT2_PORT=9092
CLIENT1_CLIPORT=9100
CLIENT2_CLIPORT=9200
LOGLEVEL=DEBUG

toscafile_test1=./tosca-templates/tosca_helloworld_nfv.yaml
test1_reffile1=./tests/refdata/test1_client1.ref
test1_reffile2=./tests/refdata/test1_client2.ref
client1_log=./tests/logdata/client1.log
client2_log=./tests/logdata/client2.log
server_log=./tests/logdata/server.log


start_server() {
  pgrep -f "python DominoServer.py" && return 0
  python DominoServer.py --log "$LOGLEVEL" > "$server_log" 2>&1 &
}

stop_server() {
  pgrep -f "python DominoServer.py" || return 0
  kill $(pgrep -f "python DominoServer.py")
  #cat server.log
}

start_client1() {
  #pgrep -f "python DominoClient.py -p $CLIENT1_PORT" && return 0
  python DominoClient.py -p $CLIENT1_PORT --cliport $CLIENT1_CLIPORT \
	--log "$LOGLEVEL" > "$client1_log" 2>&1 &
}

start_client2() {
  #pgrep -f "python DominoClient.py -p $CLIENT2_PORT" && return 0
  python DominoClient.py -p $CLIENT2_PORT --cliport $CLIENT2_CLIPORT \
        --log "$LOGLEVEL" > "$client2_log" 2>&1 &
}

stop_clients() {
  pgrep -f "python DominoClient.py" || return 0
  kill $(pgrep -f "python DominoClient.py")
  #cat client1.log
}

clean_directories() {
  if [ -f dominoserver.db ]; then
    rm dominoserver.db
  fi

  if [ -d toscafiles ]; then
    rm -rf toscafiles
  fi
}

cleanup() {
  set +e
  echo "cleanup..."
  
  echo "Stopping Domino Clients..."
  stop_clients

  echo "Stopping Domino Server..."
  stop_server

  if [ -f file1 ]; then
    rm file1
  fi

  if [ -f file2 ]; then
    rm file2
  fi
}

echo "domino/tests/run.sh has been executed."

trap cleanup EXIT

echo "Terminating any running Domino Clients..."
stop_clients

echo "Terminating any running Domino Servers..."
stop_server
sleep 1

echo "Cleaning residue files and folders from previous runs..."
clean_directories
sleep 1

echo "Launching Domino Server..."
start_server
sleep 1

echo "Launching Domino Client 1..."
start_client1
sleep 1

echo "Launching Domino Client 2..."
start_client2
sleep 1

echo "Test Heartbeat"
python domino-cli.py $CLIENT1_CLIPORT heartbeat
sleep 1

echo "Test Subscribe API"
python domino-cli.py $CLIENT1_CLIPORT subscribe -t hot \
	-l tosca.policies.Placement:properties:region:nova-1  
sleep 1
python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top OVERWRITE
sleep 1
python domino-cli.py $CLIENT1_CLIPORT subscribe -t dummy1,dummy2 --top DELETE
sleep 1
python domino-cli.py $CLIENT1_CLIPORT subscribe \
        -l tosca.policies.Placement:properties:region:nova-2
sleep 1
python domino-cli.py $CLIENT1_CLIPORT subscribe \
	-l tosca.policies.Placement:properties:region:nova-3 \
	--lop OVERWRITE
sleep 1
python domino-cli.py $CLIENT1_CLIPORT subscribe \
        -l tosca.policies.Placement:properties:region:nova-3 \
	--lop DELETE
sleep 1

echo "Test Publish API"
python domino-cli.py $CLIENT1_CLIPORT publish -t "$toscafile_test1" 

sleep 1
python domino-cli.py $CLIENT1_CLIPORT subscribe \
        -l tosca.policies.Placement.Geolocation:properties:region:us-west-1
sleep 1
python domino-cli.py $CLIENT2_CLIPORT publish -t "$toscafile_test1"
sleep 1
TUID=$(python domino-cli.py $CLIENT2_CLIPORT list-tuids | cut -c3-34)
echo $TUID
sleep 1
python domino-cli.py $CLIENT2_CLIPORT publish -t "$toscafile_test1" -k "$TUID"

#echo "Stopping Domino Client 1..."
#stop_client1

#echo "Stopping Domino Server..."
#stop_server

cut -d " " -f 4- "$client1_log" > file1
cut -d " " -f 4- "$client2_log" > file2
#will use the form below to declare success or failure
set +e

diff -q file1 "$test1_reffile1" 1>/dev/null
if [[ $? == "0" ]]
then
  echo "Log1 PASS"
else
  echo "Log1 FAIL"
fi

diff -q file2 "$test1_reffile2" 1>/dev/null
if [[ $? == "0" ]]
then
  echo "Log2 PASS"
else
  echo "Log2 FAIL"
fi

set -e

echo "done"
exit 0