-
Notifications
You must be signed in to change notification settings - Fork 6
/
csi-functions.rc
339 lines (312 loc) · 9.35 KB
/
csi-functions.rc
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# using this library requires:
# http://docs.aws.amazon.com/AWSEC2/latest/CommandLineReference/ec2-cli-get-set-up.html
#set -o nounset # Treat unset variables as an error
if [ -r ~/platform-continuous-integration/csi.rc ];then
. ~/platform-continuous-integration/csi.rc
else
echo "where is csi.rc? :("
fi
start_instances()
{
IMAGE=$1
INSTS_AMOUNT=$2
SECURITY_GROUP=$3
START=`date +%s.%N`
INSTID=`ec2-run-instances $IMAGE -n $INSTS_AMOUNT -k $PEM_CRT -g $SECURITY_GROUP --availability-zone $AV_ZONE | grep INSTANCE |awk -F " " '{print $2}'`
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "clone instance from image $IMAGE" $RC "instance ID: $INSTID" "`bc <<< $END-$START`"
if [ -n "$INSTID" ];then
echo $INSTID
return 0
fi
if [ "$RC" -ne 0 ];then
report "clone instance from image $IMAGE" $RC "instance clonning FAILED " "`bc <<< $END-$START`"
return 1
fi
}
term_instance()
{
INSTID=$1
return ec2-terminate-instances $INSTID
}
get_instance_ip()
{
INSTID=$1
IP_ADDR=`ec2-describe-instances $INSTID | grep -o -P "\d+\.\d+\.\d+\.\d+" | grep -v '^10\.'`
if [ -n "$IP_ADDR" ];then
echo $IP_ADDR
return 0
else
return 1
fi
}
get_instance_status()
{
INSTID=$1
if ec2-describe-instance-status $INSTID|grep -q "ok\s*ok\s*active";then
return 0
fi
return 1
}
install_release_file()
{
ssh -t -l$EC2_USR $IP -i$PEM_CRT_PATH $SSH_QUIET_OPTS "sudo rpm -Uhv $RELEASE_RPM_URL"
}
upgrade_kalt()
{
IP=$1
RELEASE_RPM_URL=$2
install_release_file
ssh -t -l$EC2_USR $IP -i$PEM_CRT_PATH $SSH_QUIET_OPTS 'sudo yum -y update "*kaltura*"'
}
selinux_set_permissive()
{
ssh -t -l$EC2_USR $IP -i$PEM_CRT_PATH $SSH_QUIET_OPTS "sudo setenforce permissive"
}
install_kalt_allin1()
{
RELEASE_RPM_URL=$1
KALT_IMAGE=$2
INSTS_AMOUNT=$3
install_mysql_db 1
#NFS_IP=`install_nfs_server 1`
NFS_IP=75.101.174.186
ID=`start_instances $KALT_IMAGE $INSTS_AMOUNT $SECURITY_GROUP`
if [ $? -ne 0 ];then
exit 1
fi
sleep 10
IP=`get_instance_ip $ID`
if [ -z "$IP" ];then return 1;fi
STATUS=0
ANS_FILE="allin1_${IP}.ans"
echo "My file of ans is here: $ANS_FILE" >/tmp/logger
START=`date +%s.%N`
while ! get_instance_status $ID ;do
echo "Waiting for instance to init.."
sleep 45
done
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "Kaltura allin1 instance init" $RC "instance ID: $ID" "`bc <<< $END-$START`"
sleep 2000
echo "Machine up and running.. SSHing."
selinux_set_permissive
install_release_file
START=`date +%s.%N`
ssh -t -l$EC2_USR $IP -i$PEM_CRT_PATH $SSH_QUIET_OPTS "sudo yum -y install $META_PACKAGE_NAME"
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "Kaltura RPMs download and install" $RC "yum -y install $META_PACKAGE_NAME" "`bc <<< $END-$START`"
echo "cat $CSI_HOME/all1in.template.ans >$ANS_FILE" >/tmp/logger
cat $CSI_HOME/all1in.template.ans >$ANS_FILE
if [ ! -r $ANS_FILE ];then
report "$ANS_FILE wasn't created" 1 "Bail:(" 0
fi
REG_HOST=`get_inst_reg_hostname $ID`
sed -i "s#@HOSTNAME@#$REG_HOST#g" $ANS_FILE
echo "cat $MYSQL_ANS_FILE >> $ANS_FILE" >>/tmp/logger
cat $MYSQL_ANS_FILE >> $ANS_FILE
cp $ANS_FILE /tmp/jess.ans
scp -i$PEM_CRT_PATH $SSH_QUIET_OPTS $ANS_FILE $EC2_USR@$IP:/tmp
START=`date +%s.%N`
setup_nfs_mount $IP $NFS_IP
ssh -t -l$EC2_USR $IP -i$PEM_CRT_PATH $SSH_QUIET_OPTS "echo "NO" | sudo /opt/kaltura/bin/kaltura-config-all.sh /tmp/$ANS_FILE"
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "Postinst configuration" $RC "kaltura-config-all.sh /tmp/$ANS_FILE" "`bc <<< $END-$START`"
sleep 20
echo "ROLE=allin1" >> $ANS_FILE
if [ $RC -ne 0 ];then
echo "I failed"
exit 11
fi
run_sanity_tests $ANS_FILE
}
install_kalt_cluster()
{
install_nfs_server
install_mysql_db
install_kalt_front
$BASE_DIR/bin/kaltura-db-config.sh $DB1_HOST $SUPER_USER $SUPER_USER_PASSWD $DB1_PORT $SPHINX_HOST
install_kalt_sphinx
install_kalt_batch
$BASE_DIR/bin/kaltura-dwh-config.sh "$ANSFILE"
}
install_nfs_server()
{
#ANS_FILE=$CSI_HOME/mysql.template.ans
INSTS_AMOUNT=$1
NFS_ID=`start_instances $NFS_IMG $INSTS_AMOUNT $SECURITY_GROUP`
sleep 10
NFS_IP=`get_instance_ip $NFS_ID`
if [ -z "$NFS_IP" ];then return 1;fi
STATUS=0
START=`date +%s.%N`
while ! get_instance_status $NFS_ID ;do
echo "Waiting for instance $NFS_ID to init.."
sleep 45
done
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "NFS server instance init" $RC "instance ID: $NFS_ID" "`bc <<< $END-$START`"
echo "Checking $NFS_IP on port 2049.."
nc -z $NFS_IP 2049 -w2
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "Connection to $NFS_IP on port 2049 [tcp/nfs]" $RC "nc -z $NFS_IP 2049 -w2" "`bc <<< $END-$START`"
echo "Checking $NFS_IP on port 2049.."
START=`date +%s.%N`
nc -z -u $NFS_IP 2049 -w2
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "Connection to $NFS_IP on port 2049 [udp/nfs]" $RC "nc -z $NFS_IP 2049 -w2" "`bc <<< $END-$START`"
echo $NFS_IP
}
install_mysql_db()
{
ANS_FILE=$CSI_HOME/mysql.template.ans
MY_SQL_INSTID=$MYSQL_IMG
INSTS_AMOUNT=$1
MYSQL_ID=`start_instances $MY_SQL_INSTID $INSTS_AMOUNT $SECURITY_GROUP`
sleep 10
MYSQL_IP=`get_instance_ip $MYSQL_ID`
if [ -z "$MYSQL_IP" ];then return 1;fi
STATUS=0
START=`date +%s.%N`
while ! get_instance_status $MYSQL_ID ;do
echo "Waiting for instance $MYSQL_ID to init.."
sleep 45
done
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "MySQL instance init" $RC "instance ID: $MYSQL_ID" "`bc <<< $END-$START`"
echo "Machine up and running... testing MySQL connectivity."
echo "select version();" | mysql -h$MYSQL_IP -u$MYSQL_SUPER_USER -p$MYSQL_SUPER_USER_PASSWD -P$MYSQL_PORT -N
if [ $? -ne 0 ];then
cat << EOF
Failed to run:
# mysql -h$MYSQL_IP -u$MYSQL_SUPER_USER -p$MYSQL_SUPER_USER_PASSWD -P$MYSQL_PORT."
Check your settings."
EOF
return 1
fi
sed "s#@MYSQL_HOST@#$MYSQL_IP#g" $ANS_FILE >$ANS_FILE.$MYSQL_IP
sed "s#@KALT_DB_PASS@#$KALT_DB_PASS#g" -i $ANS_FILE.$MYSQL_IP
sed "s#@MYSQL_PORT@#$MYSQL_PORT#g" -i $ANS_FILE.$MYSQL_IP
sed "s#@MYSQL_SUPER_USER_PASSWD@#$MYSQL_SUPER_USER_PASSWD#g" -i $ANS_FILE.$MYSQL_IP
sed "s#@MYSQL_SUPER_USER@#$MYSQL_SUPER_USER#g" -i $ANS_FILE.$MYSQL_IP
export MYSQL_ANS_FILE=$ANS_FILE.$MYSQL_IP
}
check_img_status()
{
IMGID=$1
while ! ec2-describe-images $IMGID | grep available;do
echo "Wait for it.."
sleep 20
done
}
get_inst_reg_hostname()
{
INSTANCE_ID=$1
echo `ec2-describe-instances $INSTANCE_ID|grep INSTANCE|awk -F " " '{print $4}'`
}
get_minus2_secret()
{
API_IP=$1
. $CSI_HOME/allin1.$API_IP.ans
ADMIN_PARTNER_SECRET=`echo "select admin_secret from partner where id=-2" | mysql -N -h $DB1_HOST -p$DB1_PASS $DB1_NAME -u$DB1_USER`
sed "s#@ADMIN_PARTNER_SECRET@#$ADMIN_PARTNER_SECRET#g" $CSI_HOME/sanity_tests/utils.template.rc > $CSI_HOME/sanity_tests/utils.rc
sed "s#@SERVICE_URL@#$SERVICE_URL#g" -i $CSI_HOME/sanity_tests/utils.rc
}
report()
{
TNAME=$1
RC=$2
TOUT=$3
TIME=$4
echo "insert into csi_log values(NULL,\"$TNAME\",`date +%s`,\"$BASE_VERSION\",\"$TOUT\",$RC,$TIME);"|sqlite3 $CSI_DB
}
create_csv()
{
LOW_R=$1
MAX_R=$2
echo '"ID","Test name","Insert time","Version","Command","RC","Exec time in seconds"' > "/tmp/ks_${BASE_VERSION}_`date +%d_%m_%Y`.csv"
echo "select * from csi_log where create_time > $LOW_R and create_time< $MAX_R;"| sqlite3 -csv $CSI_DB >> "/tmp/ks_${BASE_VERSION}_`date +%d_%m_%Y`.csv"
echo "/tmp/ks_${BASE_VERSION}_`date +%d_%m_%Y`.csv"
}
run_sanity_tests()
{
ANSFILE=$1
. $ANSFILE
if [ "$ROLE" = "allin1" ];then
for D in $ALL_DAEMONS; do
START=`date +%s.%N`
if check_daemon_status $KALTURA_VIRTUAL_HOST_NAME $D;then
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "check_daemon_status" 0 "Daemon $D is running" "`bc <<< $END-$START`"
else
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "check_daemon_status" 1 "Daemon $D is NOT running" "`bc <<< $END-$START`"
fi
START=`date +%s.%N`
if check_daemon_init_status $KALTURA_VIRTUAL_HOST_NAME $D;then
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "check_daemon_init_status" 0 "Daemon $D configured to run on init." "`bc <<< $END-$START`"
else
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "check_daemon_init_status" 1 "Daemon $D is NOT configured to run on init." "`bc <<< $END-$START`"
fi
done
fi
ADMIN_PARTNER_SECRET=`echo "select admin_secret from partner where id=-2" | mysql -N -h $DB1_HOST -p$DB1_PASS $DB1_NAME -u$DB1_USER`
START=`date +%s.%N`
report "MySQL instance init" $RC "instance ID: $MYSQL_ID" "$TIME"
PARTNER_ID=`php $CSI_HOME/sanity_tests/create_partner.php $ADMIN_PARTNER_SECRET [email protected] testingpasswd $SERVICE_URL`
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "Create Partner" $RC "New PID is $PARTNER_ID" "`bc <<< $END-$START`"
START=`date +%s.%N`
PARTNER_SECRET=`echo "select secret from partner where id=$PARTNER_ID" | mysql -N -h $DB1_HOST -p$DB1_PASS $DB1_NAME -u$DB1_USER`
OUTP=`php $CSI_HOME/sanity_tests/upload_test.php $SERVICE_URL $PARTNER_ID $PARTNER_SECRET sanity_tests/sources/cat.mp4`
RC=$?
END=`date +%s.%N`
TOTAL_T=`bc <<< $TIME`
report "Upload content" $RC "$OUTP" "`bc <<< $END-$START`"
}
get_base_version()
{
echo $VER
}
check_daemon_init_status()
{
DAEMON=$2
MACHINE=$1
if ssh -t -l$EC2_USR $MACHINE -i$PEM_CRT_PATH $SSH_QUIET_OPTS "sudo chkconfig $DAEMON";then
return 0
fi
return 1
}
check_daemon_status()
{
DAEMON=$2
MACHINE=$1
if ssh -t -l$EC2_USR $MACHINE -i$PEM_CRT_PATH $SSH_QUIET_OPTS "sudo service $DAEMON status";then
return 0
fi
return 1
}