-
Notifications
You must be signed in to change notification settings - Fork 1
/
run_tests.sh
executable file
·269 lines (249 loc) · 7.95 KB
/
run_tests.sh
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
#!/bin/bash
set -e
assertFileExists ()
{
if [ -f "$1" ]; then
echo "PASS: Existing file $1"
else
echo "FAIL: Missing file $1"
exit 1;
fi
}
assertNotFileExists ()
{
if [ -f "$1" ]; then
echo "FAIL: Existing file $1"
exit 1;
else
echo "PASS: Not existing file $1"
fi
}
assertFileEqual ()
{
ret=0
diff "$1" "$2" > /dev/null || ret=$?
if [ $ret -eq 0 ]; then
echo "PASS: Files $1 $2 are equals"
else
diff "$1" "$2"
echo "FAIL: Files $1 $2 are not equals"
exit 1;
fi
}
assertFtpFileExists ()
{
ret=0
ncftpget -c -u ${FTP_USERNAME} -p ${FTP_PASSWORD} -P ${FTP_PORT} ${FTP_HOST} $1 > /dev/null || ret=$?
if [ $ret -eq 0 ]; then
echo "PASS: Existing ftp file $1"
else
echo "FAIL: Missing ftp file $1"
exit 1;
fi
}
assertFtpNotFileExists ()
{
ret=0
ncftpget -c -u ${FTP_USERNAME} -p ${FTP_PASSWORD} -P ${FTP_PORT} ${FTP_HOST} $1 > /dev/null || ret=$?
if [ $ret -eq 0 ]; then
echo "FAIL: Existing ftp file $1"
exit 1;
else
echo "PASS: Not existing ftp file $1"
fi
}
assertSftpFileExists ()
{
ret=0
sftp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /id_rsa ${SFTP_USERNAME}@${SFTP_HOST}:$1 || ret=$?
if [ $ret -eq 0 ]; then
echo "PASS: Existing sftp file $1"
else
echo "FAIL: Missing sftp file $1"
exit 1;
fi
}
assertSftpNotFileExists ()
{
ret=0
sftp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /id_rsa ${SFTP_USERNAME}@${SFTP_HOST}:$1 || ret=$?
if [ $ret -eq 0 ]; then
echo "FAIL: Existing sftp file $1"
exit 1;
else
echo "PASS: Not existing sftp file $1"
fi
}
assertSwiftFileExists ()
{
ret=0
swift -A http://swift:5000/v2.0/ --os-username $OS_USERNAME --os-password $OS_PASSWORD --os-project-name $OS_PROJECT_NAME --os-region-name "$OS_REGION_NAME" stat test_backups $1 || ret=$?
if [ $ret -eq 0 ]; then
echo "PASS: Existing swift file $1"
else
echo "FAIL: Missing swift file $1"
exit 1;
fi
}
assertSwiftNotFileExists ()
{
ret=0
swift -A http://swift:5000/v2.0/ --os-username $OS_USERNAME --os-password $OS_PASSWORD --os-project-name $OS_PROJECT_NAME --os-region-name "$OS_REGION_NAME" stat test_backups $1 || ret=$?
if [ $ret -eq 0 ]; then
echo "FAIL: Existing swift file $1"
exit 1;
else
echo "PASS: Not existing swift file $1"
fi
}
# Export env vars for backup script
echo ">Export env vars for backup script"
export BACKUP_SOURCE=A
export MYSQL_HOST=B
export MYSQL_PORT=C
export MYSQL_USERNAME=D
export MYSQL_PASSWORD=E
export FTP_HOST=F
export FTP_PORT=G
export FTP_PATH=H
export FTP_USERNAME=I
export FTP_PASSWORD=J
export SFTP_HOST=K
export SFTP_PORT=L
export SFTP_PATH=M
export SFTP_USERNAME=N
export SFTP_PASSWORD=O
export SFTP_PRIVKEY=P
export OS_AUTH_URL=Q
export OS_USERNAME=R
export OS_PASSWORD=S
export OS_PROJECT_NAME=T
export OS_REGION_NAME=U
export OS_DELETE_AFTER=V
export OS_CONTAINER=W
export OS_PATH=X
./exportenv.sh
assertFileEqual "env.sh" "env.sh.snapshot"
unset BACKUP_SOURCE
unset MYSQL_HOST MYSQL_PORT MYSQL_USERNAME MYSQL_PASSWORD
unset FTP_HOST FTP_PORT FTP_USERNAME FTP_PATH FTP_PASSWORD
unset SFTP_HOST SFTP_PORT SFTP_PATH SFTP_USERNAME SFTP_PASSWORD SFTP_PRIVKEY
unset OS_AUTH_URL OS_USERNAME OS_PASSWORD OS_PROJECT_NAME OS_REGION_NAME OS_DELETE_AFTER OS_CONTAINER OS_PATH
# Create some stuff to backup
echo "Preparing test files... "
mkdir /backups/dir1
mkdir /backups/dir2
dd if=/dev/urandom of=/backups/dir1/file1a bs=1M count=1
dd if=/dev/urandom of=/backups/dir1/file1b bs=1M count=2
dd if=/dev/urandom of=/backups/dir2/file2a bs=1M count=1
dd if=/dev/urandom of=/backups/dir2/file2b bs=1M count=2
echo "Preparing databases... "
mysql -h mysql -u testuser -ps3cr3t testdb < /randomdata.sql
# Prepare backup env
export BACKUP_SOURCE=/backups
export BACKUP_PREFIX=testbackup
export BACKUP_TMP="/tmp/$BACKUP_PREFIX"
rm -Rf $BACKUP_TMP
mkdir $BACKUP_TMP
# Dump databases
echo ">Dump MySQL databases"
export MYSQL_HOST=mysql
export MYSQL_USERNAME=root
export MYSQL_PASSWORD=s3cr3t
assertNotFileExists "${BACKUP_SOURCE}/db-mysql/testdb.sql"
/dodump.sh
assertFileExists "${BACKUP_SOURCE}/db-mysql/testdb.sql"
# Create archives
echo ">Create archives"
assertNotFileExists "${BACKUP_TMP}/dir1.tar.gz"
assertNotFileExists "${BACKUP_TMP}/dir2.tar.gz"
assertNotFileExists "${BACKUP_TMP}/db-mysql.tar.gz"
/docompress.sh
assertFileExists "${BACKUP_TMP}/dir1.tar.gz"
assertFileExists "${BACKUP_TMP}/dir2.tar.gz"
assertFileExists "${BACKUP_TMP}/db-mysql.tar.gz"
# Do nothing
echo ">Do nothing"
/dosend.sh
# Send to FTP
echo ">Send to FTP"
export FTP_HOST=ftp
export FTP_PORT=29999
export FTP_PATH=data
export FTP_USERNAME=testuser
export FTP_PASSWORD=testpasswd
assertFtpNotFileExists "data/testbackup/dir1.tar.gz"
assertFtpNotFileExists "data/testbackup/dir2.tar.gz"
/dosend.sh
assertFtpFileExists "data/testbackup/dir1.tar.gz"
assertFtpFileExists "data/testbackup/dir2.tar.gz"
unset FTP_HOST FTP_PORT FTP_PATH FTP_USERNAME FTP_PASSWORD
# Send to SFTP (password)
echo ">Send to SFTP (password)"
export SFTP_HOST=sftp
export SFTP_USERNAME=sftpuser
export SFTP_PASSWORD=testpasswd
export SFTP_PATH=incoming
assertSftpNotFileExists "incoming/testbackup/dir1.tar.gz"
assertSftpNotFileExists "incoming/testbackup/dir2.tar.gz"
/dosend.sh
assertSftpFileExists "incoming/testbackup/dir1.tar.gz"
assertSftpFileExists "incoming/testbackup/dir2.tar.gz"
sftp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /id_rsa $SFTP_USERNAME@$SFTP_HOST <<EOF
rm incoming/testbackup/*
rmdir incoming/testbackup
exit
EOF
unset SFTP_HOST SFTP_PORT SFTP_PATH SFTP_USERNAME SFTP_PASSWORD
# Send to SFTP (key)
echo ">Send to SFTP (key)"
export SFTP_HOST=sftp
export SFTP_USERNAME=sftpuser
export SFTP_PRIVKEY=/id_rsa
export SFTP_PATH=incoming
assertSftpNotFileExists "incoming/testbackup/dir1.tar.gz"
assertSftpNotFileExists "incoming/testbackup/dir2.tar.gz"
/dosend.sh
assertSftpFileExists "incoming/testbackup/dir1.tar.gz"
assertSftpFileExists "incoming/testbackup/dir2.tar.gz"
sftp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /id_rsa $SFTP_USERNAME@$SFTP_HOST <<EOF
rm incoming/testbackup/*
rmdir incoming/testbackup
exit
EOF
unset SFTP_HOST SFTP_PORT SFTP_PATH SFTP_USERNAME SFTP_PASSWORD
# Send to OpenStack Swift
echo ">Send to OpenStack Swift"
export OS_AUTH_URL=http://swift:5000/v2.0/
export OS_USERNAME=admin
export OS_PASSWORD=s3cr3t
export OS_PROJECT_NAME=admin
export OS_REGION_NAME=RegionOne
export OS_CONTAINER=test_backups
assertSwiftNotFileExists "testbackup/dir1.tar.gz"
assertSwiftNotFileExists "testbackup/dir2.tar.gz"
/dosend.sh
assertSwiftFileExists "testbackup/dir1.tar.gz"
assertSwiftFileExists "testbackup/dir2.tar.gz"
swift -A http://swift:5000/v2.0/ --os-username $OS_USERNAME --os-password $OS_PASSWORD --os-project-name $OS_PROJECT_NAME --os-region-name "$OS_REGION_NAME" delete $OS_CONTAINER # delete container
unset OS_AUTH_URL OS_USERNAME OS_PASSWORD OS_REGION_NAME OS_PROJECT_NAME OS_CONTAINER
# Send to OpenStack Swift
echo ">Send to OpenStack Swift (With expiration)"
export OS_AUTH_URL=http://swift:5000/v2.0/
export OS_USERNAME=admin
export OS_PASSWORD=s3cr3t
export OS_PROJECT_NAME=admin
export OS_REGION_NAME=RegionOne
export OS_CONTAINER=test_backups
export OS_DELETE_AFTER=5
assertSwiftNotFileExists "testbackup/dir1.tar.gz"
assertSwiftNotFileExists "testbackup/dir2.tar.gz"
/dosend.sh
assertSwiftFileExists "testbackup/dir1.tar.gz"
assertSwiftFileExists "testbackup/dir2.tar.gz"
echo "Waiting 10s file expiration... "
sleep 10
assertSwiftNotFileExists "testbackup/dir1.tar.gz"
assertSwiftNotFileExists "testbackup/dir2.tar.gz"
swift -A http://swift:5000/v2.0/ --os-username $OS_USERNAME --os-password $OS_PASSWORD --os-project-name $OS_PROJECT_NAME --os-region-name "$OS_REGION_NAME" delete $OS_CONTAINER || true # delete container
unset OS_AUTH_URL OS_USERNAME OS_PASSWORD OS_REGION_NAME OS_DELETE_AFTER OS_PROJECT_NAME OS_CONTAINER