Add variadic ssh function to mariadb_nodes

The ssh_node function now supports printf style arguments. This is used to
simplify command execution on the nodes.

Curreltny, in addition to its old usage, it is used to drop extra
databases when replication is started.
This commit is contained in:
Markus Mäkelä
2017-10-01 10:49:11 +03:00
parent 69557c650e
commit af08647fa2
10 changed files with 208 additions and 228 deletions

View File

@ -88,14 +88,11 @@ int main(int argc, char *argv[])
Test->repl->sync_slaves(); Test->repl->sync_slaves();
Test->set_timeout(200); Test->set_timeout(200);
sprintf(str, "%s rm -f /tmp/t*.csv; %s chmod 777 /tmp", Test->repl->access_sudo[0],
Test->repl->access_sudo[0]);
Test->tprintf("%s\n", str);
for (int k = 0; k < Test->repl->N; k++) for (int k = 0; k < Test->repl->N; k++)
{ {
Test->repl->ssh_node(k, str, false); Test->repl->ssh_node(k, false, "%s rm -f /tmp/t*.csv; %s chmod 777 /tmp",
Test->repl->access_sudo[0], Test->repl->access_sudo[0]);
} }
//system(str);
Test->tprintf("Copying data from t1 to file...\n"); Test->tprintf("Copying data from t1 to file...\n");
Test->tprintf("using RWSplit: SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1;\n"); Test->tprintf("using RWSplit: SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1;\n");

View File

@ -32,13 +32,12 @@ int main(int argc, char *argv[])
sprintf(str, "%s/krb5.conf", test_dir); sprintf(str, "%s/krb5.conf", test_dir);
for (i = 0; i < Test->repl->N; i++) for (i = 0; i < Test->repl->N; i++)
{ {
Test->repl->ssh_node(i, (char *) Test->repl->ssh_node(i, true, "yum install -y MariaDB-gssapi-server MariaDB-gssapi-client krb5-workstation pam_krb5");
"yum install -y MariaDB-gssapi-server MariaDB-gssapi-client krb5-workstation pam_krb5", true);
Test->repl->copy_to_node(str, (char *) "~/", i); Test->repl->copy_to_node(str, (char *) "~/", i);
Test->repl->ssh_node(i, (char *) "cp ~/krb5.conf /etc/", true); Test->repl->ssh_node(i, true, "cp ~/krb5.conf /etc/");
Test->repl->copy_to_node((char *) "hosts", (char *) "~/", i); Test->repl->copy_to_node((char *) "hosts", (char *) "~/", i);
Test->repl->ssh_node(i, (char *) "cp ~/hosts /etc/", true); Test->repl->ssh_node(i, true, "cp ~/hosts /etc/");
} }
Test->tprintf("Copying 'hosts' and krb5.conf files to Maxscale node\n"); Test->tprintf("Copying 'hosts' and krb5.conf files to Maxscale node\n");
@ -96,12 +95,12 @@ int main(int argc, char *argv[])
{ {
sprintf(str, "%s/kerb.cnf", test_dir); sprintf(str, "%s/kerb.cnf", test_dir);
Test->repl->copy_to_node(str, (char *) "~/", i); Test->repl->copy_to_node(str, (char *) "~/", i);
Test->repl->ssh_node(i, (char *) "cp ~/kerb.cnf /etc/my.cnf.d/", true); Test->repl->ssh_node(i, true, "cp ~/kerb.cnf /etc/my.cnf.d/");
Test->repl->copy_to_node((char *) "krb5.keytab", (char *) "~/", i); Test->repl->copy_to_node((char *) "krb5.keytab", (char *) "~/", i);
Test->repl->ssh_node(i, (char *) "cp ~/krb5.keytab /etc/", true); Test->repl->ssh_node(i, true, "cp ~/krb5.keytab /etc/");
Test->repl->ssh_node(i, (char *) "kinit mariadb/maxscale.test@MAXSCALE.TEST -k -t /etc/krb5.keytab", false); Test->repl->ssh_node(i, false, "kinit mariadb/maxscale.test@MAXSCALE.TEST -k -t /etc/krb5.keytab");
} }
Test->tprintf("Installing gssapi plugin to all nodes\n"); Test->tprintf("Installing gssapi plugin to all nodes\n");
@ -118,18 +117,18 @@ int main(int argc, char *argv[])
Test->tprintf("Trying use usr1 to execute query: RW Split\n"); Test->tprintf("Trying use usr1 to execute query: RW Split\n");
Test->add_result( Test->add_result(
Test->repl->ssh_node(1, Test->repl->ssh_node(1, false,
"echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4006", false), "echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4006"),
"Error executing query against RW Split\n"); "Error executing query against RW Split\n");
Test->tprintf("Trying use usr1 to execute query: Read Connection Master\n"); Test->tprintf("Trying use usr1 to execute query: Read Connection Master\n");
Test->add_result( Test->add_result(
Test->repl->ssh_node(1, Test->repl->ssh_node(1, false,
"echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4008", false), "echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4008"),
"Error executing query against Read Connection Master\n"); "Error executing query against Read Connection Master\n");
Test->tprintf("Trying use usr1 to execute query: Read Connection Slave\n"); Test->tprintf("Trying use usr1 to execute query: Read Connection Slave\n");
Test->add_result( Test->add_result(
Test->repl->ssh_node(1, Test->repl->ssh_node(1, false,
"echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4009", false), "echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4009"),
"Error executing query against Read Connection Slave\n"); "Error executing query against Read Connection Slave\n");
int rval = Test->global_result; int rval = Test->global_result;

View File

