From b776ed782124ab991b3d877db42363be3ac11fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Fri, 11 May 2018 00:10:24 +0300 Subject: [PATCH] Don't assume source and binary directories are the same Some of the scripts assumed that other scripts would be located in the same directory where the current script was executed. Also fixed the SSL connection creation which depended on an obsolete environment variable causing all out-of-source SSL tests to fail. --- maxscale-system-test/bug561.sh | 5 ++-- maxscale-system-test/bug562.sh | 5 ++-- maxscale-system-test/bug564.sh | 9 +++---- maxscale-system-test/bug567.sh | 5 ++-- maxscale-system-test/cache_basic.sh | 22 ++++++++------- maxscale-system-test/insertstream.sh | 6 ++++- maxscale-system-test/long_insert.sh | 11 ++++---- maxscale-system-test/mariadb_func.cpp | 18 ++++--------- maxscale-system-test/mariadb_tests_hartmut.sh | 9 +++++-- .../masking_mysqltest_driver.sh | 5 ++-- maxscale-system-test/masking_user.sh | 27 ++++++++++--------- maxscale-system-test/mxs1719.cpp | 4 ++- maxscale-system-test/mxs791_base.sh | 4 ++- maxscale-system-test/mxs922_listener_ssl.cpp | 2 +- maxscale-system-test/mysqltest_driver.sh | 16 +++++------ maxscale-system-test/run_ctrl_c.sh | 5 ++-- maxscale-system-test/run_session_hang.sh | 9 ++++--- 17 files changed, 88 insertions(+), 74 deletions(-) diff --git a/maxscale-system-test/bug561.sh b/maxscale-system-test/bug561.sh index 46341e94e..b2136c4b4 100755 --- a/maxscale-system-test/bug561.sh +++ b/maxscale-system-test/bug561.sh @@ -8,6 +8,7 @@ rp=`realpath $0` +export src_dir=`dirname $rp` export test_dir=`pwd` export test_name=`basename $rp` @@ -17,7 +18,7 @@ if [ $? -ne 0 ] ; then echo "configuring maxscale failed" exit 1 fi -export ssl_options="--ssl-cert=$test_dir/ssl-cert/client-cert.pem --ssl-key=$test_dir/ssl-cert/client-key.pem" +export ssl_options="--ssl-cert=$src_dir/ssl-cert/client-cert.pem --ssl-key=$src_dir/ssl-cert/client-key.pem" #echo "Waiting for 15 seconds" #sleep 15 @@ -69,5 +70,5 @@ else echo "Messages are same" fi -$test_dir/copy_logs.sh bug561 +$src_dir/copy_logs.sh bug561 exit $res diff --git a/maxscale-system-test/bug562.sh b/maxscale-system-test/bug562.sh index 39f74762e..3f22e4a74 100755 --- a/maxscale-system-test/bug562.sh +++ b/maxscale-system-test/bug562.sh @@ -6,6 +6,7 @@ ## - compare error messages rp=`realpath $0` +export src_dir=`dirname $rp` export test_dir=`pwd` export test_name=`basename $rp` @@ -15,7 +16,7 @@ if [ $? -ne 0 ] ; then echo "configuring maxscale failed" exit 1 fi -export ssl_options="--ssl-cert=$test_dir/ssl-cert/client-cert.pem --ssl-key=$test_dir/ssl-cert/client-key.pem" +export ssl_options="--ssl-cert=$src_dir/ssl-cert/client-cert.pem --ssl-key=$src_dir/ssl-cert/client-key.pem" mariadb_err=`mysql -u no_such_user -psome_pwd -h $node_001_network $ssl_option --socket=$node_000_socket test 2>&1` maxscale_err=`mysql -u no_such_user -psome_pwd -h $maxscale_IP -P 4006 $ssl_options test 2>&1` @@ -38,5 +39,5 @@ else res=0 fi -$test_dir/copy_logs.sh bug562 +$src_dir/copy_logs.sh bug562 exit $res diff --git a/maxscale-system-test/bug564.sh b/maxscale-system-test/bug564.sh index a45c896cf..990de5160 100755 --- a/maxscale-system-test/bug564.sh +++ b/maxscale-system-test/bug564.sh @@ -6,6 +6,7 @@ ## - check output of SHOW VARIABLES LIKE 'char%' rp=`realpath $0` +export src_dir=`dirname $rp` export test_dir=`pwd` export test_name=`basename $rp` $test_dir/non_native_setup $test_name @@ -14,7 +15,7 @@ if [ $? -ne 0 ] ; then echo "configuring maxscale failed" exit 1 fi -export ssl_options="--ssl-cert=$test_dir/ssl-cert/client-cert.pem --ssl-key=$test_dir/ssl-cert/client-key.pem" +export ssl_options="--ssl-cert=$src_dir/ssl-cert/client-cert.pem --ssl-key=$src_dir/ssl-cert/client-key.pem" for char_set in "latin1" "latin2" do @@ -34,11 +35,9 @@ do if [[ $res1 != 0 ]] || [[ $res2 != 0 ]] || [[ $res3 != 0 ]] ; then echo "charset is ignored" mysql -u$node_user -p$node_password -h $maxscale_IP -P 4006 $ssl_options --default-character-set="latin2" -e "SHOW VARIABLES LIKE 'char%'" - $test_dir/copy_logs.sh bug564 + $src_dir/copy_logs.sh bug564 exit 1 fi done -$test_dir/copy_logs.sh bug564 +$src_dir/copy_logs.sh bug564 exit 0 - - diff --git a/maxscale-system-test/bug567.sh b/maxscale-system-test/bug567.sh index 7b5d90932..bcfd90b1d 100755 --- a/maxscale-system-test/bug567.sh +++ b/maxscale-system-test/bug567.sh @@ -6,6 +6,7 @@ ## check if Maxscale is alive rp=`realpath $0` +export src_dir=`dirname $rp` export test_dir=`pwd` export test_name=`basename $rp` $test_dir/non_native_setup $test_name @@ -14,7 +15,7 @@ if [ $? -ne 0 ] ; then echo "configuring maxscale failed" exit 1 fi -export ssl_options="--ssl-cert=$test_dir/ssl-cert/client-cert.pem --ssl-key=$test_dir/ssl-cert/client-key.pem" +export ssl_options="--ssl-cert=$src_dir/ssl-cert/client-cert.pem --ssl-key=$src_dir/ssl-cert/client-key.pem" #pid=`ssh -i $maxscale_sshkey -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null $maxscale_access_user@$maxscale_IP "pgrep maxscale"` #echo "Maxscale pid is $pid" @@ -29,6 +30,6 @@ echo "checking if Maxscale is alive" echo "show databases;" | mysql -u$node_user -p$node_password -h $maxscale_IP -P 4006 $ssl_options res=$? -$test_dir/copy_logs.sh bug567 +$src_dir/copy_logs.sh bug567 exit $res diff --git a/maxscale-system-test/cache_basic.sh b/maxscale-system-test/cache_basic.sh index a65b40f85..4056e6714 100755 --- a/maxscale-system-test/cache_basic.sh +++ b/maxscale-system-test/cache_basic.sh @@ -1,5 +1,8 @@ #!/bin/bash +rp=`realpath $0` +export src_dir=`dirname $rp` + user=skysql password=skysql @@ -15,18 +18,20 @@ function run_test local test_name=$1 echo $test_name + logdir=log_$test_name + mkdir -p $logdir mysqltest --host=$maxscale_IP --port=$port \ --user=$user --password=$password \ - --logdir=log \ - --test-file=t/$test_name.test \ - --result-file=r/$test_name.result \ + --logdir=$logdir \ + --test-file=$dir/t/$test_name.test \ + --result-file=$dir/r/$test_name.result \ --silent if [ $? -eq 0 ] then echo " OK" - rc=0 + rc=0 else echo " FAILED" rc=1 @@ -57,7 +62,9 @@ then echo "warning: Expected test name to be $expected_name_basic, was $1." fi -source=cache/$1/cache_rules.json +export dir="$src_dir/cache/$expected_name" + +source=$src_dir/cache/$1/cache_rules.json target=vagrant@$maxscale_IP:/home/$maxscale_access_user/cache_rules.json if [ $maxscale_IP != "127.0.0.1" ] ; then @@ -78,11 +85,6 @@ test_dir=`pwd` $test_dir/non_native_setup $1 -cd cache/$expected_name - -[ -d log ] && rm -r log -mkdir log || exit 1 - echo # We sleep slightly longer than the TTL to ensure that the TTL mechanism diff --git a/maxscale-system-test/insertstream.sh b/maxscale-system-test/insertstream.sh index dd96c31a0..55950f0ef 100755 --- a/maxscale-system-test/insertstream.sh +++ b/maxscale-system-test/insertstream.sh @@ -1,4 +1,8 @@ #!/bin/bash +rp=`realpath $0` +export src_dir=`dirname $rp` + ./non_native_setup insertstream -./mysqltest_driver.sh insertstream insertstream 4006 + +$src_dir/mysqltest_driver.sh insertstream $src_dir/insertstream 4006 diff --git a/maxscale-system-test/long_insert.sh b/maxscale-system-test/long_insert.sh index c668719a4..6788a9d76 100755 --- a/maxscale-system-test/long_insert.sh +++ b/maxscale-system-test/long_insert.sh @@ -1,29 +1,30 @@ #!/bin/bash rp=`realpath $0` +export src_dir=`dirname $rp` export test_dir=`pwd` export test_name=`basename $rp` $test_dir/non_native_setup $test_name -export ssl_options="--ssl-cert=$test_dir/ssl-cert/client-cert.pem --ssl-key=$test_dir/ssl-cert/client-key.pem" +export ssl_options="--ssl-cert=$src_dir/ssl-cert/client-cert.pem --ssl-key=$src_dir/ssl-cert/client-key.pem" IP=$Maxscale_IP -mysql -h $IP -P 4006 -u $node_user -p$node_password $ssl_options < $test_dir/long_insert_sql/test_init.sql +mysql -h $IP -P 4006 -u $node_user -p$node_password $ssl_options < $src_dir/long_insert_sql/test_init.sql echo "RWSplit router:" for ((i=0 ; i<1000 ; i++)) ; do echo "iteration: $i" - mysql -h $IP -P 4006 -u $node_user -p$node_password $ssl_options < $test_dir/long_insert_sql/test_query.sql + mysql -h $IP -P 4006 -u $node_user -p$node_password $ssl_options < $src_dir/long_insert_sql/test_query.sql done echo "ReadConn router (master):" for ((i=0 ; i<1000 ; i++)) ; do echo "iteration: $i" - mysql -h $IP -P 4008 -u $node_user -p$node_uassword $ssl_options < $test_dir/long_insert_sql/test_query.sql + mysql -h $IP -P 4008 -u $node_user -p$node_uassword $ssl_options < $src_dir/long_insert_sql/test_query.sql done res=$? -$test_dir/copy_logs.sh long_insert +$src_dir/copy_logs.sh long_insert exit $res diff --git a/maxscale-system-test/mariadb_func.cpp b/maxscale-system-test/mariadb_func.cpp index 39509948e..e1ffda07f 100644 --- a/maxscale-system-test/mariadb_func.cpp +++ b/maxscale-system-test/mariadb_func.cpp @@ -12,6 +12,7 @@ #include "mariadb_func.h" +#include "templates.h" #include #include @@ -20,20 +21,11 @@ int set_ssl(MYSQL* conn) char client_key[1024]; char client_cert[1024]; char ca[1024]; - char* test_dir = getenv("test_dir"); - if (test_dir == NULL) - { - sprintf(client_key, "./ssl-cert/client-key.pem"); - sprintf(client_cert, "./ssl-cert/client-cert.pem"); - sprintf(ca, "./ssl-cert/ca.pem"); - } - else - { - sprintf(client_key, "%s/ssl-cert/client-key.pem", test_dir); - sprintf(client_cert, "%s/ssl-cert/client-cert.pem", test_dir); - sprintf(ca, "%s/ssl-cert/ca.pem", test_dir); - } + sprintf(client_key, "%s/ssl-cert/client-key.pem", test_dir); + sprintf(client_cert, "%s/ssl-cert/client-cert.pem", test_dir); + sprintf(ca, "%s/ssl-cert/ca.pem", test_dir); + return mysql_ssl_set(conn, client_key, client_cert, ca, NULL, NULL); } diff --git a/maxscale-system-test/mariadb_tests_hartmut.sh b/maxscale-system-test/mariadb_tests_hartmut.sh index a456d6917..f23c46ce5 100755 --- a/maxscale-system-test/mariadb_tests_hartmut.sh +++ b/maxscale-system-test/mariadb_tests_hartmut.sh @@ -4,15 +4,20 @@ # # TODO: Don't test correctness of routing with mysqltest # +rp=`realpath $0` +export src_dir=`dirname $rp` + +# TODO: Don't copy this and "unmangle" the test instead +cp -r $src_dir/Hartmut_tests/maxscale-mysqltest ./Hartmut_tests/maxscale-mysqltest/ master_id=`echo "SELECT @@server_id" | mysql -u$node_user -p$node_password -h $node_000_network $ssl_options -P $node_000_port | tail -n1` echo "--disable_query_log" > Hartmut_tests/maxscale-mysqltest/testconf.inc echo "SET @TMASTER_ID=$master_id;" >> Hartmut_tests/maxscale-mysqltest/testconf.inc echo "--enable_query_log" >> Hartmut_tests/maxscale-mysqltest/testconf.inc -./mysqltest_driver.sh $1 Hartmut_tests/maxscale-mysqltest 4006 +$src_dir/mysqltest_driver.sh $1 $PWD/Hartmut_tests/maxscale-mysqltest 4006 ret=$? -./copy_logs.sh $1 +$src_dir/copy_logs.sh $1 exit $ret diff --git a/maxscale-system-test/masking_mysqltest_driver.sh b/maxscale-system-test/masking_mysqltest_driver.sh index 7fbd573a6..b9b12ea00 100755 --- a/maxscale-system-test/masking_mysqltest_driver.sh +++ b/maxscale-system-test/masking_mysqltest_driver.sh @@ -19,7 +19,8 @@ then exit 1 fi -source=masking/$1/masking_rules.json +src_dir=$(dirname $(realpath $0)) +source=$src_dir/masking/$1/masking_rules.json target=$maxscale_access_user@$maxscale_IP:/home/$maxscale_access_user/masking_rules.json if [ $maxscale_IP != "127.0.0.1" ] ; then @@ -55,4 +56,4 @@ fi # [Read Connection Listener Master] in cnf/maxscale.maxscale.cnf.template.$1 port=4008 -./mysqltest_driver.sh $1 ./masking/$1 $port $user $password +$src_dir/mysqltest_driver.sh $1 $src_dir/masking/$1 $port $user $password diff --git a/maxscale-system-test/masking_user.sh b/maxscale-system-test/masking_user.sh index 9f16ccea8..c07d95a2f 100755 --- a/maxscale-system-test/masking_user.sh +++ b/maxscale-system-test/masking_user.sh @@ -17,7 +17,9 @@ then exit 1 fi -source=masking/$1/masking_rules.json +src_dir=$(dirname $(realpath $0)) +echo "src_dir: $src_dir" +source=$src_dir/masking/$1/masking_rules.json target=vagrant@$maxscale_IP:/home/$maxscale_access_user/masking_rules.json if [ $maxscale_IP != "127.0.0.1" ] ; then @@ -37,22 +39,23 @@ echo $source copied to $target test_dir=`pwd` $test_dir/non_native_setup $1 - -cd masking/$1 -[ -d log ] && rm -r log -mkdir log || exit 1 +logdir=log_$1 +[ -d $logdir ] && rm -r $logdir +mkdir $logdir || exit 1 # [Read Connection Listener Master] in cnf/maxscale.maxscale.cnf.template.$1 port=4008 password=skysql +dir="$src_dir/masking/$1" + user=skysql test_name=masking_user mysqltest --host=$maxscale_IP --port=$port \ --user=$user --password=$password \ - --logdir=log \ - --test-file=t/$test_name.test \ - --result-file=r/"$test_name"_"$user".result \ + --logdir=$logdir \ + --test-file=$dir/t/$test_name.test \ + --result-file=$dir/r/"$test_name"_"$user".result \ --silent if [ $? -eq 0 ] then @@ -66,9 +69,9 @@ user=maxskysql test_name=masking_user mysqltest --host=$maxscale_IP --port=$port \ --user=$user --password=$password \ - --logdir=log \ - --test-file=t/$test_name.test \ - --result-file=r/"$test_name"_"$user".result \ + --logdir=$logdir \ + --test-file=$dir/t/$test_name.test \ + --result-file=$dir/r/"$test_name"_"$user".result \ --silent if [ $? -eq 0 ] then @@ -81,6 +84,6 @@ fi echo # Copy logs from the VM -$test_dir/copy_logs.sh $1 +$src_dir/copy_logs.sh $1 exit $res diff --git a/maxscale-system-test/mxs1719.cpp b/maxscale-system-test/mxs1719.cpp index 110a94bc0..9d60ca768 100644 --- a/maxscale-system-test/mxs1719.cpp +++ b/maxscale-system-test/mxs1719.cpp @@ -68,8 +68,10 @@ int main(int argc, char* argv[]) TestConnections::skip_maxscale_start(true); TestConnections test(argc, argv); + std::string src = test_dir; + src += "/mxs1719.json"; - if (test.maxscales->copy_to_node(0, "./mxs1719.json", "/home/vagrant/mxs1719.json") == 0) + if (test.maxscales->copy_to_node(0, src.c_str(), "/home/vagrant/mxs1719.json") == 0) { if (test.maxscales->start() == 0) { diff --git a/maxscale-system-test/mxs791_base.sh b/maxscale-system-test/mxs791_base.sh index f90f40aa7..8f8857c8e 100755 --- a/maxscale-system-test/mxs791_base.sh +++ b/maxscale-system-test/mxs791_base.sh @@ -1,12 +1,14 @@ #!/bin/bash +rp=`realpath $0` +export src_dir=`dirname $rp` $PWD/non_native_setup $test_name if [ $? -ne 0 ] ; then echo "configuring maxscale failed" exit 1 fi -export ssl_options="--ssl-cert=$test_dir/ssl-cert/client-cert.pem --ssl-key=$test_dir/ssl-cert/client-key.pem" +export ssl_options="--ssl-cert=$src_dir/ssl-cert/client-cert.pem --ssl-key=$src_dir/ssl-cert/client-key.pem" res=0 echo "Trying RWSplit" diff --git a/maxscale-system-test/mxs922_listener_ssl.cpp b/maxscale-system-test/mxs922_listener_ssl.cpp index 59e7a527c..252797189 100644 --- a/maxscale-system-test/mxs922_listener_ssl.cpp +++ b/maxscale-system-test/mxs922_listener_ssl.cpp @@ -22,7 +22,7 @@ int main(int argc, char *argv[]) MYSQL *conn = open_conn(test->maxscales->readconn_master_port[0], test->maxscales->IP[0], test->maxscales->user_name, test->maxscales->password, true); - test->add_result(execute_query(conn, "select @@server_id"), "SSL query failed"); + test->add_result(execute_query(conn, "select @@server_id"), "SSL query to readconnroute failed"); mysql_close(conn); test->check_maxscale_processes(0, 1); diff --git a/maxscale-system-test/mysqltest_driver.sh b/maxscale-system-test/mysqltest_driver.sh index 1ad466d57..62fbbd31f 100755 --- a/maxscale-system-test/mysqltest_driver.sh +++ b/maxscale-system-test/mysqltest_driver.sh @@ -36,26 +36,24 @@ fi test_dir=`pwd` port=$3 -cd $2 || exit 1 - res=0 # Create a directory for the mysqltest logs -[ -d log ] && rm -r log -mkdir log || exit 1 +[ -d log_$1 ] && rm -r log_$1 +mkdir log_$1 echo # Run the test -for t in `cd t; ls *.test` +for t in `$2/t/*.test|xargs -L 1 basename` do printf "$t:" test_name=${t%%.test} mysqltest --host=$maxscale_IP --port=$port \ --user=$user --password=$password \ - --logdir=log \ - --test-file=t/$test_name.test \ - --result-file=r/$test_name.result \ + --logdir=log_$1 \ + --test-file=$2/t/$test_name.test \ + --result-file=$2/r/$test_name.result \ --silent if [ $? -eq 0 ] @@ -70,6 +68,6 @@ done echo # Copy logs from the VM -$test_dir/copy_logs.sh $1 +$src_dir/copy_logs.sh $1 exit $res diff --git a/maxscale-system-test/run_ctrl_c.sh b/maxscale-system-test/run_ctrl_c.sh index f1504c9ec..47377069f 100755 --- a/maxscale-system-test/run_ctrl_c.sh +++ b/maxscale-system-test/run_ctrl_c.sh @@ -5,6 +5,7 @@ ## check that Maxscale is reacting correctly on ctrc+c signal and termination does not take ages rp=`realpath $0` +export src_dir=`dirname $rp` export test_dir=`pwd` export test_name=`basename $rp` @@ -20,12 +21,12 @@ if [ $? -ne 0 ] ; then exit 1 fi -scp -i $maxscale_sshkey -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -r $test_dir/test_ctrl_c/* $maxscale_access_user@$maxscale_IP:./ +scp -i $maxscale_sshkey -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -r $src_dir/test_ctrl_c/* $maxscale_access_user@$maxscale_IP:./ ssh -i $maxscale_sshkey -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $maxscale_access_user@$maxscale_IP "export maxscale_access_sudo=$maxscale_access_sudo; ./test_ctrl_c.sh" res=$? ssh -i $maxscale_sshkey -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $maxscale_access_user@$maxscale_IP "sudo rm -f /tmp/maxadmin.sock" -$test_dir/copy_logs.sh run_ctrl_c +$src_dir/copy_logs.sh run_ctrl_c exit $res diff --git a/maxscale-system-test/run_session_hang.sh b/maxscale-system-test/run_session_hang.sh index 236455134..e5e848b5d 100755 --- a/maxscale-system-test/run_session_hang.sh +++ b/maxscale-system-test/run_session_hang.sh @@ -5,6 +5,7 @@ ## run a set of queries in the loop (see setmix.sql) using Perl client rp=`realpath $0` +export src_dir=`dirname $rp` export test_dir=`pwd` export test_name=`basename $rp` @@ -15,7 +16,7 @@ then echo "configuring maxscale failed" exit 1 fi -export ssl_options="--ssl-cert=$test_dir/ssl-cert/client-cert.pem --ssl-key=$test_dir/ssl-cert/client-key.pem" +export ssl_options="--ssl-cert=$src_dir/ssl-cert/client-cert.pem --ssl-key=$src_dir/ssl-cert/client-key.pem" echo "drop table if exists t1; create table t1(id integer primary key); " | mysql -u$node_user -p$node_password -h$maxscale_IP -P 4006 $ssl_options test @@ -27,8 +28,8 @@ fi res=0 -$test_dir/session_hang/run_setmix.sh & -perl $test_dir/session_hang/simpletest.pl +$src_dir/session_hang/run_setmix.sh & +perl $src_dir/session_hang/simpletest.pl if [ $? -ne 0 ] then res=1 @@ -52,6 +53,6 @@ else echo "Test PASSED" fi -$test_dir/copy_logs.sh run_session_hang +$src_dir/copy_logs.sh run_session_hang exit $res