From e6c64cd620aa9d3052e7b01492d9343ab9334d65 Mon Sep 17 00:00:00 2001 From: Puneet Kaushik Date: Thu, 28 Sep 2023 16:52:19 +0530 Subject: [PATCH] removing files --- router-docker_test.sh | 105 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 90 insertions(+), 15 deletions(-) diff --git a/router-docker_test.sh b/router-docker_test.sh index 9eae67318..b453b86ab 100755 --- a/router-docker_test.sh +++ b/router-docker_test.sh @@ -1,4 +1,31 @@ -#!/usr/bin/env bash +#!/bin/bash + +if [ $# -eq 0 ]; +then + echo "$0: Missing arguments" + exit 1 +elif [ $# -gt 2 ]; +then + echo "$0: Too many arguments: $@" + exit 1 +else + echo "We got some argument(s)" + + echo "===========================" + + echo "Number of arguments.: $#" + + echo "List of arguments...: $@" + + echo "Arg #1..............: $1" + + echo "Arg #2..............: $2" + + echo "===========================" +fi + + +set -xe cleanup(){ @@ -51,7 +78,7 @@ start_mysql_containers(){ create_new_user(){ for N in 1 2 3 4 - do sudo docker exec mysql$N mysql -uroot -proot \ + do sudo docker exec -it mysql$N mysql -uroot -proot \ -e "CREATE USER 'inno'@'%' IDENTIFIED BY 'inno';" \ -e "GRANT ALL privileges ON *.* TO 'inno'@'%' with grant option;" \ -e "reset master;" @@ -61,7 +88,7 @@ create_new_user(){ verify_new_user(){ for N in 1 2 3 4 - do sudo docker exec mysql$N mysql -uinno -pinno \ + do sudo docker exec -it mysql$N mysql -uinno -pinno \ -e "SHOW VARIABLES WHERE Variable_name = 'hostname';" \ -e "SELECT user FROM mysql.user where user = 'inno';" done @@ -77,19 +104,19 @@ docker_restart(){ create_cluster(){ - sudo docker exec mysql1 mysqlsh -uinno -pinno -- dba create-cluster testCluster + sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- dba create-cluster testCluster } add_slave(){ - sudo docker exec mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql2 --recoveryMethod=incremental + sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql2 --recoveryMethod=incremental sleep 10 - sudo docker exec mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql3 --recoveryMethod=incremental + sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql3 --recoveryMethod=incremental sleep 10 - sudo docker exec mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql4 --recoveryMethod=incremental + sudo docker exec -it mysql1 mysqlsh -uinno -pinno -- cluster add-instance --uri=inno@mysql4 --recoveryMethod=incremental sleep 10 } @@ -104,24 +131,69 @@ Router_Bootstrap(){ data_add(){ sudo docker run -d --name=mysql-client --hostname=mysql-client --net=innodbnet -e MYSQL_ROOT_PASSWORD=root $1 - + sleep 10 - + echo "Adding sbtest user" - sudo docker exec mysql-client mysql -h mysql-router -P 6446 -uinno -pinno \ + sudo docker exec -it mysql-client mysql -h mysql-router -P 6446 -uinno -pinno \ -e "CREATE SCHEMA sbtest; CREATE USER sbtest@'%' IDENTIFIED with mysql_native_password by 'password';" \ -e "GRANT ALL PRIVILEGES ON sbtest.* to sbtest@'%';" echo "Verify sbtest user" - - sudo docker exec mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "select host , user from mysql.user where user='sbtest';" - + + sudo docker exec -it mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "select host , user from mysql.user where user='sbtest';" + sleep 5 - + echo "sysbench run" sudo docker run --rm=true --net=innodbnet --name=sb-prepare severalnines/sysbench sysbench --db-driver=mysql --table-size=10000 --tables=1 --threads=1 --mysql-host=mysql-router --mysql-port=6446--mysql-user=sbtest --mysql-password=password /usr/share/sysbench/oltp_insert.lua prepare + + sleep 20 + + echo "verify if data is inserted or not" + + sudo docker exec -it mysql-client mysql -h mysql-router -P 6447 -uinno -pinno -e "SELECT count(*) from sbtest.sbtest1;" +} + +verify_replication(){ + + for N in 1 2 3 4; + do + sudo docker exec -it mysql$N mysql -uinno -pinno -e "SHOW VARIABLES WHERE Variable_name = 'hostname';" -e "SELECT count(*) from sbtest.sbtest1;"; + done +} + +Fault_tolerance(){ + + echo "Stop One node" + + sudo docker stop mysql1 + + sleep 10 + + echo "check status" + + sudo docker exec -it mysql-client mysqlsh -h mysql-router -P 6446 -uinno -pinno -- cluster status >> cluster1.json + + sed '1d' cluster1.json >> cluster.json + + status=$(jq -r '.defaultReplicaSet.status' cluster.json) + + echo $status +} + +verify_status(){ + + if [[ "${status}" = "OK_PARTIAL" ]]; then + echo "Innodb cluster looks good" + exit 0 + else + echo "Issue in Innodb Cluster" + exit 1 + fi + } cleanup @@ -134,4 +206,7 @@ docker_restart create_cluster add_slave Router_Bootstrap $2 -data_add $1 +data_add $1 +verify_replication +Fault_tolerance +verify_status