github.com/percona/percona-xtradb-cluster-operator@v1.14.0/e2e-tests/one-pod/run (about)

     1  #!/bin/bash
     2  
     3  set -o errexit
     4  
     5  test_dir=$(realpath $(dirname $0))
     6  . ${test_dir}/../functions
     7  
     8  set_debug
     9  
    10  spinup_pxc() {
    11  	local cluster=$1
    12  	local config=$2
    13  	local size="${3:-3}"
    14  
    15  	desc 'create first PXC cluster'
    16  	kubectl_bin apply \
    17  		-f $conf_dir/secrets.yml
    18  
    19  	apply_config "$conf_dir/client.yml"
    20  	apply_config "$config"
    21  
    22  	desc 'check if all 3 Pods started'
    23  	wait_for_running "$cluster-pxc" "$size"
    24  	sleep 15
    25  
    26  	desc 'write data'
    27  	run_mysql \
    28  		'CREATE DATABASE IF NOT EXISTS myApp; use myApp; CREATE TABLE IF NOT EXISTS myApp (id int PRIMARY KEY);' \
    29  		"-h $cluster-pxc -uroot -proot_password"
    30  	run_mysql \
    31  		'INSERT myApp.myApp (id) VALUES (100500)' \
    32  		"-h $cluster-pxc -uroot -proot_password"
    33  
    34  	for i in $(seq 0 $((size - 1))); do
    35  		compare_mysql_cmd "select-1" "SELECT * from myApp.myApp;" "-h $cluster-pxc-$i.$cluster-pxc -uroot -proot_password"
    36  	done
    37  }
    38  
    39  check_pvc_md5() {
    40  	desc 'check backup file md5sum'
    41  	apply_config "$test_dir/conf/client.yml"
    42  	sleep 10
    43  	bak_client_pod=$(
    44  		kubectl_bin get pods \
    45  			--selector=name=backup-client \
    46  			-o 'jsonpath={.items[].metadata.name}'
    47  	)
    48  	wait_pod $bak_client_pod
    49  	kubectl_bin exec $bak_client_pod -- \
    50  		bash -c "cd /backup; md5sum -c md5sum.txt"
    51  	kubectl_bin delete \
    52  		-f $test_dir/conf/client.yml
    53  }
    54  
    55  run_backup() {
    56  	local cluster=$1
    57  	local backup1=$2
    58  
    59  	desc 'make backup'
    60  	kubectl_bin apply \
    61  		-f $test_dir/conf/$backup1.yml
    62  	wait_backup $backup1
    63  }
    64  
    65  run_recovery_check() {
    66  	local cluster=$1
    67  	local backup1=$2
    68  
    69  	desc 'write data after backup'
    70  	run_mysql \
    71  		'INSERT myApp.myApp (id) VALUES (100501)' \
    72  		"-h $cluster-pxc -uroot -proot_password"
    73  	compare_mysql_cmd "select-2" "SELECT * from myApp.myApp;" "-h $cluster-pxc-0.$cluster-pxc -uroot -proot_password"
    74  
    75  	desc 'recover backup'
    76  	kubectl_bin apply -f "$test_dir/conf/restore-${backup1}.yaml"
    77  	wait_backup_restore ${backup1}
    78  	kubectl_bin logs job/restore-job-${backup1}-${cluster}
    79  	kubectl_bin delete -f "$test_dir/conf/restore-${backup1}.yaml"
    80  	wait_for_running "$cluster-pxc" 1
    81  
    82  	desc 'check data after backup'
    83  	compare_mysql_cmd "select-1" "SELECT * from myApp.myApp;" "-h $cluster-pxc-0.$cluster-pxc -uroot -proot_password"
    84  }
    85  
    86  main() {
    87  	create_infra $namespace
    88  
    89  	cluster="one-pod"
    90  	spinup_pxc "$cluster" "$test_dir/conf/$cluster.yml" "1"
    91  
    92  	compare_kubectl statefulset/$cluster-pxc
    93  	apply_config "$test_dir/conf/config-secret.yaml"
    94  	sleep 50
    95  	compare_kubectl statefulset/$cluster-pxc "-secret"
    96  
    97  	run_backup "$cluster" "on-demand-backup-pvc"
    98  	run_recovery_check "$cluster" "on-demand-backup-pvc"
    99  	check_pvc_md5
   100  
   101  	if [ -z "$SKIP_REMOTE_BACKUPS" ]; then
   102  		run_backup "$cluster" "on-demand-backup-aws-s3"
   103  		run_recovery_check "$cluster" "on-demand-backup-aws-s3"
   104  	fi
   105  
   106  	destroy $namespace
   107  	desc "test passed"
   108  }
   109  
   110  main