@ -456,7 +456,7 @@ int execute_query_count_rows(MYSQL *conn, const char *sql)
return rval; return rval;
} }
int get_conn_num(MYSQL *conn, char * ip, char *hostname, char * db) int get_conn_num(MYSQL *conn, const char* ip, const char* hostname, const char* db)
{ {
MYSQL_RES *res; MYSQL_RES *res;
MYSQL_ROW row; MYSQL_ROW row;
@ -584,16 +584,16 @@ unsigned int get_seconds_behind_master(MYSQL *conn)
char SBM_str[16]; char SBM_str[16];
unsigned int SBM = 0; unsigned int SBM = 0;
if (find_field( if (find_field(
conn, (char *) "show slave status;", conn, (char *) "show slave status;",
(char *) "Seconds_Behind_Master", &SBM_str[0] (char *) "Seconds_Behind_Master", &SBM_str[0]
) != 1) ) != 1)
{ {
sscanf(SBM_str, "%u", &SBM); sscanf(SBM_str, "%u", &SBM);
} }
return SBM; return SBM;
} }
int read_log(char * name, char ** err_log_content_p) int read_log(const char* name, char ** err_log_content_p)
{ {
FILE *f; FILE *f;
*err_log_content_p = NULL; *err_log_content_p = NULL;

View File

@ -200,7 +200,7 @@ int execute_query_check_one(MYSQL *conn, const char *sql, const char *expected);
* @param db name of DB to which connections are counted * @param db name of DB to which connections are counted
* @return number of connections * @return number of connections
*/ */
int get_conn_num(MYSQL *conn, char * ip, char * hostname, char * db); int get_conn_num(MYSQL *conn, const char* ip, const char* hostname, const char* db);
/** /**
* @brief Find given filed in the SQL query reply * @brief Find given filed in the SQL query reply
@ -227,7 +227,7 @@ unsigned int get_seconds_behind_master(MYSQL *conn);
* @param err_log_content pointer to the buffer to store log file content * @param err_log_content pointer to the buffer to store log file content
* @return 0 in case of success, 1 in case of error * @return 0 in case of success, 1 in case of error
*/ */
int read_log(char * name, char **err_log_content_p); int read_log(const char* name, char **err_log_content_p);
int get_int_version(const std::string& version); int get_int_version(const std::string& version);
int get_int_version(const char* version); int get_int_version(const char* version);

View File

@ -17,7 +17,7 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
Mariadb_nodes::Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose): Mariadb_nodes::Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose) :
v51(false), use_ipv6(false) v51(false), use_ipv6(false)
{ {
strcpy(prefix, pref); strcpy(prefix, pref);
@ -119,7 +119,7 @@ int Mariadb_nodes::read_env()
ssl = false; ssl = false;
sprintf(env_name, "%s_ssl", prefix); sprintf(env_name, "%s_ssl", prefix);
env = getenv(env_name); env = getenv(env_name);
if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0) )) if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
{ {
ssl = true; ssl = true;
} }
@ -290,9 +290,9 @@ int Mariadb_nodes::find_master()
while ((found == 0) && (i < N)) while ((found == 0) && (i < N))
{ {
if (find_field( if (find_field(
nodes[i], (char *) "show slave status;", nodes[i], "show slave status;",
(char *) "Master_Host", &str[0] "Master_Host", &str[0]
) == 0 ) ) == 0)
{ {
found = 1; found = 1;
strcpy(master_IP, str); strcpy(master_IP, str);
@ -328,13 +328,13 @@ int Mariadb_nodes::change_master(int NewMaster, int OldMaster)
{ {
if (i != OldMaster) if (i != OldMaster)
{ {
execute_query(nodes[i], (char *) "stop slave;"); execute_query(nodes[i], "stop slave;");
} }
} }
execute_query(nodes[NewMaster], create_repl_user); execute_query(nodes[NewMaster], create_repl_user);
execute_query(nodes[OldMaster], (char *) "reset master;"); execute_query(nodes[OldMaster], "reset master;");
find_field(nodes[NewMaster], (char *) "show master status", (char *) "File", &log_file[0]); find_field(nodes[NewMaster], "show master status", "File", &log_file[0]);
find_field(nodes[NewMaster], (char *) "show master status", (char *) "Position", &log_pos[0]); find_field(nodes[NewMaster], "show master status", "Position", &log_pos[0]);
for (i = 0; i < N; i++) for (i = 0; i < N; i++)
{ {
if (i != NewMaster) if (i != NewMaster)
@ -343,15 +343,15 @@ int Mariadb_nodes::change_master(int NewMaster, int OldMaster)
execute_query(nodes[i], str); execute_query(nodes[i], str);
} }
} }
//for (i = 0; i < N; i++) {if (i != NewMaster) {execute_query(nodes[i], (char *) "start slave;"); }} //for (i = 0; i < N; i++) {if (i != NewMaster) {execute_query(nodes[i], "start slave;"); }}
} }
int Mariadb_nodes::stop_node(int node) int Mariadb_nodes::stop_node(int node)
{ {
return ssh_node(node, stop_db_command[node], true); return ssh_node(node, true, stop_db_command[node]);
} }
int Mariadb_nodes::start_node(int node, char * param) int Mariadb_nodes::start_node(int node, const char* param)
{ {
char cmd[1024]; char cmd[1024];
if (v51) if (v51)
@ -362,7 +362,7 @@ int Mariadb_nodes::start_node(int node, char * param)
{ {
sprintf(cmd, "%s %s", start_db_command[node], param); sprintf(cmd, "%s %s", start_db_command[node], param);
} }
return ssh_node(node, cmd, true); return ssh_node(node, true, cmd);
} }
int Mariadb_nodes::stop_nodes() int Mariadb_nodes::stop_nodes()
@ -374,7 +374,7 @@ int Mariadb_nodes::stop_nodes()
{ {
printf("Stopping node %d\n", i); printf("Stopping node %d\n", i);
fflush(stdout); fflush(stdout);
local_result += execute_query(nodes[i], (char *) "stop slave;"); local_result += execute_query(nodes[i], "stop slave;");
fflush(stdout); fflush(stdout);
local_result += stop_node(i); local_result += stop_node(i);
fflush(stdout); fflush(stdout);
@ -391,7 +391,7 @@ int Mariadb_nodes::stop_slaves()
{ {
printf("Stopping slave %d\n", i); printf("Stopping slave %d\n", i);
fflush(stdout); fflush(stdout);
global_result += execute_query(nodes[i], (char *) "stop slave;"); global_result += execute_query(nodes[i], "stop slave;");
} }
close_connections(); close_connections();
return global_result; return global_result;
@ -399,7 +399,7 @@ int Mariadb_nodes::stop_slaves()
int Mariadb_nodes::cleanup_db_node(int node) int Mariadb_nodes::cleanup_db_node(int node)
{ {
return ssh_node(node, cleanup_db_command[node], true); return ssh_node(node, true, cleanup_db_command[node]);
} }
int Mariadb_nodes::cleanup_db_nodes() int Mariadb_nodes::cleanup_db_nodes()
@ -417,8 +417,6 @@ int Mariadb_nodes::cleanup_db_nodes()
return local_result; return local_result;
} }
int Mariadb_nodes::start_replication() int Mariadb_nodes::start_replication()
{ {
char str[1024]; char str[1024];
@ -428,27 +426,27 @@ int Mariadb_nodes::start_replication()
// Start all nodes // Start all nodes
for (int i = 0; i < N; i++) for (int i = 0; i < N; i++)
{ {
local_result += start_node(i, (char *) ""); local_result += start_node(i, "");
sprintf(str, ssh_node(i, true,
"mysql -u root %s -e \"STOP SLAVE; RESET SLAVE; RESET SLAVE ALL; RESET MASTER; SET GLOBAL read_only=OFF;\"", "mysql -u root %s -e \"STOP SLAVE; RESET SLAVE; RESET SLAVE ALL; RESET MASTER; SET GLOBAL read_only=OFF;\"",
socket_cmd[i]); socket_cmd[i]);
ssh_node(i, str, true); ssh_node(i, true, "sudo rm -f /etc/my.cnf.d/kerb.cnf");
ssh_node(i, "sudo rm -f /etc/my.cnf.d/kerb.cnf", true); ssh_node(i, true,
"for i in `mysql -ss -u root %s -e \"SHOW DATABASES\"|grep -iv 'mysql\\|information_schema\\|performance_schema'`; "
"do mysql -u root %s -e \"DROP DATABASE $i\";"
"done", socket_cmd[i], socket_cmd[i]);
} }
sprintf(str, "%s/create_user.sh", test_dir); sprintf(str, "%s/create_user.sh", test_dir);
sprintf(dtr, "%s", access_homedir[0]); sprintf(dtr, "%s", access_homedir[0]);
copy_to_node(str, dtr , 0); copy_to_node(str, dtr, 0);
sprintf(str, "export node_user=\"%s\"; export node_password=\"%s\"; %s/create_user.sh %s", ssh_node(0, false, "export node_user=\"%s\"; export node_password=\"%s\"; %s/create_user.sh %s",
user_name, password, access_homedir[0], socket_cmd[0]); user_name, password, access_homedir[0], socket_cmd[0]);
printf("cmd: %s\n", str);
ssh_node(0, str, false);
// Create a database dump from the master and distribute it to the slaves // Create a database dump from the master and distribute it to the slaves
sprintf(str, ssh_node(0, true, "mysql -u root %s -e \"CREATE DATABASE test\"; "
"mysqldump --all-databases --add-drop-database --flush-privileges --master-data=1 --gtid %s > /tmp/master_backup.sql", "mysqldump --all-databases --add-drop-database --flush-privileges --master-data=1 --gtid %s > /tmp/master_backup.sql",
socket_cmd[0]); socket_cmd[0], socket_cmd[0]);
ssh_node(0, str, true);
sprintf(str, "%s/master_backup.sql", test_dir); sprintf(str, "%s/master_backup.sql", test_dir);
copy_from_node("/tmp/master_backup.sql", str, 0); copy_from_node("/tmp/master_backup.sql", str, 0);
@ -458,16 +456,11 @@ int Mariadb_nodes::start_replication()
printf("Starting node %d\n", i); printf("Starting node %d\n", i);
fflush(stdout); fflush(stdout);
copy_to_node(str, "/tmp/master_backup.sql", i); copy_to_node(str, "/tmp/master_backup.sql", i);
sprintf(dtr, ssh_node(i, true, "mysql -u root %s < /tmp/master_backup.sql",
"mysql -u root %s < /tmp/master_backup.sql", socket_cmd[i]);
socket_cmd[i]); ssh_node(i, true, "mysql -u root %s -e \"CHANGE MASTER TO MASTER_HOST=\\\"%s\\\", MASTER_PORT=%d, "
ssh_node(i, dtr, true); "MASTER_USER=\\\"repl\\\", MASTER_PASSWORD=\\\"repl\\\";"
char query[512]; "START SLAVE;\"", socket_cmd[i], IP_private[0], port[0]);
sprintf(query, "mysql -u root %s -e \"CHANGE MASTER TO MASTER_HOST=\\\"%s\\\", MASTER_PORT=%d, "
"MASTER_USER=\\\"repl\\\", MASTER_PASSWORD=\\\"repl\\\";"
"START SLAVE;\"", socket_cmd[i], IP_private[0], port[0]);
ssh_node(i, query, true);
} }
return local_result; return local_result;
@ -482,39 +475,30 @@ int Galera_nodes::start_galera()
local_result += stop_nodes(); local_result += stop_nodes();
// Remove the grastate.dat file // Remove the grastate.dat file
ssh_node(0, "rm -f /var/lib/mysql/grastate.dat", true); ssh_node(0, true, "rm -f /var/lib/mysql/grastate.dat");
printf("Starting new Galera cluster\n"); printf("Starting new Galera cluster\n");
fflush(stdout); fflush(stdout);
ssh_node(0, "echo [mysqld] > cluster_address.cnf", false); ssh_node(0, false, "echo [mysqld] > cluster_address.cnf");
ssh_node(0, "echo wsrep_cluster_address=gcomm:// >> cluster_address.cnf", false); ssh_node(0, false, "echo wsrep_cluster_address=gcomm:// >> cluster_address.cnf");
ssh_node(0, "cp cluster_address.cnf /etc/my.cnf.d/", true); ssh_node(0, true, "cp cluster_address.cnf /etc/my.cnf.d/");
local_result += start_node(0, (char *) " --wsrep-cluster-address=gcomm://"); local_result += start_node(0, " --wsrep-cluster-address=gcomm://");
sprintf(str, "%s/create_user_galera.sh", test_dir); sprintf(str, "%s/create_user_galera.sh", test_dir);
copy_to_node(str, "~/", 0); copy_to_node(str, "~/", 0);
sprintf(str, "export galera_user=\"%s\"; export galera_password=\"%s\"; ./create_user_galera.sh %s", user_name, ssh_node(0, false, "export galera_user=\"%s\"; export galera_password=\"%s\"; ./create_user_galera.sh %s",
password, socket_cmd[0]); user_name,
ssh_node(0, str, false); password, socket_cmd[0]);
for (i = 1; i < N; i++) for (i = 1; i < N; i++)
{ {
printf("Starting node %d\n", i); printf("Starting node %d\n", i);
fflush(stdout); ssh_node(i, true, "echo [mysqld] > cluster_address.cnf");
ssh_node(i, "echo [mysqld] > cluster_address.cnf", true); ssh_node(i, true, "echo wsrep_cluster_address=gcomm://%s >> cluster_address.cnf", IP_private[0]);
sprintf(str, "echo wsrep_cluster_address=gcomm://%s >> cluster_address.cnf", IP_private[0]); ssh_node(i, true, "cp cluster_address.cnf /etc/my.cnf.d/");
ssh_node(i, str, true); sprintf(str, " --wsrep-cluster-address=gcomm://%s", IP_private[0]);
ssh_node(i, "cp cluster_address.cnf /etc/my.cnf.d/", true); local_result += start_node(i, str);
sprintf(&sys1[0], " --wsrep-cluster-address=gcomm://%s", IP_private[0]);
if (this->verbose)
{
printf("%s\n", sys1);
fflush(stdout);
}
local_result += start_node(i, sys1);
fflush(stdout);
} }
sleep(5); sleep(5);
@ -527,44 +511,30 @@ int Galera_nodes::start_galera()
int Mariadb_nodes::clean_iptables(int node) int Mariadb_nodes::clean_iptables(int node)
{ {
char sys1[1024];
int local_result = 0; int local_result = 0;
local_result += ssh_node(node, (char *) "echo \"#!/bin/bash\" > clean_iptables.sh", false); local_result += ssh_node(node, false, "echo \"#!/bin/bash\" > clean_iptables.sh");
sprintf(sys1, local_result += ssh_node(node, false,
"echo \"while [ \\\"\\$(iptables -n -L INPUT 1|grep '%d')\\\" != \\\"\\\" ]; do iptables -D INPUT 1; done\" >> clean_iptables.sh", "echo \"while [ \\\"\\$(iptables -n -L INPUT 1|grep '%d')\\\" != \\\"\\\" ]; "
port[node]); "do iptables -D INPUT 1; done\" >> clean_iptables.sh",
local_result += ssh_node(node, (char *) sys1, false); port[node]);
sprintf(sys1, local_result += ssh_node(node, false,
"echo \"while [ \\\"\\$(ip6tables -n -L INPUT 1|grep '%d')\\\" != \\\"\\\" ]; do ip6tables -D INPUT 1; done\" >> clean_iptables.sh", "echo \"while [ \\\"\\$(ip6tables -n -L INPUT 1|grep '%d')\\\" != \\\"\\\" ]; "
port[node]); "do ip6tables -D INPUT 1; done\" >> clean_iptables.sh",
local_result += ssh_node(node, (char *) sys1, false); port[node]);
local_result += ssh_node(node, (char *) "chmod a+x clean_iptables.sh", false); local_result += ssh_node(node, false, "chmod a+x clean_iptables.sh");
local_result += ssh_node(node, (char *) "./clean_iptables.sh", true); local_result += ssh_node(node, true, "./clean_iptables.sh");
return local_result; return local_result;
} }
int Mariadb_nodes::block_node(int node) int Mariadb_nodes::block_node(int node)
{ {
char sys1[1024];
int local_result = 0; int local_result = 0;
local_result += clean_iptables(node); local_result += clean_iptables(node);
sprintf(&sys1[0], "iptables -I INPUT -p tcp --dport %d -j REJECT", port[node]);
if (this->verbose)
{
printf("%s\n", sys1);
fflush(stdout);
}
local_result += ssh_node(node, sys1, true);
sprintf(&sys1[0], "ip6tables -I INPUT -p tcp --dport %d -j REJECT", port[node]); local_result += ssh_node(node, true, "iptables -I INPUT -p tcp --dport %d -j REJECT", port[node]);
if (this->verbose) local_result += ssh_node(node, true, "ip6tables -I INPUT -p tcp --dport %d -j REJECT", port[node]);
{
printf("%s\n", sys1);
fflush(stdout);
}
local_result += ssh_node(node, sys1, true);
blocked[node] = true; blocked[node] = true;
return local_result; return local_result;
@ -572,29 +542,16 @@ int Mariadb_nodes::block_node(int node)
int Mariadb_nodes::unblock_node(int node) int Mariadb_nodes::unblock_node(int node)
{ {
char sys1[1024];
int local_result = 0; int local_result = 0;
local_result += clean_iptables(node); local_result += clean_iptables(node);
sprintf(&sys1[0], "iptables -I INPUT -p tcp --dport %d -j ACCEPT", port[node]);
if (this->verbose) local_result += ssh_node(node, true, "iptables -I INPUT -p tcp --dport %d -j ACCEPT", port[node]);
{ local_result += ssh_node(node, true, "ip6tables -I INPUT -p tcp --dport %d -j ACCEPT", port[node]);
printf("%s\n", sys1);
fflush(stdout);
}
local_result += ssh_node(node, sys1, true);
sprintf(&sys1[0], "ip6tables -I INPUT -p tcp --dport %d -j ACCEPT", port[node]);
if (this->verbose)
{
printf("%s\n", sys1);
fflush(stdout);
}
local_result += ssh_node(node, sys1, true);
blocked[node] = false; blocked[node] = false;
return local_result; return local_result;
} }
int Mariadb_nodes::unblock_all_nodes() int Mariadb_nodes::unblock_all_nodes()
{ {
int rval = 0; int rval = 0;
@ -611,7 +568,7 @@ int Mariadb_nodes::check_node_ssh(int node)
printf("Checking node %d\n", node); printf("Checking node %d\n", node);
fflush(stdout); fflush(stdout);
if (ssh_node(0, (char *) "ls > /dev/null", false) != 0) if (ssh_node(0, false, "ls > /dev/null") != 0)
{ {
printf("Node %d is not available\n", node); printf("Node %d is not available\n", node);
fflush(stdout); fflush(stdout);
@ -847,7 +804,7 @@ int Galera_nodes::check_galera()
{ {
char str[1024] = ""; char str[1024] = "";
if (find_field(conn, (char *) "SHOW STATUS WHERE Variable_name='wsrep_cluster_size';", (char *) "Value", if (find_field(conn, "SHOW STATUS WHERE Variable_name='wsrep_cluster_size';", "Value",
str) != 0) str) != 0)
{ {
printf("wsrep_cluster_size is not found in SHOW STATUS LIKE 'wsrep%%' results\n"); printf("wsrep_cluster_size is not found in SHOW STATUS LIKE 'wsrep%%' results\n");
@ -907,7 +864,7 @@ int Mariadb_nodes::get_server_id(int index)
int id = -1; int id = -1;
char str[1024]; char str[1024];
if (find_field(this->nodes[index], "SELECT @@server_id", "@@server_id", (char*) str) == 0) if (find_field(this->nodes[index], "SELECT @@server_id", "@@server_id", (char*)str) == 0)
{ {
id = atoi(str); id = atoi(str);
} }
@ -992,19 +949,55 @@ char * Mariadb_nodes::ssh_node_output(int node, const char *ssh, bool sudo, int
return result; return result;
} }
int Mariadb_nodes::ssh_node(int node, const char *ssh, bool sudo) int Mariadb_nodes::ssh_node(int node, bool sudo, const char *format, ...)
{ {
char sys[strlen(ssh) + 1024]; va_list valist;
generate_ssh_cmd(sys, node, ssh, sudo);
int return_code = system(sys); va_start(valist, format);
if (WIFEXITED(return_code)) int message_len = vsnprintf(NULL, 0, format, valist);
va_end(valist);
if (message_len < 0)
{ {
return WEXITSTATUS(return_code); return -1;
}
char *sys = (char*)malloc(message_len + 1);
va_start(valist, format);
vsnprintf(sys, message_len + 1, format, valist);
va_end(valist);
char *cmd = (char*)malloc(message_len + 1024);
if (strcmp(IP[node], "127.0.0.1") == 0)
{
sprintf(cmd, "bash");
} }
else else
{ {
return 256; sprintf(cmd,
"ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s > /dev/null",
sshkey[node], access_user[node], IP[node]);
} }
int rc = 1;
FILE *in = popen(cmd, "w");
if (in)
{
if (sudo)
{
fprintf(in, "sudo su -\n");
fprintf(in, "cd /home/%s\n", access_user[node]);
}
fprintf(in, "%s\n", sys);
rc = pclose(in);
}
free(sys);
free(cmd);
return rc;
} }
int Mariadb_nodes::flush_hosts() int Mariadb_nodes::flush_hosts()
@ -1029,7 +1022,8 @@ int Mariadb_nodes::flush_hosts()
local_result++; local_result++;
} }
if (mysql_query(nodes[i], "SELECT CONCAT('\\'', user, '\\'@\\'', host, '\\'') FROM mysql.user WHERE user = ''") == 0) if (mysql_query(nodes[i],
"SELECT CONCAT('\\'', user, '\\'@\\'', host, '\\'') FROM mysql.user WHERE user = ''") == 0)
{ {
MYSQL_RES *res = mysql_store_result(nodes[i]); MYSQL_RES *res = mysql_store_result(nodes[i]);
@ -1049,7 +1043,7 @@ int Mariadb_nodes::flush_hosts()
{ {
printf("Detected anonymous users, dropping them.\n"); printf("Detected anonymous users, dropping them.\n");
for (auto& s: users) for (auto& s : users)
{ {
std::string query = "DROP USER "; std::string query = "DROP USER ";
query += s; query += s;
@ -1089,7 +1083,7 @@ int Mariadb_nodes::get_versions()
for (int i = 0; i < N; i++) for (int i = 0; i < N; i++)
{ {
if ((local_result += find_field(nodes[i], (char *) "SELECT @@version", (char *) "@@version", version[i]))) if ((local_result += find_field(nodes[i], "SELECT @@version", "@@version", version[i])))
{ {
printf("Failed to get version: %s\n", mysql_error(nodes[i])); printf("Failed to get version: %s\n", mysql_error(nodes[i]));
} }
@ -1100,11 +1094,11 @@ int Mariadb_nodes::get_versions()
str[0] = 0; str[0] = 0;
} }
strcpy(version_major[i], version_number[i]); strcpy(version_major[i], version_number[i]);
if (strstr(version_major[i], "5.") == version_major[i]) if (strstr(version_major[i], "5.") == version_major[i])
{ {
version_major[i][3] = 0; version_major[i][3] = 0;
} }
if (strstr(version_major[i], "10.") == version_major[i]) if (strstr(version_major[i], "10.") == version_major[i])
{ {
version_major[i][4] = 0; version_major[i][4] = 0;
} }
@ -1153,7 +1147,7 @@ int Mariadb_nodes::truncate_mariadb_logs()
for (int node = 0; node < N; node++) for (int node = 0; node < N; node++)
{ {
char sys[1024]; char sys[1024];
if (strcmp(IP[node], "127.0.0.1") !=0) if (strcmp(IP[node], "127.0.0.1") != 0)
{ {
sprintf(sys, sprintf(sys,
"ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s 'sudo truncate /var/lib/mysql/*.err --size 0;sudo rm -f /etc/my.cnf.d/binlog_enc*\' &", "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s 'sudo truncate /var/lib/mysql/*.err --size 0;sudo rm -f /etc/my.cnf.d/binlog_enc*\' &",
@ -1176,13 +1170,13 @@ int Mariadb_nodes::configure_ssl(bool require)
printf("Node %d\n", i); printf("Node %d\n", i);
stop_node(i); stop_node(i);
sprintf(str, "%s/ssl-cert", test_dir); sprintf(str, "%s/ssl-cert", test_dir);
local_result += copy_to_node(str, (char *) "~/", i); local_result += copy_to_node(str, "~/", i);
sprintf(str, "%s/ssl.cnf", test_dir); sprintf(str, "%s/ssl.cnf", test_dir);
local_result += copy_to_node(str, (char *) "~/", i); local_result += copy_to_node(str, "~/", i);
local_result += ssh_node(i, (char *) "cp ~/ssl.cnf /etc/my.cnf.d/", true); local_result += ssh_node(i, true, "cp ~/ssl.cnf /etc/my.cnf.d/");
local_result += ssh_node(i, (char *) "cp -r ~/ssl-cert /etc/", true); local_result += ssh_node(i, true, "cp -r ~/ssl-cert /etc/");
local_result += ssh_node(i, (char *) "chown mysql:mysql -R /etc/ssl-cert", true); local_result += ssh_node(i, true, "chown mysql:mysql -R /etc/ssl-cert");
start_node(i, (char *) ""); start_node(i, "");
} }
if (require) if (require)
@ -1190,14 +1184,9 @@ int Mariadb_nodes::configure_ssl(bool require)
// Create DB user on first node // Create DB user on first node
printf("Set user to require ssl: %s\n", str); printf("Set user to require ssl: %s\n", str);
sprintf(str, "%s/create_user_ssl.sh", test_dir); sprintf(str, "%s/create_user_ssl.sh", test_dir);
copy_to_node(str, (char *) "~/", 0); copy_to_node(str, "~/", 0);
ssh_node(0, false, "export node_user=\"%s\"; export node_password=\"%s\"; "
sprintf(str, "export node_user=\"%s\"; export node_password=\"%s\"; ./create_user_ssl.sh %s", "./create_user_ssl.sh %s", user_name, password, socket_cmd[0]);
user_name,
password,
socket_cmd[0]);
printf("cmd: %s\n", str);
ssh_node(0, str, false);
} }
return local_result; return local_result;
@ -1211,14 +1200,14 @@ int Mariadb_nodes::disable_ssl()
local_result += connect(); local_result += connect();
sprintf(str, "DROP USER %s; grant all privileges on *.* to '%s'@'%%' identified by '%s';", user_name, sprintf(str, "DROP USER %s; grant all privileges on *.* to '%s'@'%%' identified by '%s';", user_name,
user_name, password); user_name, password);
local_result += execute_query(nodes[0], (char *) ""); local_result += execute_query(nodes[0], "");
close_connections(); close_connections();
for (int i = 0; i < N; i++) for (int i = 0; i < N; i++)
{ {
stop_node(i); stop_node(i);
local_result += ssh_node(i, (char *) "rm -f /etc/my.cnf.d/ssl.cnf", true); local_result += ssh_node(i, true, "rm -f /etc/my.cnf.d/ssl.cnf");
start_node(i, (char *) ""); start_node(i, "");
} }
return local_result; return local_result;
@ -1240,7 +1229,7 @@ int Mariadb_nodes::copy_to_node(const char* src, const char* dest, int i)
else else
{ {
sprintf(sys, "scp -q -r -i %s -o UserKnownHostsFile=/dev/null " sprintf(sys, "scp -q -r -i %s -o UserKnownHostsFile=/dev/null "
"-o StrictHostKeyChecking=no -o LogLevel=quiet %s %s@%s:%s", "-o StrictHostKeyChecking=no -o LogLevel=quiet %s %s@%s:%s",
sshkey[i], src, access_user[i], IP[i], dest); sshkey[i], src, access_user[i], IP[i], dest);
} }
if (verbose) if (verbose)
@ -1251,7 +1240,6 @@ int Mariadb_nodes::copy_to_node(const char* src, const char* dest, int i)
return system(sys); return system(sys);
} }
int Mariadb_nodes::copy_from_node(const char* src, const char* dest, int i) int Mariadb_nodes::copy_from_node(const char* src, const char* dest, int i)
{ {
if (i >= N) if (i >= N)
@ -1267,7 +1255,7 @@ int Mariadb_nodes::copy_from_node(const char* src, const char* dest, int i)
else else
{ {
sprintf(sys, "scp -q -r -i %s -o UserKnownHostsFile=/dev/null " sprintf(sys, "scp -q -r -i %s -o UserKnownHostsFile=/dev/null "
"-o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s:%s %s", "-o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s:%s %s",
sshkey[i], access_user[i], IP[i], src, dest); sshkey[i], access_user[i], IP[i], src, dest);
} }
if (verbose) if (verbose)

View File

@ -291,7 +291,7 @@ public:
* @param param command line parameters for DB server start command * @param param command line parameters for DB server start command
* @return 0 if success * @return 0 if success
*/ */
int start_node(int node, char * param); int start_node(int node, const char* param);
/** /**
* @brief Check node via ssh and restart it if it is not resposible * @brief Check node via ssh and restart it if it is not resposible
@ -354,11 +354,11 @@ public:
/** /**
* @brief executes shell command on the node using ssh * @brief executes shell command on the node using ssh
* @param index number of the node (index) * @param index number of the node (index)
* @param ssh command to execute
* @param sudo if true the command is executed with root privelegues * @param sudo if true the command is executed with root privelegues
* @return exit code of the coomand * @param ssh command to execute
* @return exit code of the command
*/ */
int ssh_node(int node, const char *ssh, bool sudo); int ssh_node(int node, bool sudo, const char *ssh, ...);
/** /**
* @brief Execute 'mysqladmin flush-hosts' on all nodes * @brief Execute 'mysqladmin flush-hosts' on all nodes

View File

@ -25,7 +25,7 @@ int main(int argc, char *argv[])
for (i = 0; i < Test->repl->N; i++) for (i = 0; i < Test->repl->N; i++)
{ {
Test->set_timeout(30); Test->set_timeout(30);
Test->repl->ssh_node(i, (char *) "touch /tmp/t1.csv", true); Test->repl->ssh_node(i, true, "touch /tmp/t1.csv");
} }
Test->add_result(create_t1(Test->conn_rwsplit), "Error creating t1\n"); Test->add_result(create_t1(Test->conn_rwsplit), "Error creating t1\n");
@ -42,7 +42,7 @@ int main(int argc, char *argv[])
for (i = 0; i < Test->repl->N; i++) for (i = 0; i < Test->repl->N; i++)
{ {
Test->set_timeout(30); Test->set_timeout(30);
Test->repl->ssh_node(i, (char *) "rm -rf /tmp/t1.csv", true); Test->repl->ssh_node(i, true, "rm -rf /tmp/t1.csv");
} }
Test->set_timeout(30); Test->set_timeout(30);

View File

@ -28,8 +28,8 @@ int main(int argc, char *argv[])
sprintf(cmd, "%s/utf64.cnf", test_dir); sprintf(cmd, "%s/utf64.cnf", test_dir);
for (int i = 0; i < Test->repl->N; i++) for (int i = 0; i < Test->repl->N; i++)
{ {
Test->repl->copy_to_node(cmd, (char *) "./", i); Test->repl->copy_to_node(cmd, "./", i);
Test->repl->ssh_node(i, (char *) "cp ./utf64.cnf /etc/my.cnf.d/", true); Test->repl->ssh_node(i, true, "cp ./utf64.cnf /etc/my.cnf.d/");
} }
Test->repl->start_replication(); Test->repl->start_replication();
@ -55,7 +55,7 @@ int main(int argc, char *argv[])
Test->tprintf("Restore backend configuration\n"); Test->tprintf("Restore backend configuration\n");
for (int i = 0; i < Test->repl->N; i++) for (int i = 0; i < Test->repl->N; i++)
{ {
Test->repl->ssh_node(i, (char *) "rm /etc/my.cnf.d/utf64.cnf", true); Test->repl->ssh_node(i, true, "rm /etc/my.cnf.d/utf64.cnf");
} }
Test->repl->start_replication(); Test->repl->start_replication();

View File

@ -213,7 +213,7 @@ TestConnections::TestConnections(int argc, char *argv[]):
if (use_snapshots) if (use_snapshots)
{ {
snapshot_reverted = revert_snapshot((char *) "clean"); snapshot_reverted = revert_snapshot("clean");
} }
if (!snapshot_reverted && maxscale::check_nodes) if (!snapshot_reverted && maxscale::check_nodes)
@ -602,7 +602,7 @@ void TestConnections::process_template(const char *template_name, const char *de
} }
mdn[j]->connect(); mdn[j]->connect();
execute_query(mdn[j]->nodes[0], (char *) "CREATE DATABASE IF NOT EXISTS test"); execute_query(mdn[j]->nodes[0], "CREATE DATABASE IF NOT EXISTS test");
mdn[j]->close_connections(); mdn[j]->close_connections();
} }
@ -616,7 +616,7 @@ void TestConnections::process_template(const char *template_name, const char *de
{ {
system("sed -i \"s/###repl51###/mysql51_replication=true/g\" maxscale.cnf"); system("sed -i \"s/###repl51###/mysql51_replication=true/g\" maxscale.cnf");
} }
copy_to_maxscale((char *) "maxscale.cnf", (char *) dest); copy_to_maxscale("maxscale.cnf", (char *) dest);
} }
int TestConnections::init_maxscale() int TestConnections::init_maxscale()
@ -711,7 +711,7 @@ int TestConnections::stop_maxscale()
return res; return res;
} }
int TestConnections::copy_mariadb_logs(Mariadb_nodes * repl, char * prefix) int TestConnections::copy_mariadb_logs(Mariadb_nodes * repl, const char* prefix)
{ {
int local_result = 0; int local_result = 0;
char * mariadb_log; char * mariadb_log;
@ -726,7 +726,7 @@ int TestConnections::copy_mariadb_logs(Mariadb_nodes * repl, char * prefix)
{ {
if (strcmp(repl->IP[i], "127.0.0.1") != 0) // Do not copy MariaDB logs in case of local backend if (strcmp(repl->IP[i], "127.0.0.1") != 0) // Do not copy MariaDB logs in case of local backend
{ {
mariadb_log = repl->ssh_node_output(i, (char *) "cat /var/lib/mysql/*.err", true, &exit_code); mariadb_log = repl->ssh_node_output(i, "cat /var/lib/mysql/*.err", true, &exit_code);
sprintf(str, "LOGS/%s/%s%d_mariadb_log", test_name, prefix, i); sprintf(str, "LOGS/%s/%s%d_mariadb_log", test_name, prefix, i);
f = fopen(str, "w"); f = fopen(str, "w");
if (f != NULL) if (f != NULL)
@ -752,8 +752,8 @@ int TestConnections::copy_all_logs()
if (!no_backend_log_copy) if (!no_backend_log_copy)
{ {
copy_mariadb_logs(repl, (char *) "node"); copy_mariadb_logs(repl, "node");
copy_mariadb_logs(galera, (char *) "galera"); copy_mariadb_logs(galera, "galera");
} }
sprintf(str, "%s/copy_logs.sh %s", test_dir, test_name); sprintf(str, "%s/copy_logs.sh %s", test_dir, test_name);
@ -857,9 +857,9 @@ int TestConnections::start_binlog()
repl->stop_nodes(); repl->stop_nodes();
binlog = open_conn_no_db(binlog_port, maxscale_IP, repl->user_name, repl->password, ssl); binlog = open_conn_no_db(binlog_port, maxscale_IP, repl->user_name, repl->password, ssl);
execute_query(binlog, (char *) "stop slave"); execute_query(binlog, "stop slave");
execute_query(binlog, (char *) "reset slave all"); execute_query(binlog, "reset slave all");
execute_query(binlog, (char *) "reset master"); execute_query(binlog, "reset master");
mysql_close(binlog); mysql_close(binlog);
tprintf("Stopping maxscale\n"); tprintf("Stopping maxscale\n");
@ -889,13 +889,13 @@ int TestConnections::start_binlog()
add_result(ssh_maxscale(true, "ls -la %s/", maxscale_binlog_dir), "ls failed\n"); add_result(ssh_maxscale(true, "ls -la %s/", maxscale_binlog_dir), "ls failed\n");
tprintf("show master status\n"); tprintf("show master status\n");
find_field(repl->nodes[0], (char *) "show master status", (char *) "File", &log_file[0]); find_field(repl->nodes[0], "show master status", "File", &log_file[0]);
find_field(repl->nodes[0], (char *) "show master status", (char *) "Position", &log_pos[0]); find_field(repl->nodes[0], "show master status", "Position", &log_pos[0]);
tprintf("Real master file: %s\n", log_file); tprintf("Real master file: %s\n", log_file);
tprintf("Real master pos : %s\n", log_pos); tprintf("Real master pos : %s\n", log_pos);
tprintf("Stopping first slave (node 1)\n"); tprintf("Stopping first slave (node 1)\n");
try_query(repl->nodes[1], (char *) "stop slave;"); try_query(repl->nodes[1], "stop slave;");
//repl->no_set_pos = true; //repl->no_set_pos = true;
repl->no_set_pos = false; repl->no_set_pos = false;
tprintf("Configure first backend slave node to be slave of real master\n"); tprintf("Configure first backend slave node to be slave of real master\n");
@ -931,8 +931,8 @@ int TestConnections::start_binlog()
// get Master status from Maxscale binlog // get Master status from Maxscale binlog
tprintf("show master status\n"); tprintf("show master status\n");
fflush(stdout); fflush(stdout);
find_field(binlog, (char *) "show master status", (char *) "File", &log_file[0]); find_field(binlog, "show master status", "File", &log_file[0]);
find_field(binlog, (char *) "show master status", (char *) "Position", &log_pos[0]); find_field(binlog, "show master status", "Position", &log_pos[0]);
tprintf("Maxscale binlog master file: %s\n", log_file); tprintf("Maxscale binlog master file: %s\n", log_file);
fflush(stdout); fflush(stdout);
@ -943,7 +943,7 @@ int TestConnections::start_binlog()
fflush(stdout); fflush(stdout);
for (i = 2; i < repl->N; i++) for (i = 2; i < repl->N; i++)
{ {
try_query(repl->nodes[i], (char *) "stop slave;"); try_query(repl->nodes[i], "stop slave;");
repl->set_slave(repl->nodes[i], maxscale_IP, binlog_port, log_file, log_pos); repl->set_slave(repl->nodes[i], maxscale_IP, binlog_port, log_file, log_pos);
} }
repl->close_connections(); repl->close_connections();
@ -1012,23 +1012,23 @@ int TestConnections::start_mm()
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
tprintf("Starting back node %d\n", i); tprintf("Starting back node %d\n", i);
global_result += repl->start_node(i, (char *) ""); global_result += repl->start_node(i, "");
} }
repl->connect(); repl->connect();
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
execute_query(repl->nodes[i], (char *) "stop slave"); execute_query(repl->nodes[i], "stop slave");
execute_query(repl->nodes[i], (char *) "reset master"); execute_query(repl->nodes[i], "reset master");
} }
execute_query(repl->nodes[0], (char *) "SET GLOBAL READ_ONLY=ON"); execute_query(repl->nodes[0], "SET GLOBAL READ_ONLY=ON");
find_field(repl->nodes[0], (char *) "show master status", (char *) "File", log_file1); find_field(repl->nodes[0], "show master status", "File", log_file1);
find_field(repl->nodes[0], (char *) "show master status", (char *) "Position", log_pos1); find_field(repl->nodes[0], "show master status", "Position", log_pos1);
find_field(repl->nodes[1], (char *) "show master status", (char *) "File", log_file2); find_field(repl->nodes[1], "show master status", "File", log_file2);
find_field(repl->nodes[1], (char *) "show master status", (char *) "Position", log_pos2); find_field(repl->nodes[1], "show master status", "Position", log_pos2);
repl->set_slave(repl->nodes[0], repl->IP[1], repl->port[1], log_file2, log_pos2); repl->set_slave(repl->nodes[0], repl->IP[1], repl->port[1], log_file2, log_pos2);
repl->set_slave(repl->nodes[1], repl->IP[0], repl->port[0], log_file1, log_pos1); repl->set_slave(repl->nodes[1], repl->IP[0], repl->port[0], log_file1, log_pos1);
@ -1056,11 +1056,11 @@ void TestConnections::check_log_err(const char * err_msg, bool expected)
set_timeout(50); set_timeout(50);
tprintf("Reading maxscale.log\n"); tprintf("Reading maxscale.log\n");
if ( ( read_log((char *) "maxscale.log", &err_log_content) != 0) || (strlen(err_log_content) < 2) ) if ( ( read_log("maxscale.log", &err_log_content) != 0) || (strlen(err_log_content) < 2) )
{ {
tprintf("Reading maxscale1.log\n"); tprintf("Reading maxscale1.log\n");
free(err_log_content); free(err_log_content);
if (read_log((char *) "maxscale1.log", &err_log_content) != 0) if (read_log("maxscale1.log", &err_log_content) != 0)
{ {
add_result(1, "Error reading log\n"); add_result(1, "Error reading log\n");
} }
@ -1103,7 +1103,7 @@ int TestConnections::find_connected_slave(int * global_result)
repl->connect(); repl->connect();
for (int i = 0; i < repl->N; i++) for (int i = 0; i < repl->N; i++)
{ {
conn_num = get_conn_num(repl->nodes[i], maxscale_ip(), maxscale_hostname, (char *) "test"); conn_num = get_conn_num(repl->nodes[i], maxscale_ip(), maxscale_hostname, "test");
tprintf("connections to %d: %u\n", i, conn_num); tprintf("connections to %d: %u\n", i, conn_num);
if ((i == 0) && (conn_num != 1)) if ((i == 0) && (conn_num != 1))
{ {
@ -1134,7 +1134,7 @@ int TestConnections::find_connected_slave1()
repl->connect(); repl->connect();
for (int i = 0; i < repl->N; i++) for (int i = 0; i < repl->N; i++)
{ {
conn_num = get_conn_num(repl->nodes[i], maxscale_ip(), maxscale_hostname, (char *) "test"); conn_num = get_conn_num(repl->nodes[i], maxscale_ip(), maxscale_hostname, "test");
tprintf("connections to %d: %u\n", i, conn_num); tprintf("connections to %d: %u\n", i, conn_num);
all_conn += conn_num; all_conn += conn_num;
if ((i != 0) && (conn_num != 0)) if ((i != 0) && (conn_num != 0))
@ -1183,13 +1183,13 @@ int TestConnections::check_maxscale_alive()
tprintf("Trying simple query against all sevices\n"); tprintf("Trying simple query against all sevices\n");
tprintf("RWSplit \n"); tprintf("RWSplit \n");
set_timeout(10); set_timeout(10);
try_query(conn_rwsplit, (char *) "show databases;"); try_query(conn_rwsplit, "show databases;");
tprintf("ReadConn Master \n"); tprintf("ReadConn Master \n");
set_timeout(10); set_timeout(10);
try_query(conn_master, (char *) "show databases;"); try_query(conn_master, "show databases;");
tprintf("ReadConn Slave \n"); tprintf("ReadConn Slave \n");
set_timeout(10); set_timeout(10);
try_query(conn_slave, (char *) "show databases;"); try_query(conn_slave, "show databases;");
set_timeout(10); set_timeout(10);
close_maxscale_connections() ; close_maxscale_connections() ;
add_result(global_result - gr, "Maxscale is not alive\n"); add_result(global_result - gr, "Maxscale is not alive\n");
@ -1377,7 +1377,7 @@ int TestConnections::copy_to_maxscale(const char* src, const char* dest)
{ {
sprintf(sys, "scp -q -i %s -o UserKnownHostsFile=/dev/null " sprintf(sys, "scp -q -i %s -o UserKnownHostsFile=/dev/null "
"-o StrictHostKeyChecking=no -o LogLevel=quiet %s %s@%s:%s", "-o StrictHostKeyChecking=no -o LogLevel=quiet %s %s@%s:%s",
maxscale_keyfile, src, maxscale_access_user, maxscale_IP, dest); maxscale_keyfile, src, maxscale_access_user, maxscale_IP, dest);
} }
return system(sys); return system(sys);
@ -1395,7 +1395,7 @@ int TestConnections::copy_from_maxscale(char* src, char* dest)
else else
{ {
sprintf(sys, "scp -i %s -o UserKnownHostsFile=/dev/null " sprintf(sys, "scp -i %s -o UserKnownHostsFile=/dev/null "
"-o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s:%s %s", "-o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s:%s %s",
maxscale_keyfile, maxscale_access_user, maxscale_IP, src, dest); maxscale_keyfile, maxscale_access_user, maxscale_IP, src, dest);
} }
return system(sys); return system(sys);
@ -1562,12 +1562,12 @@ int TestConnections::get_client_ip(char * ip)
unsigned int conn_num = 0; unsigned int conn_num = 0;
connect_rwsplit(); connect_rwsplit();
if (execute_query(conn_rwsplit, (char *) "CREATE DATABASE IF NOT EXISTS db_to_check_clent_ip") != 0 ) if (execute_query(conn_rwsplit, "CREATE DATABASE IF NOT EXISTS db_to_check_clent_ip") != 0 )
{ {
return ret; return ret;
} }
close_rwsplit(); close_rwsplit();
conn = open_conn_db(rwsplit_port, maxscale_IP, (char *) "db_to_check_clent_ip", maxscale_user, conn = open_conn_db(rwsplit_port, maxscale_IP, "db_to_check_clent_ip", maxscale_user,
maxscale_password, ssl); maxscale_password, ssl);
if (conn != NULL) if (conn != NULL)
@ -1830,7 +1830,8 @@ int TestConnections::try_query(MYSQL *conn, const char *format, ...)
va_end(valist); va_end(valist);
int res = execute_query1(conn, sql, false); int res = execute_query1(conn, sql, false);
add_result(res, "Query '%.*s%s' failed!\n", message_len < 100 ? message_len : 100, sql, message_len < 100 ? "" : "..."); add_result(res, "Query '%.*s%s' failed!\n", message_len < 100 ? message_len : 100, sql,
message_len < 100 ? "" : "...");
return res; return res;
} }
@ -1851,7 +1852,7 @@ int TestConnections::find_master_maxadmin(Mariadb_nodes * nodes)
char show_server[256]; char show_server[256];
char res[256]; char res[256];
sprintf(show_server, "show server server%d", i + 1); sprintf(show_server, "show server server%d", i + 1);
get_maxadmin_param(show_server, (char *) "Status", res); get_maxadmin_param(show_server, "Status", res);
if (strstr(res, "Master")) if (strstr(res, "Master"))
{ {
@ -1879,7 +1880,7 @@ int TestConnections::find_slave_maxadmin(Mariadb_nodes * nodes)
char show_server[256]; char show_server[256];
char res[256]; char res[256];
sprintf(show_server, "show server server%d", i + 1); sprintf(show_server, "show server server%d", i + 1);
get_maxadmin_param(show_server, (char *) "Status", res); get_maxadmin_param(show_server, "Status", res);
if (strstr(res, "Slave")) if (strstr(res, "Slave"))
{ {
@ -1934,14 +1935,9 @@ int TestConnections::check_maxadmin_param(const char *command, const char *param
return rval; return rval;
} }
int TestConnections::get_maxadmin_param(char *command, char *param, char *result) int TestConnections::get_maxadmin_param(const char* command, const char* param, char* result)
{ {
char * buf; char* buf = ssh_maxscale_output(true, "maxadmin %s", command);
buf = ssh_maxscale_output(true, "maxadmin %s", command);
//printf("%s\n", buf);
char *x = strstr(buf, param); char *x = strstr(buf, param);
if (x == NULL) if (x == NULL)
@ -1981,7 +1977,7 @@ int TestConnections::list_dirs()
for (int i = 0; i < repl->N; i++) for (int i = 0; i < repl->N; i++)
{ {
tprintf("ls on node %d\n", i); tprintf("ls on node %d\n", i);
repl->ssh_node(i, (char *) "ls -la /var/lib/mysql", true); repl->ssh_node(i, true, "ls -la /var/lib/mysql");
fflush(stdout); fflush(stdout);
} }
tprintf("ls maxscale \n"); tprintf("ls maxscale \n");
@ -2034,7 +2030,7 @@ int TestConnections::take_snapshot(char * snapshot_name)
return system(str); return system(str);
} }
int TestConnections::revert_snapshot(char * snapshot_name) int TestConnections::revert_snapshot(const char* snapshot_name)
{ {
char str[4096]; char str[4096];
sprintf(str, "%s %s", revert_snapshot_command, snapshot_name); sprintf(str, "%s %s", revert_snapshot_command, snapshot_name);

View File

@ -220,7 +220,7 @@ public:
* @param prefix file name prefix * @param prefix file name prefix
* @return 0 if success * @return 0 if success
*/ */
int copy_mariadb_logs(Mariadb_nodes *repl, char * prefix); int copy_mariadb_logs(Mariadb_nodes *repl, const char* prefix);
/** /**
* @brief no_backend_log_copy if true logs from backends are not copied (needed if case of Aurora RDS backend or similar) * @brief no_backend_log_copy if true logs from backends are not copied (needed if case of Aurora RDS backend or similar)
@ -647,7 +647,7 @@ public:
int execute_maxadmin_command(char * cmd); int execute_maxadmin_command(char * cmd);
int execute_maxadmin_command_print(char * cmd); int execute_maxadmin_command_print(char * cmd);
int check_maxadmin_param(const char *command, const char *param, const char *value); int check_maxadmin_param(const char *command, const char *param, const char *value);
int get_maxadmin_param(char *command, char *param, char *result); int get_maxadmin_param(const char* command, const char* param, char* result);
void check_current_operations(int value); void check_current_operations(int value);
void check_current_connections(int value); void check_current_connections(int value);
@ -682,7 +682,7 @@ public:
* @param snapshot_name name of snapshot to revert * @param snapshot_name name of snapshot to revert
* @return 0 in case of success or mdbci error code in case of error * @return 0 in case of success or mdbci error code in case of error
*/ */
int revert_snapshot(char * snapshot_name); int revert_snapshot(const char* snapshot_name);
/** /**
* @brief Test a bad configuration * @brief Test a bad configuration