-
Notifications
You must be signed in to change notification settings - Fork 4
/
operator-test.sh
executable file
·687 lines (626 loc) · 31 KB
/
operator-test.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
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
#!/bin/bash
NOCOLOR='\033[0m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
LIGHTBLUE='\033[1;34m'
MAGENTA='\033[1;35m'
POSTGRES_VERSION=$(cat test-resources/Dockerfile.postgres | grep FROM | awk '{print $2}')
MONGODB_VERSION=$(cat test-resources/Dockerfile.mongo | grep FROM | awk '{print $2}')
KIND_VER=v1.19.11
#KIND_VER=v1.20.7
#KIND_VER=v1.21.1
#KIND_VER=v1.22.0
# or get the latest tagged version of a specific k8s version of kind
#KIND_VER=$(curl -s https://hub.docker.com/v2/repositories/kindest/node/tags | jq -r '.results | .[].name' | grep 'v1.17' | sort -Vr | head -1)
KIND_NAME=chart-testing
OPERATOR_IMAGE=amazeeio/dbaas-operator:test-tag
CHECK_TIMEOUT=10
check_operator_log () {
echo -e "${GREEN}========= FULL OPERATOR LOG =========${NOCOLOR}"
kubectl logs $(kubectl get pods -n dbaas-operator-system --no-headers | awk '{print $1}') -c manager -n dbaas-operator-system
}
postgres_start_check () {
until $(docker-compose exec -T local-dbaas-psql-provider psql -h localhost -p 5432 -U postgres postgres -c "SELECT datname FROM pg_database" | grep -q "postgres")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Database provider not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for database provider startup reached"
exit 1
fi
done
}
mariadb_start_check () {
until $(docker-compose exec -T mysql mysql --host=local-dbaas-mariadb-provider --port=3306 -uroot -e 'show databases;' | grep -q "information_schema")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Database provider not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for database provider startup reached"
exit 1
fi
done
until $(docker-compose exec -T mysql mysql --host=local-dbaas-provider-mariadb-multi --port=3306 -uroot -e 'show databases;' | grep -q "information_schema")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Database provider not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for database provider startup reached"
exit 1
fi
done
}
mongodb_start_check () {
until $(docker-compose exec -T local-dbaas-mongo-provider mongo mongodb://root:[email protected]:27017/ --quiet --eval 'db.getMongo().getDBNames().forEach(function(db){print(db)})' | grep -q admin)
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Database provider not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for database provider startup reached"
exit 1
fi
done
}
mongodb_tls_start_check () {
until $(docker-compose exec -T local-dbaas-mongo-tls-provider mongo --tls --tlsAllowInvalidCertificates --tlsAllowInvalidHostnames mongodb://root:[email protected]:27018/ --quiet --eval 'db.getMongo().getDBNames().forEach(function(db){print(db)})' | grep -q admin)
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Database provider not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for database provider startup reached"
exit 1
fi
done
}
tear_down () {
echo -e "${GREEN}============= TEAR DOWN =============${NOCOLOR}"
kind delete cluster --name ${KIND_NAME}
docker-compose down
}
start_up () {
echo -e "${GREEN}================ BEGIN ================${NOCOLOR}"
echo -e "${GREEN}==>${NOCOLOR} Bring up local provider"
docker-compose up -d
CHECK_COUNTER=1
echo -e "${GREEN}==> Ensure mariadb database providers are running${NOCOLOR}"
mariadb_start_check
CHECK_COUNTER=1
echo -e "${LIGHTBLUE}==> Ensure postgres database provider is running${NOCOLOR}"
postgres_start_check
CHECK_COUNTER=1
echo -e "${MAGENTA}==> Ensure mongodb database provider is running${NOCOLOR}"
mongodb_start_check
CHECK_COUNTER=1
echo -e "${MAGENTA}==> Ensure mongodb tls database provider is running${NOCOLOR}"
mongodb_tls_start_check
}
build_deploy_operator () {
echo -e "${GREEN}==>${GREEN}BusyBox: ${NOCOLOR} Add a busybox pod"
kubectl apply -f test-resources/busybox.yaml
echo -e "${GREEN}==>${NOCOLOR} Build and deploy operator"
make docker-build IMG=${OPERATOR_IMAGE}
kind load docker-image ${OPERATOR_IMAGE} --name ${KIND_NAME}
make deploy IMG=${OPERATOR_IMAGE}
CHECK_COUNTER=1
echo -e "${GREEN}==>${NOCOLOR} Ensure operator is running"
until $(kubectl get pods -n dbaas-operator-system --no-headers | grep -q "Running")
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Operator not running yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for operator startup reached"
check_operator_log
tear_down
exit 1
fi
done
}
check_services () {
PRIMARY=$(kubectl get $2/$1 -o json | jq -r '.spec.consumer.services.primary')
echo "====> Check primary service ${PRIMARY}"
kubectl get service/${PRIMARY} -o yaml
}
check_services_replicas () {
REPLICAS=$(kubectl get $2/$1 -o json | jq -r '.spec.consumer.services.replicas | .[]')
for REPLICA in ${REPLICAS}
do
echo "====> Check replica service ${REPLICA}"
kubectl get service/${REPLICA} -o yaml
done
}
add_delete_consumer_mariadb_fail () {
echo -e "${GREEN}====>${NOCOLOR} Add a consumer $1 $2"
kubectl apply -f $1
CHECK_COUNTER=1
until [ $(kubectl get mariadbconsumer/$2 -o json | jq -re '.metadata.annotations."dbaas.amazee.io/failed"?') == "true" ]
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Consumer not failed yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for consumer not failed reached."
check_operator_log
tear_down
exit 1
fi
done
echo -e "${GREEN}====>${NOCOLOR} Get MariaDBConsumer"
kubectl get mariadbconsumer/$2 -o yaml
}
add_delete_consumer_mariadb () {
echo -e "${GREEN}====>${NOCOLOR} Add a consumer $1 $2"
kubectl apply -f $1
CHECK_COUNTER=1
until kubectl get mariadbconsumer/$2 -o json | jq -e '.spec.consumer.database?'
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Database not created yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for database creation reached"
check_operator_log
tear_down
exit 1
fi
done
echo -e "${GREEN}====>${NOCOLOR} Get MariaDBConsumer"
kubectl get mariadbconsumer/$2 -o yaml
DB_NAME=$(kubectl get mariadbconsumer/$2 -o json | jq -r '.spec.consumer.database')
echo -e "${GREEN}==>${NOCOLOR} Check if the operator creates the database"
DB_EXISTS=$(docker-compose exec -T mysql mysql --host=${3:-local-dbaas-mariadb-provider} --port=3306 -uroot -qfsBNe "SELECT schema_name FROM information_schema.schemata WHERE schema_name = '${DB_NAME}';")
if [[ ! -z "${DB_EXISTS}" ]]
then
echo "database ${DB_NAME} exists"
else
echo "database ${DB_NAME} does not exist"
check_operator_log
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Check services"
check_services $2 mariadbconsumer
check_services_replicas $2 mariadbconsumer
echo -e "${GREEN}==>${NOCOLOR} Delete the consumer"
timeout 60 kubectl delete -f $1
if [ $? -ne 0 ]
then
echo "timed out waiting to delete consumer, check the logs to see why"
check_operator_log
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Check if the operator deletes the database"
DB_EXISTS=$(docker-compose exec -T mysql mysql --host=${3:-local-dbaas-mariadb-provider} --port=3306 -uroot -qfsBNe "SELECT schema_name FROM information_schema.schemata WHERE schema_name = '${DB_NAME}';")
if [[ ! -z "${DB_EXISTS}" ]]
then
echo "database ${DB_NAME} exists"
check_operator_log
tear_down
exit 1
else
echo "database ${DB_NAME} does not exist"
fi
}
add_delete_consumer_psql () {
echo -e "${GREEN}====>${NOCOLOR} Add a consumer"
kubectl apply -f $1
CHECK_COUNTER=1
until kubectl get postgresqlconsumer/$2 -o json | jq -e '.spec.consumer.database?'
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Database not created yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for database creation reached"
check_operator_log
tear_down
exit 1
fi
done
echo -e "${GREEN}====>${NOCOLOR} Get PostgreSQLConsumer"
kubectl get postgresqlconsumer/$2 -o yaml
DB_NAME=$(kubectl get postgresqlconsumer/$2 -o json | jq -r '.spec.consumer.database')
echo -e "${GREEN}==>${NOCOLOR} Check if the operator creates the database"
DB_EXISTS=$(docker-compose exec -T local-dbaas-psql-provider psql -h localhost -p 5432 -U postgres postgres --no-align --tuples-only -c "SELECT datname FROM pg_database;" | grep -q "${DB_NAME}")
if [[ -z "${DB_EXISTS}" ]]
then
echo "database ${DB_NAME} exists"
else
echo "database ${DB_NAME} does not exist"
check_operator_log
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Check services"
check_services $2 postgresqlconsumer
echo -e "${GREEN}==>${NOCOLOR} Delete the consumer"
timeout 60 kubectl delete -f $1
if [ $? -ne 0 ]
then
echo "timed out waiting to delete consumer, check the logs to see why"
check_operator_log
tear_down
exit 1
fi
echo -e "${GREEN}==>${NOCOLOR} Check if the operator deletes the database"
DB_EXISTS=$(docker-compose exec -T local-dbaas-psql-provider psql -h localhost -p 5432 -U postgres postgres --no-align --tuples-only -c "SELECT datname FROM pg_database;" | grep -q "${DB_NAME}")
if [[ ! -z "${DB_EXISTS}" ]]
then
echo "database ${DB_NAME} exists"
check_operator_log
tear_down
exit 1
else
echo "database ${DB_NAME} does not exist"
fi
}
add_delete_consumer_psql_fail () {
echo -e "${GREEN}====>${NOCOLOR} Add a consumer $1 $2"
kubectl apply -f $1
CHECK_COUNTER=1
until [ $(kubectl get postgresqlconsumer/$2 -o json | jq -re '.metadata.annotations."dbaas.amazee.io/failed"?') == "true" ]
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Consumer not failed yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for consumer not failed reached."
check_operator_log
tear_down
exit 1
fi
done
echo -e "${GREEN}====>${NOCOLOR} Get PostgreSQLConsumer"
kubectl get postgresqlconsumer/$2 -o yaml
}
add_delete_consumer_mongodb () {
echo "====> Add a consumer"
kubectl apply -f $1
CHECK_COUNTER=1
until kubectl get mongodbconsumer/$2 -o json | jq -e '.spec.consumer.database?'
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Database not created yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for database creation reached"
check_operator_log
docker-compose logs local-dbaas-mongo-provider
exit 1
fi
done
echo "====> Get MongoDBConsumer"
kubectl get mongodbconsumer/$2 -o yaml
DB_NAME=$(kubectl get mongodbconsumer/$2 -o json | jq -r '.spec.consumer.database')
echo "==> Check if the operator creates the database"
if docker-compose exec -T local-dbaas-mongo-provider mongo mongodb://root:[email protected]:27017/ --quiet --eval 'db.getMongo().getDBNames().forEach(function(db){print(db)})' | grep -q "${DB_NAME}"
then
echo "database ${DB_NAME} exists"
else
echo "database ${DB_NAME} does not exist"
check_operator_log
exit 1
fi
echo "==> Check services"
check_services $2 mongodbconsumer
echo "==> Delete the consumer"
timeout 60 kubectl delete -f $1
if [ $? -ne 0 ]
then
echo "failed to delete consumer"
check_operator_log
exit 1
fi
echo "==> Check if the operator deletes the database"
if docker-compose exec -T local-dbaas-mongo-provider mongo mongodb://root:[email protected]:27017/ --quiet --eval 'db.getMongo().getDBNames().forEach(function(db){print(db)})' | grep -q "${DB_NAME}"
then
echo "database ${DB_NAME} exists"
check_operator_log
exit 1
else
echo "database ${DB_NAME} does not exist"
fi
}
add_delete_consumer_mongodb_fail () {
echo -e "${GREEN}====>${NOCOLOR} Add a consumer $1 $2"
kubectl apply -f $1
CHECK_COUNTER=1
until [ $(kubectl get mongodbconsumer/$2 -o json | jq -re '.metadata.annotations."dbaas.amazee.io/failed"?') == "true" ]
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Consumer not failed yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for consumer not failed reached."
check_operator_log
tear_down
exit 1
fi
done
echo -e "${GREEN}====>${NOCOLOR} Get MongoDBConsumer"
kubectl get mongodbconsumer/$2 -o yaml
}
add_delete_consumer_mongodb_tls () {
echo "====> Add a consumer"
kubectl apply -f $1
CHECK_COUNTER=1
until kubectl get mongodbconsumer/$2 -o json | jq -e '.spec.consumer.database?'
do
if [ $CHECK_COUNTER -lt $CHECK_TIMEOUT ]; then
let CHECK_COUNTER=CHECK_COUNTER+1
echo "Database not created yet"
sleep 5
else
echo "Timeout of $CHECK_TIMEOUT for database creation reached"
check_operator_log
docker-compose logs local-dbaas-mongo-tls-provider
exit 1
fi
done
echo "====> Get MongoDBConsumer"
kubectl get mongodbconsumer/$2 -o yaml
DB_NAME=$(kubectl get mongodbconsumer/$2 -o json | jq -r '.spec.consumer.database')
echo "==> Check if the operator creates the database"
if docker-compose exec -T local-dbaas-mongo-tls-provider mongo --tls --tlsAllowInvalidCertificates --tlsAllowInvalidHostnames mongodb://root:[email protected]:27018/ --quiet --eval 'db.getMongo().getDBNames().forEach(function(db){print(db)})' | grep -q "${DB_NAME}"
then
echo "database ${DB_NAME} exists"
else
echo "database ${DB_NAME} does not exist"
check_operator_log
exit 1
fi
echo "==> Check services"
check_services $2 mongodbconsumer
echo "==> Delete the consumer"
timeout 60 kubectl delete -f $1
if [ $? -ne 0 ]
then
echo "failed to delete consumer"
check_operator_log
exit 1
fi
echo "==> Check if the operator deletes the database"
if docker-compose exec -T local-dbaas-mongo-tls-provider mongo --tls --tlsAllowInvalidCertificates --tlsAllowInvalidHostnames mongodb://root:[email protected]:27018/ --quiet --eval 'db.getMongo().getDBNames().forEach(function(db){print(db)})' | grep -q "${DB_NAME}"
then
echo "database ${DB_NAME} exists"
check_operator_log
exit 1
else
echo "database ${DB_NAME} does not exist"
fi
}
add_delete_consumer_failure () {
echo -e "${GREEN}====>${NOCOLOR} Add a consumer"
kubectl apply -f $1
echo -e "${GREEN}==>${NOCOLOR} Wait for consumer to fail"
sleep 5
echo -e "${GREEN}==>${NOCOLOR} Delete the consumer"
kubectl delete -f $1
}
start_up
build_deploy_operator
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Check provider"
echo "Test checking the dbaas-operator http handler for a specific environment type."
echo "This test should return found true or false, true if there are any usable providers, false if there are none"
DBAAS_HTTP_RESULT=$(kubectl exec -it busybox -- wget -q -O - http://dbaas-operator-controller-backend.dbaas-operator-system.svc:5000/mariadb/non-existent)
if [ "$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)" != "false" ]; then
echo "provider http check returned found when it should have been not found"
check_operator_log
tear_down
exit 1
fi
R_FOUND=$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)
R_ERROR=$(echo ${DBAAS_HTTP_RESULT} | jq -r .error)
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Check provider result: ${R_FOUND} / ${R_ERROR}"
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Add a provider"
kubectl apply -f test-resources/mariadb/provider.yaml
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Check provider"
echo "Test checking the dbaas-operator http handler for a specific environment type."
echo "This test should return found true or false, true if there are any usable providers, false if there are none"
DBAAS_HTTP_RESULT=$(kubectl exec -it busybox -- wget -q -O - http://dbaas-operator-controller-backend.dbaas-operator-system.svc:5000/mariadb/test)
if [ "$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)" != "true" ]; then
R_ERROR=$(echo ${DBAAS_HTTP_RESULT} | jq -r .error)
echo "provider http check returned not found when it should have been found: ${R_ERROR}"
check_operator_log
tear_down
exit 1
fi
R_FOUND=$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Check provider result: ${R_FOUND}"
echo -e "${GREEN}====>${YELLOW}MariaDB: ${NOCOLOR} Test blank consumer"
echo "Test adding a blank consumer with a specific environment type."
echo "This test should create the database and user, and the associated services randomly"
add_delete_consumer_mariadb test-resources/mariadb/consumer.yaml mariadbconsumer-testing
echo -e "${YELLOW}====>${YELLOW}MariaDB: ${NOCOLOR} Blank consumer logs"
check_operator_log | grep mariadbconsumer-testing
echo -e "${GREEN}====>${YELLOW}MariaDB: ${NOCOLOR} Test seeded consumer"
echo "Test adding a seeded consumer with a specific environment type."
echo "This test already has pre-seeded database username and password, but will create the associated services"
docker-compose exec -T mysql mysql --host=local-dbaas-mariadb-provider --port=3306 -uroot -e "CREATE DATABASE IF NOT EXISTS testdb; CREATE USER IF NOT EXISTS testdb@'%' IDENTIFIED BY 'testdb'; GRANT ALL ON testdb.* TO testdb@'%'; FLUSH PRIVILEGES;"
add_delete_consumer_mariadb test-resources/mariadb/consumer-test.yaml mariadbconsumer-testing-2
echo -e "${YELLOW}====>${YELLOW}MariaDB: ${NOCOLOR} Seeded consumer logs"
check_operator_log | grep mariadbconsumer-testing-2
echo -e "${GREEN}====>${YELLOW}MariaDB: ${NOCOLOR} Test seeded consumer V2"
echo "Test adding a seeded consumer with a specific environment type."
echo "This test already has pre-seeded database username and password, but will create the associated services"
docker-compose exec -T mysql mysql --host=local-dbaas-mariadb-provider --port=3306 -uroot -e "CREATE DATABASE IF NOT EXISTS testdb1; CREATE USER IF NOT EXISTS testdb1@'%' IDENTIFIED BY 'testdb1'; GRANT ALL ON testdb1.* TO testdb1@'%'; FLUSH PRIVILEGES;"
add_delete_consumer_mariadb test-resources/mariadb/consumer-test-2.yaml mariadbconsumer-testing-3
echo -e "${YELLOW}====>${YELLOW}MariaDB: ${NOCOLOR} Seeded consumer 2 logs"
check_operator_log | grep mariadbconsumer-testing-3
echo "Test adding a blank consumer with a non existing environment type."
echo "This test should fail and set the failure annotations"
add_delete_consumer_mariadb_fail test-resources/mariadb/consumer-fail-1.yaml mariadbconsumer-testing-fail1
echo -e "${YELLOW}====>${YELLOW}MariaDB: ${NOCOLOR} Failed consumer logs"
check_operator_log | grep mariadbconsumer-testing-fail1
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Add an azure provider"
kubectl apply -f test-resources/mariadb/provider-azure.yaml
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Check provider"
echo "Test checking the dbaas-operator http handler for a specific environment type."
echo "This test should return found true or false, true if there are any usable providers, false if there are none"
DBAAS_HTTP_RESULT=$(kubectl exec -it busybox -- wget -q -O - http://dbaas-operator-controller-backend.dbaas-operator-system.svc:5000/mariadb/azure)
if [ "$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)" != "true" ]; then
R_ERROR=$(echo ${DBAAS_HTTP_RESULT} | jq -r .error)
echo "provider http check returned not found when it should have been found: ${R_ERROR}"
check_operator_log
tear_down
exit 1
fi
R_FOUND=$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Check provider result: ${R_FOUND}"
echo -e "${GREEN}====>${YELLOW}MariaDB: ${NOCOLOR} Test blank azure consumer"
echo "Test adding a blank consumer with a specific environment type, but for azure"
echo "This test should create the database and user, and the associated services randomly"
echo "As this is for azure, the username should be 'username@azurehostname'"
add_delete_consumer_mariadb test-resources/mariadb/consumer-azure.yaml mariadbconsumer-testing-azure
echo -e "${YELLOW}====>${YELLOW}MariaDB: ${NOCOLOR} Azure consumer logs"
check_operator_log | grep mariadbconsumer-testing-azure
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Add multi providers"
kubectl apply -f test-resources/mariadb/provider-multi.yaml
# testing multiple providers allows testing of the logic to ensure that the correct provider is chosen.
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Check provider"
echo "Test checking the dbaas-operator http handler for a specific environment type."
echo "This test should return found true or false, true if there are any usable providers, false if there are none"
DBAAS_HTTP_RESULT=$(kubectl exec -it busybox -- wget -q -O - http://dbaas-operator-controller-backend.dbaas-operator-system.svc:5000/mariadb/multi)
if [ "$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)" != "true" ]; then
R_ERROR=$(echo ${DBAAS_HTTP_RESULT} | jq -r .error)
echo "provider http check returned not found when it should have been found: ${R_ERROR}"
check_operator_log
tear_down
exit 1
fi
R_FOUND=$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)
echo -e "${GREEN}==>${YELLOW}MariaDB: ${NOCOLOR} Check provider result: ${R_FOUND}"
echo -e "${GREEN}====>${YELLOW}MariaDB: ${NOCOLOR} Test multi providers"
echo "Test adding a blank consumer with a specific environment type, but of a type that has multiple providers available"
echo "This test should create the database and user, and the associated services randomly, but choose the lowest table/schema count provider"
echo -e "${GREEN}======>${YELLOW}MariaDB: ${NOCOLOR} Create db multidb"
docker-compose exec -T mysql mysql --host=local-dbaas-provider-mariadb-multi --port=3306 -uroot -e "CREATE DATABASE IF NOT EXISTS multidb;CREATE TABLE multidb.Persons (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE multidb.Persons2 (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE multidb.Persons3 (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE multidb.Persons4 (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));"
echo -e "${GREEN}====>${YELLOW}MariaDB: ${NOCOLOR} Test blank multi consumer"
add_delete_consumer_mariadb test-resources/mariadb/consumer-multi.yaml mariadbconsumer-testing-multi
echo -e "${YELLOW}====>${YELLOW}MariaDB: ${NOCOLOR} Multi consumer logs"
check_operator_log | grep mariadbconsumer-testing-multi
docker-compose exec -T mysql mysql --host=local-dbaas-provider-mariadb-multi --port=3306 -uroot -e "DROP DATABASE multidb;"
echo -e "${GREEN}====>${YELLOW}MariaDB: ${NOCOLOR} Test multi providers part 2"
echo "Test adding a blank consumer with a specific environment type, but of a type that has multiple providers available"
echo "This test should create the database and user, and the associated services randomly, but choose the lowest table/schema count provider"
echo "This test adds additional tables to the first provider, so it should choose the second provider"
echo -e "${GREEN}======>${YELLOW}MariaDB: ${NOCOLOR} Create db multidb"
docker-compose exec -T mysql mysql --host=local-dbaas-mariadb-provider --port=3306 -uroot -e "CREATE DATABASE IF NOT EXISTS multidb;CREATE TABLE multidb.Persons (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE multidb.Persons2 (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE multidb.Persons3 (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE multidb.Persons4 (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));"
echo -e "${GREEN}======>${YELLOW}MariaDB: ${NOCOLOR} Create db multidb2"
docker-compose exec -T mysql mysql --host=local-dbaas-mariadb-provider --port=3306 -uroot -e "CREATE DATABASE IF NOT EXISTS multidb2;CREATE TABLE multidb2.Persons (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE multidb2.Persons2 (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE multidb2.Persons3 (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));CREATE TABLE multidb2.Persons4 (PersonID int,LastName varchar(255),FirstName varchar(255),Address varchar(255),City varchar(255));"
echo -e "${GREEN}====>${YELLOW}MariaDB: ${NOCOLOR} Test blank multi consumer part 2"
add_delete_consumer_mariadb test-resources/mariadb/consumer-multi2.yaml mariadbconsumer-testing-multi2 local-dbaas-provider-mariadb-multi
echo -e "${YELLOW}====>${YELLOW}MariaDB: ${NOCOLOR} Multi consumer 2 logs"
check_operator_log | grep mariadbconsumer-testing-multi2
docker-compose exec -T mysql mysql --host=local-dbaas-mariadb-provider --port=3306 -uroot -e "DROP DATABASE multidb;"
docker-compose exec -T mysql mysql --host=local-dbaas-mariadb-provider --port=3306 -uroot -e "DROP DATABASE multidb2;"
echo -e "${GREEN}====>${YELLOW}MariaDB: ${NOCOLOR} Test blank azure consumer with long hostname"
echo "Test adding a blank consumer with a specific environment type, but for azure"
echo "This test should attempt to create the database, but fail at the user creation"
echo "As this is for azure, the username should be 'username@azurehostname'"
echo "Testing for the failure, it should give up trying to create the user"
add_delete_consumer_failure test-resources/mariadb/consumer-azure-long.yaml mariadbconsumer-testing-azure-long
echo -e "${YELLOW}====>${YELLOW}MariaDB: ${NOCOLOR} Azure consumer logs"
check_operator_log | grep mariadbconsumer-testing-azure-long
DB_EXISTS=$(docker-compose exec -T mysql mysql --host=${3:-local-dbaas-mariadb-provider} --port=3306 -uroot -qfsBNe "SELECT schema_name FROM information_schema.schemata;" | egrep -v "information_schema|^db|performance_schema|mysql")
if [[ ! -z "${DB_EXISTS}" ]]
then
echo "databases exist when they shouldn't"
check_operator_log
tear_down
exit 1
fi
echo -e "${GREEN}==>${LIGHTBLUE}PostgreSQL: ${NOCOLOR} Test PostgreSQL"
echo -e "${GREEN}====>${LIGHTBLUE}PostgreSQL: ${NOCOLOR} Add a provider"
kubectl apply -f test-resources/postgres/provider.yaml
kubectl get postgresqlprovider/postgresprovider-testing -o yaml
echo -e "${GREEN}==>${LIGHTBLUE}PostgreSQL: ${NOCOLOR} Check provider"
echo "Test checking the dbaas-operator http handler for a specific environment type."
echo "This test should return found true or false, true if there are any usable providers, false if there are none"
DBAAS_HTTP_RESULT=$(kubectl exec -it busybox -- wget -q -O - http://dbaas-operator-controller-backend.dbaas-operator-system.svc:5000/postgres/test)
if [ "$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)" != "true" ]; then
R_ERROR=$(echo ${DBAAS_HTTP_RESULT} | jq -r .error)
echo "provider http check returned not found when it should have been found: ${R_ERROR}"
check_operator_log
tear_down
exit 1
fi
R_FOUND=$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)
echo -e "${GREEN}==>${LIGHTBLUE}PostgreSQL: ${NOCOLOR} Check provider result: ${R_FOUND}"
echo -e "${GREEN}====>${LIGHTBLUE}PostgreSQL: ${NOCOLOR} Test blank consumer"
add_delete_consumer_psql test-resources/postgres/consumer.yaml psqlconsumer-testing
echo -e "${YELLOW}====>${LIGHTBLUE}PostgreSQL: ${NOCOLOR} Blank consumer logs"
check_operator_log | grep psqlconsumer-testing
echo "Test adding a blank consumer with a non existing environment type."
echo "This test should fail and set the failure annotations"
add_delete_consumer_psql_fail test-resources/postgres/consumer-fail-1.yaml psqlconsumer-testing-fail1
echo -e "${YELLOW}====>${YELLOW}PostgreSQL: ${NOCOLOR} Failed consumer logs"
check_operator_log | grep psqlconsumer-testing-fail1
echo -e "${GREEN}==>${MAGENTA}MongoDB: ${NOCOLOR} Test MongoDB"
echo -e "${GREEN}====>${MAGENTA}MongoDB: ${NOCOLOR} Add a provider"
kubectl apply -f test-resources/mongodb/provider.yaml
kubectl get mongodbprovider/mongodbprovider-testing -o yaml
echo -e "${GREEN}==>${MAGENTA}MongoDB: ${NOCOLOR} Check provider"
echo "Test checking the dbaas-operator http handler for a specific environment type."
echo "This test should return found true or false, true if there are any usable providers, false if there are none"
DBAAS_HTTP_RESULT=$(kubectl exec -it busybox -- wget -q -O - http://dbaas-operator-controller-backend.dbaas-operator-system.svc:5000/mongodb/test)
if [ "$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)" != "true" ]; then
R_ERROR=$(echo ${DBAAS_HTTP_RESULT} | jq -r .error)
echo "provider http check returned not found when it should have been found: ${R_ERROR}"
check_operator_log
tear_down
exit 1
fi
R_FOUND=$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)
echo -e "${GREEN}==>${MAGENTA}MongoDB: ${NOCOLOR} Check provider result: ${R_FOUND}"
echo -e "${GREEN}====>${MAGENTA}MongoDB: ${NOCOLOR} Test blank consumer"
add_delete_consumer_mongodb test-resources/mongodb/consumer.yaml mongodbconsumer-testing
echo -e "${YELLOW}====>${MAGENTA}MongoDB: ${NOCOLOR} Blank consumer logs"
check_operator_log | grep mongodbconsumer-testing
echo "Test adding a blank consumer with a non existing environment type."
echo "This test should fail and set the failure annotations"
add_delete_consumer_mongodb_fail test-resources/mongodb/consumer-fail-1.yaml mongodbconsumer-testing-fail1
echo -e "${YELLOW}====>${YELLOW}MongoDB: ${NOCOLOR} Failed consumer logs"
check_operator_log | grep mongodbconsumer-testing-fail1
echo -e "${GREEN}==>${MAGENTA}MongoDB: ${NOCOLOR} Test MongoDB TLS"
echo -e "${GREEN}====>${MAGENTA}MongoDB: ${NOCOLOR} Add a TLS provider"
kubectl apply -f test-resources/mongodb/provider-tls.yaml
kubectl get mongodbprovider/mongodbprovider-tls-testing -o yaml
echo -e "${GREEN}==>${MAGENTA}MongoDB: ${NOCOLOR} Check provider"
echo "Test checking the dbaas-operator http handler for a specific environment type."
echo "This test should return found true or false, true if there are any usable providers, false if there are none"
DBAAS_HTTP_RESULT=$(kubectl exec -it busybox -- wget -q -O - http://dbaas-operator-controller-backend.dbaas-operator-system.svc:5000/mongodb/tls-test)
if [ "$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)" != "true" ]; then
R_ERROR=$(echo ${DBAAS_HTTP_RESULT} | jq -r .error)
echo "provider http check returned not found when it should have been found: ${R_ERROR}"
check_operator_log
tear_down
exit 1
fi
R_FOUND=$(echo ${DBAAS_HTTP_RESULT} | jq -r .result.found)
echo -e "${GREEN}==>${MAGENTA}MongoDB: ${NOCOLOR} Check provider result: ${R_FOUND}"
echo -e "${GREEN}====>${MAGENTA}MongoDB: ${NOCOLOR} Test blank TLS consumer"
add_delete_consumer_mongodb_tls test-resources/mongodb/consumer-tls.yaml mongodbconsumer-tls-testing
echo -e "${YELLOW}====>${MAGENTA}MongoDB: ${NOCOLOR} Blank TLS consumer logs"
check_operator_log | grep mongodbconsumer-tls-testing
echo ""; echo ""
tear_down
echo -e "${GREEN}================ END ================${NOCOLOR}"