@@ -23,6 +23,16 @@ export PATH="$PATH:$xtrabackup_dir"
2323export qascripts=" $HOME /percona-qa"
2424export logdir=" $HOME /backuplogs"
2525export mysql_start_timeout=60
26+ declare -A KMIP_CONFIGS=(
27+ # PyKMIP Docker Configuration
28+ [" pykmip" ]=" addr=127.0.0.1,image=mohitpercona/kmip:latest,port=5696,name=kmip_pykmip"
29+
30+ # Hashicorp Docker Setup Configuration
31+ [" hashicorp" ]=" addr=127.0.0.1,port=5696,name=kmip_hashicorp,setup_script=hashicorp-kmip-setup.sh"
32+
33+ # API Configuration
34+ # ["ciphertrust"]="addr=127.0.0.1,port=5696,name=kmip_ciphertrust,setup_script=setup_kmip_api.py"
35+ )
2636
2737# Set tool variables
2838load_tool=" pstress" # Set value as pstress/sysbench
@@ -35,32 +45,6 @@ tool_dir="$HOME/pstress_9.1/src" # pstress dir
3545# PXB Lock option
3646LOCK_DDL=on # lock_ddl accepted values (on, reduced)
3747
38- cleanup () {
39- echo " Cleaning up at Exit..."
40-
41- IMAGE=" mohitpercona/kmip:latest"
42- # Find containers using the image
43- container=$( docker ps -a -q --filter ancestor=" $IMAGE " )
44-
45- # Stop and remove those containers
46- if [ -n " $container " ]; then
47- echo " Removing containers using image: $IMAGE "
48- docker rm -f $container
49- fi
50-
51- # Remove the image
52- if docker images -q " $IMAGE " > /dev/null 2>&1 ; then
53- echo " Removing image: $IMAGE "
54- docker rmi -f " $IMAGE "
55- fi
56-
57- if [ -d " $HOME /certs/" ]; then
58- rm -rf " $HOME /certs/"
59- fi
60- }
61-
62- trap cleanup EXIT INT TERM
63-
6448normalize_version () {
6549 local major=0
6650 local minor=0
@@ -92,35 +76,6 @@ pt_ver=$(pt-table-checksum --version 2>/dev/null | awk '{print $NF}')
9276 exit 1
9377fi
9478
95- # Set Kmip configuration
96- setup_kmip () {
97- # Remove existing container if any
98- docker rm -f kmip 2> /dev/null || true
99-
100- # Remove the image (only if not used by any other container)
101- docker rmi mohitpercona/kmip:latest 2> /dev/null || true
102-
103- if [ -d " $HOME /certs/" ]; then
104- echo " certs directory exists"
105- rm -rf $HOME /certs/*
106- else
107- echo " does not exist. creating certs dir"
108- mkdir " $HOME /certs/"
109- fi
110- docker cp kmip:/opt/certs/root_certificate.pem " $HOME /certs/"
111- docker cp kmip:/opt/certs/client_key_jane_doe.pem " $HOME /certs/"
112- docker cp kmip:/opt/certs/client_certificate_jane_doe.pem " $HOME /certs/"
113-
114- kmip_server_address=" 0.0.0.0"
115- kmip_server_port=5696
116- kmip_client_ca=" $HOME /certs/client_certificate_jane_doe.pem"
117- kmip_client_key=" $HOME /certs/client_key_jane_doe.pem"
118- kmip_server_ca=" $HOME /certs/root_certificate.pem"
119-
120- # Sleep for 30 sec to fully initialize the KMIP server
121- sleep 30
122- }
123-
12479# For kms tests set the values of KMS_REGION, KMS_KEYID, KMS_AUTH_KEY, KMS_SECRET_KEY in the shell and then run the tests
12580kms_region=" ${KMS_REGION:- us-east-1} " # Set KMS_REGION to change default value us-east-1
12681kms_id=" ${KMS_KEYID:- } "
@@ -505,29 +460,32 @@ run_load_keyring_plugin_tests() {
505460}
506461
507462create_keyring_component_files () {
508- echo " Create global manifest file"
509- cat << -EOF >"${mysqldir} "/bin/mysqld.my
510- {
463+ local keyring_type=" $1 "
464+ local kmip_type=" $2 "
465+ if [ " $keyring_type " = " keyring_kmip" ]; then
466+ echo " Keyring type is KMIP. Taking KMIP-specific action..."
467+
468+ echo ' {
469+ "components": "file://component_keyring_kmip"
470+ }' > " $mysqldir /bin/mysqld.my"
471+
472+ start_kmip_server " $kmip_type "
473+ [ -f " ${HOME} /${kmip_config[cert_dir]} /component_keyring_kmip.cnf" ] && cp " ${HOME} /${kmip_config[cert_dir]} /component_keyring_kmip.cnf" " $mysqldir /lib/plugin/"
474+
475+ elif [ " $keyring_type " = " keyring_file" ]; then
476+ echo " Keyring type is file. Taking file-based action..."
477+
478+ echo ' {
511479 "components": "file://component_keyring_file"
512- }
513- EOF
514- if [[ ! -f " ${mysqldir} " /bin/mysqld.my ]]; then
515- echo " ERR: The global manifest could not be created in ${mysqldir} /bin/mysqld.my"
516- exit 1
517- fi
480+ }' > " $mysqldir /bin/mysqld.my"
518481
519- echo " Create global configuration file"
520- cat << -EOF >"${mysqldir} "/lib/plugin/component_keyring_file.cnf
482+ cat > " $mysqldir /lib/plugin/component_keyring_file.cnf" << -EOFL
521483 {
522- "path ": "$mysqldir /lib/plugin/component_keyring_file ",
523- "read_only": false
484+ "component_keyring_file_data ": "${ mysqldir} /keyring ",
485+ "read_only": false
524486 }
525- EOF
526- if [[ ! -f " ${mysqldir} " /lib/plugin/component_keyring_file.cnf ]]; then
527- echo " ERR: The global configuration could not be created in ${mysqldir} /lib/plugin/component_keyring_file.cnf"
528- exit 1
529- fi
530-
487+ EOFL
488+ fi
531489}
532490
533491run_load_keyring_component_tests () {
@@ -573,8 +531,23 @@ run_load_keyring_component_tests() {
573531 check_tables
574532}
575533
534+ run_kmip_component_tests () {
535+ feature=" $1 "
536+ if ! source ./kmip_helper.sh; then
537+ echo " ERROR: Failed to load KMIP helper library"
538+ exit 1
539+ fi
540+ init_kmip_configs
541+ echo " Testing keyring_kmip with vault types..."
542+ for vault_type in " ${! KMIP_CONFIGS[@]} " ; do
543+ echo " Testing with $vault_type ..."
544+ run_load_kmip_component_tests " $vault_type " " $feature "
545+ done
546+ }
547+
576548run_load_kmip_component_tests () {
577549 # This function runs the load backup tests with keyring_kmip component options
550+ kmip_type=" $1 "
578551 BACKUP_PARAMS=" --xtrabackup-plugin-dir=${xtrabackup_dir} /../lib/plugin --core-file"
579552 PREPARE_PARAMS=" ${BACKUP_PARAMS} --component-keyring-config=" ${mysqldir} " /lib/plugin/component_keyring_kmip.cnf"
580553 RESTORE_PARAMS=" ${BACKUP_PARAMS} "
@@ -596,7 +569,7 @@ run_load_kmip_component_tests() {
596569
597570 echo " Test: Incremental Backup and Restore for keyring_kmip component with ${load_tool} "
598571 cleanup
599- setup_kmip
572+ start_kmip_server $kmip_type
600573 echo " Create global manifest file"
601574 cat << -EOF >"${mysqldir} "/bin/mysqld.my
602575 {
609582 fi
610583
611584 echo " Create global configuration file"
612- cat << -EOF >"${mysqldir} "/lib/plugin/component_keyring_kmip.cnf
613- {
614- "path": "$mysqldir /keyring_kmip", "server_addr": "$kmip_server_address ", "server_port": "$kmip_server_port ", "client_ca": "$kmip_client_ca ", "client_key": "$kmip_client_key ", "server_ca": "$kmip_server_ca "
615- }
616- EOF
585+ cp " ${HOME} " /" ${kmip_config[cert_dir]} " /component_keyring_kmip.cnf " ${mysqldir} " /lib/plugin/
586+
617587 if [[ ! -f " ${mysqldir} " /lib/plugin/component_keyring_kmip.cnf ]]; then
618588 echo " ERR: The global configuration could not be created in ${mysqldir} /lib/plugin/component_keyring_kmip.cnf"
619589 exit 1
622592 tool_options_encrypt=" --tables $num_tables --records $table_size --threads $threads --seconds $seconds --undo-tbs-sql 0" # Used for pstress
623593 initialize_db
624594
625- if [[ " $1 " = " pagetracking" ]]; then
595+ if [[ " $2 " = " pagetracking" ]]; then
626596 echo " Running test with page tracking enabled"
627597 BACKUP_PARAMS=" ${BACKUP_PARAMS} --page-tracking"
628598 " ${mysqldir} " /bin/mysql -uroot -S" ${mysqldir} " /socket.sock -e " INSTALL COMPONENT 'file://component_mysqlbackup';"
@@ -731,13 +701,30 @@ EOF
731701 rm " ${mysqldir} " /lib/plugin/component_keyring_kms.cnf
732702 fi
733703}
704+ run_crash_tests_pstress_encrypted () {
705+ feature=" $1 "
706+ echo " Testing keyring_file..."
707+ run_crash_tests_pstress " keyring_file" " " " $feature "
708+
709+ if ! source ./kmip_helper.sh; then
710+ echo " ERROR: Failed to load KMIP helper library"
711+ exit 1
712+ fi
713+ init_kmip_configs
714+ echo " Testing keyring_kmip with vault types..."
715+ for vault_type in " ${! KMIP_CONFIGS[@]} " ; do
716+ echo " Testing with $vault_type ..."
717+ run_crash_tests_pstress " keyring_kmip" " $vault_type " " $feature "
718+ done
719+ }
734720
735721run_crash_tests_pstress () {
736722
737723 # This function crashes the server during load and then runs backup
738724 local test_type=" $1 "
725+ local kmip_type=" $2 "
739726
740- if [[ " ${test_type} " = " encryption " ]]; then
727+ if [[ " ${test_type} " = " *keyring* " ]]; then
741728 echo " Running crash tests with ${load_tool} and mysql running with encryption"
742729 if [ $VERSION -ge 080000 ]; then
743730 if [ " $server_type " == " MS" ]; then
@@ -763,7 +750,12 @@ run_crash_tests_pstress() {
763750 fi
764751 fi
765752 BACKUP_PARAMS=" --xtrabackup-plugin-dir=${xtrabackup_dir} /../lib/plugin --core-file --lock-ddl=$LOCK_DDL "
766- PREPARE_PARAMS=" ${BACKUP_PARAMS} --component-keyring-config=" ${mysqldir} " /lib/plugin/component_keyring_file.cnf"
753+ if [ " $test_type " = " keyring_kmip" ]; then
754+ keyring_filename=" ${mysqldir} /lib/plugin/component_keyring_kmip.cnf"
755+ elif [ " $test_type " = " keyring_file" ]; then
756+ keyring_filename=" ${mysqldir} /lib/plugin/component_keyring_file.cnf"
757+ fi
758+ PREPARE_PARAMS=" ${BACKUP_PARAMS} --component-keyring-config=$keyring_filename "
767759 RESTORE_PARAMS=" ${BACKUP_PARAMS} "
768760 elif [[ " ${test_type} " = " rocksdb" ]]; then
769761 echo " Running crash tests with ${load_tool} for rocksdb"
@@ -792,14 +784,14 @@ run_crash_tests_pstress() {
792784 log_date=$( date +" %d_%m_%Y_%M" )
793785
794786 cleanup
795- create_keyring_component_files
787+ create_keyring_component_files $keyring_type $kmip_type
796788 initialize_db
797789
798790 if [ " $test_type " = " rocksdb" ]; then
799791 $mysqldir /bin/ps-admin --enable-rocksdb -uroot -S${mysqldir} /socket.sock > /dev/null 2>&1
800792 fi
801793
802- if [[ " $2 " = " pagetracking" ]]; then
794+ if [[ " $3 " = " pagetracking" ]]; then
803795 echo " Running test with page tracking enabled"
804796 BACKUP_PARAMS=" ${BACKUP_PARAMS} --page-tracking"
805797 " ${mysqldir} " /bin/mysql -uroot -S" ${mysqldir} " /socket.sock -e " INSTALL COMPONENT 'file://component_mysqlbackup';"
@@ -984,7 +976,35 @@ cleanup() {
984976 rm -rf $mysqldir /lib/plugin/component_keyring_file
985977 echo " ..Deleted"
986978 fi
979+ echo " Checking for previously started containers..."
980+ if [ -z " ${KMIP_CONTAINER_NAMES+x} " ] || [ ${# KMIP_CONTAINER_NAMES[@]} -eq 0 ]; then
981+ get_kmip_container_names
982+ fi
983+ containers_found=false
984+
985+ for name in " ${KMIP_CONTAINER_NAMES[@]} " ; do
986+ if docker ps -aq --filter " name=$name " | grep -q . ; then
987+ containers_found=true
988+ break
989+ fi
990+ done
991+
992+ if [[ " $containers_found " == true ]]; then
993+ echo " Killing previously started containers if any..."
994+ for name in " ${KMIP_CONTAINER_NAMES[@]} " ; do
995+ cleanup_existing_container " $name "
996+ done
997+ fi
998+
999+ # Only cleanup vault directory if it exists
1000+ if [[ -d " $HOME /vault" && -n " $HOME " ]]; then
1001+ echo " Cleaning up vault directory..."
1002+ sudo rm -rf " $HOME /vault"
1003+ fi
9871004}
1005+ trap cleanup EXIT INT TERM
1006+
1007+ # # Main ##
9881008
9891009if [ " $# " -lt 1 ]; then
9901010 echo " This script tests backup with a load tool as pquery/pstress/sysbench"
@@ -1036,14 +1056,17 @@ for tsuitelist in $*; do
10361056 if [ $load_tool == " pstress" ]; then
10371057 run_crash_tests_pstress " normal"
10381058 echo " ###################################################################################"
1039- run_crash_tests_pstress " encryption "
1059+ run_crash_tests_pstress_encrypted
10401060 echo " ###################################################################################"
10411061 fi
10421062 ;;
10431063 Kmip_Encryption_tests)
1044- run_load_kmip_component_tests
1045- echo " ###################################################################################"
1046- run_load_kmip_component_tests " pagetracking"
1064+ if ! source ./kmip_helper.sh; then
1065+ echo " ERROR: Failed to load KMIP helper library"
1066+ exit 1
1067+ fi
1068+ init_kmip_configs
1069+ run_kmip_component_tests " pagetracking"
10471070 echo " ###################################################################################"
10481071 ;;
10491072 Kms_Encryption_tests)
@@ -1055,7 +1078,7 @@ for tsuitelist in $*; do
10551078 Rocksdb_tests)
10561079 if " ${mysqldir} " /bin/mysqld --version | grep " 5.7" > /dev/null 2>&1 ; then
10571080 echo " Rocksdb backup is not supported in MS/PS 5.7, skipping tests"
1058- continue
1081+ continue
10591082 fi
10601083 if ${mysqldir} /bin/mysqld --version | grep " MySQL Community Server" > /dev/null 2>&1 ; then
10611084 echo " RocksDB is unsupported in MS, skipping tests"
@@ -1086,7 +1109,7 @@ for tsuitelist in $*; do
10861109 if [ $load_tool == " pstress" ]; then
10871110 run_crash_tests_pstress " normal" " pagetracking"
10881111 echo " ###################################################################################"
1089- run_crash_tests_pstress " encryption " " pagetracking"
1112+ run_crash_tests_pstress_encrypted " pagetracking"
10901113 echo " ###################################################################################"
10911114 run_crash_tests_pstress " rocksdb" " pagetracking"
10921115 echo " ###################################################################################"
0 commit comments