diff --git a/maxscale-system-test/CMakeLists.txt b/maxscale-system-test/CMakeLists.txt index 7bf7875a7..a59227b80 100644 --- a/maxscale-system-test/CMakeLists.txt +++ b/maxscale-system-test/CMakeLists.txt @@ -46,11 +46,11 @@ else() endif() # The core library -add_library(testcore SHARED testconnections.cpp mariadb_nodes.cpp +add_library(testcore SHARED testconnections.cpp nodes.cpp mariadb_nodes.cpp maxscales.cpp mariadb_func.cpp get_com_select_insert.cpp maxadmin_operations.cpp big_transaction.cpp sql_t1.cpp test_binlog_fnc.cpp get_my_ip.cpp big_load.cpp get_com_select_insert.cpp different_size.cpp fw_copy_rules maxinfo_func.cpp config_operations.cpp rds_vpc.cpp execute_cmd.cpp - blob_test.cpp) + blob_test.cpp cdc_connector.cpp) target_link_libraries(testcore ${MYSQL_CLIENT} ${CDC_CONNECTOR_LIBRARIES} ${JANSSON_LIBRARIES} z nsl m pthread ssl dl rt crypto crypt) install(TARGETS testcore DESTINATION system-test) add_dependencies(testcore connector-c cdc_connector) @@ -121,7 +121,7 @@ add_test_executable(bug547.cpp bug547 replication LABELS readwritesplit REPL_BAC add_test_executable(bug681.cpp bug681 galera.bug681 LABELS readwritesplit GALERA_BACKEND) # Regression case for the bug "crash with tee filter" -add_test_executable(bug643.cpp bug643 bug643 LABELS tee REPL_BACKEND) +#add_test_executable(bug643.cpp bug643 bug643 LABELS tee REPL_BACKEND) # Regression case for the bug ""Different error messages from MariaDB and Maxscale" add_test_script(bug561.sh bug561.sh replication LABELS MySQLAuth REPL_BACKEND) @@ -166,13 +166,13 @@ add_test_executable(bug626.cpp bug626 replication LABELS MySQLAuth MySQLProtocol add_test_executable(bug634.cpp bug634 replication LABELS readwritesplit REPL_BACKEND) # Regression cases for several TEE filter hangs -add_test_executable(bug645.cpp bug645 bug645 LABELS tee REPL_BACKEND) -add_test_executable(bug645_1.cpp bug645_1 bug645_1 LABELS tee REPL_BACKEND) -add_test_executable(bug649.cpp bug649 bug645 LABELS tee REPL_BACKEND) -add_test_executable(bug650.cpp bug650 bug650 LABELS tee REPL_BACKEND) +#add_test_executable(bug645.cpp bug645 bug645 LABELS tee REPL_BACKEND) +#add_test_executable(bug645_1.cpp bug645_1 bug645_1 LABELS tee REPL_BACKEND) +#add_test_executable(bug649.cpp bug649 bug645 LABELS tee) +#add_test_executable(bug650.cpp bug650 bug650 LABELS tee REPL_BACKEND) # Heavy test for TEE filter -add_test_script(bug648 sql_queries bug648 LABELS tee HEAVY REPL_BACKEND) +#add_test_script(bug648 sql_queries bug648 LABELS tee UNSTABLE HEAVY REPL_BACKEND) # Crash when host name for some user in mysql.user is very long add_test_executable(bug653.cpp bug653 replication LABELS MySQLAuth MySQLProtocol REPL_BACKEND) @@ -181,7 +181,7 @@ add_test_executable(bug653.cpp bug653 replication LABELS MySQLAuth MySQLProtocol add_test_executable(bug654.cpp bug654 replication LABELS maxscale REPL_BACKEND) # Regression case for the bug "Tee filter: closing child session causes MaxScale to fail" -add_test_executable(bug657.cpp bug657 bug657 LABELS tee REPL_BACKEND) +#add_test_executable(bug657.cpp bug657 bug657 LABELS tee REPL_BACKEND) # Block backends (master or all slaves) and tries to connect Maxscale add_test_executable(bug658.cpp bug658 replication LABELS readwritesplit readconnroute maxscale REPL_BACKEND) @@ -193,7 +193,7 @@ add_test_executable(bug662.cpp bug662 bug662 LABELS readwritesplit readconnroute add_test_executable(bug664.cpp bug664 bug664 LABELS MySQLAuth MySQLProtocol) # TEE fileter: execute long sequence of queries ans session commands in the loop -add_test_executable(bug670.cpp bug670 bug670 LABELS tee REPL_BACKEND) +#add_test_executable(bug670.cpp bug670 bug670 LABELS tee REPL_BACKEND) # Regression case for the bug "MaxScale crashes if "Users table data" is empty and "show dbusers" is executed in maxadmin" add_test_executable(bug673.cpp bug673 bug673 LABELS MySQLAuth REPL_BACKEND) @@ -260,6 +260,7 @@ add_test_executable(false_monitor_state_change.cpp false_monitor_state_change re # A set of tests for Firewall filter add_test_executable(fwf.cpp fwf fwf LABELS dbfwfilter REPL_BACKEND) +add_test_executable(fwf2.cpp fwf2 fwf LABELS dbfwfilter REPL_BACKEND) add_test_executable(fwf_duplicate_rules.cpp fwf_duplicate_rules fwf LABELS dbfwfilter REPL_BACKEND) add_test_executable(fwf_prepared_stmt.cpp fwf_prepared_stmt fwf LABELS dbfwfilter REPL_BACKEND) add_test_executable(fwf_actions.cpp fwf_actions fwf_action LABELS dbfwfilter REPL_BACKEND) @@ -298,9 +299,6 @@ add_test_script(load_balancing_pers10 load_balancing load_pers10 LABELS readwrit # Test with extremely big blob inserting add_test_executable(longblob.cpp longblob longblob LABELS readwritesplit readconnroute UNSTABLE HEAVY REPL_BACKEND) -# Check that inserts of specific size don't cause a hang -add_test_executable(large_insert_hang.cpp large_insert_hang replication LABELS readwritesplit REPL_BACKEND) - # Test with extremely big blob inserting/selecting with > 16 mb data blocks add_test_executable(mxs1110_16mb.cpp mxs1110_16mb longblob_filters LABELS readwritesplit readconnroute HEAVY REPL_BACKEND) @@ -382,7 +380,7 @@ add_test_executable(mxs431.cpp mxs431 sharding LABELS schemarouter REPL_BACKEND add_test_executable(mxs47.cpp mxs47 replication LABELS MySQLProtocol LIGHT REPL_BACKEND) # Regression case for the bug "USE hangs when Tee filter uses matching" -add_test_executable(mxs501_tee_usedb.cpp mxs501_tee_usedb mxs501 LABELS tee REPL_BACKEND) +#add_test_executable(mxs501_tee_usedb.cpp mxs501_tee_usedb mxs501 LABELS tee REPL_BACKEND) # Open connection, execute 'change user', close connection in the loop add_test_executable(mxs548_short_session_change_user.cpp mxs548_short_session_change_user mxs548 LABELS MySQLProtocol REPL_BACKEND) @@ -393,6 +391,12 @@ add_test_executable(mxs559_block_master.cpp mxs559_block_master mxs559 LABELS re # Playing with blocking and unblocking nodes under INSERT load add_test_executable(mxs564_big_dump.cpp mxs564_big_dump galera_mxs564 LABELS readwritesplit readconnroute GALERA_BACKEND) +# Executes simple queries from python script in the loop +add_test_script(mxs585.py mxs585.py replication LABELS readwritesplit readconnroute UNSTABLE HEAVY REPL_BACKEND) + +# Simple transactions in the loop from python script with client SSL on +add_test_script(mxs598.py mxs598.py ssl LABELS MySQLProtocol UNSTABLE HEAVY REPL_BACKEND) + # Regression case for the bug "MaxScale fails to start silently if config file is not readable" add_test_executable(mxs621_unreadable_cnf.cpp mxs621_unreadable_cnf replication LABELS maxscale REPL_BACKEND) @@ -516,6 +520,10 @@ add_test_executable(verify_master_failure.cpp verify_master_failure verify_maste # https://jira.mariadb.org/browse/MXS-1476 add_test_executable(mxs1476.cpp mxs1476 mxs1476 LABELS GALERA_BACKEND) +# MXS-1509: Show correct server state for multisource replication +# https://jira.mariadb.org/browse/MXS-1509 +add_test_executable(mxs1509.cpp mxs1509 mxs1509 LABELS REPL_BACKEND) + # 'namedserverfilter' test add_test_executable(namedserverfilter.cpp namedserverfilter namedserverfilter LABELS namedserverfilter LIGHT REPL_BACKEND) @@ -578,7 +586,7 @@ add_test_executable(rwsplit_multi_stmt.cpp rwsplit_multi_stmt rwsplit_multi_stmt add_test_executable(rwsplit_read_only_trx.cpp rwsplit_read_only_trx rwsplit_read_only_trx LABELS readwritesplit REPL_BACKEND) # Test replication-manager with MaxScale -add_test_executable_notest(replication_manager.cpp replication_manager replication_manager LABELS maxscale REPL_BACKEND) +#add_test_executable(replication_manager.cpp replication_manager replication_manager LABELS maxscale REPL_BACKEND) #add_test_executable_notest(replication_manager_2nodes.cpp replication_manager_2nodes replication_manager_2nodes LABELS maxscale REPL_BACKEND) #add_test_executable_notest(replication_manager_3nodes.cpp replication_manager_3nodes replication_manager_3nodes LABELS maxscale REPL_BACKEND) @@ -652,7 +660,7 @@ add_test_executable(temporal_tables.cpp temporal_tables replication LABELS readw add_test_executable(test_hints.cpp test_hints hints2 LABELS hintfilter LIGHT REPL_BACKEND) # Run MaxCtrl test suite -add_test_executable(test_maxctrl.cpp test_maxctrl maxctrl LABELS REPL_BACKEND) +# add_test_executable(test_maxctrl.cpp test_maxctrl maxctrl LABELS REPL_BACKEND) # Binlogrouter tests, these heavily alter the replication so they are run last add_test_executable(avro.cpp avro avro LABELS avrorouter binlogrouter LIGHT BREAKS_REPL) diff --git a/maxscale-system-test/auroramon.cpp b/maxscale-system-test/auroramon.cpp index 39140bbc0..9fa800d10 100644 --- a/maxscale-system-test/auroramon.cpp +++ b/maxscale-system-test/auroramon.cpp @@ -41,8 +41,8 @@ int set_endspoints(RDS * cluster) } setenv("node_password", "skysqlrds", 1); - setenv("maxscale_user", "skysql", 1); - setenv("maxscale_password", "skysqlrds", 1); + setenv("maxscales->user_name", "skysql", 1); + setenv("maxscales->password", "skysqlrds", 1); setenv("no_nodes_check", "yes", 1); setenv("no_backend_log_copy", "yes", 1); return 0; @@ -60,7 +60,7 @@ void compare_masters(TestConnections* Test, RDS * cluster) for (i = 0; i < Test->repl->N; i++) { sprintf(cmd, "show server server%d", i + 1); - Test->get_maxadmin_param(cmd, (char *) "Status:", &maxadmin_status[0]); + Test->maxscales->get_maxadmin_param(0, cmd, (char *) "Status:", &maxadmin_status[0]); Test->tprintf("Server%d status %s\n", i + 1, maxadmin_status); sprintf(cmd, "node%03d", i); if (strcmp(aurora_master, cmd) == 0) @@ -115,12 +115,12 @@ int main(int argc, char *argv[]) Test->set_timeout(30); Test->tprintf("Executing a query through readwritesplit before failover"); - Test->connect_rwsplit(); - Test->try_query(Test->conn_rwsplit, "show processlist"); + Test->maxscales->connect_rwsplit(0); + Test->try_query(Test->maxscales->conn_rwsplit[0][0], "show processlist"); char server_id[1024]; Test->tprintf("Get aurora_server_id\n"); - find_field(Test->conn_rwsplit, "select @@aurora_server_id;", "server_id", &server_id[0]); - Test->close_rwsplit(); + find_field(Test->maxscales->conn_rwsplit[0][0], "select @@aurora_server_id;", "server_id", &server_id[0]); + Test->maxscales->close_rwsplit(0); Test->tprintf("server_id before failover: %s\n", server_id); Test->stop_timeout(); @@ -135,17 +135,17 @@ int main(int argc, char *argv[]) Test->set_timeout(30); Test->tprintf("Executing a query through readwritesplit after failover"); - Test->connect_rwsplit(); - Test->try_query(Test->conn_rwsplit, "show processlist"); + Test->maxscales->connect_rwsplit(0); + Test->try_query(Test->maxscales->conn_rwsplit[0][0], "show processlist"); Test->tprintf("Get aurora_server_id\n"); - find_field(Test->conn_rwsplit, "select @@aurora_server_id;", "server_id", &server_id[0]); - Test->close_rwsplit(); + find_field(Test->maxscales->conn_rwsplit[0][0], "select @@aurora_server_id;", "server_id", &server_id[0]); + Test->maxscales->close_rwsplit(0); Test->tprintf("server_id after failover: %s\n", server_id); compare_masters(Test, cluster); - //Test->check_maxscale_alive(); + //Test->check_maxscale_alive(0); Test->stop_timeout(); diff --git a/maxscale-system-test/avro.cpp b/maxscale-system-test/avro.cpp index 5c33c3c2c..12daff13a 100644 --- a/maxscale-system-test/avro.cpp +++ b/maxscale-system-test/avro.cpp @@ -23,13 +23,13 @@ using std::endl; int main(int argc, char *argv[]) { - + int exit_code; TestConnections test(argc, argv); test.set_timeout(600); - test.ssh_maxscale(true, (char *) "rm -rf /var/lib/maxscale/avro"); + test.maxscales->ssh_node(0, (char *) "rm -rf /var/lib/maxscale/avro", true); /** Start master to binlogrouter replication */ - if (!test.replicate_from_master()) + if (!test.replicate_from_master(0)) { return 1; } @@ -48,7 +48,9 @@ int main(int argc, char *argv[]) sleep(10); test.set_timeout(120); - char * output = test.ssh_maxscale_output(true, "maxavrocheck -d /var/lib/maxscale/avro/test.t1.000001.avro"); + char * output = test.maxscales->ssh_node_output(0, + "maxavrocheck -d /var/lib/maxscale/avro/test.t1.000001.avro", + true, &exit_code); std::istringstream iss; iss.str(output); diff --git a/maxscale-system-test/avro_alter.cpp b/maxscale-system-test/avro_alter.cpp index 80f9afd1a..91e954d32 100644 --- a/maxscale-system-test/avro_alter.cpp +++ b/maxscale-system-test/avro_alter.cpp @@ -9,13 +9,13 @@ int main(int argc, char *argv[]) { - + int exit_code; TestConnections test(argc, argv); test.set_timeout(600); - test.ssh_maxscale(true, (char *) "rm -rf /var/lib/maxscale/avro"); + test.maxscales->ssh_node(0, (char *) "rm -rf /var/lib/maxscale/avro", true); /** Start master to binlogrouter replication */ - if (!test.replicate_from_master()) + if (!test.replicate_from_master(0)) { return 1; } @@ -48,11 +48,11 @@ int main(int argc, char *argv[]) sleep(10); test.set_timeout(120); - for (int i = 1; i <=5; i++) + for (int i = 1; i <= 5; i++) { std::stringstream cmd; cmd << "maxavrocheck -d /var/lib/maxscale/avro/test.t1.00000" << i << ".avro"; - char* rows = test.ssh_maxscale_output(true, cmd.str().c_str()); + char* rows = test.maxscales->ssh_node_output(0, cmd.str().c_str(), true, &exit_code); int nrows = 0; std::istringstream iss; iss.str(rows); diff --git a/maxscale-system-test/avro_long.cpp b/maxscale-system-test/avro_long.cpp index 3221c9ceb..7ffe70284 100644 --- a/maxscale-system-test/avro_long.cpp +++ b/maxscale-system-test/avro_long.cpp @@ -17,10 +17,10 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(600); - Test->stop_maxscale(); - Test->ssh_maxscale(true, (char *) "rm -rf /var/lib/maxscale/avro"); + Test->maxscales->stop_maxscale(0); + Test->maxscales->ssh_node(0, (char *) "rm -rf /var/lib/maxscale/avro", true); - //Test->ssh_maxscale(true, (char *) "mkdir /var/lib/maxscale/avro; chown -R maxscale:maxscale /var/lib/maxscale/avro"); + //Test->maxscales->ssh_node(0, (char *) "mkdir /var/lib/maxscale/avro; chown -R maxscale:maxscale /var/lib/maxscale/avro", true); Test->repl->connect(); execute_query(Test->repl->nodes[0], (char *) "DROP TABLE IF EXISTS t1;"); @@ -28,17 +28,17 @@ int main(int argc, char *argv[]) sleep(5); - Test->start_binlog(); + Test->start_binlog(0); Test->set_timeout(120); - Test->stop_maxscale(); + Test->maxscales->stop_maxscale(0); - Test->ssh_maxscale(true, (char *) "rm -rf /var/lib/maxscale/avro"); + Test->maxscales->ssh_node(0, (char *) "rm -rf /var/lib/maxscale/avro", true); Test->set_timeout(120); - Test->start_maxscale(); + Test->maxscales->start_maxscale(0); Test->set_timeout(60); diff --git a/maxscale-system-test/backend_auth_fail.cpp b/maxscale-system-test/backend_auth_fail.cpp index e1504821d..1336f5adc 100644 --- a/maxscale-system-test/backend_auth_fail.cpp +++ b/maxscale-system-test/backend_auth_fail.cpp @@ -19,7 +19,7 @@ int main(int argc, char** argv) for (int i = 0; i < 100; i++) { Test->set_timeout(30); - mysql[i] = Test->open_readconn_master_connection(); + mysql[i] = Test->maxscales->open_readconn_master_connection(0); execute_query_silent(mysql[i], "select 1"); } Test->stop_timeout(); @@ -35,7 +35,7 @@ int main(int argc, char** argv) Test->stop_timeout(); sleep(5); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bad_pers.cpp b/maxscale-system-test/bad_pers.cpp index 993e7bee1..c0bdafb04 100644 --- a/maxscale-system-test/bad_pers.cpp +++ b/maxscale-system-test/bad_pers.cpp @@ -17,9 +17,9 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->connect_maxscale(); - Test->check_log_err((char *) "warning -1", true); - Test->check_maxscale_alive(); + Test->maxscales->connect_maxscale(0); + Test->check_log_err(0, (char *) "warning -1", true); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/big_load.cpp b/maxscale-system-test/big_load.cpp index 8c07daff2..592860716 100644 --- a/maxscale-system-test/big_load.cpp +++ b/maxscale-system-test/big_load.cpp @@ -25,7 +25,7 @@ void load(long int *new_inserts, long int *new_selects, long int *selects, long } nodes->connect(); - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); data.i1 = 0; data.i2 = 0; @@ -34,7 +34,7 @@ void load(long int *new_inserts, long int *new_selects, long int *selects, long data.rwsplit_only = rwsplit_only; // connect to the MaxScale server (rwsplit) - if (Test->conn_rwsplit == NULL ) + if (Test->maxscales->conn_rwsplit[0] == NULL ) { if (report_errors) { @@ -45,15 +45,15 @@ void load(long int *new_inserts, long int *new_selects, long int *selects, long } else { - create_t1(Test->conn_rwsplit); + create_t1(Test->maxscales->conn_rwsplit[0]); create_insert_string(sql, sql_l, 1); - if ((execute_query(Test->conn_rwsplit, sql) != 0) && (report_errors)) + if ((execute_query(Test->maxscales->conn_rwsplit[0], sql) != 0) && (report_errors)) { Test->add_result(1, "Query %s failed\n", sql); } // close connections - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); Test->tprintf("Waiting for the table to replicate\n"); Test->repl->sync_slaves(); @@ -104,38 +104,38 @@ void *query_thread1( void *ptr ) MYSQL * conn3; int conn_err = 0; thread_data * data = (thread_data *) ptr; - conn1 = open_conn_db_timeout(data->Test->rwsplit_port, - data->Test->maxscale_IP, + conn1 = open_conn_db_timeout(data->Test->maxscales->rwsplit_port[0], + data->Test->maxscales->IP[0], (char *) "test", - data->Test->maxscale_user, - data->Test->maxscale_password, + data->Test->maxscales->user_name, + data->Test->maxscales->password, 20, data->Test->ssl); - //conn1 = data->Test->open_rwsplit_connection(); + //conn1 = data->Test->maxscales->open_rwsplit_connection(0); if (mysql_errno(conn1) != 0) { conn_err++; } if (data->rwsplit_only == 0) { - //conn2 = data->Test->open_readconn_master_connection(); - conn2 = open_conn_db_timeout(data->Test->readconn_master_port, - data->Test->maxscale_IP, + //conn2 = data->Test->maxscales->open_readconn_master_connection(0); + conn2 = open_conn_db_timeout(data->Test->maxscales->readconn_master_port[0], + data->Test->maxscales->IP[0], (char *) "test", - data->Test->maxscale_user, - data->Test->maxscale_password, + data->Test->maxscales->user_name, + data->Test->maxscales->password, 20, data->Test->ssl); if (mysql_errno(conn2) != 0) { conn_err++; } - //conn3 = data->Test->open_readconn_slave_connection(); - conn3 = open_conn_db_timeout(data->Test->readconn_slave_port, - data->Test->maxscale_IP, + //conn3 = data->Test->maxscales->open_readconn_slave_connection(0); + conn3 = open_conn_db_timeout(data->Test->maxscales->readconn_slave_port[0], + data->Test->maxscales->IP[0], (char *) "test", - data->Test->maxscale_user, - data->Test->maxscale_password, + data->Test->maxscales->user_name, + data->Test->maxscales->password, 20, data->Test->ssl); if (mysql_errno(conn3) != 0) @@ -175,32 +175,32 @@ void *query_thread2(void *ptr ) MYSQL * conn2; MYSQL * conn3; thread_data * data = (thread_data *) ptr; - //conn1 = data->Test->open_rwsplit_connection(); - conn1 = open_conn_db_timeout(data->Test->rwsplit_port, - data->Test->maxscale_IP, + //conn1 = data->Test->maxscales->open_rwsplit_connection(0); + conn1 = open_conn_db_timeout(data->Test->maxscales->rwsplit_port[0], + data->Test->maxscales->IP[0], (char *) "test", - data->Test->maxscale_user, - data->Test->maxscale_password, + data->Test->maxscales->user_name, + data->Test->maxscales->password, 20, data->Test->ssl); if (data->rwsplit_only == 0) { - //conn2 = data->Test->open_readconn_master_connection(); - //conn3 = data->Test->open_readconn_slave_connection(); + //conn2 = data->Test->maxscales->open_readconn_master_connection(0); + //conn3 = data->Test->maxscales->open_readconn_slave_connection(0); - conn2 = open_conn_db_timeout(data->Test->readconn_master_port, - data->Test->maxscale_IP, + conn2 = open_conn_db_timeout(data->Test->maxscales->readconn_master_port[0], + data->Test->maxscales->IP[0], (char *) "test", - data->Test->maxscale_user, - data->Test->maxscale_password, + data->Test->maxscales->user_name, + data->Test->maxscales->password, 20, data->Test->ssl); //if (mysql_errno(conn2) != 0) { conn_err++; } - conn3 = open_conn_db_timeout(data->Test->readconn_slave_port, - data->Test->maxscale_IP, + conn3 = open_conn_db_timeout(data->Test->maxscales->readconn_slave_port[0], + data->Test->maxscales->IP[0], (char *) "test", - data->Test->maxscale_user, - data->Test->maxscale_password, + data->Test->maxscales->user_name, + data->Test->maxscales->password, 20, data->Test->ssl); //if (mysql_errno(conn3) != 0) { conn_err++; } diff --git a/maxscale-system-test/binary_ps.cpp b/maxscale-system-test/binary_ps.cpp index f582adb9f..235521299 100644 --- a/maxscale-system-test/binary_ps.cpp +++ b/maxscale-system-test/binary_ps.cpp @@ -17,11 +17,11 @@ int main(int argc, char** argv) sprintf(server_id[i], "%d", test.repl->get_server_id(i)); } - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.set_timeout(20); - MYSQL_STMT* stmt = mysql_stmt_init(test.conn_rwsplit); + MYSQL_STMT* stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]); const char* write_query = "SELECT @@server_id, @@last_insert_id"; const char* read_query = "SELECT @@server_id"; char buffer[100] = ""; @@ -47,7 +47,7 @@ int main(int argc, char** argv) test.add_result(strcmp(buffer, server_id[0]), "Expected server_id '%s', got '%s'", server_id[0], buffer); mysql_stmt_close(stmt); - stmt = mysql_stmt_init(test.conn_rwsplit); + stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]); // Execute read, should return a slave server ID test.add_result(mysql_stmt_prepare(stmt, read_query, strlen(read_query)), "Failed to prepare"); @@ -61,7 +61,7 @@ int main(int argc, char** argv) mysql_stmt_close(stmt); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/binary_ps_cursor.cpp b/maxscale-system-test/binary_ps_cursor.cpp index b7eadd753..306fe79b0 100644 --- a/maxscale-system-test/binary_ps_cursor.cpp +++ b/maxscale-system-test/binary_ps_cursor.cpp @@ -9,10 +9,10 @@ using std::endl; void test1(TestConnections& test) { - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.set_timeout(20); - MYSQL_STMT* stmt = mysql_stmt_init(test.conn_rwsplit); + MYSQL_STMT* stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]); const char* query = "SELECT @@server_id"; char buffer[100] = ""; my_bool err = false; @@ -43,7 +43,7 @@ void test1(TestConnections& test) cout << "Close statement" << endl; mysql_stmt_close(stmt); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); } @@ -51,8 +51,8 @@ void test2(TestConnections& test) { test.set_timeout(20); - MYSQL* conn = open_conn_db_timeout(test.rwsplit_port, test.maxscale_ip(), "test", - test.maxscale_user, test.maxscale_password, 1, false); + MYSQL* conn = open_conn_db_timeout(test.maxscales->rwsplit_port[0], test.maxscales->ip(0), "test", + test.maxscales->user_name, test.maxscales->password, 1, false); MYSQL_STMT* stmt1 = mysql_stmt_init(conn); MYSQL_STMT* stmt2 = mysql_stmt_init(conn); @@ -120,10 +120,10 @@ void test2(TestConnections& test) void test3(TestConnections& test) { - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.set_timeout(20); - MYSQL_STMT* stmt = mysql_stmt_init(test.conn_rwsplit); + MYSQL_STMT* stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]); const char* query = "SELECT @@server_id"; char buffer[100] = ""; my_bool err = false; @@ -138,9 +138,9 @@ void test3(TestConnections& test) test.add_result(mysql_stmt_prepare(stmt, query, strlen(query)), "Failed to prepare"); cout << "Start transaction" << endl; - test.add_result(mysql_query(test.conn_rwsplit, "START TRANSACTION"), + test.add_result(mysql_query(test.maxscales->conn_rwsplit[0], "START TRANSACTION"), "START TRANSACTION should succeed: %s", - mysql_error(test.conn_rwsplit)); + mysql_error(test.maxscales->conn_rwsplit[0])); unsigned long cursor_type = CURSOR_TYPE_READ_ONLY; @@ -156,12 +156,12 @@ void test3(TestConnections& test) test.add_result(strlen(buffer) == 0, "Expected result buffer to not be empty"); cout << "Commit" << endl; - test.add_result(mysql_query(test.conn_rwsplit, "COMMIT"), + test.add_result(mysql_query(test.maxscales->conn_rwsplit[0], "COMMIT"), "COMMIT should succeed: %s", - mysql_error(test.conn_rwsplit)); + mysql_error(test.maxscales->conn_rwsplit[0])); mysql_stmt_close(stmt); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); char server_id[1024]; test.repl->connect(); diff --git a/maxscale-system-test/binlog_big_transaction.cpp b/maxscale-system-test/binlog_big_transaction.cpp index bb48a390d..a847d92c1 100644 --- a/maxscale-system-test/binlog_big_transaction.cpp +++ b/maxscale-system-test/binlog_big_transaction.cpp @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) Test->repl->close_connections(); sleep(5); - Test->start_binlog(); + Test->start_binlog(0); pthread_t threads; int iret; @@ -51,7 +51,8 @@ void *disconnect_thread( void *ptr ) MYSQL * conn; char cmd[256]; int i; - conn = open_conn(Test->binlog_port, Test->maxscale_IP, Test->repl->user_name, Test->repl->password, + conn = open_conn(Test->maxscales->binlog_port[0], Test->maxscales->IP[0], Test->repl->user_name, + Test->repl->password, Test->repl->ssl); Test->add_result(mysql_errno(conn), "Error connecting to Binlog router, error: %s\n", mysql_error(conn)); i = 3; diff --git a/maxscale-system-test/binlog_change_master.cpp b/maxscale-system-test/binlog_change_master.cpp index c0f5dbae8..3ccafd04c 100644 --- a/maxscale-system-test/binlog_change_master.cpp +++ b/maxscale-system-test/binlog_change_master.cpp @@ -95,8 +95,10 @@ int main(int argc, char *argv[]) Test->repl->execute_query_all_nodes((char *) "RESET SLAVE ALL"); Test->repl->execute_query_all_nodes((char *) "RESET MASTER"); + Test->repl->verbose = true; + Test->tprintf("Starting binlog configuration\n"); - Test->start_binlog(); + Test->start_binlog(0); pthread_t disconnec_thread_t; int disconnect_iret; @@ -180,7 +182,7 @@ const char * setup_slave1 = MASTER_LOG_POS=%s,\ MASTER_PORT=%d"; const char * setup_slave_gtid = - "change master to MASTER_HOST='%s',\ + "change master to MASTER_HOST='%s',\ MASTER_USER='repl',\ MASTER_PASSWORD='repl',\ MASTER_PORT=%d, \ @@ -214,7 +216,8 @@ int select_new_master(TestConnections * test) test->tprintf("Real master pos : %s\n", log_pos); test->tprintf("Connecting to MaxScale binlog router (with any DB)\n"); - MYSQL * binlog = open_conn_no_db(test->binlog_port, test->maxscale_IP, test->repl->user_name, + MYSQL * binlog = open_conn_no_db(test->maxscales->binlog_port[0], test->maxscales->IP[0], + test->repl->user_name, test->repl->password, test->ssl); test->add_result(mysql_errno(binlog), "Error connection to binlog router %s\n", mysql_error(binlog)); @@ -253,7 +256,8 @@ int select_new_master(TestConnections * test) test->tprintf("reconnect to binlog\n"); mysql_close(binlog); - binlog = open_conn_no_db(test->binlog_port, test->maxscale_IP, test->repl->user_name, test->repl->password, + binlog = open_conn_no_db(test->maxscales->binlog_port[0], test->maxscales->IP[0], test->repl->user_name, + test->repl->password, test->ssl); test->add_result(mysql_errno(binlog), "Error connection to binlog router %s\n", mysql_error(binlog)); @@ -287,7 +291,8 @@ void *disconnect_thread( void *ptr ) MYSQL * conn; char cmd[256]; int i; - conn = open_conn(Test->binlog_port, Test->maxscale_IP, Test->repl->user_name, Test->repl->password, + conn = open_conn(Test->maxscales->binlog_port[0], Test->maxscales->IP[0], Test->repl->user_name, + Test->repl->password, Test->repl->ssl); Test->add_result(mysql_errno(conn), "Error connecting to Binlog router, error: %s\n", mysql_error(conn)); i = 3; diff --git a/maxscale-system-test/binlog_incompl.cpp b/maxscale-system-test/binlog_incompl.cpp index d0c9021e2..a32d99992 100644 --- a/maxscale-system-test/binlog_incompl.cpp +++ b/maxscale-system-test/binlog_incompl.cpp @@ -14,10 +14,10 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(60); - Test->connect_maxscale(); - Test->close_maxscale_connections(); + Test->maxscales->connect_maxscale(0); + Test->maxscales->close_maxscale_connections(0); sleep(10); - Test->check_log_err("fatal signal 11", false); + Test->check_log_err(0, "fatal signal 11", false); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/binlog_semisync.cpp b/maxscale-system-test/binlog_semisync.cpp index d3e66cb8b..30ea533f5 100644 --- a/maxscale-system-test/binlog_semisync.cpp +++ b/maxscale-system-test/binlog_semisync.cpp @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) test.repl->connect(); test.binlog_cmd_option = 1; - test.start_binlog(); + test.start_binlog(0); test.repl->connect(); test.tprintf("install semisync plugin"); execute_query(test.repl->nodes[0], @@ -57,4 +57,3 @@ int main(int argc, char *argv[]) return test.global_result; } - diff --git a/maxscale-system-test/blob_test.cpp b/maxscale-system-test/blob_test.cpp index c1af427ca..6767000d8 100644 --- a/maxscale-system-test/blob_test.cpp +++ b/maxscale-system-test/blob_test.cpp @@ -91,10 +91,10 @@ int check_longblob_data(TestConnections* Test, MYSQL * conn, unsigned long chunk { //char *select_stmt = (char *) "SELECT id, x, b FROM long_blob_table WHERE id = ?"; char *select_stmt = (char *) "SELECT id, x, b FROM long_blob_table "; - MYSQL_STMT * stmt = mysql_stmt_init(Test->conn_rwsplit); + MYSQL_STMT * stmt = mysql_stmt_init(Test->maxscales->conn_rwsplit[0]); if (stmt == NULL) { - Test->add_result(1, "stmt init error: %s\n", mysql_error(Test->conn_rwsplit)); + Test->add_result(1, "stmt init error: %s\n", mysql_error(Test->maxscales->conn_rwsplit[0])); } Test->add_result(mysql_stmt_prepare(stmt, select_stmt, strlen(select_stmt)), "Error preparing stmt: %s\n", @@ -154,7 +154,7 @@ int check_longblob_data(TestConnections* Test, MYSQL * conn, unsigned long chunk if (mysql_stmt_execute(stmt) != 0) { - Test->tprintf("Error executing stmt %s\n", mysql_error(Test->conn_rwsplit)); + Test->tprintf("Error executing stmt %s\n", mysql_error(Test->maxscales->conn_rwsplit[0])); } if (mysql_stmt_store_result(stmt) != 0) diff --git a/maxscale-system-test/bug143.cpp b/maxscale-system-test/bug143.cpp index 16df08866..8aaa808d4 100644 --- a/maxscale-system-test/bug143.cpp +++ b/maxscale-system-test/bug143.cpp @@ -12,13 +12,13 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->tprintf("Creating user 'user' with 3 different passwords for different hosts\n"); - Test->connect_maxscale(); - execute_query(Test->conn_rwsplit, "CREATE USER 'user'@'non_existing_host1' IDENTIFIED BY 'pass1'"); - execute_query(Test->conn_rwsplit, "CREATE USER 'user'@'%%' IDENTIFIED BY 'pass2'"); - execute_query(Test->conn_rwsplit, "CREATE USER 'user'@'non_existing_host2' IDENTIFIED BY 'pass3'"); - execute_query(Test->conn_rwsplit, "GRANT ALL PRIVILEGES ON *.* TO 'user'@'non_existing_host1'"); - execute_query(Test->conn_rwsplit, "GRANT ALL PRIVILEGES ON *.* TO 'user'@'%%'"); - execute_query(Test->conn_rwsplit, "GRANT ALL PRIVILEGES ON *.* TO 'user'@'non_existing_host2'"); + Test->maxscales->connect_maxscale(0); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE USER 'user'@'non_existing_host1' IDENTIFIED BY 'pass1'"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE USER 'user'@'%%' IDENTIFIED BY 'pass2'"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE USER 'user'@'non_existing_host2' IDENTIFIED BY 'pass3'"); + execute_query(Test->maxscales->conn_rwsplit[0], "GRANT ALL PRIVILEGES ON *.* TO 'user'@'non_existing_host1'"); + execute_query(Test->maxscales->conn_rwsplit[0], "GRANT ALL PRIVILEGES ON *.* TO 'user'@'%%'"); + execute_query(Test->maxscales->conn_rwsplit[0], "GRANT ALL PRIVILEGES ON *.* TO 'user'@'non_existing_host2'"); Test->tprintf("Synchronizing slaves"); Test->set_timeout(50); @@ -26,7 +26,7 @@ int main(int argc, char *argv[]) Test->tprintf("Trying first hostname, expecting failure"); Test->set_timeout(15); - MYSQL * conn = open_conn(Test->rwsplit_port, Test->maxscale_IP, (char *) "user", (char *) "pass1", Test->ssl); + MYSQL * conn = open_conn(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "user", (char *) "pass1", Test->ssl); if (mysql_errno(conn) == 0) { Test->add_result(1, "MaxScale ignores host in authentication\n"); @@ -38,7 +38,7 @@ int main(int argc, char *argv[]) Test->tprintf("Trying second hostname, expecting success"); Test->set_timeout(15); - conn = open_conn(Test->rwsplit_port, Test->maxscale_IP, (char *) "user", (char *) "pass2", Test->ssl); + conn = open_conn(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "user", (char *) "pass2", Test->ssl); Test->add_result(mysql_errno(conn), "MaxScale can't connect: %s\n", mysql_error(conn)); if (conn != NULL) { @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) Test->tprintf("Trying third hostname, expecting failure"); Test->set_timeout(15); - conn = open_conn(Test->rwsplit_port, Test->maxscale_IP, (char *) "user", (char *) "pass3", Test->ssl); + conn = open_conn(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "user", (char *) "pass3", Test->ssl); if (mysql_errno(conn) == 0) { Test->add_result(1, "MaxScale ignores host in authentication\n"); @@ -57,10 +57,10 @@ int main(int argc, char *argv[]) mysql_close(conn); } - execute_query(Test->conn_rwsplit, "DROP USER 'user'@'non_existing_host1'"); - execute_query(Test->conn_rwsplit, "DROP USER 'user'@'%%'"); - execute_query(Test->conn_rwsplit, "DROP USER 'user'@'non_existing_host2'"); - Test->close_maxscale_connections(); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP USER 'user'@'non_existing_host1'"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP USER 'user'@'%%'"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP USER 'user'@'non_existing_host2'"); + Test->maxscales->close_maxscale_connections(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug359.cpp b/maxscale-system-test/bug359.cpp index 28c6a16a2..342c0f2c6 100644 --- a/maxscale-system-test/bug359.cpp +++ b/maxscale-system-test/bug359.cpp @@ -40,10 +40,10 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->check_log_err((char *) "Unsupported router option \"slave\"", true); - Test->check_log_err((char *) "Failed to start all MaxScale services. Exiting", true); - Test->check_log_err((char *) "Couldn't find suitable Master", false); - //Test->check_maxscale_alive(); + Test->check_log_err(0, (char *) "Unsupported router option \"slave\"", true); + Test->check_log_err(0, (char *) "Failed to start all MaxScale services. Exiting", true); + Test->check_log_err(0, (char *) "Couldn't find suitable Master", false); + //Test->check_maxscale_alive(0); Test->check_maxscale_processes(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug422.cpp b/maxscale-system-test/bug422.cpp index 612568a50..6a67bca3e 100644 --- a/maxscale-system-test/bug422.cpp +++ b/maxscale-system-test/bug422.cpp @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) Test->set_timeout(10); Test->tprintf("Connecting to all MaxScale services\n"); - Test->add_result(Test->connect_maxscale(), "Can not connect to Maxscale\n"); + Test->add_result(Test->maxscales->connect_maxscale(0), "Can not connect to Maxscale\n"); Test->tprintf("executing show status %d times\n", iterations); @@ -97,25 +97,25 @@ int main(int argc, char *argv[]) for (i = 0; i < iterations; i++) { Test->set_timeout(5); - Test->add_result(execute_query(Test->conn_rwsplit, (char *) "show status"), + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], (char *) "show status"), "Query %d agains RWSplit failed\n", i); } for (i = 0; i < iterations; i++) { Test->set_timeout(5); - Test->add_result(execute_query(Test->conn_slave, (char *) "show status"), + Test->add_result(execute_query(Test->maxscales->conn_slave[0], (char *) "show status"), "Query %d agains ReadConn Slave failed\n", i); } for (i = 0; i < iterations; i++) { Test->set_timeout(5); - Test->add_result(execute_query(Test->conn_master, (char *) "show status"), + Test->add_result(execute_query(Test->maxscales->conn_master[0], (char *) "show status"), "Query %d agains ReadConn Master failed\n", i); } Test->set_timeout(10); - Test->close_maxscale_connections(); - Test->check_maxscale_alive(); + Test->maxscales->close_maxscale_connections(0); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug448.cpp b/maxscale-system-test/bug448.cpp index 72860e23b..8621742ba 100644 --- a/maxscale-system-test/bug448.cpp +++ b/maxscale-system-test/bug448.cpp @@ -19,10 +19,10 @@ int main(int argc, char *argv[]) Test->set_timeout(20); Test->repl->connect(); - get_my_ip(Test->maxscale_IP, my_ip); + get_my_ip(Test->maxscales->IP[0], my_ip); Test->tprintf("Test machine IP (got via network request) %s\n", my_ip); - Test->add_result(Test->get_client_ip(my_ip_db), "Unable to get IP using connection to DB\n"); + Test->add_result(Test->get_client_ip(0, my_ip_db), "Unable to get IP using connection to DB\n"); Test->tprintf("Test machine IP (got via Show processlist) %s\n", my_ip); @@ -32,19 +32,20 @@ int main(int argc, char *argv[]) Test->tprintf("Test machine IP with %% %s\n", my_ip); Test->tprintf("Connecting to Maxscale\n"); - Test->add_result(Test->connect_maxscale(), "Error connecting to Maxscale\n"); + Test->add_result(Test->maxscales->connect_maxscale(0), "Error connecting to Maxscale\n"); Test->tprintf("Creating user 'user1' for %s host\n", my_ip); Test->set_timeout(30); - Test->add_result(execute_query(Test->conn_rwsplit, "CREATE USER user1@'%s';", my_ip), + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], "CREATE USER user1@'%s';", my_ip), "Failed to create user"); - Test->add_result(execute_query(Test->conn_rwsplit, + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], "GRANT ALL PRIVILEGES ON *.* TO user1@'%s' identified by 'pass1'; FLUSH PRIVILEGES;", my_ip), "Failed to grant privileges."); Test->tprintf("Trying to open connection using user1\n"); - MYSQL * conn = open_conn(Test->rwsplit_port, Test->maxscale_IP, (char *) "user1", (char *) "pass1", + MYSQL * conn = open_conn(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "user1", + (char *) "pass1", Test->ssl); if (mysql_errno(conn) != 0) { @@ -59,11 +60,12 @@ int main(int argc, char *argv[]) } } - Test->add_result(execute_query(Test->conn_rwsplit, "DROP USER user1@'%s'; FLUSH PRIVILEGES;", my_ip), + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], "DROP USER user1@'%s'; FLUSH PRIVILEGES;", + my_ip), "Query Failed\n"); - Test->close_maxscale_connections(); - Test->check_maxscale_alive(); + Test->maxscales->close_maxscale_connections(0); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug466.cpp b/maxscale-system-test/bug466.cpp index fb7d0df78..941e17105 100644 --- a/maxscale-system-test/bug466.cpp +++ b/maxscale-system-test/bug466.cpp @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) Test->ConnectMaxscale(); - execute_query(Test->conn_rwsplit, (char *) "select @@server_id; -- max_slave_replication_lag=120"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- max_slave_replication_lag=120"); diff --git a/maxscale-system-test/bug469.cpp b/maxscale-system-test/bug469.cpp index 642f4ef95..71eef2f98 100644 --- a/maxscale-system-test/bug469.cpp +++ b/maxscale-system-test/bug469.cpp @@ -51,29 +51,29 @@ int main(int argc, char *argv[]) int res_d; Test->set_timeout(10); - Test->get_maxadmin_param((char *) "show server server1", (char *) "Current no. of conns:", res); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server1", (char *) "Current no. of conns:", res); sscanf(res, "%d", &res_d); Test->tprintf("Before: Current num of conn %d\n", res_d); Test->add_result(res_d, "curr num of conn is not 0\n"); - Test->get_maxadmin_param((char *) "show server server1", (char *) "Number of connections:", res); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server1", (char *) "Number of connections:", res); sscanf(res, "%d", &res_d); Test->tprintf("Before: num of conn %d\n", res_d); Test->add_result(res_d, "num of conn is not 0"); - Test->connect_rwsplit(); - Test->try_query(Test->conn_rwsplit, (char *) "select 1"); - Test->close_rwsplit(); + Test->maxscales->connect_rwsplit(0); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select 1"); + Test->maxscales->close_rwsplit(0); Test->stop_timeout(); sleep(10); Test->set_timeout(10); - Test->get_maxadmin_param((char *) "show server server1", (char *) "Current no. of conns:", res); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server1", (char *) "Current no. of conns:", res); sscanf(res, "%d", &res_d); Test->tprintf("After: Current num of conn %d\n", res_d); Test->add_result(res_d, "curr num of conn is not 0\n"); - Test->get_maxadmin_param((char *) "show server server1", (char *) "Number of connections:", res); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server1", (char *) "Number of connections:", res); sscanf(res, "%d", &res_d); Test->tprintf("After: num of conn %d\n", res_d); if (res_d != 1) @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) Test->add_result(1, "num of conn is not 1"); } - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug471.cpp b/maxscale-system-test/bug471.cpp index da0185f00..2b2eb3978 100644 --- a/maxscale-system-test/bug471.cpp +++ b/maxscale-system-test/bug471.cpp @@ -153,7 +153,7 @@ int main(int argc, char *argv[]) Test->set_timeout(10); Test->repl->connect(); - Test->add_result(Test->connect_maxscale(), "Failed to connect to MaxScale\n"); + Test->add_result(Test->maxscales->connect_maxscale(0), "Failed to connect to MaxScale\n"); char server_id[256]; char server_id_d[256]; @@ -169,7 +169,7 @@ int main(int argc, char *argv[]) Test->set_timeout(5); sprintf(hint_sql, "select @@server_id; -- maxscale route to server server%d", j + 1); - find_field(Test->conn_rwsplit, hint_sql, (char *) "@@server_id", &server_id[0]); + find_field(Test->maxscales->conn_rwsplit[0], hint_sql, (char *) "@@server_id", &server_id[0]); find_field(Test->repl->nodes[j], (char *) "select @@server_id;", (char *) "@@server_id", &server_id_d[0]); Test->tprintf("server%d ID from Maxscale: \t%s\n", j + 1, server_id); @@ -182,10 +182,10 @@ int main(int argc, char *argv[]) Test->set_timeout(10); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->repl->close_connections(); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug473.cpp b/maxscale-system-test/bug473.cpp index 33278f0f9..3912fedb5 100644 --- a/maxscale-system-test/bug473.cpp +++ b/maxscale-system-test/bug473.cpp @@ -56,40 +56,40 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->add_result(Test->connect_maxscale(), "Can not connect to Maxscale\n"); + Test->add_result(Test->maxscales->connect_maxscale(0), "Can not connect to Maxscale\n"); Test->tprintf("Trying queries that caused crashes before fix: bug473\n"); - Test->try_query(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale route to server =("); - Test->try_query(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale route to server =)"); - Test->try_query(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale route to server =:"); - Test->try_query(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale route to server =a"); - Test->try_query(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale route to server = a"); - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale route to server =("); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale route to server =)"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale route to server =:"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale route to server =a"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale route to server = a"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale route to server = кириллица åäö"); // bug472 Test->tprintf("Trying queries that caused crashes before fix: bug472\n"); - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale s1 begin route to server server3"); - Test->try_query(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale end"); - Test->try_query(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale s1 begin"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale end"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale s1 begin"); // bug470 Test->tprintf("Trying queries that caused crashes before fix: bug470\n"); fflush(stdout); - Test->try_query(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale named begin route to master"); - Test->try_query(Test->conn_rwsplit, (char *) "select @@server_id;"); - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale named begin route to master"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale named begin route to master; select @@server_id;"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checking if Maxscale is alive\n"); fflush(stdout); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug475.cpp b/maxscale-system-test/bug475.cpp index a1e03f214..522e7ecc3 100644 --- a/maxscale-system-test/bug475.cpp +++ b/maxscale-system-test/bug475.cpp @@ -36,15 +36,15 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select /* maxscale hintname prepare route to master */ @@server_id;"); - Test->try_query(Test->conn_rwsplit, (char *) "select /* maxscale hintname begin */ @@server_id;"); - Test->try_query(Test->conn_rwsplit, (char *) "select /* maxscale route to master*/ @@server_id;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select /* maxscale hintname begin */ @@server_id;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select /* maxscale route to master*/ @@server_id;"); - Test->check_log_err((char *) "Syntax error in hint", false); - Test->check_maxscale_alive(); + Test->check_log_err(0, (char *) "Syntax error in hint", false); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug479.cpp b/maxscale-system-test/bug479.cpp index bb7c4a311..80b361d2f 100644 --- a/maxscale-system-test/bug479.cpp +++ b/maxscale-system-test/bug479.cpp @@ -25,9 +25,9 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->check_log_err((char *) "Unable to find filter 'non existing filter", true); - //global_result =Test->check_log_err((char *) "не существуюший фильтер", true); - //global_result +=Test->check_maxscale_alive(); + Test->check_log_err(0, (char *) "Unable to find filter 'non existing filter", true); + //global_result =Test->check_log_err(0, (char *) "не существуюший фильтер", true); + //global_result +=Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug488.cpp b/maxscale-system-test/bug488.cpp index 4968698b7..0cc2619bd 100644 --- a/maxscale-system-test/bug488.cpp +++ b/maxscale-system-test/bug488.cpp @@ -81,7 +81,7 @@ int main(int argc, char *argv[]) int i; Test->repl->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Trying SHOW VARIABLES to different Maxscale services\n"); fflush(stdout); @@ -89,35 +89,35 @@ int main(int argc, char *argv[]) for (i = 0; i < 100; i++) { Test->set_timeout(5); - Test->try_query(Test->conn_rwsplit, (char *) "SHOW VARIABLES;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "SHOW VARIABLES;"); } Test->tprintf("ReadConn master\n"); for (i = 0; i < 100; i++) { Test->set_timeout(5); - Test->try_query(Test->conn_master, (char *) "SHOW VARIABLES;"); + Test->try_query(Test->maxscales->conn_master[0], (char *) "SHOW VARIABLES;"); } Test->tprintf("ReadConn slave\n"); for (i = 0; i < 100; i++) { Test->set_timeout(5); - Test->try_query(Test->conn_slave, (char *) "SHOW VARIABLES;"); + Test->try_query(Test->maxscales->conn_slave[0], (char *) "SHOW VARIABLES;"); } Test->tprintf("All in one loop\n"); for (i = 0; i < 100; i++) { Test->set_timeout(5); - Test->try_query(Test->conn_rwsplit, (char *) "SHOW VARIABLES;"); - Test->try_query(Test->conn_master, (char *) "SHOW VARIABLES;"); - Test->try_query(Test->conn_slave, (char *) "SHOW VARIABLES;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "SHOW VARIABLES;"); + Test->try_query(Test->maxscales->conn_master[0], (char *) "SHOW VARIABLES;"); + Test->try_query(Test->maxscales->conn_slave[0], (char *) "SHOW VARIABLES;"); } Test->set_timeout(10); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->repl->close_connections(); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug493.cpp b/maxscale-system-test/bug493.cpp index 7ef712f6b..c14aaa1a2 100644 --- a/maxscale-system-test/bug493.cpp +++ b/maxscale-system-test/bug493.cpp @@ -80,10 +80,10 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->check_log_err((char *) "Duplicate section found: server2", true); - Test->check_log_err((char *) + Test->check_log_err(0, (char *) "Duplicate section found: server2", true); + Test->check_log_err(0, (char *) "Failed to open, read or process the MaxScale configuration file /etc/maxscale.cnf. Exiting", true); - //Test->check_maxscale_alive(); + //Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug495.cpp b/maxscale-system-test/bug495.cpp index cde63223b..fef6af08f 100644 --- a/maxscale-system-test/bug495.cpp +++ b/maxscale-system-test/bug495.cpp @@ -34,8 +34,8 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->check_log_err((char *) "Unable to find server", true); - Test->check_log_err((char *) "errors were encountered while processing the configuration", true); + Test->check_log_err(0, (char *) "Unable to find server", true); + Test->check_log_err(0, (char *) "errors were encountered while processing the configuration", true); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug507.cpp b/maxscale-system-test/bug507.cpp index 2ae62fcd0..65d1f7700 100644 --- a/maxscale-system-test/bug507.cpp +++ b/maxscale-system-test/bug507.cpp @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) Test->set_timeout(60); Test->repl->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); if (Test->repl->N < 3) { @@ -79,12 +79,12 @@ int main(int argc, char *argv[]) Test->tprintf("Creating table\n"); fflush(stdout); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE IF EXISTS t2"); - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE IF EXISTS t2"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE TABLE t2 (id INT(10) NOT NULL AUTO_INCREMENT, x int, PRIMARY KEY (id));"); Test->tprintf("Doing INSERTs\n"); fflush(stdout); - Test->try_query(Test->conn_rwsplit, (char *) "insert into t2 (x) values (1);"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "insert into t2 (x) values (1);"); Test->stop_timeout(); Test->repl->sync_slaves(); @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) char last_insert_id2[1024]; if ( ( find_field( - Test->conn_rwsplit, sel1, + Test->maxscales->conn_rwsplit[0], sel1, "@@server_id", &last_insert_id1[0]) != 0 ) || ( find_field( @@ -115,10 +115,10 @@ int main(int argc, char *argv[]) "last_insert_id() are different depending in which order terms are in SELECT\n"); } - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->repl->close_connections(); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug509.cpp b/maxscale-system-test/bug509.cpp index f7d501748..779542744 100644 --- a/maxscale-system-test/bug509.cpp +++ b/maxscale-system-test/bug509.cpp @@ -1,14 +1,39 @@ /** - * @file bug509.cpp regression case for bug 509 "rw-split router does not send last_insert_id() to master" + * @file bug509.cpp regression case for bug 509 and 507 ( "Referring to a nonexisting server in servers=... doesn't even raise a warning" + * and "rw-split router does not send last_insert_id() to master" ) * * - "CREATE TABLE t2 (id INT(10) NOT NULL AUTO_INCREMENT, x int, PRIMARY KEY (id));", * - do a number of INSERTs first using RWsplit, then directly Galera nodes. * - do "select @@wsrep_node_address, last_insert_id();" and "select last_insert_id(), @@wsrep_node_address;" and compares results. - * - do "insert into t2 (x) values (i);" 50 times and compares results of + * - do "insert into t2 (x) values (i);" 1000 times and compares results of * "select @@wsrep_node_address, last_insert_id();" and "select last_insert_id(), @@wsrep_node_address;" * + * Test fails if results are different (after 5 seconds of waiting after last INSERT) */ +/* +Kolbe Kegel 2014-09-01 14:48:12 UTC +For some reason, the order of terms in the field list of a SELECT statement influences how the rw-split router decides where to send a statement. + +mariadb> select @@wsrep_node_address, last_insert_id(); ++----------------------+------------------+ +| @@wsrep_node_address | last_insert_id() | ++----------------------+------------------+ +| 192.168.30.31 | 7 | ++----------------------+------------------+ +1 row in set (0.00 sec) + +mariadb> select last_insert_id(), @@wsrep_node_address; ++------------------+----------------------+ +| last_insert_id() | @@wsrep_node_address | ++------------------+----------------------+ +| 0 | 192.168.30.33 | ++------------------+----------------------+ +1 row in set (0.00 sec) +Comment 1 Vilho Raatikka 2014-09-03 20:44:17 UTC +Added code to detect last_insert_id() function and now both types of elements are routed to master and their order of appearance doesn't matter. +*/ + #include #include "testconnections.h" @@ -22,24 +47,61 @@ int main(int argc, char *argv[]) Test->set_timeout(60); Test->galera->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); - Test->tprintf("Creating table"); - Test->try_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS t2;"); - Test->try_query(Test->conn_rwsplit, "CREATE TABLE t2 (id INT(10) NOT NULL AUTO_INCREMENT, x int, PRIMARY KEY (id));"); - Test->tprintf("Doing INSERT through readwritesplit"); - Test->try_query(Test->conn_rwsplit, "START TRANSACTION"); - Test->try_query(Test->conn_rwsplit, "insert into t2 (x) values (1);"); + if (Test->galera->N < 3) + { + Test->tprintf("There is not enoght nodes for test\n"); + delete Test; + exit(1); + } - char last_insert_id1[1024] = ""; - char last_insert_id2[1024] = ""; - find_field(Test->conn_rwsplit, sel1, "last_insert_id()", last_insert_id1); - find_field(Test->conn_rwsplit, sel2, "last_insert_id()", last_insert_id2); - Test->try_query(Test->conn_rwsplit, "COMMIT"); + Test->tprintf("Creating table\n"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE IF EXISTS t2;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], + (char *) "CREATE TABLE t2 (id INT(10) NOT NULL AUTO_INCREMENT, x int, PRIMARY KEY (id));"); + Test->tprintf("Doing INSERTs\n"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "insert into t2 (x) values (1);"); - Test->tprintf("'%s' gave last_insert_id() %s", sel1, last_insert_id1); - Test->tprintf("'%s' gave last_insert_id() %s", sel2, last_insert_id2); - Test->add_result(strcmp(last_insert_id1, last_insert_id2), "last_insert_id() are different depending in which order terms are in SELECT"); + Test->try_query(Test->galera->nodes[0], (char *) "insert into t2 (x) values (2);"); + Test->try_query(Test->galera->nodes[0], (char *) "insert into t2 (x) values (3);"); + + Test->try_query(Test->galera->nodes[1], (char *) "insert into t2 (x) values (4);"); + Test->try_query(Test->galera->nodes[1], (char *) "insert into t2 (x) values (5);"); + Test->try_query(Test->galera->nodes[1], (char *) "insert into t2 (x) values (6);"); + + Test->try_query(Test->galera->nodes[2], (char *) "insert into t2 (x) values (7);"); + Test->try_query(Test->galera->nodes[2], (char *) "insert into t2 (x) values (8);"); + Test->try_query(Test->galera->nodes[2], (char *) "insert into t2 (x) values (9);"); + Test->try_query(Test->galera->nodes[2], (char *) "insert into t2 (x) values (10);"); + + Test->stop_timeout(); + Test->repl->sync_slaves(); + + Test->tprintf("Trying \n"); + char last_insert_id1[1024]; + char last_insert_id2[1024]; + if ( ( + find_field( + Test->maxscales->conn_rwsplit[0], sel1, + "last_insert_id()", &last_insert_id1[0]) + != 0 ) || ( + find_field( + Test->maxscales->conn_rwsplit[0], sel2, + "last_insert_id()", &last_insert_id2[0]) + != 0 )) + { + Test->tprintf("last_insert_id() fied not found!!\n"); + delete Test; + exit(1); + } + else + { + Test->tprintf("'%s' gave last_insert_id() %s\n", sel1, last_insert_id1); + Test->tprintf("'%s' gave last_insert_id() %s\n", sel2, last_insert_id2); + Test->add_result(strcmp(last_insert_id1, last_insert_id2), + "last_insert_id() are different depending in which order terms are in SELECT\n"); + } char id_str[1024]; char str1[1024]; @@ -48,13 +110,12 @@ int main(int argc, char *argv[]) for (int i = 100; i < iterations; i++) { Test->set_timeout(50); - Test->try_query(Test->conn_rwsplit, "START TRANSACTION"); - Test->add_result(execute_query(Test->conn_rwsplit, "insert into t2 (x) values (%d);", i), "Query failed"); + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], "insert into t2 (x) values (%d);", i), "Query failed"); sprintf(str1, "select * from t2 where x=%d;", i); - find_field(Test->conn_rwsplit, sel1, "last_insert_id()", last_insert_id1); - find_field(Test->conn_rwsplit, str1, "id", id_str); + find_field(Test->maxscales->conn_rwsplit[0], sel1, "last_insert_id()", &last_insert_id1[0]); + find_field(Test->maxscales->conn_rwsplit[0], str1, "id", &id_str[0]); int n = 0; @@ -62,12 +123,10 @@ int main(int argc, char *argv[]) { Test->tprintf("Replication is lagging"); sleep(1); - find_field(Test->conn_rwsplit, str1, "id", &id_str[0]); + find_field(Test->maxscales->conn_rwsplit[0], str1, "id", &id_str[0]); n++; } - Test->try_query(Test->conn_rwsplit, "COMMIT"); - Test->add_result(strcmp(last_insert_id1, id_str), "last_insert_id is not equal to id even after waiting 5 seconds"); @@ -77,8 +136,7 @@ int main(int argc, char *argv[]) } } - Test->try_query(Test->conn_rwsplit, "DROP TABLE t2;"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug519.cpp b/maxscale-system-test/bug519.cpp index 87a930463..f4dc362af 100644 --- a/maxscale-system-test/bug519.cpp +++ b/maxscale-system-test/bug519.cpp @@ -1,7 +1,7 @@ /** * @file bug519.cpp - Jira task is MAX-345 * - fill t1 with data - * - execute SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1; against all routers + * - execute SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1; against all maxscales->routers[0] * - DROP TABLE t1 * - LOAD DATA LOCAL INFILE 't1.csv' INTO TABLE t1; using RWSplit * - check if t1 contains right data @@ -76,50 +76,53 @@ int main(int argc, char *argv[]) char str[1024]; Test->set_timeout(60); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("Create t1\n"); - create_t1(Test->conn_rwsplit); + create_t1(Test->maxscales->conn_rwsplit[0]); Test->tprintf("Insert data into t1\n"); Test->set_timeout(60); - insert_into_t1(Test->conn_rwsplit, N); + insert_into_t1(Test->maxscales->conn_rwsplit[0], N); Test->stop_timeout(); Test->repl->sync_slaves(); 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++) { - 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]); + Test->repl->ssh_node(k, str, false); } + //system(str); Test->tprintf("Copying data from t1 to file...\n"); Test->tprintf("using RWSplit: SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1;\n"); - Test->try_query(Test->conn_rwsplit, (char *) "SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1;"); Test->tprintf("using ReadConn master: SELECT * INTO OUTFILE '/tmp/t2.csv' FROM t1;\n"); - Test->try_query(Test->conn_master, (char *) "SELECT * INTO OUTFILE '/tmp/t2.csv' FROM t1;"); + Test->try_query(Test->maxscales->conn_master[0], (char *) "SELECT * INTO OUTFILE '/tmp/t2.csv' FROM t1;"); Test->tprintf("using ReadConn slave: SELECT * INTO OUTFILE '/tmp/t3.csv' FROM t1;\n"); - Test->try_query(Test->conn_slave, (char *) "SELECT * INTO OUTFILE '/tmp/t3.csv' FROM t1;"); + Test->try_query(Test->maxscales->conn_slave[0], (char *) "SELECT * INTO OUTFILE '/tmp/t3.csv' FROM t1;"); Test->tprintf("Copying t1.cvs from Maxscale machine:\n"); - Test->repl->copy_from_node("/tmp/t1.csv", "./t1.csv", 0); + Test->repl->copy_from_node_legacy("/tmp/t1.csv", "./t1.csv", 0); MYSQL *srv[2]; - srv[0] = Test->conn_rwsplit; - srv[1] = Test->conn_master; + srv[0] = Test->maxscales->conn_rwsplit[0]; + srv[1] = Test->maxscales->conn_master[0]; for (int i = 0; i < iterations; i++) { Test->set_timeout(100); Test->tprintf("Dropping t1 \n"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE t1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE t1;"); Test->stop_timeout(); Test->repl->sync_slaves(); Test->set_timeout(200); Test->tprintf("Create t1\n"); - create_t1(Test->conn_rwsplit); + create_t1(Test->maxscales->conn_rwsplit[0]); Test->tprintf("Loading data to t1 from file\n"); Test->try_query(srv[i], (char *) "LOAD DATA LOCAL INFILE 't1.csv' INTO TABLE t1;"); Test->stop_timeout(); @@ -127,15 +130,15 @@ int main(int argc, char *argv[]) Test->set_timeout(100); Test->tprintf("SELECT: rwsplitter\n"); - Test->add_result(select_from_t1(Test->conn_rwsplit, N), "Wrong data in 't1'"); + Test->add_result(select_from_t1(Test->maxscales->conn_rwsplit[0], N), "Wrong data in 't1'"); Test->tprintf("SELECT: master\n"); - Test->add_result(select_from_t1(Test->conn_master, N), "Wrong data in 't1'"); + Test->add_result(select_from_t1(Test->maxscales->conn_master[0], N), "Wrong data in 't1'"); Test->tprintf("SELECT: slave\n"); - Test->add_result(select_from_t1(Test->conn_slave, N), "Wrong data in 't1'"); + Test->add_result(select_from_t1(Test->maxscales->conn_slave[0], N), "Wrong data in 't1'"); } Test->repl->close_connections(); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug526.cpp b/maxscale-system-test/bug526.cpp index fa8042c4b..f81dfc143 100644 --- a/maxscale-system-test/bug526.cpp +++ b/maxscale-system-test/bug526.cpp @@ -42,25 +42,25 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(20); - if (Test->connect_rwsplit() == 0) + if (Test->maxscales->connect_rwsplit(0) == 0) { Test->add_result(1, "Filter config is broken, but service is started\n"); } - if (Test->connect_readconn_master() == 0) + if (Test->maxscales->connect_readconn_master(0) == 0) { Test->add_result(1, "Filter config is broken, but Maxscale is started\n"); } - if (Test->connect_readconn_slave() == 0) + if (Test->maxscales->connect_readconn_slave(0) == 0) { Test->add_result(1, "Filter config is broken, but Maxscale is started\n"); } //sleep(5); - Test->execute_maxadmin_command((char*) "sync logs"); - Test->check_log_err((char *) "Unable to find library for module: foobar", true); - Test->check_log_err((char *) "Failed to load filter module 'foobar'", true); - Test->check_log_err((char *) "Failed to load filter 'testfilter' for service 'RW Split Router'", true); - Test->check_log_err((char *) + Test->maxscales->execute_maxadmin_command(0, (char*) "sync logs"); + Test->check_log_err(0, (char *) "Unable to find library for module: foobar", true); + Test->check_log_err(0, (char *) "Failed to load filter module 'foobar'", true); + Test->check_log_err(0, (char *) "Failed to load filter 'testfilter' for service 'RW Split Router'", true); + Test->check_log_err(0, (char *) "Failed to open, read or process the MaxScale configuration file /etc/maxscale.cnf. Exiting", true); int rval = Test->global_result; diff --git a/maxscale-system-test/bug529.cpp b/maxscale-system-test/bug529.cpp index 0607cd740..3c21b8f3a 100644 --- a/maxscale-system-test/bug529.cpp +++ b/maxscale-system-test/bug529.cpp @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) Test->repl->connect(); - conn = Test->open_rwsplit_connection(); + conn = Test->maxscales->open_rwsplit_connection(0); execute_query(conn, (char *) "USE test;"); create_t1(conn); mysql_close(conn); @@ -158,9 +158,9 @@ int main(int argc, char *argv[]) for (i = 0; i < conn_N; i++) { Test->set_timeout(60); - rwsplit_conn[i] = Test->open_rwsplit_connection(); - master_conn[i] = Test->open_readconn_master_connection(); - slave_conn[i] = Test->open_readconn_slave_connection(); + rwsplit_conn[i] = Test->maxscales->open_rwsplit_connection(0); + master_conn[i] = Test->maxscales->open_readconn_master_connection(0); + slave_conn[i] = Test->maxscales->open_readconn_slave_connection(0); sprintf(sql, "INSERT INTO t1 (x1, fl) VALUES(%d, 1);", i); execute_query(rwsplit_conn[i], sql); sprintf(sql, "INSERT INTO t1 (x1, fl) VALUES(%d, 2);", i); @@ -171,7 +171,7 @@ int main(int argc, char *argv[]) for (i = 0; i < Test->repl->N; i++) { Test->set_timeout(60); - num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscale_IP, Test->maxscale_hostname, (char *) "test"); + num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscales->IP[0], Test->maxscales->hostname[0], (char *) "test"); Test->tprintf("Connections to node %d (%s): %d\n", i, Test->repl->IP[i], num_conn); if ((i == 0) && (num_conn > 2 * conn_N)) { @@ -189,7 +189,7 @@ int main(int argc, char *argv[]) for (i = 0; i < Test->repl->N; i++) { Test->set_timeout(60); - num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscale_IP, Test->maxscale_hostname, (char *) "test"); + num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscales->IP[0], Test->maxscales->hostname[0], (char *) "test"); printf("Connections to node %d (%s): %d\n", i, Test->repl->IP[i], num_conn); if ((i == 0) && (num_conn > 2 * conn_N)) { @@ -203,7 +203,7 @@ int main(int argc, char *argv[]) for (i = 0; i < Test->repl->N; i++) { - num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscale_IP, Test->maxscale_hostname, (char *) "test"); + num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscales->IP[0], Test->maxscales->hostname[0], (char *) "test"); printf("Connections to node %d (%s): %d\n", i, Test->repl->IP[i], num_conn); if ((i == 0) && (num_conn > 2 * conn_N)) { @@ -218,7 +218,7 @@ int main(int argc, char *argv[]) for (i = 0; i < Test->repl->N; i++) { Test->set_timeout(60); - num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscale_IP, Test->maxscale_hostname, (char *) "test"); + num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscales->IP[0], Test->maxscales->hostname[0], (char *) "test"); printf("Connections to node %d (%s): %d\n", i, Test->repl->IP[i], num_conn); if ((i == 0) && (num_conn != 0)) { @@ -235,7 +235,7 @@ int main(int argc, char *argv[]) for (i = 0; i < Test->repl->N; i++) { Test->set_timeout(60); - num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscale_IP, Test->maxscale_hostname, (char *) "test"); + num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscales->IP[0], Test->maxscales->hostname[0], (char *) "test"); Test->tprintf("Connections to node %d (%s): %d\n", i, Test->repl->IP[i], num_conn); if ((i == 0) && (num_conn != 0)) { @@ -247,7 +247,7 @@ int main(int argc, char *argv[]) for (i = 0; i < conn_N; i++) { Test->set_timeout(60); - slave_conn[i] = Test->open_readconn_slave_connection(); + slave_conn[i] = Test->maxscales->open_readconn_slave_connection(0); sprintf(sql, "SELECT * FROM t1"); execute_query(slave_conn[i], sql); fflush(stdout); @@ -256,7 +256,7 @@ int main(int argc, char *argv[]) for (i = 0; i < Test->repl->N; i++) { Test->set_timeout(60); - num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscale_IP, Test->maxscale_hostname, (char *) "test"); + num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscales->IP[0], Test->maxscales->hostname[0], (char *) "test"); Test->tprintf("Connections to node %d (%s): %d\n", i, Test->repl->IP[i], num_conn); if ((i == 0) && (num_conn != 0)) { @@ -275,7 +275,7 @@ int main(int argc, char *argv[]) for (i = 0; i < Test->repl->N; i++) { Test->set_timeout(60); - num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscale_IP, Test->maxscale_hostname, (char *) "test"); + num_conn = get_conn_num(Test->repl->nodes[i], Test->maxscales->IP[0], Test->maxscales->hostname[0], (char *) "test"); Test->tprintf("Connections to node %d (%s): %d\n", i, Test->repl->IP[i], num_conn); if ((i == 0) && (num_conn != 0)) { @@ -295,7 +295,7 @@ void *parall_traffic( void *ptr ) int i; for (i = 0; i < conn_N; i++) { - slave_conn1[i] = Test->open_readconn_slave_connection(); + slave_conn1[i] = Test->maxscales->open_readconn_slave_connection(0); execute_query(slave_conn1[i], "SELECT * FROM t1"); } diff --git a/maxscale-system-test/bug539.cpp b/maxscale-system-test/bug539.cpp index 25ce79914..00aeb6e88 100644 --- a/maxscale-system-test/bug539.cpp +++ b/maxscale-system-test/bug539.cpp @@ -21,35 +21,32 @@ int main(int argc, char *argv[]) int N_cmd = 2; char * fail_cmd[N_cmd - 1]; - int N_ports = 3; - int ports[N_ports]; + + fail_cmd[0] = (char *) "fail backendfd"; fail_cmd[1] = (char *) "fail clientfd"; - ports[0] = Test->rwsplit_port; - ports[1] = Test->readconn_master_port; - ports[2] = Test->readconn_slave_port; for (i = 0; i < N_cmd; i++) { - for (j = 0; j < N_ports; j++) + for (j = 0; j < Test->maxscales->N_ports[0]; j++) { Test->tprintf("Executing MaxAdmin command '%s'\n", fail_cmd[i]); - if (execute_maxadmin_command(Test->maxscale_IP, (char *) "admin", Test->maxadmin_password, fail_cmd[i]) != 0) + if (maxscales->execute_maxadmin_command(0, Test->maxscales->IP[0], (char *) "admin", Test->maxscales->maxadmin_password[0], fail_cmd[i]) != 0) { Test->add_result(1, "MaxAdmin command failed\n"); } else { - printf("Trying query against %d\n", ports[j]); - conn = open_conn(ports[j], Test->maxscale_IP, Test->maxscale_user, Test->maxscale_user, Test->ssl); + printf("Trying query against %d\n", Test->maxscales->ports[0][j]); + conn = open_conn(ports[j], Test->maxscales->IP[0], Test->maxscales->user_name, Test->maxscales->password, Test->ssl); Test->try_query(conn, (char *) "show processlist;"); } } } - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug547.cpp b/maxscale-system-test/bug547.cpp index 001fa1cc4..aca5fbadf 100644 --- a/maxscale-system-test/bug547.cpp +++ b/maxscale-system-test/bug547.cpp @@ -39,27 +39,27 @@ int main(int argc, char *argv[]) Test->set_timeout(30); Test->tprintf("Connecting to all MaxScale services, expecting error\n"); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->set_timeout(30); Test->tprintf("Trying some queries, expecting failure, but not a crash\n"); - execute_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS t1"); - execute_query(Test->conn_rwsplit, "CREATE TABLE t1 (x INT)"); - execute_query(Test->conn_rwsplit, "INSERT INTO t1 (x) VALUES (1)"); - execute_query(Test->conn_rwsplit, "select * from t1"); - execute_query(Test->conn_master, "select * from t1"); - execute_query(Test->conn_slave, "select * from t1"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS t1"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE TABLE t1 (x INT)"); + execute_query(Test->maxscales->conn_rwsplit[0], "INSERT INTO t1 (x) VALUES (1)"); + execute_query(Test->maxscales->conn_rwsplit[0], "select * from t1"); + execute_query(Test->maxscales->conn_master[0], "select * from t1"); + execute_query(Test->maxscales->conn_slave[0], "select * from t1"); Test->set_timeout(10); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->set_timeout(30); Test->repl->unblock_all_nodes(); Test->stop_timeout(); sleep(15); - Test->check_log_err("fatal signal 11", false); - Test->check_log_err("Failed to create new router session for service", true); + Test->check_log_err(0, "fatal signal 11", false); + Test->check_log_err(0, "Failed to create new router session for service", true); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug565.cpp b/maxscale-system-test/bug565.cpp index deaa749ff..fe303ca7f 100644 --- a/maxscale-system-test/bug565.cpp +++ b/maxscale-system-test/bug565.cpp @@ -62,19 +62,19 @@ int main(int argc, char *argv[]) Test->repl->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); - conn_found_rows = open_conn_db_flags(Test->rwsplit_port, Test->maxscale_IP, (char *) "test", - Test->maxscale_user, Test->maxscale_password, CLIENT_FOUND_ROWS, Test->ssl); + conn_found_rows = open_conn_db_flags(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "test", + Test->maxscales->user_name, Test->maxscales->password, CLIENT_FOUND_ROWS, Test->ssl); Test->set_timeout(30); - execute_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS t1"); - execute_query(Test->conn_rwsplit, "CREATE TABLE t1(id INT PRIMARY KEY, val INT, msg VARCHAR(100))"); - execute_query(Test->conn_rwsplit, + execute_query(Test->maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS t1"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE TABLE t1(id INT PRIMARY KEY, val INT, msg VARCHAR(100))"); + execute_query(Test->maxscales->conn_rwsplit[0], "INSERT INTO t1 VALUES (1, 1, 'foo'), (2, 1, 'bar'), (3, 2, 'baz'), (4, 2, 'abc')"); Test->set_timeout(30); - execute_query_affected_rows(Test->conn_rwsplit, "UPDATE t1 SET msg='xyz' WHERE val=2", &rows); + execute_query_affected_rows(Test->maxscales->conn_rwsplit[0], "UPDATE t1 SET msg='xyz' WHERE val=2", &rows); Test->tprintf("update #1: %ld (expeced value is 2)\n", (long) rows); if (rows != 2) { @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) } Test->set_timeout(30); - execute_query_affected_rows(Test->conn_rwsplit, "UPDATE t1 SET msg='xyz' WHERE val=2", &rows); + execute_query_affected_rows(Test->maxscales->conn_rwsplit[0], "UPDATE t1 SET msg='xyz' WHERE val=2", &rows); Test->tprintf("update #2: %ld (expeced value is 0)\n", (long) rows); if (rows != 0) { @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) Test->add_result(1, "Affected rows is not 2\n"); } - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug571.cpp b/maxscale-system-test/bug571.cpp index d9e7ab492..ed893484c 100644 --- a/maxscale-system-test/bug571.cpp +++ b/maxscale-system-test/bug571.cpp @@ -124,17 +124,17 @@ int main(int argc, char *argv[]) Test->tprintf("Connecting to all MaxScale services\n"); Test->set_timeout(10); - Test->add_result(Test->connect_maxscale(), "Error connectiong to Maxscale\n"); + Test->add_result(Test->maxscales->connect_maxscale(0), "Error connectiong to Maxscale\n"); Test->tprintf("executing fetch * from mysql.user \n"); Test->set_timeout(10); - Test->try_query(Test->conn_rwsplit, (char *) "fetch * from mysql.user;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "fetch * from mysql.user;"); Test->set_timeout(10); - Test->try_query(Test->conn_rwsplit, (char *) "fetch count(*) form mysql.user;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "fetch count(*) form mysql.user;"); Test->set_timeout(10); - Test->close_maxscale_connections(); - Test->check_maxscale_alive(); + Test->maxscales->close_maxscale_connections(0); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug572.cpp b/maxscale-system-test/bug572.cpp index e6e91c97b..cebeebb3f 100644 --- a/maxscale-system-test/bug572.cpp +++ b/maxscale-system-test/bug572.cpp @@ -32,13 +32,13 @@ int main(int argc, char *argv[]) Test->set_timeout(10); Test->repl->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Trying GRANT for with bad IP: RWSplit\n"); - create_drop_bad_user(Test->conn_rwsplit, Test); + create_drop_bad_user(Test->maxscales->conn_rwsplit[0], Test); Test->tprintf("Trying SELECT to check if Maxscale hangs\n"); - Test->try_query(Test->conn_rwsplit, (char *) "select * from mysql.user"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "select * from mysql.user"); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug587.cpp b/maxscale-system-test/bug587.cpp index 1a9a96670..04f2edaf8 100644 --- a/maxscale-system-test/bug587.cpp +++ b/maxscale-system-test/bug587.cpp @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); Test->repl->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); char server_id[256]; char server_id_d[256]; @@ -87,7 +87,7 @@ int main(int argc, char *argv[]) sprintf(hint_sql, "select @@server_id; -- maxscale route to server server%d", j + 1); Test->tprintf("%s\n", hint_sql); - find_field(Test->conn_rwsplit, hint_sql, (char *) "@@server_id", &server_id[0]); + find_field(Test->maxscales->conn_rwsplit[0], hint_sql, (char *) "@@server_id", &server_id[0]); find_field(Test->repl->nodes[j], (char *) "select @@server_id;", (char *) "@@server_id", &server_id_d[0]); Test->tprintf("server%d ID from Maxscale: \t%s\n", j + 1, server_id); @@ -97,10 +97,10 @@ int main(int argc, char *argv[]) } } - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->repl->close_connections(); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug592.cpp b/maxscale-system-test/bug592.cpp index 5c0488b3c..a2c595b07 100644 --- a/maxscale-system-test/bug592.cpp +++ b/maxscale-system-test/bug592.cpp @@ -95,16 +95,16 @@ int main(int argc, char *argv[]) int i; Test->repl->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); for (i = 1; i < Test->repl->N; i++) { execute_query(Test->repl->nodes[i], (char *) "stop slave;"); } - execute_query(Test->conn_rwsplit, (char *) "CREATE USER 'test_user'@'%%' IDENTIFIED BY 'pass'"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE USER 'test_user'@'%%' IDENTIFIED BY 'pass'"); - MYSQL * conn = open_conn_no_db(Test->rwsplit_port, Test->maxscale_IP, (char *) "test_user", (char *) "pass", + MYSQL * conn = open_conn_no_db(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "test_user", (char *) "pass", Test->ssl); if (conn == NULL) @@ -117,10 +117,10 @@ int main(int argc, char *argv[]) execute_query(Test->repl->nodes[i], (char *) "start slave;"); } - execute_query(Test->conn_rwsplit, (char *) "DROP USER 'test_user'@'%%'"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP USER 'test_user'@'%%'"); Test->repl->close_connections(); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug601.cpp b/maxscale-system-test/bug601.cpp index 4b1205fe7..43a771c8b 100644 --- a/maxscale-system-test/bug601.cpp +++ b/maxscale-system-test/bug601.cpp @@ -64,12 +64,12 @@ int main(int argc, char *argv[]) Test->repl->execute_query_all_nodes((char *) "set global max_connect_errors=1000;"); Test->repl->execute_query_all_nodes((char *) "set global max_connections=1000;"); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Creating one user 'user@%%'"); - execute_query_silent(Test->conn_rwsplit, (char *) "DROP USER user@'%'"); - Test->try_query(Test->conn_rwsplit, (char *) "CREATE USER user@'%%' identified by 'pass2'"); - Test->try_query(Test->conn_rwsplit, (char *) "GRANT SELECT ON test.* TO user@'%%';"); - Test->try_query(Test->conn_rwsplit, (char *) "FLUSH PRIVILEGES;"); + execute_query_silent(Test->maxscales->conn_rwsplit[0], (char *) "DROP USER user@'%'"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE USER user@'%%' identified by 'pass2'"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "GRANT SELECT ON test.* TO user@'%%';"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "FLUSH PRIVILEGES;"); Test->tprintf("Starting parallel thread which opens/closes session in the loop"); @@ -82,10 +82,10 @@ int main(int argc, char *argv[]) for (int i = 0; i < iterations; i++) { Test->set_timeout(15); - Test->add_result(mysql_change_user(Test->conn_rwsplit, "user", "pass2", (char *) "test"), - "change_user failed! %", mysql_error(Test->conn_rwsplit)); - Test->add_result(mysql_change_user(Test->conn_rwsplit, Test->maxscale_user, Test->maxscale_password, - (char *) "test"), "change_user failed! %s", mysql_error(Test->conn_rwsplit)); + Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], "user", "pass2", (char *) "test"), + "change_user failed! %", mysql_error(Test->maxscales->conn_rwsplit[0])); + Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], Test->maxscales->user_name, Test->maxscales->password, + (char *) "test"), "change_user failed! %s", mysql_error(Test->maxscales->conn_rwsplit[0])); } Test->tprintf("Waiting for all threads to finish"); @@ -98,13 +98,13 @@ int main(int argc, char *argv[]) Test->tprintf("All threads are finished"); Test->repl->flush_hosts(); - Test->tprintf("Change user to '%s' in order to be able to DROP user", Test->maxscale_user); + Test->tprintf("Change user to '%s' in order to be able to DROP user", Test->maxscales->user_name); Test->set_timeout(30); - mysql_change_user(Test->conn_rwsplit, Test->maxscale_user, Test->maxscale_password, NULL); + mysql_change_user(Test->maxscales->conn_rwsplit[0], Test->maxscales->user_name, Test->maxscales->password, NULL); - Test->tprintf("Dropping user", Test->maxscale_user); - Test->try_query(Test->conn_rwsplit, (char *) "DROP USER user@'%%';"); - Test->check_maxscale_alive(); + Test->tprintf("Dropping user", Test->maxscales->user_name); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP USER user@'%%';"); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; @@ -116,7 +116,7 @@ void *parall_traffic( void *ptr ) MYSQL * conn; while (exit_flag == 0) { - conn = Test->open_rwsplit_connection(); + conn = Test->maxscales->open_rwsplit_connection(0); mysql_close(conn); if (Test->backend_ssl) { diff --git a/maxscale-system-test/bug620.cpp b/maxscale-system-test/bug620.cpp index e321504f5..b4f9b29fe 100644 --- a/maxscale-system-test/bug620.cpp +++ b/maxscale-system-test/bug620.cpp @@ -221,21 +221,21 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(30); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Creating 'root'@'%%'\n"); - //global_result += execute_query(Test->conn_rwsplit, (char *) "CREATE USER 'root'@'%'; SET PASSWORD FOR 'root'@'%' = PASSWORD('skysqlroot');"); + //global_result += execute_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE USER 'root'@'%'; SET PASSWORD FOR 'root'@'%' = PASSWORD('skysqlroot');"); - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%%' IDENTIFIED BY 'skysqlroot';"); - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY 'skysqlroot';"); sleep(10); MYSQL * conn; Test->tprintf("Connecting using 'root'@'%%'\n"); - conn = open_conn(Test->rwsplit_port, Test->maxscale_IP, (char *) "root", (char *) "skysqlroot", Test->ssl); + conn = open_conn(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "root", (char *) "skysqlroot", Test->ssl); if (mysql_errno(conn) != 0) { Test->add_result(1, "Connection using 'root' user failed, error: %s\n", mysql_error(conn)); @@ -253,15 +253,15 @@ int main(int argc, char *argv[]) } Test->tprintf("Dropping 'root'@'%%'\n"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP USER 'root'@'%%';"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP USER 'root'@'%%';"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - Test->check_log_err((char *) "Failed to add user skysql", false); - Test->check_log_err((char *) "getaddrinfo failed", false); - Test->check_log_err((char *) "Couldn't find suitable Master", false); + Test->check_log_err(0, (char *) "Failed to add user skysql", false); + Test->check_log_err(0, (char *) "getaddrinfo failed", false); + Test->check_log_err(0, (char *) "Couldn't find suitable Master", false); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug626.cpp b/maxscale-system-test/bug626.cpp index a7bd23fa7..c6b1fe8f5 100644 --- a/maxscale-system-test/bug626.cpp +++ b/maxscale-system-test/bug626.cpp @@ -154,7 +154,7 @@ int main(int argc, char *argv[]) Test->set_timeout(20); printf("Trying to connect using user with old style password\n"); - MYSQL * conn = open_conn(Test->rwsplit_port, Test->maxscale_IP, (char *) "old", (char *) "old", Test->ssl); + MYSQL * conn = open_conn(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "old", (char *) "old", Test->ssl); if ( mysql_errno(conn) != 0) { @@ -171,8 +171,8 @@ int main(int argc, char *argv[]) execute_query(Test->repl->nodes[0], "DROP USER 'old'@'%%'"); - Test->check_log_err((char *) "MaxScale does not support these old passwords", true); - Test->check_maxscale_alive(); + Test->check_log_err(0, (char *) "MaxScale does not support these old passwords", true); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug634.cpp b/maxscale-system-test/bug634.cpp index 877f6f8ef..effb2b5df 100644 --- a/maxscale-system-test/bug634.cpp +++ b/maxscale-system-test/bug634.cpp @@ -25,17 +25,17 @@ int main(int argc, char *argv[]) char master_ip[100]; - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); for (int i = 0; i < 100; i++) { Test->set_timeout(5); - Test->add_result(find_field(Test->conn_rwsplit, (char *) "SHOW SLAVE STATUS", (char *) "Master_Host", + Test->add_result(find_field(Test->maxscales->conn_rwsplit[0], (char *) "SHOW SLAVE STATUS", (char *) "Master_Host", master_ip), "Master_host files is not found in the SHOW SLAVE STATUS reply, probably query went to master\n"); Test->add_result(strcmp(master_ip, Test->repl->IP_private[0]), "Master IP is wrong\n"); } - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug643.cpp b/maxscale-system-test/bug643.cpp index acccc97c3..a2d465611 100644 --- a/maxscale-system-test/bug643.cpp +++ b/maxscale-system-test/bug643.cpp @@ -32,21 +32,21 @@ int main(int argc, char *argv[]) Test->tprintf("Trying to connect to all Maxscale services\n"); fflush(stdout); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Trying to send query to ReadConn master\n"); fflush(stdout); - Test->try_query(Test->conn_master, (char *) "show processlist"); + Test->try_query(Test->maxscales->conn_master[0], (char *) "show processlist"); Test->tprintf("Trying to send query to ReadConn slave\n"); fflush(stdout); - Test->try_query(Test->conn_slave, (char *) "show processlist"); + Test->try_query(Test->maxscales->conn_slave[0], (char *) "show processlist"); Test->tprintf("Trying to send query to RWSplit, expecting failure\n"); fflush(stdout); - if (execute_query(Test->conn_rwsplit, (char *) "show processlist") == 0) + if (execute_query(Test->maxscales->conn_rwsplit[0], (char *) "show processlist") == 0) { Test->add_result(1, "FAIL: Query to broken service succeeded!\n"); } - Test->close_maxscale_connections(); - Test->check_log_err("Recursive use of tee filter in service", true); + Test->maxscales->close_maxscale_connections(0); + Test->check_log_err(0, "Recursive use of tee filter in service", true); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug643_1.cpp b/maxscale-system-test/bug643_1.cpp index 0cc2aa7d5..7c5b16e3b 100644 --- a/maxscale-system-test/bug643_1.cpp +++ b/maxscale-system-test/bug643_1.cpp @@ -75,19 +75,19 @@ int main(int argc, char *argv[]) Test->tprintf("Trying to connect to all Maxscale services\n"); fflush(stdout); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Trying to send query to RWSplit\n"); fflush(stdout); - execute_query(Test->conn_rwsplit, (char *) "show processlist"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "show processlist"); Test->tprintf("Trying to send query to ReadConn master\n"); fflush(stdout); - execute_query(Test->conn_master, (char *) "show processlist"); + execute_query(Test->maxscales->conn_master[0], (char *) "show processlist"); Test->tprintf("Trying to send query to ReadConn slave\n"); fflush(stdout); - execute_query(Test->conn_slave, (char *) "show processlist"); - Test->close_maxscale_connections(); + execute_query(Test->maxscales->conn_slave[0], (char *) "show processlist"); + Test->maxscales->close_maxscale_connections(0); - Test->check_log_err((char *) "Unable to find filter 'tests' for service 'RW Split2'", true); + Test->check_log_err(0, (char *) "Unable to find filter 'tests' for service 'RW Split2'", true); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug645.cpp b/maxscale-system-test/bug645.cpp index 9d5062c10..d4eb5204f 100644 --- a/maxscale-system-test/bug645.cpp +++ b/maxscale-system-test/bug645.cpp @@ -182,7 +182,7 @@ Comment 3 Vilho Raatikka 2014-12-11 16:35:46 UTC Using readconnroute _where_? in tee? Comment 4 Vilho Raatikka 2014-12-12 08:27:41 UTC gwbuf_type is not set and that is the immediate cause for assertion with Debug version. -Reason why the type is not set is in the way the packets are first processed in mysql_client.c client protocol module and then passed optionally to filters and router. There is a bug because it is assumed that when client protocol module reads incoming packet it can resolve which router will handle the packet processing. The code doesn't take into account that same packet can be processed by many different routers, like in the case of readconnrouter->tee->readwritesplit. +Reason why the type is not set is in the way the packets are first processed in mysql_client.c client protocol module and then passed optionally to filters and router. There is a bug because it is assumed that when client protocol module reads incoming packet it can resolve which router will handle the packet processing. The code doesn't take into account that same packet can be processed by many different maxscales->routers[0], like in the case of readconnrouter->tee->readwritesplit. Another problem is in readwritesplit where it is assumed that it is the first and the only router that will process tha data. So it includes checks that the buffer has correct type. Required changes are: @@ -199,13 +199,13 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->connect_maxscale(); - Test->try_query(Test->conn_master, (char *) "show processlist"); - Test->try_query(Test->conn_slave, (char *) "show processlist"); - Test->try_query(Test->conn_rwsplit, (char *) "show processlist"); - Test->close_maxscale_connections(); + Test->maxscales->connect_maxscale(0); + Test->try_query(Test->maxscales->conn_master[0], (char *) "show processlist"); + Test->try_query(Test->maxscales->conn_slave[0], (char *) "show processlist"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "show processlist"); + Test->maxscales->close_maxscale_connections(0); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug645_1.cpp b/maxscale-system-test/bug645_1.cpp index b5a1b6068..a6e4ca62c 100644 --- a/maxscale-system-test/bug645_1.cpp +++ b/maxscale-system-test/bug645_1.cpp @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) { TestConnections test(argc, argv); - test.check_maxscale_alive(); - test.check_log_err( "Couldn't find suitable Master from 2 candidates", true); + test.check_maxscale_alive(0); + test.check_log_err(0, "Couldn't find suitable Master from 2 candidates", true); return test.global_result; } diff --git a/maxscale-system-test/bug649.cpp b/maxscale-system-test/bug649.cpp index 9102c7914..2a269038b 100644 --- a/maxscale-system-test/bug649.cpp +++ b/maxscale-system-test/bug649.cpp @@ -53,14 +53,22 @@ int main(int argc, char *argv[]) int check_iret[threads_num]; Test = new TestConnections(argc, argv); - int time_to_run = 10; - Test->set_timeout(60); + int time_to_run = (Test->smoke) ? 10 : 30; + Test->set_timeout(10); + + Test->tprintf("Connecting to RWSplit %s\n", Test->maxscales->IP[0]); + Test->maxscales->connect_rwsplit(0); Test->repl->connect(); - create_t1(Test->repl->nodes[0]); - Test->repl->sync_slaves(); + Test->tprintf("Drop t1 if exists\n"); + execute_query(Test->repl->nodes[0], "DROP TABLE IF EXISTS t1;"); + Test->tprintf("Create t1\n"); + Test->add_result(create_t1(Test->repl->nodes[0]), "t1 creation Failed\n"); Test->repl->close_connections(); + Test->stop_timeout(); + sleep(5); + create_insert_string(sql, 65000, 1); Test->tprintf("Creating query threads\n", time_to_run); for (int j = 0; j < threads_num; j++) @@ -82,7 +90,14 @@ int main(int argc, char *argv[]) Test->set_timeout(30); Test->tprintf("Trying query to RWSplit, expecting failure, but not a crash\n"); - Test->add_result(execute_query(Test->conn_rwsplit, "show processlist;") == 0, "Query should fail"); + if (execute_query_silent(Test->maxscales->conn_rwsplit[0], (char *) "show processlist;") == 0) + { + Test->add_result(1, "Failure is expected, but query is ok\n"); + } + + Test->stop_timeout(); + sleep(time_to_run); + Test->tprintf("Setup firewall back to allow mysql\n"); Test->repl->unblock_node(0); fflush(stdout); @@ -95,14 +110,23 @@ int main(int argc, char *argv[]) pthread_join(parall_traffic1[i], NULL); Test->tprintf("exit %d\n", i); } + Test->stop_timeout(); + sleep(5); Test->set_timeout(20); Test->tprintf("Checking Maxscale is alive\n"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); + + Test->set_timeout(20); + Test->tprintf("Reconnecting to RWSplit ...\n"); + Test->maxscales->connect_rwsplit(0); + Test->tprintf(" ... and trying query\n"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "show processlist;"); + Test->maxscales->close_rwsplit(0); /** Clean up */ Test->repl->connect(); - execute_query(Test->repl->nodes[0], "DROP TABLE t1;"); + execute_query(Test->repl->nodes[0], "DROP TABLE IF EXISTS t1;"); int rval = Test->global_result; delete Test; @@ -114,7 +138,7 @@ void *parall_traffic( void *ptr ) { MYSQL * conn; mysql_thread_init(); - conn = Test->open_rwsplit_connection(); + conn = Test->maxscales->open_rwsplit_connection(0); if ((conn != NULL) && (mysql_errno(conn) == 0)) { while (exit_flag == 0) diff --git a/maxscale-system-test/bug650.cpp b/maxscale-system-test/bug650.cpp index d7cfce143..d42f1ea00 100644 --- a/maxscale-system-test/bug650.cpp +++ b/maxscale-system-test/bug650.cpp @@ -9,8 +9,8 @@ int main(int argc, char *argv[]) { TestConnections test(argc, argv); - test.check_maxscale_alive(); - test.check_log_err( "Couldn't find suitable Master from 2 candidates", true); - test.check_log_err( "Failed to create new router session for service 'RW_Split'", true); + test.check_maxscale_alive(0); + test.check_log_err(0, "Couldn't find suitable Master from 2 candidates", true); + test.check_log_err(0, "Failed to create new router session for service 'RW_Split'", true); return test.global_result; } diff --git a/maxscale-system-test/bug653.cpp b/maxscale-system-test/bug653.cpp index 261eb579a..0fa1637de 100644 --- a/maxscale-system-test/bug653.cpp +++ b/maxscale-system-test/bug653.cpp @@ -42,17 +42,17 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(50); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Creating user with old style password\n"); - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE USER 'user_long_host11'@'very_long_hostname_that_probably_caused_crashhh.com.net.org' IDENTIFIED BY 'old'"); - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "GRANT ALL PRIVILEGES ON *.* TO 'user_long_host11'@'very_long_hostname_that_probably_caused_crashhh.com.net.org' WITH GRANT OPTION"); sleep(10); Test->tprintf("Trying to connect using user with old style password\n"); - MYSQL * conn = open_conn(Test->rwsplit_port, Test->maxscale_IP, (char *) "user_long_host11", (char *) "old", + MYSQL * conn = open_conn(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "user_long_host11", (char *) "old", Test->ssl); if ( mysql_errno(conn) != 0 ) @@ -68,11 +68,11 @@ int main(int argc, char *argv[]) mysql_close(conn); } - Test->try_query(Test->conn_rwsplit, + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP USER 'user_long_host11'@'very_long_hostname_that_probably_caused_crashhh.com.net.org'"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug654.cpp b/maxscale-system-test/bug654.cpp index 4fd192446..30df767be 100644 --- a/maxscale-system-test/bug654.cpp +++ b/maxscale-system-test/bug654.cpp @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) Test->set_timeout(30); char result[1024]; - Test->get_maxadmin_param((char *) "show dbusers RW Split Router", (char *) "Incorrect number of arguments:", + Test->maxscales->get_maxadmin_param(0, (char *) "show dbusers RW Split Router", (char *) "Incorrect number of arguments:", result); Test->tprintf("result %s\n", result); @@ -71,57 +71,57 @@ int main(int argc, char *argv[]) Test->add_result(1, "there is NO \"show dbusers expects 1 argument\" message"); } Test->set_timeout(30); - Test->get_maxadmin_param((char *) "show dbusers \"RW Split Router\"", (char *) "User names:", result); + Test->maxscales->get_maxadmin_param(0, (char *) "show dbusers \"RW Split Router\"", (char *) "User names:", result); Test->tprintf("result %s\n", result); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "reload dbusers 0x232fed0"); + Test->maxscales->execute_maxadmin_command(0, (char *) "reload dbusers 0x232fed0"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "reload dbusers Хрен"); + Test->maxscales->execute_maxadmin_command(0, (char *) "reload dbusers Хрен"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "reload dbusers Хрен моржовый"); + Test->maxscales->execute_maxadmin_command(0, (char *) "reload dbusers Хрен моржовый"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "Хрен моржовый"); + Test->maxscales->execute_maxadmin_command(0, (char *) "Хрен моржовый"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "khren morzhovyj"); + Test->maxscales->execute_maxadmin_command(0, (char *) "khren morzhovyj"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show Хрен"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show Хрен"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show Хрен моржовый"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show Хрен моржовый"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show khren morzhovyj"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show khren morzhovyj"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show dcb Хрен"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show dcb Хрен"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show dcb Хрен моржовый"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show dcb Хрен моржовый"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show dcb khren morzhovyj"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show dcb khren morzhovyj"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show server Хрен"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show server Хрен"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show server Хрен моржовый"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show server Хрен моржовый"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show server khren morzhovyj"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show server khren morzhovyj"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show service Хрен"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show service Хрен"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show service Хрен моржовый"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show service Хрен моржовый"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show service khren morzhovyj"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show service khren morzhovyj"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "show service khren morzhovyj"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show service khren morzhovyj"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "list listeners"); + Test->maxscales->execute_maxadmin_command(0, (char *) "list listeners"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "restart monitor"); + Test->maxscales->execute_maxadmin_command(0, (char *) "restart monitor"); Test->set_timeout(30); - Test->execute_maxadmin_command((char *) "restart service"); + Test->maxscales->execute_maxadmin_command(0, (char *) "restart service"); if (!Test->smoke) { @@ -186,15 +186,15 @@ int main(int argc, char *argv[]) Test->set_timeout(30); sprintf(str1, "%s %s", cmd[i1], garbage[i2]); Test->tprintf("Trying '%s'\n", str1); - Test->execute_maxadmin_command(str1); + Test->maxscales->execute_maxadmin_command(0, str1); sprintf(str1, "%s %s%s%s%s %s ", cmd[i1], garbage[i2], garbage[i2], garbage[i2], garbage[i2], garbage[i2]); Test->tprintf("Trying '%s'\n", str1); - Test->execute_maxadmin_command(str1); + Test->maxscales->execute_maxadmin_command(0, str1); } } } - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug656.cpp b/maxscale-system-test/bug656.cpp index d27a45aa7..8401fd030 100644 --- a/maxscale-system-test/bug656.cpp +++ b/maxscale-system-test/bug656.cpp @@ -15,24 +15,24 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(30); - Test->tprintf("Connecting to RWSplit %s\n", Test->maxscale_IP); - Test->connect_rwsplit(); + Test->tprintf("Connecting to RWSplit %s\n", Test->maxscales->IP[0]); + Test->maxscales->connect_rwsplit(0); Test->tprintf("Setup firewall to block mysql on master\n"); Test->repl->block_node(0); //printf("Trying query to RWSplit, expecting failure, but not a crash\n"); fflush(stdout); - //execute_query(Test->conn_rwsplit, (char *) "show processlist;"); - execute_maxadmin_command_print(Test->maxscale_IP, (char *) "admin", Test->maxadmin_password, + //execute_query(Test->maxscales->conn_rwsplit[0], (char *) "show processlist;"); + execute_maxadmin_command_print(Test->maxscales->IP[0], (char *) "admin", Test->maxscales->maxadmin_password[0], (char *) "show servers"); Test->tprintf("Setup firewall back to allow mysql and wait\n"); Test->repl->unblock_node(0); sleep(10); - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug657.cpp b/maxscale-system-test/bug657.cpp index cf41028ad..00b397d9d 100644 --- a/maxscale-system-test/bug657.cpp +++ b/maxscale-system-test/bug657.cpp @@ -49,8 +49,8 @@ int main(int argc, char *argv[]) TestConnections *Test = new TestConnections(argc, argv); Test->set_timeout(200); - Test->tprintf("Connecting to ReadConn Master %s\n", Test->maxscale_IP); - Test->connect_readconn_master(); + Test->tprintf("Connecting to ReadConn Master %s\n", Test->maxscales->IP[0]); + Test->maxscales->connect_readconn_master(0); sleep(1); @@ -60,8 +60,8 @@ int main(int argc, char *argv[]) sleep(10); Test->tprintf("Reconnecting to ReadConnMaster\n"); - Test->close_readconn_master(); - Test->connect_readconn_master(); + Test->maxscales->close_readconn_master(0); + Test->maxscales->connect_readconn_master(0); sleep(5); @@ -70,12 +70,12 @@ int main(int argc, char *argv[]) Test->tprintf("Closing connection\n"); - Test->close_readconn_master(); + Test->maxscales->close_readconn_master(0); fflush(stdout); Test->tprintf("Checking Maxscale is alive\n"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug658.cpp b/maxscale-system-test/bug658.cpp index b8c6cced4..94314ab19 100644 --- a/maxscale-system-test/bug658.cpp +++ b/maxscale-system-test/bug658.cpp @@ -31,8 +31,8 @@ int main(int argc, char *argv[]) Test->set_timeout(40); int i; - Test->tprintf("Connecting to Maxscale %s\n", Test->maxscale_IP); - Test->connect_maxscale(); + Test->tprintf("Connecting to Maxscale %s\n", Test->maxscales->IP[0]); + Test->maxscales->connect_maxscale(0); printf("Setup firewall to block mysql on master\n"); fflush(stdout); @@ -41,13 +41,13 @@ int main(int argc, char *argv[]) sleep(1); Test->tprintf("Trying query to RWSplit, expecting failure, but not a crash\n"); - execute_query(Test->conn_rwsplit, (char *) "show processlist;"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "show processlist;"); fflush(stdout); Test->tprintf("Trying query to ReadConn master, expecting failure, but not a crash\n"); - execute_query(Test->conn_master, (char *) "show processlist;"); + execute_query(Test->maxscales->conn_master[0], (char *) "show processlist;"); fflush(stdout); Test->tprintf("Trying query to ReadConn slave, expecting failure, but not a crash\n"); - execute_query(Test->conn_slave, (char *) "show processlist;"); + execute_query(Test->maxscales->conn_slave[0], (char *) "show processlist;"); fflush(stdout); sleep(1); @@ -55,16 +55,16 @@ int main(int argc, char *argv[]) Test->repl->unblock_node(0); sleep(10); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checking Maxscale is alive\n"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); Test->set_timeout(20); Test->tprintf("Connecting to Maxscale %s to check its behaviour in case of blocking all bacxkends\n", - Test->maxscale_IP); - Test->connect_maxscale(); + Test->maxscales->IP[0]); + Test->maxscales->connect_maxscale(0); if (!Test->smoke) { @@ -77,13 +77,13 @@ int main(int argc, char *argv[]) sleep(1); Test->tprintf("Trying query to RWSplit, expecting failure, but not a crash\n"); - execute_query(Test->conn_rwsplit, (char *) "show processlist;"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "show processlist;"); fflush(stdout); Test->tprintf("Trying query to ReadConn master, expecting failure, but not a crash\n"); - execute_query(Test->conn_master, (char *) "show processlist;"); + execute_query(Test->maxscales->conn_master[0], (char *) "show processlist;"); fflush(stdout); Test->tprintf("Trying query to ReadConn slave, expecting failure, but not a crash\n"); - execute_query(Test->conn_slave, (char *) "show processlist;"); + execute_query(Test->maxscales->conn_slave[0], (char *) "show processlist;"); fflush(stdout); sleep(1); @@ -101,9 +101,9 @@ int main(int argc, char *argv[]) Test->set_timeout(20); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checking Maxscale is alive\n"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug662.cpp b/maxscale-system-test/bug662.cpp index efc399875..3e7c7c632 100644 --- a/maxscale-system-test/bug662.cpp +++ b/maxscale-system-test/bug662.cpp @@ -15,11 +15,11 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); int i; - Test->tprintf("Connecting to Maxscale %s\n", Test->maxscale_IP); + Test->tprintf("Connecting to Maxscale %s\n", Test->maxscales->IP[0]); Test->tprintf("Connecting to Maxscale %s to check its behaviour in case of blocking all backends\n", - Test->maxscale_IP); - Test->connect_maxscale(); + Test->maxscales->IP[0]); + Test->maxscales->connect_maxscale(0); for (i = 0; i < Test->repl->N; i++) { @@ -31,10 +31,10 @@ int main(int argc, char *argv[]) Test->set_timeout(200); Test->tprintf("Restarting MaxScale"); - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); Test->tprintf("Checking if MaxScale is alive by connecting to MaxAdmin\n"); - Test->add_result(Test->execute_maxadmin_command((char* ) "show servers"), "Maxadmin execution failed.\n"); + Test->add_result(Test->maxscales->execute_maxadmin_command(0, (char* ) "show servers"), "Maxadmin execution failed.\n"); for (i = 0; i < Test->repl->N; i++) { @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) Test->set_timeout(30); Test->tprintf("Checking Maxscale is alive\n"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug664.cpp b/maxscale-system-test/bug664.cpp index f1937ca0d..93a48a9bf 100644 --- a/maxscale-system-test/bug664.cpp +++ b/maxscale-system-test/bug664.cpp @@ -11,7 +11,7 @@ int main(int argc, char *argv[]) { TestConnections test(argc, argv); - test.check_maxscale_alive(); - test.check_log_err("Failed to create new router session for service 'RW_Split'", true); + test.check_maxscale_alive(0); + test.check_log_err(0, "Failed to create new router session for service 'RW_Split'", true); return test.global_result; } diff --git a/maxscale-system-test/bug670.cpp b/maxscale-system-test/bug670.cpp index dcd68d8a0..d9b28e3fd 100644 --- a/maxscale-system-test/bug670.cpp +++ b/maxscale-system-test/bug670.cpp @@ -193,7 +193,7 @@ Comment 3 Vilho Raatikka 2014-12-30 12:05:49 UTC Created attachment 173 [details] List of statements used by run_setmix.sh Comment 4 Vilho Raatikka 2014-12-31 19:13:21 UTC -tee filter doesn't send reply to client before both routers have replied. This required adding upstream processing to tee filter. First reply is routed to client. By this tee ensures that new query is never sent to either router before they have replied to previous one. +tee filter doesn't send reply to client before both maxscales->routers[0] have replied. This required adding upstream processing to tee filter. First reply is routed to client. By this tee ensures that new query is never sent to either router before they have replied to previous one. Comment 5 Timofey Turenko 2015-01-08 12:40:34 UTC test added, closing Comment 6 Timofey Turenko 2015-02-28 18:11:16 UTC @@ -233,33 +233,33 @@ int main(int argc, char *argv[]) int i; Test->tprintf("Connecting to all MaxScale services\n"); - Test->add_result(Test->connect_maxscale(), "Error connecting to Maxscale\n"); + Test->add_result(Test->maxscales->connect_maxscale(0), "Error connecting to Maxscale\n"); Test->tprintf("executing sql 100 times (ReadConn Slave)\n"); for (i = 0; i < 100; i++) { Test->set_timeout(15); - execute_query_silent(Test->conn_slave, bug670_sql); + execute_query_silent(Test->maxscales->conn_slave[0], bug670_sql); } Test->tprintf("executing sql 100 times (ReadConn Master)\n"); for (i = 0; i < 100; i++) { Test->set_timeout(15); - execute_query_silent(Test->conn_master, bug670_sql); + execute_query_silent(Test->maxscales->conn_master[0], bug670_sql); } Test->tprintf("executing sql 100 times (RWSplit)\n"); for (i = 0; i < 100; i++) { Test->set_timeout(15); - execute_query_silent(Test->conn_rwsplit, bug670_sql); + execute_query_silent(Test->maxscales->conn_rwsplit[0], bug670_sql); } Test->set_timeout(10); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug673.cpp b/maxscale-system-test/bug673.cpp index 860281c78..51f9a9437 100644 --- a/maxscale-system-test/bug673.cpp +++ b/maxscale-system-test/bug673.cpp @@ -18,9 +18,9 @@ int main(int argc, char *argv[]) for (int i = 0; i < 2; i++) { char result[1024]; - test.add_result(test.get_maxadmin_param("show dbusers \"RW Split Router\"", "User names:", result) == 0, + test.add_result(test.maxscales->get_maxadmin_param(0, "show dbusers \"RW Split Router\"", "User names:", result) == 0, "Old style objects in maxadmin commands should fail"); - test.add_result(test.get_maxadmin_param("show dbusers RW-Split-Router", "User names:", result), + test.add_result(test.maxscales->get_maxadmin_param(0, "show dbusers RW-Split-Router", "User names:", result), "New style objects in maxadmin commands should succeed"); } diff --git a/maxscale-system-test/bug676.cpp b/maxscale-system-test/bug676.cpp index 0f43bb1ca..8e247c01c 100644 --- a/maxscale-system-test/bug676.cpp +++ b/maxscale-system-test/bug676.cpp @@ -18,10 +18,10 @@ int main(int argc, char *argv[]) test.set_timeout(30); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.tprintf("Stopping node 0"); test.galera->block_node(0); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); test.stop_timeout(); @@ -30,10 +30,10 @@ int main(int argc, char *argv[]) test.set_timeout(30); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "USE test"); - test.try_query(test.conn_rwsplit, "show processlist;"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "USE test"); + test.try_query(test.maxscales->conn_rwsplit[0], "show processlist;"); + test.maxscales->close_maxscale_connections(0); test.stop_timeout(); diff --git a/maxscale-system-test/bug681.cpp b/maxscale-system-test/bug681.cpp index 519ff660b..50eb46095 100644 --- a/maxscale-system-test/bug681.cpp +++ b/maxscale-system-test/bug681.cpp @@ -30,21 +30,21 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(20); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); - if (mysql_errno(Test->conn_rwsplit) == 0) + if (mysql_errno(Test->maxscales->conn_rwsplit[0]) == 0) { Test->add_result(1, "RWSplit services should fail, but it is started\n"); } Test->tprintf("Trying query to ReadConn master\n"); - Test->try_query(Test->conn_master, "show processlist;"); + Test->try_query(Test->maxscales->conn_master[0], "show processlist;"); Test->tprintf("Trying query to ReadConn slave\n"); - Test->try_query(Test->conn_slave, "show processlist;"); + Test->try_query(Test->maxscales->conn_slave[0], "show processlist;"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - Test->check_log_err("There are too few backend servers configured in", true); + Test->check_log_err(0, "There are too few backend servers configured in", true); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug694.cpp b/maxscale-system-test/bug694.cpp index 9949bf98d..eeebf21ee 100644 --- a/maxscale-system-test/bug694.cpp +++ b/maxscale-system-test/bug694.cpp @@ -41,11 +41,11 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(120); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); - Test->try_query(Test->conn_rwsplit, "USE test"); - Test->try_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS test"); - Test->try_query(Test->conn_rwsplit, "CREATE TABLE test (b integer)"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "USE test"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS test"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "CREATE TABLE test (b integer)"); const int iter = Test->smoke ? 10 : 100; Test->tprintf("Creating and inserting %d rows into a table\n", iter); @@ -53,34 +53,34 @@ int main(int argc, char *argv[]) for (int i = 0; i < iter; i++) { Test->set_timeout(30); - execute_query(Test->conn_rwsplit, "insert into test value(2);"); + execute_query(Test->maxscales->conn_rwsplit[0], "insert into test value(2);"); Test->stop_timeout(); } Test->set_timeout(200); Test->tprintf("Trying SELECT @a:=@a+1 as a, test.b FROM test\n"); - if (execute_query(Test->conn_rwsplit, "SELECT @a:=@a+1 as a, test.b FROM test;") == 0) + if (execute_query(Test->maxscales->conn_rwsplit[0], "SELECT @a:=@a+1 as a, test.b FROM test;") == 0) { Test->add_result(1, "Query succeded, but expected to fail.\n"); } Test->tprintf("Trying USE test\n"); - Test->try_query(Test->conn_rwsplit, "USE test"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "USE test"); - Test->try_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS test"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS test"); Test->tprintf("Checking if MaxScale alive\n"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checking logs\n"); - Test->check_log_err((char *) + Test->check_log_err(0, (char *) "The query can't be routed to all backend servers because it includes SELECT and SQL variable modifications which is not supported", true); - Test->check_log_err((char *) + Test->check_log_err(0, (char *) "SELECT with session data modification is not supported if configuration parameter use_sql_variables_in=all", true); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug699.cpp b/maxscale-system-test/bug699.cpp index 6f209ffa2..ea1dc2833 100644 --- a/maxscale-system-test/bug699.cpp +++ b/maxscale-system-test/bug699.cpp @@ -188,7 +188,7 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(20); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Trying \n"); @@ -197,11 +197,11 @@ int main(int argc, char *argv[]) if ( ( find_field( - Test->conn_rwsplit, sel3, + Test->maxscales->conn_rwsplit[0], sel3, "@@server_id", &serverid1[0]) != 0 ) || ( find_field( - Test->conn_rwsplit, sel4, + Test->maxscales->conn_rwsplit[0], sel4, "@@server_id", &serverid2[0]) != 0 )) { @@ -219,11 +219,11 @@ int main(int argc, char *argv[]) if ( ( find_field( - Test->conn_rwsplit, sel1, + Test->maxscales->conn_rwsplit[0], sel1, "@@hostname", &serverid1[0]) != 0 ) || ( find_field( - Test->conn_rwsplit, sel2, + Test->maxscales->conn_rwsplit[0], sel2, "@@hostname", &serverid2[0]) != 0 )) { @@ -239,8 +239,8 @@ int main(int argc, char *argv[]) "hostname are different depending in which order terms are in SELECT\n"); } - Test->close_maxscale_connections(); - Test->check_maxscale_alive(); + Test->maxscales->close_maxscale_connections(0); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug705.cpp b/maxscale-system-test/bug705.cpp index 63b28dcfc..46db8c2a1 100644 --- a/maxscale-system-test/bug705.cpp +++ b/maxscale-system-test/bug705.cpp @@ -243,10 +243,10 @@ int main(int argc, char *argv[]) Test->tprintf("Restarting MaxScale\n"); Test->set_timeout(120); - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); - Test->check_log_err((char *) "Loading database names", false); - Test->check_log_err((char *) "Unknown column", false); + Test->check_log_err(0, (char *) "Loading database names", false); + Test->check_log_err(0, (char *) "Unknown column", false); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug711.cpp b/maxscale-system-test/bug711.cpp index 23e74d0a7..baec9762d 100644 --- a/maxscale-system-test/bug711.cpp +++ b/maxscale-system-test/bug711.cpp @@ -1,7 +1,7 @@ /** * @file bug711.cpp bug711 regression case (Some MySQL Workbench Management actions hang with R/W split router) * - configure rwsplit with use_sql_variables_in=all - * - try SHOW GLOBAL STATUS with all routers + * - try SHOW GLOBAL STATUS with all maxscales->routers[0] * - check if Maxscale is still alive */ @@ -43,15 +43,15 @@ using namespace std; int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->set_timeout(10); Test->tprintf("Trying SHOW GLOBAL STATUS against RWSplit\n"); - Test->try_query(Test->conn_rwsplit, (char *) "SHOW GLOBAL STATUS;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "SHOW GLOBAL STATUS;"); Test->tprintf("Trying SHOW GLOBAL STATUS against ReadConn master\n"); - Test->try_query(Test->conn_master, (char *) "SHOW GLOBAL STATUS;"); + Test->try_query(Test->maxscales->conn_master[0], (char *) "SHOW GLOBAL STATUS;"); Test->tprintf("Trying SHOW GLOBAL STATUS against ReadConn slave\n"); - Test->try_query(Test->conn_slave, (char *) "SHOW GLOBAL STATUS;"); - Test->check_maxscale_alive(); + Test->try_query(Test->maxscales->conn_slave[0], (char *) "SHOW GLOBAL STATUS;"); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/bug718.cpp b/maxscale-system-test/bug718.cpp index fbb512e61..791bd7e23 100644 --- a/maxscale-system-test/bug718.cpp +++ b/maxscale-system-test/bug718.cpp @@ -27,18 +27,18 @@ int main(int argc, char *argv[]) Test->set_timeout(20); int i; - Test->execute_maxadmin_command((char *) "set server server1 master"); - Test->execute_maxadmin_command((char *) "set server server2 slave"); - Test->execute_maxadmin_command((char *) "set server server3 slave"); - Test->execute_maxadmin_command((char *) "set server server4 slave"); + Test->maxscales->execute_maxadmin_command(0, (char *) "set server server1 master"); + Test->maxscales->execute_maxadmin_command(0, (char *) "set server server2 slave"); + Test->maxscales->execute_maxadmin_command(0, (char *) "set server server3 slave"); + Test->maxscales->execute_maxadmin_command(0, (char *) "set server server4 slave"); - Test->execute_maxadmin_command((char *) "set server g_server1 master"); - Test->execute_maxadmin_command((char *) "set server g_server2 slave"); - Test->execute_maxadmin_command((char *) "set server g_server3 slave"); - Test->execute_maxadmin_command((char *) "set server g_server4 slave"); + Test->maxscales->execute_maxadmin_command(0, (char *) "set server g_server1 master"); + Test->maxscales->execute_maxadmin_command(0, (char *) "set server g_server2 slave"); + Test->maxscales->execute_maxadmin_command(0, (char *) "set server g_server3 slave"); + Test->maxscales->execute_maxadmin_command(0, (char *) "set server g_server4 slave"); Test->tprintf("Connecting to all MaxScale services\n"); - Test->add_result(Test->connect_maxscale(), "Error connection to Maxscale\n"); + Test->add_result(Test->maxscales->connect_maxscale(0), "Error connection to Maxscale\n"); //MYSQL * galera_rwsplit = open_conn(4016, Test->Maxscale_IP, Test->Maxscale_User, Test->Maxscale_Password); @@ -53,11 +53,11 @@ int main(int argc, char *argv[]) iret1[i] = pthread_create(&thread_v1[i], NULL, thread1, NULL); } - create_t1(Test->conn_rwsplit); + create_t1(Test->maxscales->conn_rwsplit[0]); for (i = 0; i < iterations; i++) { Test->set_timeout(200); - insert_into_t1(Test->conn_rwsplit, 4); + insert_into_t1(Test->maxscales->conn_rwsplit[0], 4); printf("i=%d\n", i); } Test->set_timeout(300); @@ -66,8 +66,8 @@ int main(int argc, char *argv[]) pthread_join(thread_v1[i], NULL); } - Test->close_maxscale_connections(); - Test->check_maxscale_alive(); + Test->maxscales->close_maxscale_connections(0); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; @@ -76,9 +76,9 @@ int main(int argc, char *argv[]) void *thread1( void *ptr ) { - MYSQL * conn = open_conn(Test->rwsplit_port , Test->maxscale_IP, Test->maxscale_user, Test->maxscale_password, + MYSQL * conn = open_conn(Test->maxscales->rwsplit_port[0] , Test->maxscales->IP[0], Test->maxscales->user_name, Test->maxscales->password, Test->ssl); - MYSQL * g_conn = open_conn(4016 , Test->maxscale_IP, Test->maxscale_user, Test->maxscale_password, Test->ssl); + MYSQL * g_conn = open_conn(4016 , Test->maxscales->IP[0], Test->maxscales->user_name, Test->maxscales->password, Test->ssl); char sql[1034]; sprintf(sql, "CREATE DATABASE IF NOT EXISTS test%d;", db1_num); diff --git a/maxscale-system-test/bug729.cpp b/maxscale-system-test/bug729.cpp index f68c8c8a4..343e406d0 100644 --- a/maxscale-system-test/bug729.cpp +++ b/maxscale-system-test/bug729.cpp @@ -58,13 +58,13 @@ int main(int argc, char *argv[]) Test->set_timeout(30); char str[1024]; - sprintf(str, "php %s/bug729.php %s %d %s %s", test_dir, Test->maxscale_IP, Test->rwsplit_port, - Test->maxscale_user, Test->maxscale_password); + sprintf(str, "php %s/bug729.php %s %d %s %s", test_dir, Test->maxscales->IP[0], Test->maxscales->rwsplit_port[0], + Test->maxscales->user_name, Test->maxscales->password); Test->tprintf("Executing PHP script: %s\n", str); Test->add_result(system(str), "PHP script FAILED!\n"); - Test->check_log_err((char *) "Can't route MYSQL_COM_STMT_PREPARE", false); + Test->check_log_err(0, (char *) "Can't route MYSQL_COM_STMT_PREPARE", false); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bug730.cpp b/maxscale-system-test/bug730.cpp index 152e84edb..4eac4c533 100644 --- a/maxscale-system-test/bug730.cpp +++ b/maxscale-system-test/bug730.cpp @@ -1,7 +1,7 @@ /** * @file bug730.cpp regression case for bug 730 ("Regex filter and shorter than original replacement queries MaxScale") * - * - setup regex filter, add it to all routers + * - setup regex filter, add it to all maxscales->routers[0] * @verbatim [MySetOptionFilter] type=filter @@ -11,7 +11,7 @@ match=SET OPTION SQL_QUOTE_SHOW_CREATE replace=SET SQL_QUOTE_SHOW_CREATE @endverbatim - * - try SET OPTION SQL_QUOTE_SHOW_CREATE = 1; against all routers + * - try SET OPTION SQL_QUOTE_SHOW_CREATE = 1; against all maxscales->routers[0] * - check if Maxscale alive */ @@ -45,21 +45,21 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("RWSplit: \n"); fflush(stdout); - Test->try_query(Test->conn_rwsplit, (char *) "SET OPTION SQL_QUOTE_SHOW_CREATE = 1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "SET OPTION SQL_QUOTE_SHOW_CREATE = 1;"); Test->tprintf("ReadConn master: \n"); fflush(stdout); - Test->try_query(Test->conn_master, (char *) "SET OPTION SQL_QUOTE_SHOW_CREATE = 1;"); + Test->try_query(Test->maxscales->conn_master[0], (char *) "SET OPTION SQL_QUOTE_SHOW_CREATE = 1;"); Test->tprintf("readConn slave: \n"); fflush(stdout); - Test->try_query(Test->conn_slave, (char *) "SET OPTION SQL_QUOTE_SHOW_CREATE = 1;"); + Test->try_query(Test->maxscales->conn_slave[0], (char *) "SET OPTION SQL_QUOTE_SHOW_CREATE = 1;"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/bulk_insert.cpp b/maxscale-system-test/bulk_insert.cpp index d5202551f..2b00333db 100644 --- a/maxscale-system-test/bulk_insert.cpp +++ b/maxscale-system-test/bulk_insert.cpp @@ -202,23 +202,24 @@ int main(int argc, char** argv) { TestConnections::require_repl_version("10.2"); TestConnections test(argc, argv); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.repl->connect(); + test.tprintf("Testing column-wise binding with a direct connection"); test.add_result(bind_by_column(test.repl->nodes[0]), "Bulk inserts with a direct connection should work"); test.tprintf("Testing column-wise binding with readwritesplit"); - test.add_result(bind_by_column(test.conn_rwsplit), "Bulk inserts with readwritesplit should work"); + test.add_result(bind_by_column(test.maxscales->conn_rwsplit[0]), "Bulk inserts with readwritesplit should work"); test.tprintf("Testing column-wise binding with readconnroute"); - test.add_result(bind_by_column(test.conn_master), "Bulk inserts with readconnroute should work"); + test.add_result(bind_by_column(test.maxscales->conn_master[0]), "Bulk inserts with readconnroute should work"); test.tprintf("Testing row-wise binding with a direct connection"); test.add_result(bind_by_row(test.repl->nodes[0]), "Bulk inserts with a direct connection should work"); test.tprintf("Testing row-wise binding with readwritesplit"); - test.add_result(bind_by_row(test.conn_rwsplit), "Bulk inserts with readwritesplit should work"); + test.add_result(bind_by_row(test.maxscales->conn_rwsplit[0]), "Bulk inserts with readwritesplit should work"); test.tprintf("Testing row-wise binding with readconnroute"); - test.add_result(bind_by_row(test.conn_master), "Bulk inserts with readconnroute should work"); + test.add_result(bind_by_row(test.maxscales->conn_master[0]), "Bulk inserts with readconnroute should work"); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/ccrfilter.cpp b/maxscale-system-test/ccrfilter.cpp index fd9469780..a289303dd 100644 --- a/maxscale-system-test/ccrfilter.cpp +++ b/maxscale-system-test/ccrfilter.cpp @@ -56,84 +56,84 @@ int main(int argc, char *argv[]) execute_query(test->repl->nodes[0], "CREATE OR REPLACE TABLE test.t1 (id INT);"); execute_query(test->repl->nodes[0], "CREATE OR REPLACE TABLE test.t2 (id INT);"); - test->connect_maxscale(); + test->maxscales->connect_maxscale(0); test->tprintf("Test `time`. The first SELECT within 10 seconds should go the " "master and all SELECTs after it should go to the slaves."); - test->try_query(test->conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); + test->try_query(test->maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); sleep(1); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the first SELECT"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the first SELECT"); sleep(11); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the second SELECT"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the second SELECT"); test->tprintf("Change test setup for `count`, the first three selects after an " "insert should go to the master."); - test->close_maxscale_connections(); - test->ssh_maxscale(true, "sed -i -e 's/time.*/time=0/' /etc/maxscale.cnf"); - test->ssh_maxscale(true, "sed -i -e 's/###count/count/' /etc/maxscale.cnf"); - test->restart_maxscale(); - test->connect_maxscale(); + test->maxscales->close_maxscale_connections(0); + test->maxscales->ssh_node(0, "sed -i -e 's/time.*/time=0/' /etc/maxscale.cnf", true); + test->maxscales->ssh_node(0, "sed -i -e 's/###count/count/' /etc/maxscale.cnf", true); + test->maxscales->restart_maxscale(0); + test->maxscales->connect_maxscale(0); - test->try_query(test->conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the first SELECT"); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the second SELECT"); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the third SELECT"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the fourth SELECT"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the fifth SELECT"); + test->try_query(test->maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the first SELECT"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the second SELECT"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the third SELECT"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the fourth SELECT"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the fifth SELECT"); test->tprintf("Change test setup for `count` and `match`, selects after an insert " "to t1 should go to the slaves and selects after an insert to t2 " "should go to the master."); - test->close_maxscale_connections(); - test->ssh_maxscale(true, "sed -i -e 's/###match/match/' /etc/maxscale.cnf"); - test->restart_maxscale(); - test->connect_maxscale(); + test->maxscales->close_maxscale_connections(0); + test->maxscales->ssh_node(0, "sed -i -e 's/###match/match/' /etc/maxscale.cnf", true); + test->maxscales->restart_maxscale(0); + test->maxscales->connect_maxscale(0); test->tprintf("t1 first, should be ignored"); - test->try_query(test->conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the first SELECT"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the second SELECT"); + test->try_query(test->maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the first SELECT"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the second SELECT"); test->tprintf("t2 should match and trigger the critical reads"); - test->try_query(test->conn_rwsplit, "INSERT INTO test.t2 VALUES (1)"); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the first SELECT"); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the second SELECT"); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the third SELECT"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the fourth SELECT"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the fifth SELECT"); + test->try_query(test->maxscales->conn_rwsplit[0], "INSERT INTO test.t2 VALUES (1)"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the first SELECT"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the second SELECT"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the third SELECT"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the fourth SELECT"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the fifth SELECT"); test->tprintf("Change test setup for `count` and `ignore`, expects the same " "results as previous test."); - test->close_maxscale_connections(); - test->ssh_maxscale(true, "sed -i -e 's/match/###match/' /etc/maxscale.cnf"); - test->ssh_maxscale(true, "sed -i -e 's/###ignore/ignore/' /etc/maxscale.cnf"); - test->restart_maxscale(); - test->connect_maxscale(); + test->maxscales->close_maxscale_connections(0); + test->maxscales->ssh_node(0, "sed -i -e 's/match/###match/' /etc/maxscale.cnf", true); + test->maxscales->ssh_node(0, "sed -i -e 's/###ignore/ignore/' /etc/maxscale.cnf", true); + test->maxscales->restart_maxscale(0); + test->maxscales->connect_maxscale(0); test->tprintf("t1 first, should be ignored"); - test->try_query(test->conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the first SELECT"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the second SELECT"); + test->try_query(test->maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the first SELECT"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the second SELECT"); test->tprintf("t2 should match and trigger the critical reads"); - test->try_query(test->conn_rwsplit, "INSERT INTO test.t2 VALUES (1)"); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the first SELECT"); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the second SELECT"); - test->add_result(!is_master(test->conn_rwsplit), "Master should reply to the third SELECT"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the fourth SELECT"); - test->add_result(is_master(test->conn_rwsplit), "Master should NOT reply to the fifth SELECT"); + test->try_query(test->maxscales->conn_rwsplit[0], "INSERT INTO test.t2 VALUES (1)"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the first SELECT"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the second SELECT"); + test->add_result(!is_master(test->maxscales->conn_rwsplit[0]), "Master should reply to the third SELECT"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the fourth SELECT"); + test->add_result(is_master(test->maxscales->conn_rwsplit[0]), "Master should NOT reply to the fifth SELECT"); execute_query(test->repl->nodes[0], "DROP TABLE test.t1"); execute_query(test->repl->nodes[0], "DROP TABLE test.t2"); diff --git a/maxscale-system-test/cdc_client.cpp b/maxscale-system-test/cdc_client.cpp index 2c3b7fe1f..f54263014 100644 --- a/maxscale-system-test/cdc_client.cpp +++ b/maxscale-system-test/cdc_client.cpp @@ -38,7 +38,7 @@ bool cdc_com(TestConnections *Test) { int max_inserted_val = Test->smoke ? 25 : 100; int sock = create_tcp_socket(); - char *ip = get_ip(Test->maxscale_IP); + char *ip = get_ip(Test->maxscales->IP[0]); if (ip == NULL) { @@ -187,26 +187,26 @@ int main(int argc, char *argv[]) Test = new TestConnections(argc, argv); Test->set_timeout(600); - Test->stop_maxscale(); + Test->maxscales->stop_maxscale(0); // Remove old data files and make sure that port 4001 is open - Test->ssh_maxscale(true, "rm -rf /var/lib/maxscale/avro;" - "iptables -n -L INPUT|grep 4001 || iptables -I INPUT -p tcp --dport 4001 -j ACCEPT;"); + Test->maxscales->ssh_node_f(0, true, "rm -rf /var/lib/maxscale/avro;" + "iptables -n -L INPUT|grep 4001 || iptables -I INPUT -p tcp --dport 4001 -j ACCEPT;"); Test->repl->connect(); execute_query(Test->repl->nodes[0], "DROP TABLE IF EXISTS t1;"); Test->repl->close_connections(); sleep(5); - Test->start_binlog(); + Test->start_binlog(0); Test->set_timeout(120); - Test->stop_maxscale(); + Test->maxscales->stop_maxscale(0); - Test->ssh_maxscale(true, "rm -rf /var/lib/maxscale/avro"); + Test->maxscales->ssh_node(0, "rm -rf /var/lib/maxscale/avro", true); Test->set_timeout(120); - Test->start_maxscale(); + Test->maxscales->start_maxscale(0); Test->set_timeout(60); Test->repl->connect(); diff --git a/maxscale-system-test/cdc_connector.cpp b/maxscale-system-test/cdc_connector.cpp new file mode 100644 index 000000000..b811c2297 --- /dev/null +++ b/maxscale-system-test/cdc_connector.cpp @@ -0,0 +1,316 @@ +#include "cdc_connector.h" +#include +#include +#include +#include +#include +#include +#include + +#define CDC_CONNECTOR_VERSION "1.0.0" + +#define ERRBUF_SIZE 512 +#define READBUF_SIZE 1024 + +static const char OK_RESPONSE[] = "OK\n"; + +static const char CLOSE_MSG[] = "CLOSE"; +static const char REGISTER_MSG[] = "REGISTER UUID=CDC_CONNECTOR-" CDC_CONNECTOR_VERSION ", TYPE="; +static const char REQUEST_MSG[] = "REQUEST-DATA "; + +namespace +{ + +static inline int nointr_read(int fd, void *dest, size_t size) +{ + int rc = read(fd, dest, size); + + while (rc == -1 && errno == EINTR) + { + rc = read(fd, dest, size); + } + + return rc; +} + +static inline int nointr_write(int fd, const void *src, size_t size) +{ + int rc = write(fd, src, size); + + while (rc == -1 && errno == EINTR) + { + rc = write(fd, src, size); + } + + return rc; +} + +static std::string bin2hex(const uint8_t *data, size_t len) +{ + std::string result; + static const char hexconvtab[] = "0123456789abcdef"; + + for (int i = 0; i < len; i++) + { + result += hexconvtab[data[i] >> 4]; + result += hexconvtab[data[i] & 0x0f]; + } + + return result; +} + +std::string generateAuthString(const std::string& user, const std::string& password) +{ + uint8_t digest[SHA_DIGEST_LENGTH]; + SHA1(reinterpret_cast (password.c_str()), password.length(), digest); + + std::string auth_str = user; + auth_str += ":"; + + std::string part1 = bin2hex((uint8_t*)auth_str.c_str(), auth_str.length()); + std::string part2 = bin2hex(digest, sizeof(digest)); + + return part1 + part2; +} +} + +namespace CDC +{ + +/** + * Public functions + */ + +Connection::Connection(const std::string& address, + uint16_t port, + const std::string& user, + const std::string& password, + uint32_t flags) : + m_fd(-1), + m_address(address), + m_port(port), + m_user(user), + m_password(password), + m_flags(flags) { } + +Connection::~Connection() +{ + closeConnection(); +} + +bool Connection::createConnection() +{ + bool rval = false; + struct sockaddr_in remote = {}; + + remote.sin_port = htons(m_port); + remote.sin_family = AF_INET; + + if (inet_aton(m_address.c_str(), (struct in_addr*)&remote.sin_addr.s_addr) == 0) + { + m_error = "Invalid address: "; + m_error += m_address; + } + else + { + int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (fd == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to create socket: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + + m_fd = fd; + + if (connect(fd, (struct sockaddr*) &remote, sizeof (remote)) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to connect: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else if (doAuth()) + { + rval = doRegistration(); + } + } + + return rval; +} + +void Connection::closeConnection() +{ + if (m_fd != -1) + { + nointr_write(m_fd, CLOSE_MSG, sizeof (CLOSE_MSG) - 1); + close(m_fd); + m_fd = -1; + } +} + +bool Connection::requestData(const std::string& table, const std::string& gtid) +{ + bool rval = true; + + std::string req_msg(REQUEST_MSG); + req_msg += table; + + if (gtid.length()) + { + req_msg += " "; + req_msg += gtid; + } + + if (nointr_write(m_fd, req_msg.c_str(), req_msg.length()) == -1) + { + rval = false; + char err[ERRBUF_SIZE]; + m_error = "Failed to write request: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + + if (rval) + { + /** Read the Avro schema */ + rval = readRow(m_schema); + } + + return rval; +} + +bool Connection::readRow(std::string& dest) +{ + bool rval = true; + + while (true) + { + char buf; + int rc = nointr_read(m_fd, &buf, 1); + + if (rc == -1) + { + rval = false; + char err[ERRBUF_SIZE]; + m_error = "Failed to read row: "; + m_error += strerror_r(errno, err, sizeof (err)); + break; + } + + if (buf == '\n') + { + break; + } + else + { + dest += buf; + + if (dest[0] == 'E' && dest[1] == 'R' & dest[2] == 'R') + { + m_error = "Server responded with an error: "; + m_error += dest; + rval = false; + break; + } + } + } + + return rval; +} + +/** + * Private functions + */ + +bool Connection::doAuth() +{ + bool rval = false; + std::string auth_str = generateAuthString(m_user, m_password); + + /** Send the auth string */ + if (nointr_write(m_fd, auth_str.c_str(), auth_str.length()) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to write authentication data: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else + { + /** Read the response */ + char buf[READBUF_SIZE]; + int bytes; + + if ((bytes = nointr_read(m_fd, buf, sizeof (buf))) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to read authentication response: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else if (memcmp(buf, OK_RESPONSE, sizeof (OK_RESPONSE) - 1) != 0) + { + buf[bytes] = '\0'; + m_error = "Authentication failed: "; + m_error += buf; + } + else + { + rval = true; + } + } + + return rval; +} + +bool Connection::doRegistration() +{ + bool rval = false; + std::string reg_msg(REGISTER_MSG); + + const char *type = ""; + + if (m_flags & CDC_REQUEST_TYPE_JSON) + { + type = "JSON"; + } + else if (m_flags & CDC_REQUEST_TYPE_AVRO) + { + type = "AVRO"; + } + + reg_msg += type; + + /** Send the registration message */ + if (nointr_write(m_fd, reg_msg.c_str(), reg_msg.length()) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to write registration message: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else + { + /** Read the response */ + char buf[READBUF_SIZE]; + int bytes; + + if ((bytes = nointr_read(m_fd, buf, sizeof (buf))) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to read registration response: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else if (memcmp(buf, OK_RESPONSE, sizeof (OK_RESPONSE) - 1) != 0) + { + buf[bytes] = '\0'; + m_error = "Registration failed: "; + m_error += buf; + } + else + { + rval = true; + } + } + + return rval; +} + +} diff --git a/maxscale-system-test/cdc_connector.h b/maxscale-system-test/cdc_connector.h new file mode 100644 index 000000000..74969bfb9 --- /dev/null +++ b/maxscale-system-test/cdc_connector.h @@ -0,0 +1,47 @@ +#include +#include + +/** Request format flags */ +#define CDC_REQUEST_TYPE_JSON (1 << 0) +#define CDC_REQUEST_TYPE_AVRO (1 << 1) + +namespace CDC +{ + +class Connection +{ +public: + Connection(const std::string& address, + uint16_t port, + const std::string& user, + const std::string& password, + uint32_t flags = CDC_REQUEST_TYPE_JSON); + virtual ~Connection(); + bool createConnection(); + bool requestData(const std::string& table, const std::string& gtid = ""); + bool readRow(std::string& dest); + void closeConnection(); + const std::string& getSchema() const + { + return m_schema; + } + const std::string& getError() const + { + return m_error; + } + +private: + int m_fd; + uint32_t m_flags; + uint16_t m_port; + std::string m_address; + std::string m_user; + std::string m_password; + std::string m_error; + std::string m_schema; + + bool doAuth(); + bool doRegistration(); +}; + +} diff --git a/maxscale-system-test/cdc_connector/CMakeLists.txt b/maxscale-system-test/cdc_connector/CMakeLists.txt new file mode 100644 index 000000000..6164df48b --- /dev/null +++ b/maxscale-system-test/cdc_connector/CMakeLists.txt @@ -0,0 +1,21 @@ +project(cdc_connector) +cmake_minimum_required(VERSION 2.8) + +enable_testing() + +include(ExternalProject) +include(cmake/BuildJansson.cmake) + +set(CMAKE_CXX_FLAGS "-fPIC -std=c++0x") +set(CMAKE_CXX_FLAGS_DEBUG "-fPIC -std=c++0x -ggdb") +set(CMAKE_CXX_FLAGS_RELEASE "-fPIC -std=c++0x -O2") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-fPIC -std=c++0x -O2") + +include_directories(${JANSSON_INCLUDE_DIR}) +add_library(cdc_connector SHARED cdc_connector.cpp) +target_link_libraries(cdc_connector ${JANSSON_LIBRARIES} crypto) +add_dependencies(cdc_connector jansson) +install(TARGETS cdc_connector DESTINATION lib) +install(FILES cdc_connector.h DESTINATION include) + +include(CTest) diff --git a/maxscale-system-test/cdc_connector/cdc_connector.cpp b/maxscale-system-test/cdc_connector/cdc_connector.cpp new file mode 100644 index 000000000..407b3564d --- /dev/null +++ b/maxscale-system-test/cdc_connector/cdc_connector.cpp @@ -0,0 +1,454 @@ +#include "cdc_connector.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define CDC_CONNECTOR_VERSION "1.0.0" + +#define ERRBUF_SIZE 512 +#define READBUF_SIZE 1024 + +static const char OK_RESPONSE[] = "OK\n"; + +static const char CLOSE_MSG[] = "CLOSE"; +static const char REGISTER_MSG[] = "REGISTER UUID=CDC_CONNECTOR-" CDC_CONNECTOR_VERSION ", TYPE="; +static const char REQUEST_MSG[] = "REQUEST-DATA "; + +namespace +{ + +static inline int nointr_read(int fd, void *dest, size_t size) +{ + int rc = read(fd, dest, size); + + while (rc == -1 && errno == EINTR) + { + rc = read(fd, dest, size); + } + + return rc; +} + +static inline int nointr_write(int fd, const void *src, size_t size) +{ + int rc = write(fd, src, size); + + while (rc == -1 && errno == EINTR) + { + rc = write(fd, src, size); + } + + return rc; +} + +static std::string bin2hex(const uint8_t *data, size_t len) +{ + std::string result; + static const char hexconvtab[] = "0123456789abcdef"; + + for (int i = 0; i < len; i++) + { + result += hexconvtab[data[i] >> 4]; + result += hexconvtab[data[i] & 0x0f]; + } + + return result; +} + +std::string generateAuthString(const std::string& user, const std::string& password) +{ + uint8_t digest[SHA_DIGEST_LENGTH]; + SHA1(reinterpret_cast (password.c_str()), password.length(), digest); + + std::string auth_str = user; + auth_str += ":"; + + std::string part1 = bin2hex((uint8_t*)auth_str.c_str(), auth_str.length()); + std::string part2 = bin2hex(digest, sizeof(digest)); + + return part1 + part2; +} + + +std::string json_to_string(json_t* json) +{ + std::stringstream ss; + + switch (json_typeof(json)) + { + case JSON_STRING: + ss << json_string_value(json); + break; + + case JSON_INTEGER: + ss << json_integer_value(json); + break; + + case JSON_REAL: + ss << json_real_value(json); + break; + + case JSON_TRUE: + ss << "true"; + break; + + case JSON_FALSE: + ss << "false"; + break; + + case JSON_NULL: + break; + + default: + break; + + } + + return ss.str(); +} + +} + +namespace CDC +{ + +/** + * Public functions + */ + +Connection::Connection(const std::string& address, + uint16_t port, + const std::string& user, + const std::string& password, + uint32_t flags) : + m_fd(-1), + m_address(address), + m_port(port), + m_user(user), + m_password(password), + m_flags(flags) +{ +} + +Connection::~Connection() +{ + closeConnection(); +} + +bool Connection::createConnection() +{ + bool rval = false; + struct sockaddr_in remote = {}; + + remote.sin_port = htons(m_port); + remote.sin_family = AF_INET; + + if (inet_aton(m_address.c_str(), (struct in_addr*)&remote.sin_addr.s_addr) == 0) + { + m_error = "Invalid address: "; + m_error += m_address; + } + else + { + int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + + if (fd == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to create socket: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + + m_fd = fd; + + if (connect(fd, (struct sockaddr*) &remote, sizeof (remote)) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to connect: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else if (doAuth()) + { + rval = doRegistration(); + } + } + + return rval; +} + +void Connection::closeConnection() +{ + if (m_fd != -1) + { + nointr_write(m_fd, CLOSE_MSG, sizeof (CLOSE_MSG) - 1); + close(m_fd); + m_fd = -1; + } +} + +bool Connection::requestData(const std::string& table, const std::string& gtid) +{ + bool rval = true; + + std::string req_msg(REQUEST_MSG); + req_msg += table; + + if (gtid.length()) + { + req_msg += " "; + req_msg += gtid; + } + + if (nointr_write(m_fd, req_msg.c_str(), req_msg.length()) == -1) + { + rval = false; + char err[ERRBUF_SIZE]; + m_error = "Failed to write request: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + + return rval; +} + +static inline bool is_schema(json_t* json) +{ + bool rval = false; + json_t* j = json_object_get(json, "fields"); + + if (j && json_is_array(j) && json_array_size(j)) + { + rval = json_object_get(json_array_get(j, 0), "name") != NULL; + } + + return rval; +} + +void Connection::processSchema(json_t* json) +{ + m_keys.clear(); + m_types.clear(); + + json_t* arr = json_object_get(json, "fields"); + char* raw = json_dumps(json, 0); + size_t i; + json_t* v; + + json_array_foreach(arr, i, v) + { + json_t* name = json_object_get(v, "name"); + json_t* type = json_object_get(v, "real_type"); + std::string nameval = name ? json_string_value(name) : ""; + std::string typeval = type ? json_string_value(type) : "undefined"; + m_keys.push_back(nameval); + m_types.push_back(typeval); + } +} + +Row Connection::processRow(json_t* js) +{ + ValueList values; + m_error.clear(); + + for (ValueList::iterator it = m_keys.begin(); + it != m_keys.end(); it++) + { + json_t* v = json_object_get(js, it->c_str()); + + if (v) + { + values.push_back(json_to_string(v)); + } + else + { + m_error = "No value for key found: "; + m_error += *it; + break; + } + } + + Row rval; + + if (m_error.empty()) + { + rval = Row(new InternalRow(m_keys, m_types, values)); + } + + return rval; +} + +Row Connection::read() +{ + Row rval; + std::string row; + + if (readRow(row)) + { + json_error_t err; + json_t* js = json_loads(row.c_str(), JSON_ALLOW_NUL, &err); + + if (js) + { + if (is_schema(js)) + { + processSchema(js); + rval = Connection::read(); + } + else + { + rval = processRow(js); + } + + json_decref(js); + } + else + { + m_error = "Failed to parse JSON: "; + m_error += err.text; + } + } + + return rval; +} + +/** + * Private functions + */ + +bool Connection::doAuth() +{ + bool rval = false; + std::string auth_str = generateAuthString(m_user, m_password); + + /** Send the auth string */ + if (nointr_write(m_fd, auth_str.c_str(), auth_str.length()) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to write authentication data: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else + { + /** Read the response */ + char buf[READBUF_SIZE]; + int bytes; + + if ((bytes = nointr_read(m_fd, buf, sizeof (buf))) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to read authentication response: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else if (memcmp(buf, OK_RESPONSE, sizeof (OK_RESPONSE) - 1) != 0) + { + buf[bytes] = '\0'; + m_error = "Authentication failed: "; + m_error += buf; + } + else + { + rval = true; + } + } + + return rval; +} + +bool Connection::doRegistration() +{ + bool rval = false; + std::string reg_msg(REGISTER_MSG); + + const char *type = ""; + + if (m_flags & CDC_REQUEST_TYPE_JSON) + { + type = "JSON"; + } + else if (m_flags & CDC_REQUEST_TYPE_AVRO) + { + type = "AVRO"; + } + + reg_msg += type; + + /** Send the registration message */ + if (nointr_write(m_fd, reg_msg.c_str(), reg_msg.length()) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to write registration message: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else + { + /** Read the response */ + char buf[READBUF_SIZE]; + int bytes; + + if ((bytes = nointr_read(m_fd, buf, sizeof (buf))) == -1) + { + char err[ERRBUF_SIZE]; + m_error = "Failed to read registration response: "; + m_error += strerror_r(errno, err, sizeof (err)); + } + else if (memcmp(buf, OK_RESPONSE, sizeof (OK_RESPONSE) - 1) != 0) + { + buf[bytes] = '\0'; + m_error = "Registration failed: "; + m_error += buf; + } + else + { + rval = true; + } + } + + return rval; +} + +bool Connection::readRow(std::string& dest) +{ + bool rval = true; + + while (true) + { + char buf; + int rc = nointr_read(m_fd, &buf, 1); + + if (rc == -1) + { + rval = false; + char err[ERRBUF_SIZE]; + m_error = "Failed to read row: "; + m_error += strerror_r(errno, err, sizeof (err)); + break; + } + + if (buf == '\n') + { + break; + } + else + { + dest += buf; + + if (dest[0] == 'E' && dest[1] == 'R' & dest[2] == 'R') + { + m_error = "Server responded with an error: "; + m_error += dest; + rval = false; + break; + } + } + } + + return rval; +} + +} diff --git a/maxscale-system-test/cdc_connector/cdc_connector.h b/maxscale-system-test/cdc_connector/cdc_connector.h new file mode 100644 index 000000000..42b9c57f7 --- /dev/null +++ b/maxscale-system-test/cdc_connector/cdc_connector.h @@ -0,0 +1,122 @@ +#include +#include +#include +#include +#include +#include + +/** Request format flags */ +#define CDC_REQUEST_TYPE_JSON (1 << 0) +#define CDC_REQUEST_TYPE_AVRO (1 << 1) + +namespace CDC +{ + +// The typedef for the Row type +class InternalRow; +typedef std::tr1::shared_ptr Row; + +typedef std::vector ValueList; + +// A class that represents a CDC connection +class Connection +{ +public: + Connection(const std::string& address, + uint16_t port, + const std::string& user, + const std::string& password, + uint32_t flags = CDC_REQUEST_TYPE_JSON); + virtual ~Connection(); + bool createConnection(); + bool requestData(const std::string& table, const std::string& gtid = ""); + Row read(); + void closeConnection(); + const std::string& getSchema() const + { + return m_schema; + } + const std::string& getError() const + { + return m_error; + } + +private: + int m_fd; + uint32_t m_flags; + uint16_t m_port; + std::string m_address; + std::string m_user; + std::string m_password; + std::string m_error; + std::string m_schema; + ValueList m_keys; + ValueList m_types; + + bool doAuth(); + bool doRegistration(); + bool readRow(std::string& dest); + void processSchema(json_t* json); + Row processRow(json_t*); +}; + +// Internal representation of a row, used via the Row type +class InternalRow +{ +public: + + size_t fieldCount() const + { + return m_values.size(); + } + + const std::string& value(size_t i) const + { + return m_values[i]; + } + + const std::string& value(const std::string& str) const + { + ValueList::const_iterator it = std::find(m_keys.begin(), m_keys.end(), str); + return m_values[it - m_keys.begin()]; + } + + const std::string& key(size_t i) const + { + return m_keys[i]; + } + + const std::string& type(size_t i) const + { + return m_types[i]; + } + + ~InternalRow() + { + } + +private: + ValueList m_keys; + ValueList m_types; + ValueList m_values; + + // Not intended to be copied + InternalRow(const InternalRow&); + InternalRow& operator=(const InternalRow&); + InternalRow(); + + // Only a Connection should construct an InternalRow + friend class Connection; + + InternalRow(const ValueList& keys, + const ValueList& types, + const ValueList& values): + m_keys(keys), + m_types(types), + m_values(values) + { + } + +}; + +} diff --git a/maxscale-system-test/cdc_connector/cmake/BuildJansson.cmake b/maxscale-system-test/cdc_connector/cmake/BuildJansson.cmake new file mode 100644 index 000000000..78e038a01 --- /dev/null +++ b/maxscale-system-test/cdc_connector/cmake/BuildJansson.cmake @@ -0,0 +1,20 @@ +# If the Jansson library is not found, download it and build it from source. + +set(JANSSON_REPO "https://github.com/akheron/jansson.git" CACHE STRING "Jansson Git repository") + +# Release 2.9 of Jansson +set(JANSSON_TAG "v2.9" CACHE STRING "Jansson Git tag") + +ExternalProject_Add(jansson + GIT_REPOSITORY ${JANSSON_REPO} + GIT_TAG ${JANSSON_TAG} + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/jansson/install -DCMAKE_C_FLAGS=-fPIC -DJANSSON_BUILD_DOCS=OFF + BINARY_DIR ${CMAKE_BINARY_DIR}/jansson + INSTALL_DIR ${CMAKE_BINARY_DIR}/jansson/install + UPDATE_COMMAND "") + +set(JANSSON_FOUND TRUE CACHE INTERNAL "") +set(JANSSON_STATIC_FOUND TRUE CACHE INTERNAL "") +set(JANSSON_INCLUDE_DIR ${CMAKE_BINARY_DIR}/jansson/install/include CACHE INTERNAL "") +set(JANSSON_STATIC_LIBRARIES ${CMAKE_BINARY_DIR}/jansson/install/lib/libjansson.a CACHE INTERNAL "") +set(JANSSON_LIBRARIES ${JANSSON_STATIC_LIBRARIES} CACHE INTERNAL "") diff --git a/maxscale-system-test/cdc_datatypes/cdc_datatypes.cpp b/maxscale-system-test/cdc_datatypes/cdc_datatypes.cpp index 6beda311e..f11af0a8a 100644 --- a/maxscale-system-test/cdc_datatypes/cdc_datatypes.cpp +++ b/maxscale-system-test/cdc_datatypes/cdc_datatypes.cpp @@ -176,9 +176,9 @@ bool run_test(TestConnections& test) test.set_timeout(60); test.tprintf("Testing type: %s", test_set[x].types[i]); std::string name = type_to_table_name(test_set[x].types[i]); - CDC::Connection conn(test.maxscale_IP, 4001, "skysql", "skysql"); + CDC::Connection conn(test.maxscales->IP[0], 4001, "skysql", "skysql"); - if (conn.connect(name)) + if (conn.createConnection() && conn.requestData(name)) { for (int j = 0; test_set[x].values[j]; j++) { @@ -198,14 +198,14 @@ bool run_test(TestConnections& test) } else { - std::string err = conn.error(); + std::string err = conn.getError(); test.tprintf("Failed to read data: %s", err.c_str()); } } } else { - std::string err = conn.error(); + std::string err = conn.getError(); test.tprintf("Failed to request data: %s", err.c_str()); rval = false; break; @@ -222,13 +222,13 @@ int main(int argc, char *argv[]) TestConnections::check_nodes(false); TestConnections test(argc, argv); - test.replicate_from_master(); + test.replicate_from_master(0); if (!run_test(test)) { test.add_result(1, "Test failed"); } - test.check_maxscale_processes(1); + test.check_maxscale_processes(0, 1); return test.global_result; } diff --git a/maxscale-system-test/change_master_during_session.cpp b/maxscale-system-test/change_master_during_session.cpp index 382cdf647..f0d073c3c 100644 --- a/maxscale-system-test/change_master_during_session.cpp +++ b/maxscale-system-test/change_master_during_session.cpp @@ -21,11 +21,11 @@ int main(int argc, char *argv[]) Test->repl->connect(); printf("Connecting to RWsplit\n"); - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); Test->set_timeout(30); - Test->add_result(create_t1(Test->conn_rwsplit), "Error creating 't1'\n"); + Test->add_result(create_t1(Test->maxscales->conn_rwsplit[0]), "Error creating 't1'\n"); - Test->try_query(Test->conn_rwsplit, (char *) "INSERT INTO t1 (x1, fl) VALUES(0, 1);"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "INSERT INTO t1 (x1, fl) VALUES(0, 1);"); Test->tprintf("Changing master to node 1\n"); Test->set_timeout(60); Test->repl->change_master(1, 0); @@ -35,13 +35,13 @@ int main(int argc, char *argv[]) Test->set_timeout(60); sprintf(sql, "INSERT INTO t1 (x1, fl) VALUES(%d, 2);", i); Test->tprintf("Trying: %d\n", i); - execute_query(Test->conn_rwsplit, sql); + execute_query(Test->maxscales->conn_rwsplit[0], sql); } Test->set_timeout(60); Test->tprintf("executing SELECT\n"); - execute_query(Test->conn_rwsplit, (char *) "SELECT * FROM t1;"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "SELECT * FROM t1;"); - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); /** Sleep for at least one monitor interval */ Test->tprintf("Waiting for monitor to detect changes\n"); @@ -49,10 +49,10 @@ int main(int argc, char *argv[]) sleep(3); Test->set_timeout(60); - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); Test->tprintf("Reconnecting and executing SELECT again\n"); Test->set_timeout(60); - Test->try_query(Test->conn_rwsplit, (char *) "SELECT * FROM t1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "SELECT * FROM t1;"); Test->tprintf("Changing master back to node 0\n"); Test->set_timeout(60); diff --git a/maxscale-system-test/change_user.cpp b/maxscale-system-test/change_user.cpp index b4c6128a0..a12515c5a 100644 --- a/maxscale-system-test/change_user.cpp +++ b/maxscale-system-test/change_user.cpp @@ -20,69 +20,69 @@ int main(int argc, char *argv[]) Test->set_timeout(60); Test->repl->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Creating user 'user' \n"); - execute_query(Test->conn_rwsplit, "DROP USER 'user'@'%%'"); - Test->try_query(Test->conn_rwsplit, (char *) "CREATE USER user@'%%' identified by 'pass2'"); - Test->try_query(Test->conn_rwsplit, (char *) "GRANT SELECT ON test.* TO user@'%%'"); - Test->try_query(Test->conn_rwsplit, (char *) "FLUSH PRIVILEGES;"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE IF EXISTS t1"); - Test->try_query(Test->conn_rwsplit, (char *) "CREATE TABLE t1 (x1 int, fl int)"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP USER 'user'@'%%'"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE USER user@'%%' identified by 'pass2'"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "GRANT SELECT ON test.* TO user@'%%'"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "FLUSH PRIVILEGES;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE IF EXISTS t1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE TABLE t1 (x1 int, fl int)"); Test->tprintf("Changing user... \n"); - Test->add_result(mysql_change_user(Test->conn_rwsplit, (char *) "user", (char *) "pass2", (char *) "test") , + Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], (char *) "user", (char *) "pass2", (char *) "test") , "changing user failed \n"); - Test->tprintf("mysql_error is %s\n", mysql_error(Test->conn_rwsplit)); + Test->tprintf("mysql_error is %s\n", mysql_error(Test->maxscales->conn_rwsplit[0])); Test->tprintf("Trying INSERT (expecting access denied)... \n"); - if ( execute_query(Test->conn_rwsplit, (char *) "INSERT INTO t1 VALUES (77, 11);") == 0) + if ( execute_query(Test->maxscales->conn_rwsplit[0], (char *) "INSERT INTO t1 VALUES (77, 11);") == 0) { Test->add_result(1, "INSERT query succedded to user which does not have INSERT PRIVILEGES\n"); } Test->tprintf("Changing user back... \n"); - Test->add_result(mysql_change_user(Test->conn_rwsplit, Test->repl->user_name, Test->repl->password, + Test->add_result(mysql_change_user(Test->maxscales->conn_rwsplit[0], Test->repl->user_name, Test->repl->password, (char *) "test"), "changing user failed \n"); Test->tprintf("Trying INSERT (expecting success)... \n"); - Test->try_query(Test->conn_rwsplit, (char *) "INSERT INTO t1 VALUES (77, 12);"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "INSERT INTO t1 VALUES (77, 12);"); Test->tprintf("Changing user with wrong password... \n"); - if (mysql_change_user(Test->conn_rwsplit, (char *) "user", (char *) "wrong_pass2", (char *) "test") == 0) + if (mysql_change_user(Test->maxscales->conn_rwsplit[0], (char *) "user", (char *) "wrong_pass2", (char *) "test") == 0) { Test->add_result(1, "changing user with wrong password successed! \n"); } - Test->tprintf("%s\n", mysql_error(Test->conn_rwsplit)); - if ((strstr(mysql_error(Test->conn_rwsplit), "Access denied for user")) == NULL) + Test->tprintf("%s\n", mysql_error(Test->maxscales->conn_rwsplit[0])); + if ((strstr(mysql_error(Test->maxscales->conn_rwsplit[0]), "Access denied for user")) == NULL) { Test->add_result(1, "There is no proper error message\n"); } Test->tprintf("Trying INSERT again (expecting success - use change should fail)... \n"); - Test->try_query(Test->conn_rwsplit, (char *) "INSERT INTO t1 VALUES (77, 13);"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "INSERT INTO t1 VALUES (77, 13);"); Test->tprintf("Changing user with wrong password using ReadConn \n"); - if (mysql_change_user(Test->conn_slave, (char *) "user", (char *) "wrong_pass2", (char *) "test") == 0) + if (mysql_change_user(Test->maxscales->conn_slave[0], (char *) "user", (char *) "wrong_pass2", (char *) "test") == 0) { Test->add_result(1, "FAILED: changing user with wrong password successed! \n"); } - Test->tprintf("%s\n", mysql_error(Test->conn_slave)); - if ((strstr(mysql_error(Test->conn_slave), "Access denied for user")) == NULL) + Test->tprintf("%s\n", mysql_error(Test->maxscales->conn_slave[0])); + if ((strstr(mysql_error(Test->maxscales->conn_slave[0]), "Access denied for user")) == NULL) { Test->add_result(1, "There is no proper error message\n"); } Test->tprintf("Changing user for ReadConn \n"); - Test->add_result(mysql_change_user(Test->conn_slave, (char *) "user", (char *) "pass2", (char *) "test") , + Test->add_result(mysql_change_user(Test->maxscales->conn_slave[0], (char *) "user", (char *) "pass2", (char *) "test") , "changing user failed \n"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP USER user@'%%';"); - execute_query_silent(Test->conn_rwsplit, "DROP TABLE test.t1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP USER user@'%%';"); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "DROP TABLE test.t1"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/check_backend.cpp b/maxscale-system-test/check_backend.cpp index 2c4ae6852..71aaa8533 100644 --- a/maxscale-system-test/check_backend.cpp +++ b/maxscale-system-test/check_backend.cpp @@ -8,18 +8,20 @@ int main(int argc, char *argv[]) { + int exit_code; TestConnections * Test = new TestConnections(argc, argv); - /*Test->restart_maxscale(); + /*Test->maxscales->restart_maxscale(0); sleep(5);*/ Test->set_timeout(10); - Test->tprintf("Connecting to Maxscale routers with Master/Slave backend\n"); - Test->connect_maxscale(); + Test->tprintf("Connecting to Maxscale maxscales->routers[0] with Master/Slave backend\n"); + Test->maxscales->connect_maxscale(0); Test->tprintf("Testing connections\n"); - Test->add_result(Test->test_maxscale_connections(true, true, true), "Can't connect to backend\n"); + Test->add_result(Test->test_maxscale_connections(0, true, true, true), "Can't connect to backend\n"); Test->tprintf("Connecting to Maxscale router with Galera backend\n"); - MYSQL * g_conn = open_conn(4016 , Test->maxscale_IP, Test->maxscale_user, Test->maxscale_password, Test->ssl); + MYSQL * g_conn = open_conn(4016 , Test->maxscales->IP[0], Test->maxscales->user_name, + Test->maxscales->password, Test->ssl); if (g_conn != NULL ) { Test->tprintf("Testing connection\n"); @@ -27,10 +29,10 @@ int main(int argc, char *argv[]) (char *) "Error executing query against RWSplit Galera\n"); } Test->tprintf("Closing connections\n"); - Test->close_maxscale_connections(); - Test->check_maxscale_alive(); + Test->maxscales->close_maxscale_connections(0); + Test->check_maxscale_alive(0); - char * ver = Test->ssh_maxscale_output(false, "maxscale --version-full"); + char * ver = Test->maxscales->ssh_node_output(0, "maxscale --version-full", false, &exit_code); Test->tprintf("Maxscale_full_version_start:\n%s\nMaxscale_full_version_end\n", ver); if ((Test->global_result == 0) && (Test->use_snapshots)) diff --git a/maxscale-system-test/cnf/maxscale.cnf.template.replication_manager b/maxscale-system-test/cnf/maxscale.cnf.template.replication_manager index 7ba16b355..d685f2424 100644 --- a/maxscale-system-test/cnf/maxscale.cnf.template.replication_manager +++ b/maxscale-system-test/cnf/maxscale.cnf.template.replication_manager @@ -12,8 +12,6 @@ monitor_interval=1000 detect_standalone_master=true failcount=2 allow_cluster_recovery=true -events=master_down -script=/home/vagrant/replication-manager --hosts=$LIST --user=skysql:skysql --rpluser=skysql:skysql --switchover-at-sync=false --log-level=3 --logfile=/tmp/mrm.log switchover [RW Split Router] type=service diff --git a/maxscale-system-test/config_operations.cpp b/maxscale-system-test/config_operations.cpp index dedd2c8b1..6ebd1526c 100644 --- a/maxscale-system-test/config_operations.cpp +++ b/maxscale-system-test/config_operations.cpp @@ -33,13 +33,13 @@ void Config::add_server(int num) { test_->tprintf("Adding the servers"); test_->set_timeout(120); - test_->ssh_maxscale(true, "maxadmin add server server%d " SERVICE_NAME1, num); - test_->ssh_maxscale(true, "maxadmin add server server%d " SERVICE_NAME2, num); - test_->ssh_maxscale(true, "maxadmin add server server%d " SERVICE_NAME3, num); + test_->maxscales->ssh_node_f(0, true, "maxadmin add server server%d " SERVICE_NAME1, num); + test_->maxscales->ssh_node_f(0, true, "maxadmin add server server%d " SERVICE_NAME2, num); + test_->maxscales->ssh_node_f(0, true, "maxadmin add server server%d " SERVICE_NAME3, num); for (auto& a : created_monitors_) { - test_->ssh_maxscale(true, "maxadmin add server server%d %s", num, a.c_str()); + test_->maxscales->ssh_node_f(0, true, "maxadmin add server server%d %s", num, a.c_str()); } test_->stop_timeout(); @@ -48,13 +48,13 @@ void Config::add_server(int num) void Config::remove_server(int num) { test_->set_timeout(120); - test_->ssh_maxscale(true, "maxadmin remove server server%d " SERVICE_NAME1, num); - test_->ssh_maxscale(true, "maxadmin remove server server%d " SERVICE_NAME2, num); - test_->ssh_maxscale(true, "maxadmin remove server server%d " SERVICE_NAME3, num); + test_->maxscales->ssh_node_f(0, true, "maxadmin remove server server%d " SERVICE_NAME1, num); + test_->maxscales->ssh_node_f(0, true, "maxadmin remove server server%d " SERVICE_NAME2, num); + test_->maxscales->ssh_node_f(0, true, "maxadmin remove server server%d " SERVICE_NAME3, num); for (auto& a : created_monitors_) { - test_->ssh_maxscale(true, "maxadmin remove server server%d %s", num, a.c_str()); + test_->maxscales->ssh_node_f(0, true, "maxadmin remove server server%d %s", num, a.c_str()); } test_->stop_timeout(); @@ -64,14 +64,14 @@ void Config::add_created_servers(const char *object) { for (auto a : created_servers_) { - test_->ssh_maxscale(true, "maxadmin add server server%d %s", a, object); + test_->maxscales->ssh_node_f(0, true, "maxadmin add server server%d %s", a, object); } } void Config::destroy_server(int num) { test_->set_timeout(120); - test_->ssh_maxscale(true, "maxadmin destroy server server%d", num); + test_->maxscales->ssh_node_f(0, true, "maxadmin destroy server server%d", num); created_servers_.erase(num); test_->stop_timeout(); } @@ -79,35 +79,35 @@ void Config::destroy_server(int num) void Config::create_server(int num) { test_->set_timeout(120); - test_->ssh_maxscale(true, "maxadmin create server server%d %s %d", - num, test_->repl->IP[num], test_->repl->port[num]); + test_->maxscales->ssh_node_f(0, true, "maxadmin create server server%d %s %d", + num, test_->repl->IP[num], test_->repl->port[num]); created_servers_.insert(num); test_->stop_timeout(); } void Config::alter_server(int num, const char *key, const char *value) { - test_->ssh_maxscale(true, "maxadmin alter server server%d %s=%s", num, key, value); + test_->maxscales->ssh_node_f(0, true, "maxadmin alter server server%d %s=%s", num, key, value); } void Config::alter_server(int num, const char *key, int value) { - test_->ssh_maxscale(true, "maxadmin alter server server%d %s=%d", num, key, value); + test_->maxscales->ssh_node_f(0, true, "maxadmin alter server server%d %s=%d", num, key, value); } void Config::alter_server(int num, const char *key, float value) { - test_->ssh_maxscale(true, "maxadmin alter server server%d %s=%f", num, key, value); + test_->maxscales->ssh_node_f(0, true, "maxadmin alter server server%d %s=%f", num, key, value); } void Config::create_monitor(const char *name, const char *module, int interval) { test_->set_timeout(120); - test_->ssh_maxscale(true, "maxadmin create monitor %s %s", name, module); + test_->maxscales->ssh_node_f(0, true, "maxadmin create monitor %s %s", name, module); alter_monitor(name, "monitor_interval", interval); - alter_monitor(name, "user", test_->maxscale_user); - alter_monitor(name, "password", test_->maxscale_password); - test_->ssh_maxscale(true, "maxadmin restart monitor %s", name); + alter_monitor(name, "user", test_->maxscales->user_name); + alter_monitor(name, "password", test_->maxscales->password); + test_->maxscales->ssh_node_f(0, true, "maxadmin restart monitor %s", name); test_->stop_timeout(); created_monitors_.insert(std::string(name)); @@ -115,28 +115,28 @@ void Config::create_monitor(const char *name, const char *module, int interval) void Config::alter_monitor(const char* name, const char *key, const char *value) { - test_->ssh_maxscale(true, "maxadmin alter monitor %s %s=%s", name, key, value); + test_->maxscales->ssh_node_f(0, true, "maxadmin alter monitor %s %s=%s", name, key, value); } void Config::alter_monitor(const char* name, const char *key, int value) { - test_->ssh_maxscale(true, "maxadmin alter monitor %s %s=%d", name, key, value); + test_->maxscales->ssh_node_f(0, true, "maxadmin alter monitor %s %s=%d", name, key, value); } void Config::alter_monitor(const char* name, const char *key, float value) { - test_->ssh_maxscale(true, "maxadmin alter monitor %s %s=%f", name, key, value); + test_->maxscales->ssh_node_f(0, true, "maxadmin alter monitor %s %s=%f", name, key, value); } void Config::start_monitor(const char *name) { - test_->ssh_maxscale(true, "maxadmin restart monitor %s", name); + test_->maxscales->ssh_node_f(0, true, "maxadmin restart monitor %s", name); } void Config::destroy_monitor(const char *name) { test_->set_timeout(120); - test_->ssh_maxscale(true, "maxadmin destroy monitor %s", name); + test_->maxscales->ssh_node_f(0, true, "maxadmin destroy monitor %s", name); test_->stop_timeout(); created_monitors_.erase(std::string(name)); } @@ -145,8 +145,8 @@ void Config::restart_monitors() { for (auto& a : created_monitors_) { - test_->ssh_maxscale(true, "maxadmin shutdown monitor \"%s\"", a.c_str()); - test_->ssh_maxscale(true, "maxadmin restart monitor \"%s\"", a.c_str()); + test_->maxscales->ssh_node_f(0, true, "maxadmin shutdown monitor \"%s\"", a.c_str()); + test_->maxscales->ssh_node_f(0, true, "maxadmin restart monitor \"%s\"", a.c_str()); } } @@ -155,10 +155,10 @@ void Config::create_listener(Config::Service service) int i = static_cast(service); test_->set_timeout(120); - test_->ssh_maxscale(true, "maxadmin create listener %s %s default %d", - services[i].service, - services[i].listener, - services[i].port); + test_->maxscales->ssh_node_f(0, true, "maxadmin create listener %s %s default %d", + services[i].service, + services[i].listener, + services[i].port); test_->stop_timeout(); } @@ -167,13 +167,13 @@ void Config::create_ssl_listener(Config::Service service) int i = static_cast(service); test_->set_timeout(120); - test_->ssh_maxscale(true, "maxadmin create listener %s %s default %d default default default " - "/home/vagrant/certs/server-key.pem " - "/home/vagrant/certs/server-cert.pem " - "/home/vagrant/certs/ca.pem ", - services[i].service, - services[i].listener, - services[i].port); + test_->maxscales->ssh_node_f(0, true, "maxadmin create listener %s %s default %d default default default " + "/home/vagrant/certs/server-key.pem " + "/home/vagrant/certs/server-cert.pem " + "/home/vagrant/certs/ca.pem ", + services[i].service, + services[i].listener, + services[i].port); test_->stop_timeout(); } @@ -182,8 +182,8 @@ void Config::destroy_listener(Config::Service service) int i = static_cast(service); test_->set_timeout(120); - test_->ssh_maxscale(true, "maxadmin destroy listener %s %s", - services[i].service, services[i].listener); + test_->maxscales->ssh_node_f(0, true, "maxadmin destroy listener %s %s", + services[i].service, services[i].listener); test_->stop_timeout(); } @@ -211,8 +211,9 @@ bool Config::check_server_count(int expected) { bool rval = true; - if (test_->ssh_maxscale(true, "test \"`maxadmin list servers|grep 'server[0-9]'|wc -l`\" == \"%d\"", - expected)) + if (test_->maxscales->ssh_node_f(0, true, + "test \"`maxadmin list servers|grep 'server[0-9]'|wc -l`\" == \"%d\"", + expected)) { test_->add_result(1, "Number of servers is not %d.", expected); rval = false; diff --git a/maxscale-system-test/config_test.cpp b/maxscale-system-test/config_test.cpp index fca2f88f9..adfc4cc63 100644 --- a/maxscale-system-test/config_test.cpp +++ b/maxscale-system-test/config_test.cpp @@ -28,12 +28,12 @@ int main(int argc, char **argv) TestConnections *test = new TestConnections(argc, argv); int rval = 0; - test->stop_maxscale(); + test->maxscales->stop_maxscale(0); for (int i = 0; bad_configs[i]; i++) { printf("Testing %s...\n", bad_configs[i]); - if (test->test_bad_config(bad_configs[i])) + if (test->test_bad_config(0, bad_configs[i])) { printf("FAILED\n"); rval++; diff --git a/maxscale-system-test/connect_to_nonexisting_db.cpp b/maxscale-system-test/connect_to_nonexisting_db.cpp index bd348cdbc..44fcd1d1d 100644 --- a/maxscale-system-test/connect_to_nonexisting_db.cpp +++ b/maxscale-system-test/connect_to_nonexisting_db.cpp @@ -7,14 +7,14 @@ bool try_connect(TestConnections& test) { - const char* ip = test.maxscale_IP; - const char* user = test.maxscale_user; - const char* pw = test.maxscale_password; + const char* ip = test.maxscales->IP[0]; + const char* user = test.maxscales->user_name; + const char* pw = test.maxscales->password; const char* db = "test_db"; - MYSQL* rwsplit = open_conn_db(test.rwsplit_port, ip, db, user, pw, false); - MYSQL* master = open_conn_db(test.readconn_master_port, ip, db, user, pw, false); - MYSQL* slave = open_conn_db(test.readconn_slave_port, ip, db, user, pw, false); + MYSQL* rwsplit = open_conn_db(test.maxscales->rwsplit_port[0], ip, db, user, pw, false); + MYSQL* master = open_conn_db(test.maxscales->readconn_master_port[0], ip, db, user, pw, false); + MYSQL* slave = open_conn_db(test.maxscales->readconn_slave_port[0], ip, db, user, pw, false); bool rval = false; if (rwsplit && master && slave && @@ -40,8 +40,9 @@ int main(int argc, char *argv[]) test.tprintf("Connecting to RWSplit"); test.set_timeout(30); - MYSQL* conn = open_conn_no_db(test.rwsplit_port, test.maxscale_IP, test.maxscale_user, - test.maxscale_password, test.ssl); + MYSQL* conn = open_conn_no_db(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], + test.maxscales->user_name, + test.maxscales->password, test.ssl); test.add_result(conn == NULL, "Error connecting to MaxScale"); test.tprintf("Removing 'test_db' DB"); @@ -52,12 +53,12 @@ int main(int argc, char *argv[]) sleep(5); test.set_timeout(30); - test.tprintf("Connection to non-existing DB (all routers)"); + test.tprintf("Connection to non-existing DB (all maxscales->routers[0])"); test.add_result(try_connect(test), "Connection with dropped database should fail"); test.tprintf("Connecting to RWSplit again to recreate 'test_db' db"); - conn = open_conn_no_db(test.rwsplit_port, test.maxscale_IP, test.maxscale_user, - test.maxscale_password, test.ssl); + conn = open_conn_no_db(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], test.maxscales->user_name, + test.maxscales->password, test.ssl); test.add_result(conn == NULL, "Error connecting to MaxScale"); test.tprintf("Creating and selecting 'test_db' DB"); @@ -72,8 +73,8 @@ int main(int argc, char *argv[]) test.tprintf("Trying simple operations with t1 "); - conn = open_conn_no_db(test.rwsplit_port, test.maxscale_IP, test.maxscale_user, - test.maxscale_password, test.ssl); + conn = open_conn_no_db(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], test.maxscales->user_name, + test.maxscales->password, test.ssl); test.try_query(conn, "USE test_db"); test.try_query(conn, "INSERT INTO t1 (x1, fl) VALUES(0, 1)"); test.set_timeout(60); diff --git a/maxscale-system-test/connection_limit.cpp b/maxscale-system-test/connection_limit.cpp index 46294ba52..7873ddf94 100644 --- a/maxscale-system-test/connection_limit.cpp +++ b/maxscale-system-test/connection_limit.cpp @@ -19,15 +19,17 @@ int check_max_conn(int router, int max_conn, TestConnections * Test) int i; for (i = 0; i < max_conn; i++) { - conn[i] = open_conn(Test->ports[router], Test->maxscale_IP, Test->maxscale_user, Test->maxscale_password, + conn[i] = open_conn(Test->maxscales->ports[0][router], Test->maxscales->IP[0], Test->maxscales->user_name, + Test->maxscales->password, Test->ssl); if (mysql_errno(conn[i]) != 0) { Test->add_result(1, "Connection %d failed, error is %s\n", i, mysql_error(conn[i])); } } - conn[max_conn] = open_conn(Test->ports[router], Test->maxscale_IP, Test->maxscale_user, - Test->maxscale_password, Test->ssl); + conn[max_conn] = open_conn(Test->maxscales->ports[0][router], Test->maxscales->IP[0], + Test->maxscales->user_name, + Test->maxscales->password, Test->ssl); if (mysql_errno(conn[i]) != 1040) { Test->add_result(1, "Max_xonnections reached, but error is not 1040, it is %d %s\n", mysql_errno(conn[i]), @@ -52,9 +54,8 @@ int main(int argc, char *argv[]) sleep(10); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; } - diff --git a/maxscale-system-test/crash_out_of_files.cpp b/maxscale-system-test/crash_out_of_files.cpp index 62bf8d8ec..88a175946 100644 --- a/maxscale-system-test/crash_out_of_files.cpp +++ b/maxscale-system-test/crash_out_of_files.cpp @@ -44,8 +44,8 @@ int main(int argc, char *argv[]) Test->repl->close_connections(); Test->stop_timeout(); - Test->check_log_err((char *) "refresh rate limit exceeded", false); - Test->check_maxscale_alive(); + Test->check_log_err(0, (char *) "refresh rate limit exceeded", false); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/crash_out_of_files_galera.cpp b/maxscale-system-test/crash_out_of_files_galera.cpp index ec733270b..cec708657 100644 --- a/maxscale-system-test/crash_out_of_files_galera.cpp +++ b/maxscale-system-test/crash_out_of_files_galera.cpp @@ -42,11 +42,11 @@ int main(int argc, char *argv[]) } Test->galera->close_connections(); - Test->check_log_err((char *) "refresh rate limit exceeded", false); + Test->check_log_err(0, (char *) "refresh rate limit exceeded", false); Test->galera->execute_query_all_nodes((char *) "set global max_connections = 100;"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/different_size.cpp b/maxscale-system-test/different_size.cpp index 250e53ded..6715f03f3 100644 --- a/maxscale-system-test/different_size.cpp +++ b/maxscale-system-test/different_size.cpp @@ -36,7 +36,7 @@ MYSQL * connect_to_serv(TestConnections* Test, bool binlog) } else { - conn = Test->open_rwsplit_connection(); + conn = Test->maxscales->open_rwsplit_connection(0); } return conn; } @@ -52,9 +52,9 @@ void set_max_packet(TestConnections* Test, bool binlog, char * cmd) } else { - Test->connect_maxscale(); - Test->try_query(Test->conn_rwsplit, cmd); - Test->close_maxscale_connections(); + Test->maxscales->connect_maxscale(0); + Test->try_query(Test->maxscales->conn_rwsplit[0], cmd); + Test->maxscales->close_maxscale_connections(0); } Test->tprintf(".. done\n"); } diff --git a/maxscale-system-test/different_size_binlog.cpp b/maxscale-system-test/different_size_binlog.cpp index b98c1c296..6d1a96e3f 100644 --- a/maxscale-system-test/different_size_binlog.cpp +++ b/maxscale-system-test/different_size_binlog.cpp @@ -19,10 +19,10 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(300); - Test->start_binlog(); + Test->start_binlog(0); different_packet_size(Test, true); - Test->check_maxscale_processes(1); + Test->check_maxscale_processes(0, 1); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/different_size_rwsplit.cpp b/maxscale-system-test/different_size_rwsplit.cpp index 2079ef793..33400406b 100644 --- a/maxscale-system-test/different_size_rwsplit.cpp +++ b/maxscale-system-test/different_size_rwsplit.cpp @@ -19,7 +19,7 @@ int main(int argc, char *argv[]) different_packet_size(Test, false); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/encrypted_passwords.cpp b/maxscale-system-test/encrypted_passwords.cpp index 9accc94d0..35c728c90 100644 --- a/maxscale-system-test/encrypted_passwords.cpp +++ b/maxscale-system-test/encrypted_passwords.cpp @@ -10,11 +10,14 @@ int create_key(TestConnections *test) { int res = 0; + int exit_code; test->set_timeout(120); test->tprintf("Creating new encryption keys\n"); - test->ssh_maxscale(true, "test -f /var/lib/maxscale/.secrets && sudo rm /var/lib/maxscale/.secrets"); - test->ssh_maxscale(true, "maxkeys"); - char *result = test->ssh_maxscale_output(false, "sudo test -f /var/lib/maxscale/.secrets && echo SUCCESS"); + test->maxscales->ssh_node(0, "test -f /var/lib/maxscale/.secrets && sudo rm /var/lib/maxscale/.secrets", + true); + test->maxscales->ssh_node(0, "maxkeys", true); + char *result = test->maxscales->ssh_node_output(0, "sudo test -f /var/lib/maxscale/.secrets && echo SUCCESS", + false, &exit_code); if (strncmp(result, "SUCCESS", 7) != 0) { @@ -23,7 +26,7 @@ int create_key(TestConnections *test) } else { - test->ssh_maxscale(true, "sudo chown maxscale:maxscale /var/lib/maxscale/.secrets"); + test->maxscales->ssh_node(0, "sudo chown maxscale:maxscale /var/lib/maxscale/.secrets", true); } free(result); @@ -34,12 +37,13 @@ int create_key(TestConnections *test) /** Hash a new password and start MaxScale */ int hash_password(TestConnections *test) { - test->stop_maxscale(); + test->maxscales->stop_maxscale(0); test->stop_timeout(); int res = 0; + int exit_code; test->tprintf("Creating a new encrypted password\n"); - char *enc_pw = test->ssh_maxscale_output(true, "maxpasswd /var/lib/maxscale/ skysql"); + char *enc_pw = test->maxscales->ssh_node_output(0, "maxpasswd /var/lib/maxscale/ skysql", true, &exit_code); char *ptr = strchr(enc_pw, '\n'); if (ptr) @@ -48,15 +52,16 @@ int hash_password(TestConnections *test) } test->tprintf("Encrypted password is: %s\n", enc_pw); - test->ssh_maxscale(true, "sed -i -e 's/passwd[[:space:]]*=[[:space:]]*skysql/passwd=%s/' /etc/maxscale.cnf", - enc_pw); + test->maxscales->ssh_node_f(0, true, + "sed -i -e 's/passwd[[:space:]]*=[[:space:]]*skysql/passwd=%s/' /etc/maxscale.cnf", + enc_pw); free(enc_pw); test->tprintf("Starting MaxScale\n"); - test->start_maxscale(); + test->maxscales->start_maxscale(0); test->tprintf("Checking if MaxScale is alive\n"); - return test->check_maxscale_alive(); + return test->check_maxscale_alive(0); } diff --git a/maxscale-system-test/failover_mysqlmon.cpp b/maxscale-system-test/failover_mysqlmon.cpp index 52f2a9ed1..e663dfaf9 100644 --- a/maxscale-system-test/failover_mysqlmon.cpp +++ b/maxscale-system-test/failover_mysqlmon.cpp @@ -15,13 +15,14 @@ int main(int argc, char *argv[]) { + int exit_code; TestConnections * test = new TestConnections(argc, argv); test->tprintf(" Create the test table and insert some data "); - test->connect_maxscale(); - test->try_query(test->conn_rwsplit, "CREATE OR REPLACE TABLE test.t1 (id int)"); - test->try_query(test->conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); - test->close_maxscale_connections(); + test->maxscales->connect_maxscale(0); + test->try_query(test->maxscales->conn_rwsplit[0], "CREATE OR REPLACE TABLE test.t1 (id int)"); + test->try_query(test->maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); + test->maxscales->close_maxscale_connections(0); test->tprintf(" Block all but one node "); test->repl->block_node(0); @@ -34,12 +35,12 @@ int main(int argc, char *argv[]) sleep(15); test->tprintf(" Connect and insert should work "); - char *output = test->ssh_maxscale_output(true, "maxadmin list servers"); + char *output = test->maxscales->ssh_node_output(0, "maxadmin list servers", true, &exit_code); test->tprintf("%s", output); free(output); - test->connect_maxscale(); - test->try_query(test->conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); - test->close_maxscale_connections(); + test->maxscales->connect_maxscale(0); + test->try_query(test->maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); + test->maxscales->close_maxscale_connections(0); test->tprintf(" Unblock nodes "); test->repl->unblock_node(0); @@ -52,18 +53,18 @@ int main(int argc, char *argv[]) test->tprintf("Check that we are still using the last node to which we failed over " "to and that the old nodes are in maintenance mode"); - test->connect_maxscale(); - test->try_query(test->conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); + test->maxscales->connect_maxscale(0); + test->try_query(test->maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); char maxscale_id[256], real_id[256]; - find_field(test->conn_rwsplit, "SELECT @@server_id", "@@server_id", maxscale_id); + find_field(test->maxscales->conn_rwsplit[0], "SELECT @@server_id", "@@server_id", maxscale_id); test->repl->connect(); find_field(test->repl->nodes[3], "SELECT @@server_id", "@@server_id", real_id); test->add_result(strcmp(maxscale_id, real_id) != 0, "@@server_id is different: %s != %s", maxscale_id, real_id); - test->close_maxscale_connections(); + test->maxscales->close_maxscale_connections(0); test->tprintf(" Check that MaxScale is running "); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); int rval = test->global_result; delete test; diff --git a/maxscale-system-test/failover_mysqlmon_mrm.cpp b/maxscale-system-test/failover_mysqlmon_mrm.cpp index 6e26211a4..5b979e35b 100644 --- a/maxscale-system-test/failover_mysqlmon_mrm.cpp +++ b/maxscale-system-test/failover_mysqlmon_mrm.cpp @@ -6,14 +6,16 @@ void get_output(TestConnections& test) { + int ec; test.tprintf("Maxadmin output:"); - char *output = test.ssh_maxscale_output(true, "maxadmin list servers"); + char *output = test.maxscales->ssh_node_output(0, "maxadmin list servers", true, &ec); test.tprintf("%s", output); free(output); test.tprintf("MaxScale output:"); - output = test.ssh_maxscale_output(true, "cat /var/log/maxscale/maxscale.log && " - "sudo truncate -s 0 /var/log/maxscale/maxscale.log"); + output = test.maxscales->ssh_node_output(0, "cat /var/log/maxscale/maxscale.log && " + "sudo truncate -s 0 /var/log/maxscale/maxscale.log", + true, &ec); test.tprintf("%s", output); free(output); } @@ -22,7 +24,7 @@ static int inserts = 0; void check(TestConnections& test) { - MYSQL *conn = test.open_rwsplit_connection(); + MYSQL *conn = test.maxscales->open_rwsplit_connection(0); const char *query1 = "INSERT INTO test.t1 VALUES (%d)"; const char *query2 = "SELECT * FROM test.t1"; @@ -63,7 +65,7 @@ void check(TestConnections& test) */ int get_server_id(TestConnections& test) { - MYSQL *conn = test.open_rwsplit_connection(); + MYSQL *conn = test.maxscales->open_rwsplit_connection(0); int id = -1; char str[1024]; @@ -90,10 +92,10 @@ void get_input() void fix_replication_create_table(TestConnections& test) { test.tprintf("Fix replication and recreate table."); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); test.repl->fix_replication(); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "CREATE OR REPLACE TABLE test.t1(id INT)"); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "CREATE OR REPLACE TABLE test.t1(id INT)"); test.repl->sync_slaves(); inserts = 0; @@ -116,8 +118,8 @@ int main(int argc, char** argv) test.tprintf("Creating table and inserting data."); get_input(); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "CREATE OR REPLACE TABLE test.t1(id INT)"); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "CREATE OR REPLACE TABLE test.t1(id INT)"); test.repl->sync_slaves(); check(test); @@ -175,8 +177,8 @@ int main(int argc, char** argv) const char* log_slave = "log_slave_updates=1"; test.repl->add_server_setting(1, log_slave); test.repl->add_server_setting(3, log_slave); - test.repl->start_node(1, ""); - test.repl->start_node(3, ""); + test.repl->start_node(1, (char *) ""); + test.repl->start_node(3, (char *) ""); sleep(4); test.tprintf("Settings changed."); get_output(test); @@ -196,17 +198,17 @@ int main(int argc, char** argv) // Restore server 2 and 4 settings. Because server 4 is now the master, shutting it down causes // another failover. Prevent this by stopping maxscale. test.tprintf("Restoring server settings."); - test.stop_maxscale(); + test.maxscales->stop_maxscale(0); test.repl->stop_node(1); test.repl->stop_node(3); sleep(4); test.repl->restore_server_settings(1); test.repl->restore_server_settings(3); - test.repl->start_node(0, ""); - test.repl->start_node(1, ""); - test.repl->start_node(3, ""); + test.repl->start_node(0, (char *) ""); + test.repl->start_node(1, (char *) ""); + test.repl->start_node(3, (char *) ""); sleep(4); - test.start_maxscale(); + test.maxscales->start_maxscale(0); sleep(2); get_output(test); get_input(); diff --git a/maxscale-system-test/false_monitor_state_change.cpp b/maxscale-system-test/false_monitor_state_change.cpp index 268d90797..b05c1eb74 100644 --- a/maxscale-system-test/false_monitor_state_change.cpp +++ b/maxscale-system-test/false_monitor_state_change.cpp @@ -15,14 +15,14 @@ int main(int argc, char *argv[]) sleep(10); test.tprintf("Clear master status"); - test.ssh_maxscale(true, "maxadmin clear server server1 master"); + test.maxscales->ssh_node(0, "maxadmin clear server server1 master", true); sleep(5); test.repl->unblock_node(0); sleep(5); - test.check_maxscale_alive(); - test.check_log_err("debug assert", false); + test.check_maxscale_alive(0); + test.check_log_err(0, "debug assert", false); return test.global_result; } diff --git a/maxscale-system-test/fw2/deny1 b/maxscale-system-test/fw2/deny1 new file mode 100644 index 000000000..08df3dd10 --- /dev/null +++ b/maxscale-system-test/fw2/deny1 @@ -0,0 +1,3 @@ +drop table if exists t1; +create table t1(id int); +alter table t1 add column b int; diff --git a/maxscale-system-test/fw2/deny2 b/maxscale-system-test/fw2/deny2 new file mode 100644 index 000000000..afd589610 --- /dev/null +++ b/maxscale-system-test/fw2/deny2 @@ -0,0 +1,2 @@ +grant select on *.* to 'skysql'@'localhost'; +revoke select on *.* from 'skysql'@'localhost'; diff --git a/maxscale-system-test/fw2/deny3 b/maxscale-system-test/fw2/deny3 new file mode 100644 index 000000000..dee339a0e --- /dev/null +++ b/maxscale-system-test/fw2/deny3 @@ -0,0 +1,2 @@ +use test; +load data local infile 'test.csv' into table test.t1; diff --git a/maxscale-system-test/fw2/deny4 b/maxscale-system-test/fw2/deny4 new file mode 100644 index 000000000..6a9af9f10 --- /dev/null +++ b/maxscale-system-test/fw2/deny4 @@ -0,0 +1,12 @@ +select sum(1) from test.t1; +select avg(1) from test.t1; +select sum(avg(1)) from test.t1; +select my_function(1) from test.t1; +select my_function("1") from test.t1; +select * from test.t1 where 1 = 1; +select * from test.t1 where 1 >= 1; +select * from test.t1 where 1 <= 1; +select * from test.t1 where 1 != 1; +select * from test.t1 where 1 <> 1; +select function(*) from test.t1; +select insert(*) from test.t1; diff --git a/maxscale-system-test/fw2/deny5 b/maxscale-system-test/fw2/deny5 new file mode 100644 index 000000000..ab290eb4c --- /dev/null +++ b/maxscale-system-test/fw2/deny5 @@ -0,0 +1 @@ +select 1; diff --git a/maxscale-system-test/fw2/pass1 b/maxscale-system-test/fw2/pass1 new file mode 100644 index 000000000..8487c645f --- /dev/null +++ b/maxscale-system-test/fw2/pass1 @@ -0,0 +1,3 @@ +select * from mysql.user; +use mysql; +set @var = 1; diff --git a/maxscale-system-test/fw2/pass2 b/maxscale-system-test/fw2/pass2 new file mode 100644 index 000000000..8487c645f --- /dev/null +++ b/maxscale-system-test/fw2/pass2 @@ -0,0 +1,3 @@ +select * from mysql.user; +use mysql; +set @var = 1; diff --git a/maxscale-system-test/fw2/pass3 b/maxscale-system-test/fw2/pass3 new file mode 100644 index 000000000..2b68250d3 --- /dev/null +++ b/maxscale-system-test/fw2/pass3 @@ -0,0 +1,2 @@ +select * from mysql.user; +set @var = 1; diff --git a/maxscale-system-test/fw2/pass4 b/maxscale-system-test/fw2/pass4 new file mode 100644 index 000000000..6894c8432 --- /dev/null +++ b/maxscale-system-test/fw2/pass4 @@ -0,0 +1,6 @@ +create or replace table test.t1(id int); +create function my_function (arg int) returns int deterministic return arg * arg; +select "sum(1)"; +select (1); +select * from(select 1) as a; +insert into test.t1 values (1); diff --git a/maxscale-system-test/fw2/pass5 b/maxscale-system-test/fw2/pass5 new file mode 100644 index 000000000..3bbec0fac --- /dev/null +++ b/maxscale-system-test/fw2/pass5 @@ -0,0 +1 @@ +create or replace table t1 (id int); diff --git a/maxscale-system-test/fw2/rules1 b/maxscale-system-test/fw2/rules1 new file mode 100644 index 000000000..bb40bd532 --- /dev/null +++ b/maxscale-system-test/fw2/rules1 @@ -0,0 +1,4 @@ +rule test1 deny regex '.*' on_queries drop +rule test2 deny regex '.*' on_queries create +rule test3 deny regex '.*' on_queries alter +users %@% match any rules test1 test2 test3 diff --git a/maxscale-system-test/fw2/rules2 b/maxscale-system-test/fw2/rules2 new file mode 100644 index 000000000..2d6dc47db --- /dev/null +++ b/maxscale-system-test/fw2/rules2 @@ -0,0 +1,3 @@ +rule test1 deny regex '.*' on_queries grant +rule test2 deny regex '.*' on_queries revoke +users %@% match any rules test1 test2 diff --git a/maxscale-system-test/fw2/rules3 b/maxscale-system-test/fw2/rules3 new file mode 100644 index 000000000..6672bca49 --- /dev/null +++ b/maxscale-system-test/fw2/rules3 @@ -0,0 +1,3 @@ +rule test1 deny regex '.*' on_queries use +rule test2 deny regex '.*' on_queries load +users %@% match any rules test1 test2 diff --git a/maxscale-system-test/fw2/rules4 b/maxscale-system-test/fw2/rules4 new file mode 100644 index 000000000..c104917f8 --- /dev/null +++ b/maxscale-system-test/fw2/rules4 @@ -0,0 +1,5 @@ +rule test1 deny function sum avg on_queries select +rule test2 deny function my_function on_queries select +rule test3 deny function = >= <= != <> on_queries select +rule test4 deny function `function` `insert` +users %@% match any rules test1 test2 test3 test4 diff --git a/maxscale-system-test/fw2/rules5 b/maxscale-system-test/fw2/rules5 new file mode 100644 index 000000000..9b3902fa8 --- /dev/null +++ b/maxscale-system-test/fw2/rules5 @@ -0,0 +1,2 @@ +rule no_selects deny on_queries select +users %@% match any rules no_selects diff --git a/maxscale-system-test/fw_copy_rules.cpp b/maxscale-system-test/fw_copy_rules.cpp index 10f0a4685..3216ba2bb 100644 --- a/maxscale-system-test/fw_copy_rules.cpp +++ b/maxscale-system-test/fw_copy_rules.cpp @@ -7,9 +7,9 @@ void copy_rules(TestConnections* Test, const char* rules_name, const char* rules std::stringstream dest; src << rules_dir << "/" << rules_name; - dest << Test->maxscale_access_homedir << "/rules/rules.txt"; + dest << Test->maxscales->access_homedir[0] << "/rules/rules.txt"; Test->set_timeout(30); - Test->copy_to_maxscale(src.str().c_str(), dest.str().c_str()); + Test->maxscales->copy_to_node_legacy(src.str().c_str(), dest.str().c_str(), 0); Test->stop_timeout(); } diff --git a/maxscale-system-test/fwf.cpp b/maxscale-system-test/fwf.cpp index f0841bede..487bd80ca 100644 --- a/maxscale-system-test/fwf.cpp +++ b/maxscale-system-test/fwf.cpp @@ -32,11 +32,11 @@ int main(int argc, char *argv[]) char rules_dir[4096]; FILE* file; - Test->ssh_maxscale(true, "cd %s;" - "rm -rf rules;" - "mkdir rules;" - "chown vagrant:vagrant rules", - Test->maxscale_access_homedir); + Test->maxscales->ssh_node_f(0, true, "cd %s;" + "rm -rf rules;" + "mkdir rules;" + "chown vagrant:vagrant rules", + Test->maxscales->access_homedir[0]); sprintf(rules_dir, "%s/fw/", test_dir); int N = 18; @@ -50,8 +50,8 @@ int main(int argc, char *argv[]) sprintf(str, "rules%d", i); copy_rules(Test, str, rules_dir); - Test->restart_maxscale(); - Test->connect_rwsplit(); + Test->maxscales->restart_maxscale(0); + Test->maxscales->connect_rwsplit(0); sprintf(pass_file, "%s/fw/pass%d", test_dir, i); sprintf(deny_file, "%s/fw/deny%d", test_dir, i); @@ -77,7 +77,7 @@ int main(int argc, char *argv[]) { Test->tprintf("%s", sql); } - int rv = execute_query(Test->conn_rwsplit, sql); + int rv = execute_query(Test->maxscales->conn_rwsplit[0], sql); Test->add_result(rv, "Query should succeed: %s", sql); local_result += rv; } @@ -105,11 +105,11 @@ int main(int argc, char *argv[]) { Test->tprintf("%s", sql); } - execute_query_silent(Test->conn_rwsplit, sql); - if (mysql_errno(Test->conn_rwsplit) != 1141) + execute_query_silent(Test->maxscales->conn_rwsplit[0], sql); + if (mysql_errno(Test->maxscales->conn_rwsplit[0]) != 1141) { Test->tprintf("Expected 1141, Access Denied but got %d, %s instead: %s", - mysql_errno(Test->conn_rwsplit), mysql_error(Test->conn_rwsplit), sql); + mysql_errno(Test->maxscales->conn_rwsplit[0]), mysql_error(Test->maxscales->conn_rwsplit[0]), sql); local_result++; } } @@ -130,7 +130,7 @@ int main(int argc, char *argv[]) Test->tprintf("********** rules%d test PASSED", i); } - mysql_close(Test->conn_rwsplit); + mysql_close(Test->maxscales->conn_rwsplit[0]); } Test->set_timeout(180); @@ -148,20 +148,21 @@ int main(int argc, char *argv[]) Test->tprintf("DELETE quries without WHERE clause will be blocked during the 15 seconds"); Test->tprintf("Put time to rules.txt: %s", str); } - Test->ssh_maxscale(false, "start_time=`date +%%T`;" - "stop_time=` date --date \"now +15 secs\" +%%T`;" - "%s sed -i \"s/###time###/$start_time-$stop_time/\" %s/rules/rules.txt", - Test->maxscale_access_sudo, Test->maxscale_access_homedir); + Test->maxscales->ssh_node_f(0, false, "start_time=`date +%%T`;" + "stop_time=` date --date \"now +15 secs\" +%%T`;" + "%s sed -i \"s/###time###/$start_time-$stop_time/\" %s/rules/rules.txt", + Test->maxscales->access_sudo[0], Test->maxscales->access_homedir[0]); - Test->restart_maxscale(); - Test->connect_rwsplit(); + Test->maxscales->restart_maxscale(0); + Test->maxscales->connect_rwsplit(0); Test->tprintf("Trying 'DELETE FROM t1' and expecting FAILURE"); - execute_query_silent(Test->conn_rwsplit, "DELETE FROM t1"); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "DELETE FROM t1"); - if (mysql_errno(Test->conn_rwsplit) != 1141) + if (mysql_errno(Test->maxscales->conn_rwsplit[0]) != 1141) { - Test->add_result(1, "Query succeded, but fail expected, errono is %d", mysql_errno(Test->conn_rwsplit)); + Test->add_result(1, "Query succeded, but fail expected, errono is %d", + mysql_errno(Test->maxscales->conn_rwsplit[0])); } Test->tprintf("Waiting 16 seconds and trying 'DELETE FROM t1', expecting OK"); @@ -169,22 +170,23 @@ int main(int argc, char *argv[]) Test->stop_timeout(); sleep(16); Test->set_timeout(180); - Test->try_query(Test->conn_rwsplit, "DELETE FROM t1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DELETE FROM t1"); - mysql_close(Test->conn_rwsplit); - Test->stop_maxscale(); + mysql_close(Test->maxscales->conn_rwsplit[0]); + Test->maxscales->stop_maxscale(0); Test->tprintf("Trying limit_queries clause"); Test->tprintf("Copying rules to Maxscale machine: %s", str); copy_rules(Test, (char *) "rules_limit_queries", rules_dir); - Test->start_maxscale(); - Test->connect_rwsplit(); + Test->maxscales->start_maxscale(0); + Test->maxscales->connect_rwsplit(0); Test->tprintf("Trying 10 quries as fast as possible"); for (i = 0; i < 10; i++) { - Test->add_result(execute_query_silent(Test->conn_rwsplit, "SELECT * FROM t1"), "%d -query failed", i); + Test->add_result(execute_query_silent(Test->maxscales->conn_rwsplit[0], "SELECT * FROM t1"), + "%d -query failed", i); } Test->tprintf("Expecting failures during next 5 seconds"); @@ -200,7 +202,8 @@ int main(int argc, char *argv[]) elapsedTime = (t2.tv_sec - t1.tv_sec); elapsedTime += (double) (t2.tv_usec - t1.tv_usec) / 1000000.0; } - while ((execute_query_silent(Test->conn_rwsplit, "SELECT * FROM t1") != 0) && (elapsedTime < 10)); + while ((execute_query_silent(Test->maxscales->conn_rwsplit[0], "SELECT * FROM t1") != 0) && + (elapsedTime < 10)); Test->tprintf("Quries were blocked during %f (using clock_gettime())", elapsedTime); Test->tprintf("Quries were blocked during %lu (using time())", time(NULL) - start_time_clock); @@ -215,7 +218,7 @@ int main(int argc, char *argv[]) for (i = 0; i < 12; i++) { sleep(1); - Test->add_result(execute_query_silent(Test->conn_rwsplit, "SELECT * FROM t1"), "query failed"); + Test->add_result(execute_query_silent(Test->maxscales->conn_rwsplit[0], "SELECT * FROM t1"), "query failed"); if (Test->verbose) { Test->tprintf("%d ", i); @@ -226,5 +229,3 @@ int main(int argc, char *argv[]) delete Test; return rval; } - - diff --git a/maxscale-system-test/fwf2.cpp b/maxscale-system-test/fwf2.cpp new file mode 100644 index 000000000..ab2fa535c --- /dev/null +++ b/maxscale-system-test/fwf2.cpp @@ -0,0 +1,102 @@ +/** + * @file fwf - Firewall filtyer test + * - setup Firewall filter to use rules from rule file fw/ruleXX, where XX - number of sub-test + * - execute queries for fw/passXX file, expect OK + * - execute queries from fw/denyXX, expect Access Denied error (mysql_error 1141) + * - repeat for all XX + * - setup Firewall filter to block queries next 2 minutes using 'at_time' statement (see template fw/rules_at_time) + * - start sending queries, expect Access Denied now and OK after two mintes + * - setup Firewall filter to limit a number of queries during certain time + * - start sending queries as fast as possible, expect OK for N first quries and Access Denied for next queries + * - wait, start sending queries again, but only one query per second, expect OK + * - try to load rules with syntax error, expect failure for all sessions and queries + */ + + +#include +#include +#include "testconnections.h" +#include "maxadmin_operations.h" +#include "sql_t1.h" +#include "fw_copy_rules.h" + +int read_and_execute_queries(TestConnections *Test, const char* filename, int expected) +{ + FILE *file = fopen(filename, "r"); + int local_result = 0; + if (file != NULL) + { + char sql[4096]; + while (fgets(sql, sizeof(sql), file)) + { + Test->set_timeout(60); + if (strlen(sql) > 1) + { + Test->tprintf("%s", sql); + if (execute_query(Test->maxscales->conn_rwsplit[0], sql) != expected && + (expected == 1 || mysql_errno(Test->maxscales->conn_rwsplit[0]) == 1141)) + { + Test->tprintf("Query %s, but %s expected, MySQL error: %d, %s\n", + expected ? "succeeded" : "failed", + expected ? "failure" : "success", + mysql_errno(Test->maxscales->conn_rwsplit[0]), mysql_error(Test->maxscales->conn_rwsplit[0])); + local_result++; + } + } + } + fclose(file); + } + else + { + Test->add_result(1, "Error opening file '%s'\n", filename); + } + return local_result; +} + +int main(int argc, char *argv[]) +{ + TestConnections::skip_maxscale_start(true); + TestConnections * Test = new TestConnections(argc, argv); + int local_result; + char str[4096]; + char pass_file[4096]; + char deny_file[4096]; + char rules_dir[4096]; + FILE* file; + + sprintf(rules_dir, "%s/fw2/", test_dir); + int N = 5; + int i; + + for (i = 1; i < N + 1; i++) + { + Test->set_timeout(60); + local_result = 0; + + Test->stop_maxscale(0); + + sprintf(str, "rules%d", i); + copy_rules(Test, str, rules_dir); + + Test->maxscales->start_maxscale(0); + Test->maxscales->connect_rwsplit(0); + + sprintf(pass_file, "%s/fw2/pass%d", test_dir, i); + sprintf(deny_file, "%s/fw2/deny%d", test_dir, i); + + Test->tprintf("********** Trying queries that should be OK ********** \n"); + local_result += read_and_execute_queries(Test, pass_file, 0); + + Test->tprintf("********** Trying queries that should FAIL ********** \n"); + local_result += read_and_execute_queries(Test, deny_file, 1); + + Test->add_result(local_result, "********** rules%d test FAILED\n", i); + mysql_close(Test->maxscales->conn_rwsplit[0]); + } + + Test->check_maxscale_processes(0, 1); + + int rval = Test->global_result; + delete Test; + return rval; +} diff --git a/maxscale-system-test/fwf_actions.cpp b/maxscale-system-test/fwf_actions.cpp index 78652ae1c..dee2f27f3 100644 --- a/maxscale-system-test/fwf_actions.cpp +++ b/maxscale-system-test/fwf_actions.cpp @@ -21,54 +21,54 @@ int main(int argc, char** argv) test->stop_timeout(); test->tprintf("Creating rules\n"); - test->stop_maxscale(); + test->maxscales->stop_maxscale(0); sprintf(rules_dir, "%s/fw/", test_dir); copy_rules(test, (char*) "rules_actions", rules_dir); test->set_timeout(60); - test->start_maxscale(); + test->maxscales->start_maxscale(0); test->set_timeout(30); - test->connect_maxscale(); + test->maxscales->connect_maxscale(0); /** Test blacklisting functionality */ test->tprintf("Trying matching query to blacklisted RWSplit, expecting failure\n"); test->set_timeout(30); - test->add_result(!execute_query_silent(test->conn_rwsplit, "select 1"), + test->add_result(!execute_query_silent(test->maxscales->conn_rwsplit[0], "select 1"), "Matching query to blacklist service should fail.\n"); test->tprintf("Trying non-matching query to blacklisted RWSplit, expecting success\n"); test->set_timeout(30); - test->add_result(execute_query_silent(test->conn_rwsplit, "show status"), + test->add_result(execute_query_silent(test->maxscales->conn_rwsplit[0], "show status"), "Non-matching query to blacklist service should succeed.\n"); /** Test whitelisting functionality */ test->tprintf("Trying matching query to whitelisted Conn slave, expecting success\n"); test->set_timeout(30); - test->add_result(execute_query_silent(test->conn_slave, "select 1"), + test->add_result(execute_query_silent(test->maxscales->conn_slave[0], "select 1"), "Query to whitelist service should succeed.\n"); test->tprintf("Trying non-matching query to whitelisted Conn slave, expecting failure\n"); test->set_timeout(30); - test->add_result(!execute_query_silent(test->conn_slave, "show status"), + test->add_result(!execute_query_silent(test->maxscales->conn_slave[0], "show status"), "Non-matching query to blacklist service should fail.\n"); /** Testing NO OP mode */ test->tprintf("Trying matching query to ignoring Conn master, expecting success\n"); test->set_timeout(30); - test->add_result(execute_query_silent(test->conn_master, "select 1"), + test->add_result(execute_query_silent(test->maxscales->conn_master[0], "select 1"), "Query to ignoring service should succeed.\n"); test->tprintf("Trying non-matching query to ignoring Conn master, expecting success\n"); test->set_timeout(30); - test->add_result(execute_query_silent(test->conn_master, "show status"), + test->add_result(execute_query_silent(test->maxscales->conn_master[0], "show status"), "Non-matching query to ignoring service should succeed.\n"); test->stop_timeout(); test->tprintf("Checking if MaxScale is alive\n"); - test->check_maxscale_processes(1); - test->stop_maxscale(); + test->check_maxscale_processes(0, 1); + test->maxscales->stop_maxscale(0); sleep(10); test->tprintf("Checking if MaxScale was succesfully terminated\n"); - test->check_maxscale_processes(0); + test->check_maxscale_processes(0, 0); int rval = test->global_result; delete test; return rval; diff --git a/maxscale-system-test/fwf_com_ping.cpp b/maxscale-system-test/fwf_com_ping.cpp index 5bbaa1d26..7b4a62aec 100644 --- a/maxscale-system-test/fwf_com_ping.cpp +++ b/maxscale-system-test/fwf_com_ping.cpp @@ -19,15 +19,17 @@ int main(int argc, char** argv) TestConnections::skip_maxscale_start(true); TestConnections test(argc, argv); - test.ssh_maxscale(true, "mkdir -p /home/vagrant/rules/; chown -R vagrant:vagrant /home/vagrant/rules/"); - test.copy_to_maxscale((char*)"rules.txt", (char*)"~/rules/rules.txt"); - test.ssh_maxscale(true, "chmod a+r /home/vagrant/rules/rules.txt;"); + test.maxscales->ssh_node(0, "mkdir -p /home/vagrant/rules/; chown -R vagrant:vagrant /home/vagrant/rules/", + true); + test.maxscales->copy_to_node_legacy((char*)"rules.txt", (char*)"~/rules/rules.txt", 0); + test.maxscales->ssh_node(0, "chmod a+r /home/vagrant/rules/rules.txt;", true); - test.restart_maxscale(); - test.connect_maxscale(); + test.maxscales->restart_maxscale(0); + test.maxscales->connect_maxscale(0); test.tprintf("Pinging MaxScale, expecting success"); - test.add_result(mysql_ping(test.conn_rwsplit), "Ping should not fail: %s", mysql_error(test.conn_rwsplit)); - test.close_maxscale_connections(); + test.add_result(mysql_ping(test.maxscales->conn_rwsplit[0]), "Ping should not fail: %s", + mysql_error(test.maxscales->conn_rwsplit[0])); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/fwf_duplicate_rules.cpp b/maxscale-system-test/fwf_duplicate_rules.cpp index 0b9d556f7..6ba2618df 100644 --- a/maxscale-system-test/fwf_duplicate_rules.cpp +++ b/maxscale-system-test/fwf_duplicate_rules.cpp @@ -20,13 +20,14 @@ int main(int argc, char** argv) TestConnections::skip_maxscale_start(true); TestConnections test(argc, argv); - test.ssh_maxscale(true, "mkdir -p /home/vagrant/rules/; chown -R vagrant:vagrant /home/vagrant/rules/"); - test.copy_to_maxscale((char*)"rules.txt", (char*)"~/rules/rules.txt"); - test.ssh_maxscale(true, "chmod a+r /home/vagrant/rules/rules.txt;"); + test.maxscales->ssh_node(0, "mkdir -p /home/vagrant/rules/; chown -R vagrant:vagrant /home/vagrant/rules/", + true); + test.maxscales->copy_to_node_legacy((char*)"rules.txt", (char*)"~/rules/rules.txt", 0); + test.maxscales->ssh_node(0, "chmod a+r /home/vagrant/rules/rules.txt;", true); int rc = 0; - if (test.restart_maxscale() == 0) + if (test.maxscales->restart_maxscale(0) == 0) { test.tprintf("Restarting MaxScale succeeded when it should've failed!"); rc = 1; diff --git a/maxscale-system-test/fwf_logging.cpp b/maxscale-system-test/fwf_logging.cpp index 2095a2180..a677103f0 100644 --- a/maxscale-system-test/fwf_logging.cpp +++ b/maxscale-system-test/fwf_logging.cpp @@ -21,34 +21,36 @@ int main(int argc, char** argv) sprintf(rules_dir, "%s/fw/", test_dir); test->tprintf("Creating rules\n"); - test->stop_maxscale(); + test->maxscales->stop_maxscale(0); copy_rules(test, (char*) "rules_logging", rules_dir); - test->start_maxscale(); + test->maxscales->start_maxscale(0); test->set_timeout(20); - test->connect_maxscale(); + test->maxscales->connect_maxscale(0); test->tprintf("trying first: 'select 1'\n"); test->set_timeout(20); - test->add_result(execute_query_silent(test->conn_slave, "select 1"), "First query should succeed\n"); + test->add_result(execute_query_silent(test->maxscales->conn_slave[0], "select 1"), + "First query should succeed\n"); test->tprintf("trying second: 'select 2'\n"); test->set_timeout(20); - test->add_result(execute_query_silent(test->conn_slave, "select 2"), "Second query should succeed\n"); + test->add_result(execute_query_silent(test->maxscales->conn_slave[0], "select 2"), + "Second query should succeed\n"); /** Check that MaxScale is alive */ test->stop_timeout(); - test->check_maxscale_processes(1); + test->check_maxscale_processes(0, 1); /** Check that MaxScale was terminated successfully */ - test->stop_maxscale(); + test->maxscales->stop_maxscale(0); sleep(10); - test->check_maxscale_processes(0); + test->check_maxscale_processes(0, 0); /** Check that the logs contains entries for both matching and * non-matching queries */ - test->check_log_err("matched by", true); - test->check_log_err("was not matched", true); + test->check_log_err(0, "matched by", true); + test->check_log_err(0, "was not matched", true); int rval = test->global_result; delete test; diff --git a/maxscale-system-test/fwf_prepared_stmt.cpp b/maxscale-system-test/fwf_prepared_stmt.cpp index c2d013cb8..930b94d15 100644 --- a/maxscale-system-test/fwf_prepared_stmt.cpp +++ b/maxscale-system-test/fwf_prepared_stmt.cpp @@ -11,37 +11,39 @@ int main(int argc, char** argv) { TestConnections::skip_maxscale_start(true); TestConnections test(argc, argv); - test.ssh_maxscale(true, "mkdir -p /home/vagrant/rules/;" - "echo 'rule test1 deny columns c on_queries select' > /home/vagrant/rules/rules.txt;" - "echo 'users %%@%% match any rules test1' >> /home/vagrant/rules/rules.txt;" - "chmod a+r /home/vagrant/rules/rules.txt;"); + test.maxscales->ssh_node_f(0, true, "mkdir -p /home/vagrant/rules/;" + "echo 'rule test1 deny columns c on_queries select' > /home/vagrant/rules/rules.txt;" + "echo 'users %%@%% match any rules test1' >> /home/vagrant/rules/rules.txt;" + "chmod a+r /home/vagrant/rules/rules.txt;"); - test.add_result(test.restart_maxscale(), "Restarting MaxScale failed"); + test.add_result(test.maxscales->restart_maxscale(0), "Restarting MaxScale failed"); - test.connect_maxscale(); - execute_query_silent(test.conn_rwsplit, "DROP TABLE test.t1"); + test.maxscales->connect_maxscale(0); + execute_query_silent(test.maxscales->conn_rwsplit[0], "DROP TABLE test.t1"); - test.try_query(test.conn_rwsplit, "CREATE TABLE test.t1(a INT, b INT, c INT)"); - test.try_query(test.conn_rwsplit, "INSERT INTO test.t1 VALUES (1, 1, 1)"); + test.try_query(test.maxscales->conn_rwsplit[0], "CREATE TABLE test.t1(a INT, b INT, c INT)"); + test.try_query(test.maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1, 1, 1)"); - test.add_result(execute_query(test.conn_rwsplit, "PREPARE my_ps FROM 'SELECT a, b FROM test.t1'"), + test.add_result(execute_query(test.maxscales->conn_rwsplit[0], + "PREPARE my_ps FROM 'SELECT a, b FROM test.t1'"), "Text protocol preparation should succeed"); - test.add_result(execute_query(test.conn_rwsplit, "EXECUTE my_ps"), + test.add_result(execute_query(test.maxscales->conn_rwsplit[0], "EXECUTE my_ps"), "Text protocol execution should succeed"); - test.add_result(execute_query(test.conn_rwsplit, "PREPARE my_ps2 FROM 'SELECT c FROM test.t1'") == 0, + test.add_result(execute_query(test.maxscales->conn_rwsplit[0], + "PREPARE my_ps2 FROM 'SELECT c FROM test.t1'") == 0, "Text protocol preparation should fail"); - test.add_result(execute_query(test.conn_rwsplit, "EXECUTE my_ps2") == 0, + test.add_result(execute_query(test.maxscales->conn_rwsplit[0], "EXECUTE my_ps2") == 0, "Text protocol execution should fail"); - MYSQL_STMT* stmt = mysql_stmt_init(test.conn_rwsplit); + MYSQL_STMT* stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]); const char *query = "SELECT a, b FROM test.t1"; test.add_result(mysql_stmt_prepare(stmt, query, strlen(query)), "Binary protocol preparation should succeed"); test.add_result(mysql_stmt_execute(stmt), "Binary protocol execution should succeed"); mysql_stmt_close(stmt); - stmt = mysql_stmt_init(test.conn_rwsplit); + stmt = mysql_stmt_init(test.maxscales->conn_rwsplit[0]); query = "SELECT c FROM test.t1"; test.add_result(!mysql_stmt_prepare(stmt, query, strlen(query)), "Binary protocol preparation should fail"); diff --git a/maxscale-system-test/fwf_reload.cpp b/maxscale-system-test/fwf_reload.cpp index e57c07481..0a36875a8 100644 --- a/maxscale-system-test/fwf_reload.cpp +++ b/maxscale-system-test/fwf_reload.cpp @@ -22,12 +22,13 @@ int main(int argc, char *argv[]) sprintf(rules_dir, "%s/fw/", test_dir); int N = 13; int i; + int exit_code; - Test->stop_maxscale(); + Test->maxscales->stop_maxscale(0); char first_rule[] = "rules1"; copy_rules(Test, first_rule, rules_dir); - Test->start_maxscale(); - Test->connect_rwsplit(); + Test->maxscales->start_maxscale(0); + Test->maxscales->connect_rwsplit(0); for (i = 1; i <= N; i++) @@ -36,7 +37,7 @@ int main(int argc, char *argv[]) sprintf(str, "rules%d", i); Test->set_timeout(180); copy_rules(Test, str, rules_dir); - Test->ssh_maxscale(true, "maxadmin call command dbfwfilter rules/reload Database-Firewall"); + Test->maxscales->ssh_node(0, "maxadmin call command dbfwfilter rules/reload Database-Firewall", true); int local_result = 0; sprintf(pass_file, "%s/fw/pass%d", test_dir, i); @@ -50,7 +51,7 @@ int main(int argc, char *argv[]) { Test->set_timeout(180); - if (execute_query_from_file(Test->conn_rwsplit, file) == 1) + if (execute_query_from_file(Test->maxscales->conn_rwsplit[0], file) == 1) { Test->tprintf("Query should succeed: %s\n", sql); local_result++; @@ -75,10 +76,10 @@ int main(int argc, char *argv[]) { Test->set_timeout(180); - int rc = execute_query_from_file(Test->conn_rwsplit, file); + int rc = execute_query_from_file(Test->maxscales->conn_rwsplit[0], file); if (rc != -1 && (rc == 0 || - mysql_errno(Test->conn_rwsplit) != 1141)) + mysql_errno(Test->maxscales->conn_rwsplit[0]) != 1141)) { Test->tprintf("Query should fail: %s\n", sql); local_result++; @@ -99,14 +100,12 @@ int main(int argc, char *argv[]) Test->tprintf("Trying rules with syntax error\n"); copy_rules(Test, (char *) "rules_syntax_error", rules_dir); - char *output = Test->ssh_maxscale_output(true, - "maxadmin call command dbfwfilter rules/reload Database-Firewall"); + char *output = Test->maxscales->ssh_node_output(0, + "maxadmin call command dbfwfilter rules/reload Database-Firewall", true, &exit_code); Test->add_result(strcasestr(output, "Failed") == NULL, "Reloading rules should fail with syntax errors"); - Test->check_maxscale_processes(1); + Test->check_maxscale_processes(0, 1); int rval = Test->global_result; delete Test; return rval; } - - diff --git a/maxscale-system-test/fwf_syntax.cpp b/maxscale-system-test/fwf_syntax.cpp index ce7df236a..04df1a428 100644 --- a/maxscale-system-test/fwf_syntax.cpp +++ b/maxscale-system-test/fwf_syntax.cpp @@ -43,7 +43,7 @@ const char *rules_failure[] = void truncate_maxscale_logs(TestConnections& test) { - test.ssh_maxscale(true, "truncate -s 0 /var/log/maxscale/*"); + test.maxscales->ssh_node(0, "truncate -s 0 /var/log/maxscale/*", true); } void create_rule(const char *rule, const char* user) @@ -58,7 +58,7 @@ int main(int argc, char** argv) { TestConnections::skip_maxscale_start(true); TestConnections test(argc, argv); - test.stop_maxscale(); + test.maxscales->stop_maxscale(0); for (int i = 0; rules_failure[i]; i++) { @@ -68,12 +68,12 @@ int main(int argc, char** argv) copy_rules(&test, (char*)temp_rules, (char*)test_dir); test.tprintf("Testing rule: %s\n", rules_failure[i]); - test.add_result(test.start_maxscale() == 0, "MaxScale should fail to start"); + test.add_result(test.maxscales->start_maxscale(0) == 0, "MaxScale should fail to start"); /** Check that MaxScale did not start and that the log contains * a message about the syntax error. */ - test.check_maxscale_processes(0); - test.check_log_err("syntax error", true); + test.check_maxscale_processes(0, 0); + test.check_log_err(0, "syntax error", true); truncate_maxscale_logs(test); } diff --git a/maxscale-system-test/galera_priority.cpp b/maxscale-system-test/galera_priority.cpp index 538bf61e2..80f4026c3 100644 --- a/maxscale-system-test/galera_priority.cpp +++ b/maxscale-system-test/galera_priority.cpp @@ -21,9 +21,9 @@ int check_server_id(TestConnections* test, char *node_id) { char str[1024]; int rval = 0; - if (execute_query(test->conn_rwsplit, "BEGIN") || - find_field(test->conn_rwsplit, "SELECT @@server_id", "@@server_id", str) || - execute_query(test->conn_rwsplit, "COMMIT")) + if (execute_query(test->maxscales->conn_rwsplit[0], "BEGIN") || + find_field(test->maxscales->conn_rwsplit[0], "SELECT @@server_id", "@@server_id", str) || + execute_query(test->maxscales->conn_rwsplit[0], "COMMIT")) { test->tprintf("Failed to compare @@server_id.\n"); rval = 1; @@ -53,13 +53,13 @@ int simple_failover(TestConnections* test) { /** Node 3 should be master */ test->tprintf("Executing SELECT @@server_id, expecting '%s'...\n", server_id[2]); - if (test->connect_rwsplit() || check_server_id(test, server_id[2])) + if (test->maxscales->connect_rwsplit(0) || check_server_id(test, server_id[2])) { test->tprintf("Test failed without any blocked nodes.\n"); rval = 1; break; } - test->close_rwsplit(); + test->maxscales->close_rwsplit(0); test->galera->block_node(2); blocked = true; test->tprintf("OK\n"); @@ -67,39 +67,39 @@ int simple_failover(TestConnections* test) /** Block node 3 and node 1 should be master */ test->tprintf("Expecting '%s'...\n", server_id[0]); - if (test->connect_rwsplit() || check_server_id(test, server_id[0])) + if (test->maxscales->connect_rwsplit(0) || check_server_id(test, server_id[0])) { test->tprintf("Test failed with first blocked node.\n"); rval = 1; break; } - test->close_rwsplit(); + test->maxscales->close_rwsplit(0); test->galera->block_node(0); test->tprintf("OK\n"); sleep(15); /** Block node 1 and node 4 should be master */ test->tprintf("Expecting '%s'...\n", server_id[3]); - if (test->connect_rwsplit() || check_server_id(test, server_id[3])) + if (test->maxscales->connect_rwsplit(0) || check_server_id(test, server_id[3])) { test->tprintf("Test failed with second blocked node.\n"); rval = 1; break; } - test->close_rwsplit(); + test->maxscales->close_rwsplit(0); test->galera->block_node(3); test->tprintf("OK\n"); sleep(15); /** Block node 4 and node 2 should be master */ test->tprintf("Expecting '%s'...\n", server_id[1]); - if (test->connect_rwsplit() || check_server_id(test, server_id[1])) + if (test->maxscales->connect_rwsplit(0) || check_server_id(test, server_id[1])) { test->tprintf("Test failed with third blocked node.\n"); rval = 1; break; } - test->close_rwsplit(); + test->maxscales->close_rwsplit(0); test->galera->block_node(1); test->tprintf("OK\n"); sleep(15); @@ -107,11 +107,11 @@ int simple_failover(TestConnections* test) /** All nodes blocked, expect failure */ test->tprintf("Expecting failure...\n"); int myerrno = 0; - if ((myerrno = test->connect_rwsplit()) == 0 && test->conn_rwsplit) + if ((myerrno = test->maxscales->connect_rwsplit(0)) == 0 && test->maxscales->conn_rwsplit[0]) { test->tprintf("Connecting to rwsplit was expected to fail but it was" " successful. Returned error was %d.\n", myerrno); - if (execute_query(test->conn_rwsplit, "SELECT @@server_id") == 0) + if (execute_query(test->maxscales->conn_rwsplit[0], "SELECT @@server_id") == 0) { test->tprintf("SELECT @@server_id was expected to fail but the query was successful.\n"); } @@ -129,13 +129,13 @@ int simple_failover(TestConnections* test) blocked = false; sleep(15); test->tprintf("Expecting '%s'...\n", server_id[2]); - if (test->connect_rwsplit() || check_server_id(test, server_id[2])) + if (test->maxscales->connect_rwsplit(0) || check_server_id(test, server_id[2])) { test->tprintf("Test failed after unblocking all nodes.\n"); rval = 1; break; } - test->close_rwsplit(); + test->maxscales->close_rwsplit(0); test->tprintf("OK\n"); } while (false); diff --git a/maxscale-system-test/gatekeeper.cpp b/maxscale-system-test/gatekeeper.cpp index a01a15344..cc5bf5113 100644 --- a/maxscale-system-test/gatekeeper.cpp +++ b/maxscale-system-test/gatekeeper.cpp @@ -42,50 +42,50 @@ const char* denied_queries[] = int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); - Test->ssh_maxscale(true, "rm -f /var/lib/maxscale/gatekeeper.data"); + Test->maxscales->ssh_node_f(0, true, "rm -f /var/lib/maxscale/gatekeeper.data"); Test->set_timeout(30); - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); - Test->try_query(Test->conn_rwsplit, "CREATE OR REPLACE TABLE test.t1 (id INT)"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "CREATE OR REPLACE TABLE test.t1 (id INT)"); for (int i = 0; training_queries[i]; i++) { - Test->try_query(Test->conn_rwsplit, training_queries[i]); + Test->try_query(Test->maxscales->conn_rwsplit[0], training_queries[i]); } - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); - Test->ssh_maxscale(true, "sed -i -e 's/mode=learn/mode=enforce/' /etc/maxscale.cnf"); + Test->maxscales->ssh_node_f(0, true, "sed -i -e 's/mode=learn/mode=enforce/' /etc/maxscale.cnf"); - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); sleep(5); - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); for (int i = 0; training_queries[i]; i++) { Test->set_timeout(30); - Test->add_result(execute_query(Test->conn_rwsplit, training_queries[i]), "Query should not fail: %s", + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], training_queries[i]), "Query should not fail: %s", training_queries[i]); } for (int i = 0; allowed_queries[i]; i++) { Test->set_timeout(30); - Test->add_result(execute_query(Test->conn_rwsplit, allowed_queries[i]), "Query should not fail: %s", + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], allowed_queries[i]), "Query should not fail: %s", allowed_queries[i]); } for (int i = 0; denied_queries[i]; i++) { Test->set_timeout(30); - Test->add_result(execute_query(Test->conn_rwsplit, denied_queries[i]) == 0, "Query should fail: %s", + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], denied_queries[i]) == 0, "Query should fail: %s", denied_queries[i]); } - Test->ssh_maxscale(true, "rm -f /var/lib/maxscale/gatekeeper.data"); + Test->maxscales->ssh_node_f(0, true, "rm -f /var/lib/maxscale/gatekeeper.data"); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/kerberos_setup.cpp b/maxscale-system-test/kerberos_setup.cpp index 72556325a..8ceb024fb 100644 --- a/maxscale-system-test/kerberos_setup.cpp +++ b/maxscale-system-test/kerberos_setup.cpp @@ -27,82 +27,95 @@ int main(int argc, char *argv[]) fprintf(f, "%s node_%03d.maxscale.test\n", Test->repl->IP[i], i); fprintf(f, "%s node_%03d\n", Test->repl->IP[i], i); } - fprintf(f, "%s maxscale.maxscale.test\n", Test->maxscale_IP); - fprintf(f, "%s maxscale\n", Test->maxscale_IP); + fprintf(f, "%s maxscale.maxscale.test\n", Test->maxscales->IP[0]); + fprintf(f, "%s maxscale\n", Test->maxscales->IP[0]); fclose(f); Test->tprintf("Copying 'hosts' and krb5.conf files to all nodes, installing kerberos client and MariaDB plugins\n"); sprintf(str, "%s/krb5.conf", test_dir); for (i = 0; i < Test->repl->N; i++) { - Test->repl->ssh_node(i, true, "yum install -y MariaDB-gssapi-server MariaDB-gssapi-client krb5-workstation pam_krb5"); - Test->repl->copy_to_node(str, (char *) "~/", i); - Test->repl->ssh_node(i, true, "cp %s/krb5.conf /etc/", Test->repl->access_homedir[i]); + Test->repl->ssh_node(i, (char *) + "yum clean all", true); + Test->repl->ssh_node(i, (char *) + "yum install -y MariaDB-gssapi-server MariaDB-gssapi-client krb5-workstation pam_krb5", true); + Test->repl->copy_to_node_legacy(str, Test->repl->access_homedir[i], i); + sprintf(str1, "cp %s/krb5.conf /etc/", Test->repl->access_homedir[i]); + Test->repl->ssh_node(i, str1, true); - Test->repl->copy_to_node((char *) "hosts", (char *) "~/", i); - Test->repl->ssh_node(i, true, "cp %s/hosts /etc/", Test->repl->access_homedir[i]); + Test->repl->copy_to_node_legacy((char *) "hosts", Test->repl->access_homedir[i], i); + sprintf(str1, "cp %s/hosts /etc/", Test->repl->access_homedir[i]); + Test->repl->ssh_node(i, str1, true); } Test->tprintf("Copying 'hosts' and krb5.conf files to Maxscale node\n"); - Test->copy_to_maxscale((char *) "hosts", (char *) "~/"); - Test->ssh_maxscale(true, (char *) "cp %s/hosts /etc/", Test->maxscale_access_homedir); + Test->maxscales->copy_to_node_legacy((char *) "hosts", Test->maxscales->access_homedir[0], 0); + Test->maxscales->ssh_node_f(0, true, (char *) "cp %s/hosts /etc/", Test->maxscales->access_homedir[0]); - Test->copy_to_maxscale(str, (char *) "~/"); - Test->ssh_maxscale(true, (char *) "cp %s/krb5.conf /etc/", Test->maxscale_access_homedir); + Test->maxscales->copy_to_node_legacy(str, Test->maxscales->access_homedir[0], 0); + Test->maxscales->ssh_node_f(0, true, (char *) "cp %s/krb5.conf /etc/", Test->maxscales->access_homedir[0]); Test->tprintf("Instaling Kerberos server packages to Maxscale node\n"); - Test->ssh_maxscale(true, (char *) "yum clean all"); - Test->ssh_maxscale(true, (char *) "yum install rng-tools -y"); - Test->ssh_maxscale(true, (char *) "rngd -r /dev/urandom -o /dev/random"); + Test->maxscales->ssh_node(0, (char *) "yum clean all", true); + Test->maxscales->ssh_node(0, (char *) "yum install rng-tools -y", true); + Test->maxscales->ssh_node(0, (char *) "rngd -r /dev/urandom -o /dev/random", true); - Test->ssh_maxscale(true, (char *) - "yum install -y MariaDB-gssapi-server MariaDB-gssapi-client krb5-server krb5-workstation pam_krb5"); + Test->maxscales->ssh_node_f(0, true, (char *) + "yum install -y MariaDB-gssapi-server MariaDB-gssapi-client krb5-server krb5-workstation pam_krb5", true); Test->tprintf("Configuring Kerberos server\n"); - Test->ssh_maxscale(true, (char *) "sed -i \"s/EXAMPLE.COM/MAXSCALE.TEST/\" /var/kerberos/krb5kdc/kdc.conf"); - Test->ssh_maxscale(true, (char *) "sed -i \"s/EXAMPLE.COM/MAXSCALE.TEST/\" /var/kerberos/krb5kdc/kadm5.acl"); + Test->maxscales->ssh_node(0, (char *) + "sed -i \"s/EXAMPLE.COM/MAXSCALE.TEST/\" /var/kerberos/krb5kdc/kdc.conf", true); + Test->maxscales->ssh_node(0, (char *) + "sed -i \"s/EXAMPLE.COM/MAXSCALE.TEST/\" /var/kerberos/krb5kdc/kadm5.acl", true); Test->tprintf("Creating Kerberos DB and admin principal\n"); - Test->ssh_maxscale(true, (char *) "kdb5_util create -P skysql -r MAXSCALE.TEST -s"); - Test->ssh_maxscale(true, (char *) "kadmin.local -q \"addprinc -pw skysql admin/admin@MAXSCALE.TEST\""); + Test->maxscales->ssh_node(0, (char *) "kdb5_util create -P skysql -r MAXSCALE.TEST -s", true); + Test->maxscales->ssh_node(0, (char *) "kadmin.local -q \"addprinc -pw skysql admin/admin@MAXSCALE.TEST\"", + true); Test->tprintf("Opening ports 749 and 88\n"); - Test->ssh_maxscale(true, (char *) "iptables -I INPUT -p tcp --dport 749 -j ACCEPT"); - Test->ssh_maxscale(true, (char *) "iptables -I INPUT -p tcp --dport 88 -j ACCEPT"); + Test->maxscales->ssh_node(0, (char *) "iptables -I INPUT -p tcp --dport 749 -j ACCEPT", true); + Test->maxscales->ssh_node(0, (char *) "iptables -I INPUT -p tcp --dport 88 -j ACCEPT", true); Test->tprintf("Starting Kerberos\n"); - Test->ssh_maxscale(true, (char *) "service krb5kdc start"); - Test->ssh_maxscale(true, (char *) "service kadmin start"); + Test->maxscales->ssh_node(0, (char *) "service krb5kdc start", true); + Test->maxscales->ssh_node(0, (char *) "service kadmin start", true); Test->tprintf("Creating principal\n"); - Test->ssh_maxscale(true, (char *) - "echo \"skysql\" | sudo kadmin -p admin/admin -q \"addprinc -randkey mariadb/maxscale.test\""); + Test->maxscales->ssh_node(0, (char *) + "echo \"skysql\" | sudo kadmin -p admin/admin -q \"addprinc -randkey mariadb/maxscale.test\"", true); Test->tprintf("Creating keytab file\n"); - Test->ssh_maxscale(true, (char *) - "echo \"skysql\" | sudo kadmin -p admin/admin -q \"ktadd mariadb/maxscale.test\""); + Test->maxscales->ssh_node(0, (char *) + "echo \"skysql\" | sudo kadmin -p admin/admin -q \"ktadd mariadb/maxscale.test\"", true); Test->tprintf("Making keytab file readable for all\n"); - Test->ssh_maxscale(true, (char *) "chmod a+r /etc/krb5.keytab;"); + Test->maxscales->ssh_node(0, (char *) "chmod a+r /etc/krb5.keytab;", true); - Test->ssh_maxscale(false, (char *) "kinit mariadb/maxscale.test@MAXSCALE.TEST -k -t /etc/krb5.keytab"); - Test->ssh_maxscale(true, (char *) - "su maxscale --login -s /bin/sh -c \"kinit mariadb/maxscale.test@MAXSCALE.TEST -k -t /etc/krb5.keytab\""); + Test->maxscales->ssh_node(0, (char *) "kinit mariadb/maxscale.test@MAXSCALE.TEST -k -t /etc/krb5.keytab", + false); + Test->maxscales->ssh_node(0, (char *) + "mkdir -p /home/maxscale", true); + Test->maxscales->ssh_node(0, (char *) + "su maxscale --login -s /bin/sh -c \"kinit mariadb/maxscale.test@MAXSCALE.TEST -k -t /etc/krb5.keytab\"", + true); Test->tprintf("Coping keytab file from Maxscale node\n"); - Test->copy_from_maxscale((char *) "/etc/krb5.keytab", (char *) "."); + Test->maxscales->copy_from_node_legacy((char *) "/etc/krb5.keytab", (char *) ".", 0); Test->tprintf("Coping keytab and .cnf files to all nodes and executing knit for all nodes\n"); for (i = 0; i < Test->repl->N; i++) { sprintf(str, "%s/kerb.cnf", test_dir); - Test->repl->copy_to_node(str, (char *) "~/", i); - Test->repl->ssh_node(i, true, "cp %s/kerb.cnf /etc/my.cnf.d/", Test->repl->access_homedir[i]); + Test->repl->copy_to_node_legacy(str, Test->repl->access_homedir[i], i); + Test->repl->ssh_node_f(i, true, "cp %s/kerb.cnf /etc/my.cnf.d/", Test->repl->access_homedir[i]); - Test->repl->copy_to_node((char *) "krb5.keytab", (char *) "~/", i); - Test->repl->ssh_node(i, true, "cp %s/krb5.keytab /etc/", Test->repl->access_homedir[i]); + Test->repl->copy_to_node_legacy((char *) "krb5.keytab", Test->repl->access_homedir[i], i); + Test->repl->ssh_node(i, (char *) "cp ~/krb5.keytab /etc/", true); + Test->repl->ssh_node_f(i, true, "cp %s/krb5.keytab /etc/", Test->repl->access_homedir[i]); - Test->repl->ssh_node(i, false, "kinit mariadb/maxscale.test@MAXSCALE.TEST -k -t /etc/krb5.keytab"); + Test->repl->ssh_node(i, (char *) "kinit mariadb/maxscale.test@MAXSCALE.TEST -k -t /etc/krb5.keytab", false); } Test->tprintf("Installing gssapi plugin to all nodes\n"); @@ -119,27 +132,26 @@ int main(int argc, char *argv[]) Test->tprintf("Trying use usr1 to execute query: RW Split\n"); Test->add_result( - Test->repl->ssh_node(1, false, - "echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4006"), + Test->repl->ssh_node(1, + "echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4006", false), "Error executing query against RW Split\n"); Test->tprintf("Trying use usr1 to execute query: Read Connection Master\n"); Test->add_result( - Test->repl->ssh_node(1, false, - "echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4008"), + Test->repl->ssh_node(1, + "echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4008", false), "Error executing query against Read Connection Master\n"); Test->tprintf("Trying use usr1 to execute query: Read Connection Slave\n"); Test->add_result( - Test->repl->ssh_node(1, false, - "echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4009"), + Test->repl->ssh_node(1, + "echo select User,Host from mysql.user | mysql -uusr1 -h maxscale.maxscale.test -P 4009", false), "Error executing query against Read Connection Slave\n"); for (int i = 0; i < Test->repl->N; i++) { - Test->repl->ssh_node(i, true, "rm -f /etc/my.cnf.d/kerb.cnf"); + Test->repl->ssh_node(i, "sudo rm -f /etc/my.cnf.d/kerb.cnf", true); } int rval = Test->global_result; delete Test; return rval; } - diff --git a/maxscale-system-test/kill_master.cpp b/maxscale-system-test/kill_master.cpp index 2fb8fb243..626e9b0be 100644 --- a/maxscale-system-test/kill_master.cpp +++ b/maxscale-system-test/kill_master.cpp @@ -16,8 +16,8 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(20); - Test->tprintf("Connecting to RWSplit %s\n", Test->maxscale_IP); - Test->connect_rwsplit(); + Test->tprintf("Connecting to RWSplit %s\n", Test->maxscales->IP[0]); + Test->maxscales->connect_rwsplit(0); Test->set_timeout(30); Test->tprintf("Setup firewall to block mysql on master\n"); @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) Test->tprintf("Trying query to RWSplit, expecting failure, but not a crash\n"); Test->set_timeout(30); - execute_query(Test->conn_rwsplit, (char *) "show processlist;"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "show processlist;"); Test->set_timeout(30); Test->tprintf("Setup firewall back to allow mysql\n"); @@ -36,11 +36,11 @@ int main(int argc, char *argv[]) Test->set_timeout(30); Test->tprintf("Reconnecting and trying query to RWSplit\n"); - Test->connect_rwsplit(); - Test->try_query(Test->conn_rwsplit, (char *) "show processlist;"); - Test->close_rwsplit(); + Test->maxscales->connect_rwsplit(0); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "show processlist;"); + Test->maxscales->close_rwsplit(0); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/load_balancing.cpp b/maxscale-system-test/load_balancing.cpp index a7c23df87..79a6244a8 100644 --- a/maxscale-system-test/load_balancing.cpp +++ b/maxscale-system-test/load_balancing.cpp @@ -80,7 +80,7 @@ int main(int argc, char *argv[]) Test->repl->close_connections(); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); Test->repl->start_replication(); diff --git a/maxscale-system-test/load_balancing_galera.cpp b/maxscale-system-test/load_balancing_galera.cpp index 8c36881b1..3da6b604d 100644 --- a/maxscale-system-test/load_balancing_galera.cpp +++ b/maxscale-system-test/load_balancing_galera.cpp @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) long int i1, i2; Test->set_timeout(20); - master = Test->find_master_maxadmin(Test->galera); + master = Test->maxscales->find_master_maxadmin(0, Test->galera); if (master >= 0) { @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) } Test->galera->close_connections(); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); } else { diff --git a/maxscale-system-test/long_sysbench.cpp b/maxscale-system-test/long_sysbench.cpp index b63559db3..760c947e0 100644 --- a/maxscale-system-test/long_sysbench.cpp +++ b/maxscale-system-test/long_sysbench.cpp @@ -19,13 +19,13 @@ int main(int argc, char *argv[]) int port[3]; int current_port; - port[0] = Test->rwsplit_port; - port[1] = Test->readconn_master_port; - port[2] = Test->readconn_slave_port; + port[0] = Test->maxscales->rwsplit_port[0]; + port[1] = Test->maxscales->readconn_master_port[0]; + port[2] = Test->maxscales->readconn_slave_port[0]; - Test->tprintf("Connecting to RWSplit %s\n", Test->maxscale_IP); + Test->tprintf("Connecting to RWSplit %s\n", Test->maxscales->IP[0]); - sprintf(&sys1[0], sysbench_prepare, Test->sysbench_dir, Test->sysbench_dir, Test->maxscale_IP); + sprintf(&sys1[0], sysbench_prepare, Test->sysbench_dir, Test->sysbench_dir, Test->maxscales->IP[0]); Test->tprintf("Preparing sysbench tables\n%s\n", sys1); Test->set_timeout(10000); @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) Test->tprintf("Trying test with port %d\n", current_port); - if (current_port == Test->readconn_slave_port ) + if (current_port == Test->maxscales->readconn_slave_port[0] ) { readonly = ro_on; } @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) readonly = ro_off; } - sprintf(&sys1[0], sysbench_command_long, Test->sysbench_dir, Test->sysbench_dir, Test->maxscale_IP, + sprintf(&sys1[0], sysbench_command_long, Test->sysbench_dir, Test->sysbench_dir, Test->maxscales->IP[0], current_port, readonly); Test->set_log_copy_interval(300); Test->tprintf("Executing sysbench \n%s\n", sys1); @@ -59,29 +59,29 @@ int main(int argc, char *argv[]) Test->tprintf("Error executing sysbench test\n"); } - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); printf("Dropping sysbanch tables!\n"); fflush(stdout); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest1"); if (!Test->smoke) { - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest2"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest3"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest4"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest2"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest3"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest4"); } - //global_result += execute_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest"); + //global_result += execute_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest"); printf("closing connections to MaxScale!\n"); fflush(stdout); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checking if MaxScale is still alive!\n"); fflush(stdout); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/longblob.cpp b/maxscale-system-test/longblob.cpp index 8809e4e32..a1afa07c1 100644 --- a/maxscale-system-test/longblob.cpp +++ b/maxscale-system-test/longblob.cpp @@ -14,71 +14,71 @@ int main(int argc, char *argv[]) Test->repl->execute_query_all_nodes( (char *) "set global max_allowed_packet=10000000"); - /*Test->connect_maxscale(); + /*Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("LONGBLOB: Trying send data directly to Master\n"); test_longblob(Test, Test->repl->nodes[0], (char *) "LONGBLOB", 1000000, 20, 1); Test->repl->close_connections(); - Test->close_maxscale_connections();*/ + Test->maxscales->close_maxscale_connections(0);*/ - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("LONGBLOB: Trying send data via RWSplit\n"); - test_longblob(Test, Test->conn_rwsplit, (char *) "LONGBLOB", 1000000, 20, 1); + test_longblob(Test, Test->maxscales->conn_rwsplit[0], (char *) "LONGBLOB", 1000000, 20, 1); Test->repl->close_connections(); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("LONGBLOB: Trying send data via ReadConn master\n"); - test_longblob(Test, Test->conn_master, (char *) "LONGBLOB", 1000000, 20, 1); + test_longblob(Test, Test->maxscales->conn_master[0], (char *) "LONGBLOB", 1000000, 20, 1); Test->repl->close_connections(); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - /*Test->connect_maxscale(); + /*Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("BLOB: Trying send data directly to Master\n"); test_longblob(Test, Test->repl->nodes[0], (char *) "BLOB", 1000, 8, 1); Test->repl->close_connections(); - Test->close_maxscale_connections();*/ + Test->maxscales->close_maxscale_connections(0);*/ - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("BLOB: Trying send data via RWSplit\n"); - test_longblob(Test, Test->conn_rwsplit, (char *) "BLOB", 1000, 8, 1); + test_longblob(Test, Test->maxscales->conn_rwsplit[0], (char *) "BLOB", 1000, 8, 1); Test->repl->close_connections(); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("BLOB: Trying send data via ReadConn master\n"); - test_longblob(Test, Test->conn_master, (char *) "BLOB", 1000, 8, 1); + test_longblob(Test, Test->maxscales->conn_master[0], (char *) "BLOB", 1000, 8, 1); Test->repl->close_connections(); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - /*Test->connect_maxscale(); + /*Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("MEDIUMBLOB: Trying send data directly to Master\n"); test_longblob(Test, Test->repl->nodes[0], (char *) "MEDIUMBLOB", 1000000, 2, 1); Test->repl->close_connections(); - Test->close_maxscale_connections();*/ + Test->maxscales->close_maxscale_connections(0);*/ - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("MEDIUMBLOB: Trying send data via RWSplit\n"); - test_longblob(Test, Test->conn_rwsplit, (char *) "MEDIUMBLOB", 1000000, 2, 1); + test_longblob(Test, Test->maxscales->conn_rwsplit[0], (char *) "MEDIUMBLOB", 1000000, 2, 1); Test->repl->close_connections(); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("MEDIUMBLOB: Trying send data via ReadConn master\n"); - test_longblob(Test, Test->conn_master, (char *) "MEDIUMBLOB", 1000000, 2, 1); + test_longblob(Test, Test->maxscales->conn_master[0], (char *) "MEDIUMBLOB", 1000000, 2, 1); Test->repl->close_connections(); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/lots_of_rows.cpp b/maxscale-system-test/lots_of_rows.cpp index 29e9c0a44..0debd5384 100644 --- a/maxscale-system-test/lots_of_rows.cpp +++ b/maxscale-system-test/lots_of_rows.cpp @@ -14,28 +14,28 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); char sql[10240]; - Test->connect_maxscale(); - create_t1(Test->conn_rwsplit); + Test->maxscales->connect_maxscale(0); + create_t1(Test->maxscales->conn_rwsplit[0]); Test->tprintf("INSERTing data"); - Test->try_query(Test->conn_rwsplit, "BEGIN"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "BEGIN"); for (int i = 0; i < 2000; i++) { Test->set_timeout(20); create_insert_string(sql, 100, i); - Test->try_query(Test->conn_rwsplit, sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], sql); } - Test->try_query(Test->conn_rwsplit, "COMMIT"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "COMMIT"); Test->tprintf("done, syncing slaves"); Test->stop_timeout(); Test->repl->sync_slaves(); Test->tprintf("Trying SELECT"); Test->set_timeout(60); - Test->try_query(Test->conn_rwsplit, (char *) "SELECT * FROM t1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "SELECT * FROM t1"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/manage_mrm.sh b/maxscale-system-test/manage_mrm.sh index e68fe7a79..72f1bd3db 100755 --- a/maxscale-system-test/manage_mrm.sh +++ b/maxscale-system-test/manage_mrm.sh @@ -117,6 +117,9 @@ EOF do_ssh < #include -Mariadb_nodes::Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose) : - v51(false), use_ipv6(false) +Mariadb_nodes::Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose): + v51(false) { + use_ipv6 = false; strcpy(prefix, pref); memset(this->nodes, 0, sizeof(this->nodes)); memset(blocked, 0, sizeof(blocked)); @@ -79,21 +80,14 @@ void Mariadb_nodes::close_connections() } } + + int Mariadb_nodes::read_env() { char * env; char env_name[64]; - sprintf(env_name, "%s_N", prefix); - env = getenv(env_name); - if (env != NULL) - { - sscanf(env, "%d", &N); - } - else - { - N = 0; - } + read_basic_env(); sprintf(env_name, "%s_user", prefix); env = getenv(env_name); @@ -119,48 +113,15 @@ int Mariadb_nodes::read_env() ssl = false; sprintf(env_name, "%s_ssl", prefix); 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; } - if ((N > 0) && (N < 255)) { for (int i = 0; i < N; i++) { - //reading IPs - sprintf(env_name, "%s_%03d_network", prefix, i); - env = getenv(env_name); - if (env != NULL) - { - sprintf(IP[i], "%s", env); - } - - //reading private IPs - sprintf(env_name, "%s_%03d_private_ip", prefix, i); - env = getenv(env_name); - if (env != NULL) - { - sprintf(IP_private[i], "%s", env); - } - else - { - sprintf(IP_private[i], "%s", IP[i]); - } - - //reading IPv6 - sprintf(env_name, "%s_%03d_network6", prefix, i); - env = getenv(env_name); - if (env != NULL) - { - sprintf(IP6[i], "%s", env); - } - else - { - sprintf(IP6[i], "%s", IP[i]); - } - //reading ports sprintf(env_name, "%s_%03d_port", prefix, i); env = getenv(env_name); @@ -185,17 +146,7 @@ int Mariadb_nodes::read_env() sprintf(socket[i], " "); sprintf(socket_cmd[i], " "); } - //reading sshkey - sprintf(env_name, "%s_%03d_keyfile", prefix, i); - env = getenv(env_name); - if (env != NULL) - { - sprintf(sshkey[i], "%s", env); - } - else - { - sprintf(sshkey[i], "vagrant.pem"); - } + //reading start_db_command sprintf(env_name, "%s_%03d_start_db_command", prefix, i); @@ -232,38 +183,6 @@ int Mariadb_nodes::read_env() { sprintf(cleanup_db_command[i], " "); } - - sprintf(env_name, "%s_%03d_whoami", prefix, i); - env = getenv(env_name); - if (env != NULL) - { - sprintf(access_user[i], "%s", env); - } - else - { - sprintf(access_user[i], "root"); - } - - sprintf(env_name, "%s_%03d_access_sudo", prefix, i); - env = getenv(env_name); - if (env != NULL) - { - sprintf(access_sudo[i], "%s", env); - } - else - { - sprintf(access_sudo[i], " "); - } - - if (strcmp(access_user[i], "root") == 0) - { - sprintf(access_homedir[i], "/%s/", access_user[i]); - } - else - { - sprintf(access_homedir[i], "/home/%s/", access_user[i]); - } - } } } @@ -290,9 +209,9 @@ int Mariadb_nodes::find_master() while ((found == 0) && (i < N)) { if (find_field( - nodes[i], "show slave status;", - "Master_Host", &str[0] - ) == 0) + nodes[i], (char *) "show slave status;", + (char *) "Master_Host", &str[0] + ) == 0 ) { found = 1; strcpy(master_IP, str); @@ -328,13 +247,13 @@ int Mariadb_nodes::change_master(int NewMaster, int OldMaster) { if (i != OldMaster) { - execute_query(nodes[i], "stop slave;"); + execute_query(nodes[i], (char *) "stop slave;"); } } execute_query(nodes[NewMaster], create_repl_user); - execute_query(nodes[OldMaster], "reset master;"); - find_field(nodes[NewMaster], "show master status", "File", &log_file[0]); - find_field(nodes[NewMaster], "show master status", "Position", &log_pos[0]); + execute_query(nodes[OldMaster], (char *) "reset master;"); + find_field(nodes[NewMaster], (char *) "show master status", (char *) "File", &log_file[0]); + find_field(nodes[NewMaster], (char *) "show master status", (char *) "Position", &log_pos[0]); for (i = 0; i < N; i++) { if (i != NewMaster) @@ -343,15 +262,15 @@ int Mariadb_nodes::change_master(int NewMaster, int OldMaster) execute_query(nodes[i], str); } } - //for (i = 0; i < N; i++) {if (i != NewMaster) {execute_query(nodes[i], "start slave;"); }} + //for (i = 0; i < N; i++) {if (i != NewMaster) {execute_query(nodes[i], (char *) "start slave;"); }} } int Mariadb_nodes::stop_node(int node) { - return ssh_node(node, true, stop_db_command[node]); + return ssh_node(node, stop_db_command[node], true); } -int Mariadb_nodes::start_node(int node, const char* param) +int Mariadb_nodes::start_node(int node, char * param) { char cmd[1024]; if (v51) @@ -362,7 +281,7 @@ int Mariadb_nodes::start_node(int node, const char* param) { sprintf(cmd, "%s %s", start_db_command[node], param); } - return ssh_node(node, true, cmd); + return ssh_node(node, cmd, true); } int Mariadb_nodes::stop_nodes() @@ -374,7 +293,7 @@ int Mariadb_nodes::stop_nodes() { printf("Stopping node %d\n", i); fflush(stdout); - local_result += execute_query(nodes[i], "stop slave;"); + local_result += execute_query(nodes[i], (char *) "stop slave;"); fflush(stdout); local_result += stop_node(i); fflush(stdout); @@ -391,7 +310,7 @@ int Mariadb_nodes::stop_slaves() { printf("Stopping slave %d\n", i); fflush(stdout); - global_result += execute_query(nodes[i], "stop slave;"); + global_result += execute_query(nodes[i], (char *) "stop slave;"); } close_connections(); return global_result; @@ -399,7 +318,7 @@ int Mariadb_nodes::stop_slaves() int Mariadb_nodes::cleanup_db_node(int node) { - return ssh_node(node, true, cleanup_db_command[node]); + return ssh_node(node, cleanup_db_command[node], true); } int Mariadb_nodes::cleanup_db_nodes() @@ -426,41 +345,45 @@ int Mariadb_nodes::start_replication() // Start all nodes for (int i = 0; i < N; i++) { - local_result += start_node(i, ""); - ssh_node(i, true, - "mysql -u root %s -e \"STOP SLAVE; RESET SLAVE; RESET SLAVE ALL; RESET MASTER; SET GLOBAL read_only=OFF;\"", - socket_cmd[i]); - ssh_node(i, true, "sudo rm -f /etc/my.cnf.d/kerb.cnf"); - 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]); + local_result += start_node(i, (char *) ""); + sprintf(str, + "mysql -u root %s -e \"STOP SLAVE; RESET SLAVE; RESET SLAVE ALL; RESET MASTER; SET GLOBAL read_only=OFF;\"", + socket_cmd[i]); + ssh_node(i, str, true); } sprintf(str, "%s/create_user.sh", test_dir); sprintf(dtr, "%s", access_homedir[0]); - copy_to_node(str, dtr, 0); - 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]); + copy_to_node_legacy(str, dtr , 0); + sprintf(str, "export node_user=\"%s\"; export node_password=\"%s\"; %s/create_user.sh %s", + 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 - 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", - socket_cmd[0], socket_cmd[0]); + sprintf(str, + "mysqldump --all-databases --add-drop-database --flush-privileges --master-data=1 --gtid %s > /tmp/master_backup.sql", + socket_cmd[0]); + ssh_node(0, str, true); sprintf(str, "%s/master_backup.sql", test_dir); - copy_from_node("/tmp/master_backup.sql", str, 0); + copy_from_node_legacy("/tmp/master_backup.sql", str, 0); for (int i = 1; i < N; i++) { // Reset all nodes by first loading the dump and then starting the replication printf("Starting node %d\n", i); fflush(stdout); - copy_to_node(str, "/tmp/master_backup.sql", i); - ssh_node(i, true, "mysql -u root %s < /tmp/master_backup.sql", - socket_cmd[i]); - ssh_node(i, true, "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]); + copy_to_node_legacy(str, "/tmp/master_backup.sql", i); + sprintf(dtr, + "mysql -u root %s < /tmp/master_backup.sql", + socket_cmd[i]); + ssh_node(i, dtr, true); + char query[512]; + + 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; @@ -475,30 +398,40 @@ int Galera_nodes::start_galera() local_result += stop_nodes(); // Remove the grastate.dat file - ssh_node(0, true, "rm -f /var/lib/mysql/grastate.dat"); + ssh_node(0, "rm -f /var/lib/mysql/grastate.dat", true); printf("Starting new Galera cluster\n"); fflush(stdout); - ssh_node(0, false, "echo [mysqld] > cluster_address.cnf"); - ssh_node(0, false, "echo wsrep_cluster_address=gcomm:// >> cluster_address.cnf"); - ssh_node(0, true, "cp cluster_address.cnf /etc/my.cnf.d/"); - local_result += start_node(0, " --wsrep-cluster-address=gcomm://"); + ssh_node(0, "echo [mysqld] > cluster_address.cnf", false); + ssh_node(0, "echo wsrep_cluster_address=gcomm:// >> cluster_address.cnf", false); + ssh_node(0, "cp cluster_address.cnf /etc/my.cnf.d/", true); + local_result += start_node(0, (char *) " --wsrep-cluster-address=gcomm://"); sprintf(str, "%s/create_user_galera.sh", test_dir); - copy_to_node(str, "~/", 0); + copy_to_node_legacy(str, "~/", 0); - ssh_node(0, false, "export galera_user=\"%s\"; export galera_password=\"%s\"; ./create_user_galera.sh %s", - user_name, - password, socket_cmd[0]); + sprintf(str, "export galera_user=\"%s\"; export galera_password=\"%s\"; ./create_user_galera.sh %s", + user_name, + password, socket_cmd[0]); + ssh_node(0, str, false); for (i = 1; i < N; i++) { printf("Starting node %d\n", i); - ssh_node(i, true, "echo [mysqld] > cluster_address.cnf"); - ssh_node(i, true, "echo wsrep_cluster_address=gcomm://%s >> cluster_address.cnf", IP_private[0]); - ssh_node(i, true, "cp cluster_address.cnf /etc/my.cnf.d/"); - sprintf(str, " --wsrep-cluster-address=gcomm://%s", IP_private[0]); - local_result += start_node(i, str); + fflush(stdout); + ssh_node(i, "echo [mysqld] > cluster_address.cnf", true); + sprintf(str, "echo wsrep_cluster_address=gcomm://%s >> cluster_address.cnf", IP_private[0]); + ssh_node(i, str, true); + ssh_node(i, "cp cluster_address.cnf /etc/my.cnf.d/", true); + + 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); @@ -511,30 +444,44 @@ int Galera_nodes::start_galera() int Mariadb_nodes::clean_iptables(int node) { + char sys1[1024]; int local_result = 0; - local_result += ssh_node(node, false, "echo \"#!/bin/bash\" > clean_iptables.sh"); - local_result += ssh_node(node, false, - "echo \"while [ \\\"\\$(iptables -n -L INPUT 1|grep '%d')\\\" != \\\"\\\" ]; " - "do iptables -D INPUT 1; done\" >> clean_iptables.sh", - port[node]); - local_result += ssh_node(node, false, - "echo \"while [ \\\"\\$(ip6tables -n -L INPUT 1|grep '%d')\\\" != \\\"\\\" ]; " - "do ip6tables -D INPUT 1; done\" >> clean_iptables.sh", - port[node]); + local_result += ssh_node(node, (char *) "echo \"#!/bin/bash\" > clean_iptables.sh", false); + sprintf(sys1, + "echo \"while [ \\\"\\$(iptables -n -L INPUT 1|grep '%d')\\\" != \\\"\\\" ]; do iptables -D INPUT 1; done\" >> clean_iptables.sh", + port[node]); + local_result += ssh_node(node, (char *) sys1, false); + sprintf(sys1, + "echo \"while [ \\\"\\$(ip6tables -n -L INPUT 1|grep '%d')\\\" != \\\"\\\" ]; do ip6tables -D INPUT 1; done\" >> clean_iptables.sh", + port[node]); + local_result += ssh_node(node, (char *) sys1, false); - local_result += ssh_node(node, false, "chmod a+x clean_iptables.sh"); - local_result += ssh_node(node, true, "./clean_iptables.sh"); + local_result += ssh_node(node, (char *) "chmod a+x clean_iptables.sh", false); + local_result += ssh_node(node, (char *) "./clean_iptables.sh", true); return local_result; } int Mariadb_nodes::block_node(int node) { + char sys1[1024]; int local_result = 0; 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); - local_result += ssh_node(node, true, "iptables -I INPUT -p tcp --dport %d -j REJECT", port[node]); - local_result += ssh_node(node, true, "ip6tables -I INPUT -p tcp --dport %d -j REJECT", port[node]); + sprintf(&sys1[0], "ip6tables -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); blocked[node] = true; return local_result; @@ -542,16 +489,29 @@ int Mariadb_nodes::block_node(int node) int Mariadb_nodes::unblock_node(int node) { + char sys1[1024]; int local_result = 0; local_result += clean_iptables(node); - - 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]); + sprintf(&sys1[0], "iptables -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); + 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; return local_result; } + int Mariadb_nodes::unblock_all_nodes() { int rval = 0; @@ -562,36 +522,6 @@ int Mariadb_nodes::unblock_all_nodes() return rval; } -int Mariadb_nodes::check_node_ssh(int node) -{ - int res = 0; - printf("Checking node %d\n", node); - fflush(stdout); - - if (ssh_node(0, false, "ls > /dev/null") != 0) - { - printf("Node %d is not available\n", node); - fflush(stdout); - res = 1; - } - else - { - printf("Node %d is OK\n", node); - fflush(stdout); - } - return res; -} - -int Mariadb_nodes::check_nodes() -{ - int res = 0; - for (int i = 0; i < N; i++) - { - res += check_node_ssh(i); - } - return res; -} - bool Mariadb_nodes::check_master_node(MYSQL *conn) { bool rval = true; @@ -804,7 +734,7 @@ int Galera_nodes::check_galera() { char str[1024] = ""; - if (find_field(conn, "SHOW STATUS WHERE Variable_name='wsrep_cluster_size';", "Value", + if (find_field(conn, (char *) "SHOW STATUS WHERE Variable_name='wsrep_cluster_size';", (char *) "Value", str) != 0) { printf("wsrep_cluster_size is not found in SHOW STATUS LIKE 'wsrep%%' results\n"); @@ -864,7 +794,7 @@ int Mariadb_nodes::get_server_id(int index) int id = -1; 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); } @@ -883,123 +813,6 @@ std::string Mariadb_nodes::get_server_id_str(int index) return ss.str(); } -void Mariadb_nodes::generate_ssh_cmd(char *cmd, int node, const char *ssh, bool sudo) -{ - if (strcmp(IP[node], "127.0.0.1") == 0) - { - if (sudo) - { - sprintf(cmd, "%s %s", - access_sudo[node], ssh); - } - else - { - sprintf(cmd, "%s", - ssh); - - } - } - else - { - - if (sudo) - { - sprintf(cmd, - "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s '%s %s\'", - sshkey[node], access_user[node], IP[node], access_sudo[node], ssh); - } - else - { - sprintf(cmd, - "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s '%s'", - sshkey[node], access_user[node], IP[node], ssh); - } - } -} - -char * Mariadb_nodes::ssh_node_output(int node, const char *ssh, bool sudo, int *exit_code) -{ - char sys[strlen(ssh) + 1024]; - generate_ssh_cmd(sys, node, ssh, sudo); - FILE *output = popen(sys, "r"); - if (output == NULL) - { - printf("Error opening ssh %s\n", strerror(errno)); - return NULL; - } - char buffer[1024]; - size_t rsize = sizeof(buffer); - char* result = (char*)calloc(rsize, sizeof(char)); - - while (fgets(buffer, sizeof(buffer), output)) - { - result = (char*)realloc(result, sizeof(buffer) + rsize); - rsize += sizeof(buffer); - strcat(result, buffer); - } - int code = pclose(output); - if (WIFEXITED(code)) - { - * exit_code = WEXITSTATUS(code); - } - else - { - * exit_code = 256; - } - return result; -} - -int Mariadb_nodes::ssh_node(int node, bool sudo, const char *format, ...) -{ - va_list valist; - - va_start(valist, format); - int message_len = vsnprintf(NULL, 0, format, valist); - va_end(valist); - - if (message_len < 0) - { - 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 - { - 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() { @@ -1083,7 +896,7 @@ int Mariadb_nodes::get_versions() for (int i = 0; i < N; i++) { - if ((local_result += find_field(nodes[i], "SELECT @@version", "@@version", version[i]))) + if ((local_result += find_field(nodes[i], (char *) "SELECT @@version", (char *) "@@version", version[i]))) { printf("Failed to get version: %s\n", mysql_error(nodes[i])); } @@ -1094,11 +907,11 @@ int Mariadb_nodes::get_versions() str[0] = 0; } 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; } - if (strstr(version_major[i], "10.") == version_major[i]) + if (strstr(version_major[i], "10.") == version_major[i]) { version_major[i][4] = 0; } @@ -1170,13 +983,13 @@ int Mariadb_nodes::configure_ssl(bool require) printf("Node %d\n", i); stop_node(i); sprintf(str, "%s/ssl-cert", test_dir); - local_result += copy_to_node(str, "~/", i); + local_result += copy_to_node_legacy(str, (char *) "~/", i); sprintf(str, "%s/ssl.cnf", test_dir); - local_result += copy_to_node(str, "~/", i); - local_result += ssh_node(i, true, "cp ~/ssl.cnf /etc/my.cnf.d/"); - local_result += ssh_node(i, true, "cp -r ~/ssl-cert /etc/"); - local_result += ssh_node(i, true, "chown mysql:mysql -R /etc/ssl-cert"); - start_node(i, ""); + local_result += copy_to_node_legacy(str, (char *) "~/", i); + local_result += ssh_node(i, (char *) "cp ~/ssl.cnf /etc/my.cnf.d/", true); + local_result += ssh_node(i, (char *) "cp -r ~/ssl-cert /etc/", true); + local_result += ssh_node(i, (char *) "chown mysql:mysql -R /etc/ssl-cert", true); + start_node(i, (char *) ""); } if (require) @@ -1184,9 +997,14 @@ int Mariadb_nodes::configure_ssl(bool require) // Create DB user on first node printf("Set user to require ssl: %s\n", str); sprintf(str, "%s/create_user_ssl.sh", test_dir); - copy_to_node(str, "~/", 0); - ssh_node(0, false, "export node_user=\"%s\"; export node_password=\"%s\"; " - "./create_user_ssl.sh %s", user_name, password, socket_cmd[0]); + copy_to_node_legacy(str, (char *) "~/", 0); + + sprintf(str, "export node_user=\"%s\"; export node_password=\"%s\"; ./create_user_ssl.sh %s", + user_name, + password, + socket_cmd[0]); + printf("cmd: %s\n", str); + ssh_node(0, str, false); } return local_result; @@ -1200,77 +1018,23 @@ int Mariadb_nodes::disable_ssl() local_result += connect(); sprintf(str, "DROP USER %s; grant all privileges on *.* to '%s'@'%%' identified by '%s';", user_name, user_name, password); - local_result += execute_query(nodes[0], ""); + local_result += execute_query(nodes[0], (char *) ""); close_connections(); for (int i = 0; i < N; i++) { stop_node(i); - local_result += ssh_node(i, true, "rm -f /etc/my.cnf.d/ssl.cnf"); - start_node(i, ""); + local_result += ssh_node(i, (char *) "rm -f /etc/my.cnf.d/ssl.cnf", true); + start_node(i, (char *) ""); } return local_result; } -int Mariadb_nodes::copy_to_node(const char* src, const char* dest, int i) -{ - if (i >= N) - { - return 1; - } - char sys[strlen(src) + strlen(dest) + 1024]; - - if (strcmp(IP[i], "127.0.0.1") == 0) - { - sprintf(sys, "cp %s %s", - src, dest); - } - else - { - sprintf(sys, "scp -q -r -i %s -o UserKnownHostsFile=/dev/null " - "-o StrictHostKeyChecking=no -o LogLevel=quiet %s %s@%s:%s", - sshkey[i], src, access_user[i], IP[i], dest); - } - if (verbose) - { - printf("%s\n", sys); - } - - return system(sys); -} - -int Mariadb_nodes::copy_from_node(const char* src, const char* dest, int i) -{ - if (i >= N) - { - return 1; - } - char sys[strlen(src) + strlen(dest) + 1024]; - if (strcmp(IP[i], "127.0.0.1") == 0) - { - sprintf(sys, "cp %s %s", - src, dest); - } - else - { - sprintf(sys, "scp -q -r -i %s -o UserKnownHostsFile=/dev/null " - "-o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s:%s %s", - sshkey[i], access_user[i], IP[i], src, dest); - } - if (verbose) - { - printf("%s\n", sys); - } - - return system(sys); -} - static void wait_until_pos(MYSQL *mysql, int filenum, int pos) { int slave_filenum = 0; int slave_pos = 0; - bool error = false; do { @@ -1285,36 +1049,29 @@ static void wait_until_pos(MYSQL *mysql, int filenum, int pos) if (res) { MYSQL_ROW row = mysql_fetch_row(res); - error = true; - if (row && row[5] && row[21]) + if (row && row[6] && row[21]) { - char *file_suffix = strchr(row[5], '.'); - if (file_suffix) - { - file_suffix++; - slave_filenum = atoi(file_suffix); - slave_pos = atoi(row[21]); - error = false; - } + char *file_suffix = strchr(row[5], '.') + 1; + slave_filenum = atoi(file_suffix); + slave_pos = atoi(row[21]); } mysql_free_result(res); } } - while ((slave_filenum < filenum || slave_pos < pos) && !error); + while (slave_filenum < filenum || slave_pos < pos); } void Mariadb_nodes::sync_slaves(int node) { - if (this->nodes[node] == NULL && this->connect()) + if (this->nodes[node] == NULL) { - printf("Failed to connect to all nodes.\n"); - return; + this->connect(); } if (mysql_query(this->nodes[node], "SHOW MASTER STATUS")) { - printf("Failed to execute SHOW MASTER STATUS: %s\n", mysql_error(this->nodes[node])); + printf("Failed to execute SHOW MASTER STATUS: %s", mysql_error(this->nodes[node])); } else { @@ -1323,26 +1080,18 @@ void Mariadb_nodes::sync_slaves(int node) if (res) { MYSQL_ROW row = mysql_fetch_row(res); - if (row && row[0] && row[1]) + if (row && row[node] && row[1]) { - const char* file_suffix = strchr(row[0], '.'); - if (file_suffix) - { - file_suffix++; - int filenum = atoi(file_suffix); - int pos = atoi(row[1]); + const char* file_suffix = strchr(row[node], '.') + 1; + int filenum = atoi(file_suffix); + int pos = atoi(row[1]); - for (int i = 0; i < this->N; i++) - { - if (i != node) - { - wait_until_pos(this->nodes[i], filenum, pos); - } - } - } - else + for (int i = 0; i < this->N; i++) { - printf("Cannot sync slaves, invalid binlog file name: %s\n", row[0]); + if (i != node) + { + wait_until_pos(this->nodes[i], filenum, pos); + } } } mysql_free_result(res); @@ -1383,23 +1132,22 @@ void Mariadb_nodes::close_active_connections() void Mariadb_nodes::stash_server_settings(int node) { - ssh_node(node, true, "sudo mkdir /etc/my.cnf.d.backup"); - ssh_node(node, true, "sudo cp -r /etc/my.cnf.d/* /etc/my.cnf.d.backup/"); + ssh_node(node, "sudo mkdir /etc/my.cnf.d.backup", true); + ssh_node(node, "sudo cp -r /etc/my.cnf.d/* /etc/my.cnf.d.backup/", true); } void Mariadb_nodes::restore_server_settings(int node) { - ssh_node(node, true, "sudo mv -f /etc/my.cnf.d.backup/* /etc/my.cnf.d/"); + ssh_node(node, "sudo mv -f /etc/my.cnf.d.backup/* /etc/my.cnf.d/", true); } void Mariadb_nodes::disable_server_setting(int node, const char* setting) { - ssh_node(node, true, "sudo sed -i 's/%s/#%s/' /etc/my.cnf.d/*", setting, setting); + ssh_node_f(node, true, "sudo sed -i 's/%s/#%s/' /etc/my.cnf.d/*", setting, setting); } void Mariadb_nodes::add_server_setting(int node, const char* setting) { - ssh_node(node, true, "sudo sed -i '$a [server]' /etc/my.cnf.d/server.cnf", setting); - ssh_node(node, true, "sudo sed -i '$a %s' /etc/my.cnf.d/server.cnf", setting); + ssh_node_f(node, true, "sudo sed -i '$a [server]' /etc/my.cnf.d/server.cnf", setting); + ssh_node_f(node, true, "sudo sed -i '$a %s' /etc/my.cnf.d/server.cnf", setting); } - diff --git a/maxscale-system-test/mariadb_nodes.h b/maxscale-system-test/mariadb_nodes.h index e55c5ec15..690d7b4e3 100644 --- a/maxscale-system-test/mariadb_nodes.h +++ b/maxscale-system-test/mariadb_nodes.h @@ -17,6 +17,7 @@ #include "mariadb_func.h" #include #include +#include "nodes.h" /** * @brief A class to handle backend nodes @@ -28,7 +29,7 @@ * prefix_User - User name to access backend setup (should have full access to 'test' DB with GRANT OPTION) * prefix_Password - Password to access backend setup */ -class Mariadb_nodes +class Mariadb_nodes: public Nodes { public: /** @@ -46,20 +47,7 @@ public: /** * @brief IP address strings for every backend node */ - char IP[256][1024]; - /** - * @brief private IP address strings for every backend node (for AWS) - */ - char IP_private[256][1024]; - /** - * @brief IP address strings for every backend node (IPv6) - */ - char IP6[256][1024]; - /** - * @brief use_ipv6 If true IPv6 addresses will be used to connect Maxscale and backed - * Also IPv6 addresses go to maxscale.cnf - */ - bool use_ipv6; + /** * @brief MariaDB port for every backend node */ @@ -72,14 +60,7 @@ public: * @brief 'socket=$socket' line */ char socket_cmd[256][1024]; - /** - * @brief Path to ssh key for every backend node - */ - char sshkey[256][4096]; - /** - * @brief Number of backend nodes - */ - int N; + /** * @brief User name to access backend nodes */ @@ -92,10 +73,7 @@ public: * @brief master index of node which was last configured to be Master */ int master; - /** - * @brief name of backend setup (like 'repl' or 'galera') - */ - char prefix[16]; + /** * @brief start_db_command Command to start DB server */ @@ -117,32 +95,11 @@ public: */ int ssl; - /** - * @brief access_user Unix users name to access nodes via ssh - */ - char access_user[256][256]; - - /** - * @brief access_sudo empty if sudo is not needed or "sudo " if sudo is needed. - */ - char access_sudo[256][64]; - - - /** - * @brief access_homedir home directory of access_user - */ - char access_homedir[256][256]; - /** * @brief no_set_pos if set to true setup_binlog function do not set log position */ bool no_set_pos; - /** - * @brief Verbose command output - */ - bool verbose; - /** * @brief version Value of @@version */ @@ -173,7 +130,6 @@ public: */ char test_dir[4096]; - /** * @brief List of blocked nodes */ @@ -291,14 +247,7 @@ public: * @param param command line parameters for DB server start command * @return 0 if success */ - int start_node(int node, const char* param = ""); - - /** - * @brief Check node via ssh and restart it if it is not resposible - * @param node Node index - * @return 0 if node is ok, 1 if start failed - */ - int check_nodes(); + int start_node(int node, char * param); /** * @brief Check if all slaves have "Slave_IO_Running" set to "Yes" and master has N-1 slaves @@ -332,34 +281,6 @@ public: int get_server_id(int index); std::string get_server_id_str(int index); - /** - * @brief Generate command line to execute command on the node via ssh - * @param cmd result - * @param index index number of the node (index) - * @param ssh command to execute - * @param sudo if true the command is executed with root privelegues - */ - void generate_ssh_cmd(char * cmd, int node, const char *ssh, bool sudo); - - /** - * @brief executes shell command on the node using ssh - * @param index number of the node (index) - * @param ssh command to execute - * @param sudo if true the command is executed with root privelegues - * @param pointer to variable to store process exit code - * @return output of the command - */ - char *ssh_node_output(int node, const char *ssh, bool sudo, int *exit_code); - - /** - * @brief executes shell command on the node using ssh - * @param index number of the node (index) - * @param sudo if true the command is executed with root privelegues - * @param ssh command to execute - * @return exit code of the command - */ - int ssh_node(int node, bool sudo, const char *ssh, ...); - /** * @brief Execute 'mysqladmin flush-hosts' on all nodes * @return 0 in case of success @@ -379,7 +300,6 @@ public: */ int get_versions(); - /** * @brief Return lowest server version in the cluster * @return The version string of the server with the lowest version number @@ -404,24 +324,6 @@ public: */ int disable_ssl(); - /** - * @brief Copy a local file to the Node i machine - * @param src Source file on the local filesystem - * @param dest Destination file on the remote file system - * @param i Node index - * @return exit code of the system command or 1 in case of i > N - */ - int copy_to_node(const char* src, const char* dest, int i); - - /** - * @brief Copy a local file to the Node i machine - * @param src Source file on the remote filesystem - * @param dest Destination file on the local file system - * @param i Node index - * @return exit code of the system command or 1 in case of i > N - */ - int copy_from_node(const char* src, const char* dest, int i); - /** * @brief Synchronize slaves with the master * @@ -474,9 +376,10 @@ public: * @param setting Line to add */ void add_server_setting(int node, const char* setting); + + private: - int check_node_ssh(int node); bool check_master_node(MYSQL *conn); }; diff --git a/maxscale-system-test/max_connections.cpp b/maxscale-system-test/max_connections.cpp index 0f93dcbca..778c4cf6d 100644 --- a/maxscale-system-test/max_connections.cpp +++ b/maxscale-system-test/max_connections.cpp @@ -25,7 +25,7 @@ int main(int argc, char** argv) { Test->tprintf("Opening connection %d\n", i + 1); Test->set_timeout(30); - mysql[i] = Test->open_rwsplit_connection(); + mysql[i] = Test->maxscales->open_rwsplit_connection(0); if (execute_query_silent(mysql[i], "select 1")) { /** Monitors and such take up some connections so we'll set the @@ -47,8 +47,8 @@ int main(int argc, char** argv) for (int i = 0; i < ITER; i++) { Test->set_timeout(30); - mysql[limit - 1] = Test->open_rwsplit_connection(); - mysql[limit] = Test->open_rwsplit_connection(); + mysql[limit - 1] = Test->maxscales->open_rwsplit_connection(0); + mysql[limit] = Test->maxscales->open_rwsplit_connection(0); Test->add_result(execute_query_silent(mysql[limit - 1], "select 1"), "Query should succeed\n"); Test->add_result(!execute_query_silent(mysql[limit], "select 1"), "Query should fail\n"); mysql_close(mysql[limit - 1]); @@ -64,7 +64,7 @@ int main(int argc, char** argv) sleep(5); Test->stop_timeout(); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); Test->repl->execute_query_all_nodes((char *) "set global max_connections = 100;"); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/maxinfo.cpp b/maxscale-system-test/maxinfo.cpp index fdf648cb5..9bf1c7276 100644 --- a/maxscale-system-test/maxinfo.cpp +++ b/maxscale-system-test/maxinfo.cpp @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) pthread_join(thread1[i], NULL); } - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/maxinfo_func.cpp b/maxscale-system-test/maxinfo_func.cpp index a41066132..9324b1db7 100644 --- a/maxscale-system-test/maxinfo_func.cpp +++ b/maxscale-system-test/maxinfo_func.cpp @@ -77,7 +77,7 @@ char * get_maxinfo(const char * page, TestConnections* Test) char buf[BUFSIZ + 1]; sock = create_tcp_socket(); - ip = get_ip(Test->maxscale_IP); + ip = get_ip(Test->maxscales->IP[0]); if (ip == NULL) { Test->add_result(1, "Can't get IP\n"); @@ -103,7 +103,7 @@ char * get_maxinfo(const char * page, TestConnections* Test) Test->add_result(1, "Could not connect\n"); return NULL; } - get = build_get_query(Test->maxscale_IP, page); + get = build_get_query(Test->maxscales->IP[0], page); //Test->tprintf("Query is:\n<>\n%s<>\n", get); //Send the query to the server diff --git a/maxscale-system-test/maxpython.py b/maxscale-system-test/maxpython.py new file mode 100644 index 000000000..254c13c32 --- /dev/null +++ b/maxscale-system-test/maxpython.py @@ -0,0 +1,89 @@ + +import sys +import subprocess +import os +import time +import jaydebeapi + +# Abstract SQL connection +class SQLConnection: + def __init__(self, port = '3306', host = '127.0.0.1', user = 'root', password = ''): + self.host = str(host) + self.port = str(port) + self.user = str(user) + self.password = str(password) + + # Connect to a server + def connect(self, options = ""): + try: + self.conn = jaydebeapi.connect("org.mariadb.jdbc.Driver", ["jdbc:mariadb://" + self.host + ":" + self.port + "/test?" + options, self.user, self.password],"./maxscale/java/mariadb-java-client-1.3.3.jar") + except Exception as ex: + print("Failed to connect to " + self.host + ":" + self.port + " as " + self.user + ":" + self.password) + print(unicode(ex)) + exit(1) + + # Start a transaction + def begin(self): + curs = self.conn.cursor() + curs.execute("BEGIN") + curs.close() + # Commit a transaction + def commit(self): + curs = self.conn.cursor() + curs.execute("COMMIT") + curs.close() + + # Query and test if the result matches the expected value if one is provided + def query(self, query, compare = None, column = 0): + curs = self.conn.cursor() + curs.execute(query) + return curs.fetchall() + + def query_and_compare(self, query, column): + data = self.query(query) + for row in data: + if str(row[column]) == compare: + return True + return False + + def disconnect(self): + self.conn.close() + + def query_and_close(self, query): + self.connect() + self.query(query) + self.disconnect() + +# Test environment abstraction +class MaxScaleTest: + def __init__(self, testname = "python_test"): + + self.testname = testname + prepare_test(testname) + + # MaxScale connections + self.maxscale = dict() + self.maxscale['rwsplit'] = SQLConnection(host = os.getenv("maxscale_IP"), port = "4006", user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + self.maxscale['rcmaster'] = SQLConnection(host = os.getenv("maxscale_IP"), port = "4008", user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + self.maxscale['rcslave'] = SQLConnection(host = os.getenv("maxscale_IP"), port = "4009", user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + + # Master-Slave nodes + self.repl = dict() + self.repl['node0'] = SQLConnection(host = os.getenv("node_000_network"), port = os.getenv("node_000_port"), user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + self.repl['node1'] = SQLConnection(host = os.getenv("node_001_network"), port = os.getenv("node_001_port"), user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + self.repl['node2'] = SQLConnection(host = os.getenv("node_002_network"), port = os.getenv("node_002_port"), user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + self.repl['node3'] = SQLConnection(host = os.getenv("node_003_network"), port = os.getenv("node_003_port"), user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + + # Galera nodes + self.galera = dict() + self.galera['node0'] = SQLConnection(host = os.getenv("galera_000_network"), port = os.getenv("galera_000_port"), user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + self.galera['node1'] = SQLConnection(host = os.getenv("galera_001_network"), port = os.getenv("galera_001_port"), user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + self.galera['node2'] = SQLConnection(host = os.getenv("galera_002_network"), port = os.getenv("galera_002_port"), user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + self.galera['node3'] = SQLConnection(host = os.getenv("galera_003_network"), port = os.getenv("galera_003_port"), user = os.getenv("maxscale_user"), password = os.getenv("maxscale_password")) + + def __del__(self): + subprocess.call(os.getcwd() + "/copy_logs.sh " + str(self.testname), shell=True) + +# Read test environment variables +def prepare_test(testname = "replication"): + subprocess.call(os.getcwd() + "/non_native_setup " + str(testname), shell=True) diff --git a/maxscale-system-test/maxscale_process_user.cpp b/maxscale-system-test/maxscale_process_user.cpp index 54b3fa10f..9170ca530 100644 --- a/maxscale-system-test/maxscale_process_user.cpp +++ b/maxscale-system-test/maxscale_process_user.cpp @@ -11,9 +11,11 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); + int exit_code; Test->set_timeout(50); - char *user = Test->ssh_maxscale_output(false, "ps -FC maxscale|tail -n 1|cut -f 1 -d \" \""); + char *user = Test->maxscales->ssh_node_output(0, "ps -FC maxscale|tail -n 1|cut -f 1 -d \" \"", false, + &exit_code); char *nl = user ? strchr(user, '\n') : NULL; if (nl) diff --git a/maxscale-system-test/maxscales.cpp b/maxscale-system-test/maxscales.cpp new file mode 100644 index 000000000..6eb7ce442 --- /dev/null +++ b/maxscale-system-test/maxscales.cpp @@ -0,0 +1,419 @@ +#include "maxscales.h" + +Maxscales::Maxscales(const char *pref, const char *test_cwd, bool verbose) +{ + strcpy(prefix, pref); + this->verbose = verbose; + strcpy(test_dir, test_cwd); + read_env(); +} + +int Maxscales::read_env() +{ + char * env; + char env_name[64]; + + read_basic_env(); + + if ((N > 0) && (N < 255)) + { + for (int i = 0; i < N; i++) + { + sprintf(env_name, "%s_%03d_cnf", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_cnf", prefix); + env = getenv(env_name); + } + if (env != NULL) + { + sprintf(maxscale_cnf[i], "%s", env); + } + else + { + sprintf(maxscale_cnf[i], "/etc/maxscale.cnf"); + } + + sprintf(env_name, "%s_%03d_log_dir", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_log_dir", prefix); + env = getenv(env_name); + } + + if (env != NULL) + { + sprintf(maxscale_log_dir[i], "%s", env); + } + else + { + sprintf(maxscale_log_dir[i], "/var/log/maxscale/"); + } + + sprintf(env_name, "%s_%03d_binlog_dir", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_binlog_dir", prefix); + env = getenv(env_name); + } + if (env != NULL) + { + sprintf(maxscale_binlog_dir[i], "%s", env); + } + else + { + sprintf(maxscale_binlog_dir[i], "/var/lib/maxscale/Binlog_Service/"); + } + + sprintf(env_name, "%s_%03d_maxadmin_password", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_maxadmin_password", prefix); + env = getenv(env_name); + } + if (env != NULL) + { + sprintf(maxadmin_password[i], "%s", env); + } + else + { + sprintf(maxadmin_password[i], "mariadb"); + } + + rwsplit_port[i] = 4006; + readconn_master_port[i] = 4008; + readconn_slave_port[i] = 4009; + binlog_port[i] = 5306; + + ports[i][0] = rwsplit_port[i]; + ports[i][1] = readconn_master_port[i]; + ports[i][2] = readconn_slave_port[i]; + + N_ports[0] = 3; + + } + } + + return 0; +} + + +int Maxscales::connect_rwsplit(int m) +{ + if (use_ipv6) + { + conn_rwsplit[m] = open_conn(rwsplit_port[m], IP6[m], user_name, + password, ssl); + } + else + { + conn_rwsplit[m] = open_conn(rwsplit_port[m], IP[m], user_name, + password, ssl); + } + routers[m][0] = conn_rwsplit[m]; + + int rc = 0; + int my_errno = mysql_errno(conn_rwsplit[m]); + + if (my_errno) + { + if (verbose) + { + printf("Failed to connect to readwritesplit: %d, %s", my_errno, mysql_error(conn_rwsplit[m])); + } + rc = my_errno; + } + + return rc; +} + +int Maxscales::connect_readconn_master(int m) +{ + if (use_ipv6) + { + conn_master[m] = open_conn(readconn_master_port[m], IP6[m], + user_name, password, ssl); + } + else + { + conn_master[m] = open_conn(readconn_master_port[m], IP[m], + user_name, password, ssl); + } + routers[m][1] = conn_master[m]; + + int rc = 0; + int my_errno = mysql_errno(conn_master[m]); + + if (my_errno) + { + if (verbose) + { + printf("Failed to connect to readwritesplit: %d, %s", my_errno, mysql_error(conn_master[m])); + } + rc = my_errno; + } + + return rc; +} + +int Maxscales::connect_readconn_slave(int m) +{ + if (use_ipv6) + { + conn_slave[m] = open_conn(readconn_slave_port[m], IP6[m], + user_name, password, ssl); + } + else + { + conn_slave[m] = open_conn(readconn_slave_port[m], IP[m], + user_name, password, ssl); + } + routers[m][2] = conn_slave[m]; + + int rc = 0; + int my_errno = mysql_errno(conn_slave[m]); + + if (my_errno) + { + if (verbose) + { + printf("Failed to connect to readwritesplit: %d, %s", my_errno, mysql_error(conn_slave[m])); + } + rc = my_errno; + } + + return rc; +} + +int Maxscales::connect_maxscale(int m) +{ + return connect_rwsplit(m) + + connect_readconn_master(m) + + connect_readconn_slave(m); +} + +int Maxscales::close_maxscale_connections(int m) +{ + mysql_close(conn_master[m]); + mysql_close(conn_slave[m]); + mysql_close(conn_rwsplit[m]); + return 0; +} + +int Maxscales::restart_maxscale(int m) +{ + int res = ssh_node(m, "service maxscale restart", true); + fflush(stdout); + return res; +} + +int Maxscales::start_maxscale(int m) +{ + int res = ssh_node(m, "service maxscale start", true); + fflush(stdout); + return res; +} + +int Maxscales::stop_maxscale(int m) +{ + int res = ssh_node(m, "service maxscale stop", true); + fflush(stdout); + return res; +} + + +int Maxscales::execute_maxadmin_command(int m, char * cmd) +{ + return ssh_node_f(m, true, "maxadmin %s", cmd); +} +int Maxscales::execute_maxadmin_command_print(int m, char * cmd) +{ + int exit_code; + printf("%s\n", ssh_node_output_f(m, true, &exit_code, "maxadmin %s", cmd)); + return exit_code; +} + +int Maxscales::check_maxadmin_param(int m, const char *command, const char *param, const char *value) +{ + char result[1024]; + int rval = 1; + + if (get_maxadmin_param(m, (char*)command, (char*)param, (char*)result) == 0) + { + char *end = strchr(result, '\0') - 1; + + while (isspace(*end)) + { + *end-- = '\0'; + } + + char *start = result; + + while (isspace(*start)) + { + start++; + } + + if (strcmp(start, value) == 0) + { + rval = 0; + } + else + { + printf("Expected %s, got %s\n", value, start); + } + } + + return rval; +} + +int Maxscales::get_maxadmin_param(int m, const char *command, const char *param, char *result) +{ + char * buf; + int exit_code; + + buf = ssh_node_output_f(m, true, &exit_code, "maxadmin %s", command); + + //printf("%s\n", buf); + + char *x = strstr(buf, param); + + if (x == NULL) + { + return 1; + } + + x += strlen(param); + + // Skip any trailing parts of the parameter name + while (!isspace(*x)) + { + x++; + } + + // Trim leading whitespace + while (!isspace(*x)) + { + x++; + } + + char *end = strchr(x, '\n'); + + // Trim trailing whitespace + while (isspace(*end)) + { + *end-- = '\0'; + } + + strcpy(result, x); + + return exit_code; +} + + +long unsigned Maxscales::get_maxscale_memsize(int m) +{ + int exit_code; + char * ps_out = ssh_node_output(m, "ps -e -o pid,vsz,comm= | grep maxscale", false, &exit_code); + long unsigned mem = 0; + pid_t pid; + sscanf(ps_out, "%d %lu", &pid, &mem); + return mem; +} + + +int Maxscales::find_master_maxadmin(int m, Mariadb_nodes * nodes) +{ + bool found = false; + int master = -1; + + for (int i = 0; i < nodes->N; i++) + { + char show_server[256]; + char res[256]; + sprintf(show_server, "show server server%d", i + 1); + get_maxadmin_param(m, show_server, (char *) "Status", res); + + if (strstr(res, "Master")) + { + if (found) + { + master = -1; + } + else + { + master = i; + found = true; + } + } + } + + return master; +} + +int Maxscales::find_slave_maxadmin(int m, Mariadb_nodes * nodes) +{ + int slave = -1; + + for (int i = 0; i < nodes->N; i++) + { + char show_server[256]; + char res[256]; + sprintf(show_server, "show server server%d", i + 1); + get_maxadmin_param(m, show_server, (char *) "Status", res); + + if (strstr(res, "Slave")) + { + slave = i; + } + } + + return slave; +} + +StringSet Maxscales::get_server_status(int m, const char* name) +{ + std::set rval; + int exit_code; + char* res = ssh_node_output_f(m, true, &exit_code, "maxadmin list servers|grep \'%s\'", name); + char* pipe = strrchr(res, '|'); + + if (res && pipe) + { + pipe++; + char* tok = strtok(pipe, ","); + + while (tok) + { + char* p = tok; + char *end = strchr(tok, '\n'); + if (!end) + { + end = strchr(tok, '\0'); + } + + // Trim leading whitespace + while (p < end && isspace(*p)) + { + p++; + } + + // Trim trailing whitespace + while (end > tok && isspace(*end)) + { + *end-- = '\0'; + } + + rval.insert(p); + tok = strtok(NULL, ",\n"); + } + + free(res); + } + + return rval; +} diff --git a/maxscale-system-test/maxscales.h b/maxscale-system-test/maxscales.h new file mode 100644 index 000000000..9b757f55c --- /dev/null +++ b/maxscale-system-test/maxscales.h @@ -0,0 +1,232 @@ +#ifndef MAXSCALES_H +#define MAXSCALES_H + +#include "nodes.h" +#include "mariadb_func.h" +#include "mariadb_nodes.h" + +class Maxscales: public Nodes +{ +public: + Maxscales(const char *pref, const char *test_cwd, bool verbose); + int read_env(); + + /** + * @brief rwsplit_port RWSplit service port + */ + int rwsplit_port[256]; + + /** + * @brief readconn_master_port ReadConnection in master mode service port + */ + int readconn_master_port[256]; + + /** + * @brief readconn_slave_port ReadConnection in slave mode service port + */ + int readconn_slave_port[256]; + + /** + * @brief binlog_port binlog router service port + */ + int binlog_port[256]; + + /** + * @brief conn_rwsplit MYSQL connection struct to RWSplit service + */ + MYSQL *conn_rwsplit[256]; + + /** + * @brief conn_master MYSQL connection struct to ReadConnection in master mode service + */ + MYSQL *conn_master[256]; + + /** + * @brief conn_slave MYSQL connection struct to ReadConnection in slave mode service + */ + MYSQL *conn_slave[256]; + + /** + * @brief routers Array of 3 MYSQL handlers which contains copies of conn_rwsplit, conn_master, conn_slave + */ + MYSQL *routers[256][3]; + + /** + * @brief ports of 3 int which contains copies of rwsplit_port, readconn_master_port, readconn_slave_port + */ + int ports[256][3]; + + /** + * @brief maxadmin_Password Password to access Maxadmin tool + */ + char maxadmin_password[256][256]; + + /** + * @brief maxscale_cnf full name of Maxscale configuration file + */ + char maxscale_cnf[256][4096]; + + /** + * @brief maxscale_log_dir name of log files directory + */ + char maxscale_log_dir[256][4096]; + + /** + * @brief maxscale_lbinog_dir name of binlog files (for binlog router) directory + */ + char maxscale_binlog_dir[256][4096]; + + /** + * @brief N_ports Default number of routers + */ + int N_ports[256]; + + + /** + * @brief test_dir path to test application + */ + char test_dir[4096]; + + bool ssl; + + /** + * @brief ConnectMaxscale Opens connections to RWSplit, ReadConn master and ReadConn slave Maxscale services + * Opens connections to RWSplit, ReadConn master and ReadConn slave Maxscale services + * Connections stored in maxscales->conn_rwsplit[0], maxscales->conn_master[0] and maxscales->conn_slave[0] MYSQL structs + * @return 0 in case of success + */ + int connect_maxscale(int m); + + /** + * @brief CloseMaxscaleConn Closes connection that were opened by ConnectMaxscale() + * @return 0 + */ + int close_maxscale_connections(int m); + + /** + * @brief ConnectRWSplit Opens connections to RWSplit and store MYSQL struct in maxscales->conn_rwsplit[0] + * @return 0 in case of success + */ + int connect_rwsplit(int m); + + /** + * @brief ConnectReadMaster Opens connections to ReadConn master and store MYSQL struct in maxscales->conn_master[0] + * @return 0 in case of success + */ + int connect_readconn_master(int m); + + /** + * @brief ConnectReadSlave Opens connections to ReadConn slave and store MYSQL struct in maxscales->conn_slave[0] + * @return 0 in case of success + */ + int connect_readconn_slave(int m); + + /** + * @brief OpenRWSplitConn Opens new connections to RWSplit and returns MYSQL struct + * To close connection mysql_close() have to be called + * @return MYSQL struct + */ + MYSQL * open_rwsplit_connection(int m) + { + return open_conn(rwsplit_port[m], IP[m], user_name, password, ssl); + } + + /** + * @brief OpenReadMasterConn Opens new connections to ReadConn master and returns MYSQL struct + * To close connection mysql_close() have to be called + * @return MYSQL struct + */ + MYSQL * open_readconn_master_connection(int m) + { + return open_conn(readconn_master_port[m], IP[m], user_name, + password, ssl); + } + + /** + * @brief OpenReadSlaveConn Opens new connections to ReadConn slave and returns MYSQL struct + * To close connection mysql_close() have to be called + * @return MYSQL struct + */ + MYSQL * open_readconn_slave_connection(int m) + { + return open_conn(readconn_slave_port[m], IP[m], user_name, + password, ssl); + } + + /** + * @brief CloseRWSplit Closes RWplit connections stored in maxscales->conn_rwsplit[0] + */ + void close_rwsplit(int m) + { + mysql_close(conn_rwsplit[m]); + conn_rwsplit[m] = NULL; + } + + /** + * @brief CloseReadMaster Closes ReadConn master connections stored in maxscales->conn_master[0] + */ + void close_readconn_master(int m) + { + mysql_close(conn_master[m]); + conn_master[m] = NULL; + } + + /** + * @brief CloseReadSlave Closes ReadConn slave connections stored in maxscales->conn_slave[0] + */ + void close_readconn_slave(int m) + { + mysql_close(conn_slave[m]); + conn_slave[m] = NULL; + } + + /** + * @brief restart_maxscale Issues 'service maxscale restart' command + */ + int restart_maxscale(int m); + + /** + * @brief start_maxscale Issues 'service maxscale start' command + */ + int start_maxscale(int m); + + /** + * @brief stop_maxscale Issues 'service maxscale stop' command + */ + int stop_maxscale(int m); + + int execute_maxadmin_command(int m, char * cmd); + int execute_maxadmin_command_print(int m, char * cmd); + int check_maxadmin_param(int m, const char *command, const char *param, const char *value); + int get_maxadmin_param(int m, const char *command, const char *param, char *result); + + /** + * @brief get_maxscale_memsize Gets size of the memory consumed by Maxscale process + * @return memory size in kilobytes + */ + long unsigned get_maxscale_memsize(int m); + + int try_query_all(int m, const char *sql); + + /** + * @brief find_master_maxadmin Tries to find node with 'Master' status using Maxadmin connand 'show server' + * @param nodes Mariadb_nodes object + * @return node index if one master found, -1 if no master found or several masters found + */ + int find_master_maxadmin(int m, Mariadb_nodes * nodes); + int find_slave_maxadmin(int m, Mariadb_nodes * nodes); + + /** + * @brief Get the set of labels that are assigned to server @c name + * + * @param name The name of the server that must be present in the output `maxadmin list servers` + * + * @param m Number of Maxscale node + * + * @return A set of string labels assigned to this server + */ + StringSet get_server_status(int m, const char* name); + +}; + +#endif // MAXSCALES_H diff --git a/maxscale-system-test/mm.cpp b/maxscale-system-test/mm.cpp index 225d77e52..84a878009 100644 --- a/maxscale-system-test/mm.cpp +++ b/maxscale-system-test/mm.cpp @@ -32,14 +32,14 @@ int check_conf(TestConnections* Test, int blocked_node) Test->set_timeout(60); Test->repl->connect(); - Test->connect_rwsplit(); - create_t1(Test->conn_rwsplit); - global_result += insert_into_t1(Test->conn_rwsplit, 3); + Test->maxscales->connect_rwsplit(0); + create_t1(Test->maxscales->conn_rwsplit[0]); + global_result += insert_into_t1(Test->maxscales->conn_rwsplit[0], 4); printf("Sleeping to let replication happen\n"); fflush(stdout); Test->stop_timeout(); - sleep(15); + sleep(30); for (int i = 0; i < 2; i++) { @@ -47,17 +47,17 @@ int check_conf(TestConnections* Test, int blocked_node) { Test->tprintf("Checking data from node %d (%s)\n", i, Test->repl->IP[i]); Test->set_timeout(100); - global_result += select_from_t1(Test->repl->nodes[i], 3); + global_result += select_from_t1(Test->repl->nodes[i], 4); } } Test->set_timeout(100); printf("Checking data from rwsplit\n"); fflush(stdout); - global_result += select_from_t1(Test->conn_rwsplit, 3); - global_result += execute_query(Test->conn_rwsplit, "DROP TABLE t1"); + global_result += select_from_t1(Test->maxscales->conn_rwsplit[0], 4); + global_result += execute_query(Test->maxscales->conn_rwsplit[0], "DROP TABLE t1"); Test->repl->close_connections(); - mysql_close(Test->conn_rwsplit); + mysql_close(Test->maxscales->conn_rwsplit[0]); Test->stop_timeout(); return global_result; @@ -72,17 +72,17 @@ int main(int argc, char *argv[]) Test->repl->set_repl_user(); - Test->start_mm(); // first node - slave, second - master + Test->start_mm(0); // first node - slave, second - master Test->set_timeout(120); - Test->get_maxadmin_param((char *) "show server server1", (char *) "Status:", maxadmin_result); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server1", (char *) "Status:", maxadmin_result); Test->tprintf("node0 %s\n", maxadmin_result); if (strstr(maxadmin_result, "Slave, Running") == NULL ) { Test->add_result(1, "Node0 is not slave, status is %s\n", maxadmin_result); } Test->set_timeout(120); - Test->get_maxadmin_param((char *) "show server server2", (char *) "Status:", maxadmin_result); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server2", (char *) "Status:", maxadmin_result); Test->tprintf("node1 %s\n", maxadmin_result); if (strstr(maxadmin_result, "Master, Running") == NULL ) { @@ -95,9 +95,9 @@ int main(int argc, char *argv[]) Test->tprintf("Block slave\n"); Test->repl->block_node(0); Test->stop_timeout(); - sleep(10); + sleep(15); Test->set_timeout(120); - Test->get_maxadmin_param((char *) "show server server1", (char *) "Status:", maxadmin_result); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server1", (char *) "Status:", maxadmin_result); printf("node0 %s\n", maxadmin_result); if (strstr(maxadmin_result, "Down") == NULL ) { @@ -110,13 +110,13 @@ int main(int argc, char *argv[]) Test->set_timeout(120); Test->tprintf("Unlock slave\n"); Test->repl->unblock_node(0); - sleep(10); + sleep(15); Test->set_timeout(120); Test->tprintf("Block master\n"); Test->repl->block_node(1); - sleep(10); - Test->get_maxadmin_param((char *) "show server server2", (char *) "Status:", maxadmin_result); + sleep(15); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server2", (char *) "Status:", maxadmin_result); printf("node1 %s\n", maxadmin_result); if (strstr(maxadmin_result, "Down") == NULL ) { @@ -129,35 +129,35 @@ int main(int argc, char *argv[]) execute_query(Test->repl->nodes[0], (char *) "SET GLOBAL READ_ONLY=OFF"); Test->repl->close_connections(); - sleep(10); + sleep(15); Test->set_timeout(120); Test->tprintf("Put some data and check\n"); Test->add_result(check_conf(Test, 1), "configuration broken\n"); printf("Unlock slave\n"); Test->repl->unblock_node(1); - sleep(10); + sleep(15); Test->set_timeout(120); printf("Make node 2 slave\n"); Test->repl->connect(); execute_query(Test->repl->nodes[1], (char *) "SET GLOBAL READ_ONLY=ON"); Test->repl->close_connections(); - sleep(10); + sleep(15); Test->set_timeout(120); printf("Put some data and check\n"); Test->add_result(check_conf(Test, 2), "Configuration broken\n"); Test->set_timeout(60); - Test->get_maxadmin_param((char *) "show server server2", (char *) "Status:", maxadmin_result); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server2", (char *) "Status:", maxadmin_result); printf("node1 %s\n", maxadmin_result); if (strstr(maxadmin_result, "Slave, Running") == NULL ) { Test->add_result(1, "Node1 is not slave, status is %s\n", maxadmin_result); } Test->set_timeout(60); - Test->get_maxadmin_param((char *) "show server server1", (char *) "Status:", maxadmin_result); + Test->maxscales->get_maxadmin_param(0, (char *) "show server server1", (char *) "Status:", maxadmin_result); Test->tprintf("node0 %s\n", maxadmin_result); if (strstr(maxadmin_result, "Master, Running") == NULL ) { diff --git a/maxscale-system-test/mm_mysqlmon.cpp b/maxscale-system-test/mm_mysqlmon.cpp index 59efd914b..65e7a7df2 100644 --- a/maxscale-system-test/mm_mysqlmon.cpp +++ b/maxscale-system-test/mm_mysqlmon.cpp @@ -26,7 +26,7 @@ void check_status(TestConnections *Test, const char *server, const char *status) sprintf(cmd, "show server %s", server); Test->set_timeout(120); - Test->get_maxadmin_param(cmd, (char *) "Status:", maxadmin_result); + Test->maxscales->get_maxadmin_param(0, cmd, (char *) "Status:", maxadmin_result); if (maxadmin_result == NULL) { Test->add_result(1, "maxadmin execution error\n"); @@ -42,7 +42,8 @@ void check_status(TestConnections *Test, const char *server, const char *status) void check_group(TestConnections *Test, const char *server, const char *group) { - char *output = Test->ssh_maxscale_output(true, "maxadmin show monitor MySQL-Monitor"); + int exit_code; + char *output = Test->maxscales->ssh_node_output(0, "maxadmin show monitor MySQL-Monitor", true, &exit_code); if (output == NULL) { @@ -83,21 +84,15 @@ void check_group(TestConnections *Test, const char *server, const char *group) void change_master(TestConnections *Test, int slave, int master) { - execute_query(Test->repl->nodes[slave], "CHANGE MASTER TO master_host='%s', master_port=3306, " + execute_query(Test->repl->nodes[slave], "CHANGE MASTER TO master_host='%s', master_port=%d, " "master_log_file='mar-bin.000001', master_log_pos=4, master_user='repl', master_password='repl';START SLAVE", - Test->repl->IP[master], Test->repl->user_name, Test->repl->password); + Test->repl->IP[master], Test->repl->port[master]); } int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); - Test->tprintf("Checking initial state of the servers"); - check_status(Test, "server1", "Master, Running"); - check_status(Test, "server2", "Slave, Running"); - check_status(Test, "server3", "Slave, Running"); - check_status(Test, "server4", "Slave, Running"); - Test->tprintf("Test 1 - Configure all servers into a multi-master ring with one slave"); Test->set_timeout(120); diff --git a/maxscale-system-test/mxs1045.cpp b/maxscale-system-test/mxs1045.cpp index 1437ed8b7..74a2152e7 100644 --- a/maxscale-system-test/mxs1045.cpp +++ b/maxscale-system-test/mxs1045.cpp @@ -24,8 +24,8 @@ int main(int argc, char *argv[]) test.tprintf("Check that there are no zombies"); - int res = test.ssh_maxscale(false, - "if [ \"`ps -ef|grep defunct|grep -v grep`\" != \"\" ]; then exit 1; fi"); + int res = test.maxscales->ssh_node(0, + "if [ \"`ps -ef|grep defunct|grep -v grep`\" != \"\" ]; then exit 1; fi", false); test.add_result(res, "Zombie processes were found"); test.repl->unblock_node(0); diff --git a/maxscale-system-test/mxs1071_maxrows.cpp b/maxscale-system-test/mxs1071_maxrows.cpp index 3f6253c5d..deec523e0 100644 --- a/maxscale-system-test/mxs1071_maxrows.cpp +++ b/maxscale-system-test/mxs1071_maxrows.cpp @@ -208,7 +208,7 @@ int compare_expected(TestConnections * Test, const char * sql, my_ulonglong exp_ my_ulonglong i; Test->set_timeout(30); - execute_query_num_of_rows(Test->conn_rwsplit, sql, rows, &i); + execute_query_num_of_rows(Test->maxscales->conn_rwsplit[0], sql, rows, &i); Test->tprintf("Result sets number is %llu\n", i); @@ -275,11 +275,12 @@ int compare_stmt_expected(TestConnections * Test, MYSQL_STMT * stmt, my_ulonglon */ void err_check(TestConnections* Test, unsigned int expected_err) { - Test->tprintf("Error text '%s'' error code %d\n", mysql_error(Test->conn_rwsplit), - mysql_errno(Test->conn_rwsplit)); - if (mysql_errno(Test->conn_rwsplit) != expected_err) + Test->tprintf("Error text '%s'' error code %d\n", mysql_error(Test->maxscales->conn_rwsplit[0]), + mysql_errno(Test->maxscales->conn_rwsplit[0])); + if (mysql_errno(Test->maxscales->conn_rwsplit[0]) != expected_err) { - Test->add_result(1, "Error code is not %d, it is %d\n", expected_err, mysql_errno(Test->conn_rwsplit)); + Test->add_result(1, "Error code is not %d, it is %d\n", expected_err, + mysql_errno(Test->maxscales->conn_rwsplit[0])); } } @@ -291,10 +292,10 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(30); - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); - create_t1(Test->conn_rwsplit); - insert_into_t1(Test->conn_rwsplit, 1); + create_t1(Test->maxscales->conn_rwsplit[0]); + insert_into_t1(Test->maxscales->conn_rwsplit[0], 1); Test->stop_timeout(); sleep(5); @@ -312,8 +313,8 @@ int main(int argc, char *argv[]) compare_expected(Test, (char *) "select * from t1 limit 10", 1, exp_rows); Test->set_timeout(60); - create_t1(Test->conn_rwsplit); - insert_into_t1(Test->conn_rwsplit, 3); + create_t1(Test->maxscales->conn_rwsplit[0]); + insert_into_t1(Test->maxscales->conn_rwsplit[0], 3); Test->stop_timeout(); sleep(5); @@ -330,8 +331,8 @@ int main(int argc, char *argv[]) Test->tprintf("**** Test 3 ****\n"); exp_rows[0] = 2; exp_rows[1] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test03_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test03_sql); compare_expected(Test, "CALL multi()", 2, exp_rows); Test->tprintf("**** Test 4 ****\n"); @@ -339,8 +340,8 @@ int main(int argc, char *argv[]) exp_rows[1] = 2; exp_rows[2] = 1; exp_rows[3] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test04_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test04_sql); compare_expected(Test, "CALL multi()", 4, exp_rows); Test->tprintf("**** Test 5 ****\n"); @@ -349,23 +350,23 @@ int main(int argc, char *argv[]) exp_rows[2] = 1; exp_rows[3] = 1; exp_rows[4] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test05_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test05_sql); compare_expected(Test, "CALL multi()", 5, exp_rows); Test->tprintf("**** Test 6 ****\n"); exp_rows[0] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test06_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test06_sql); compare_expected(Test, "CALL multi()", 1, exp_rows); Test->tprintf("LONGBLOB: Trying send data via RWSplit\n"); - Test->try_query(Test->conn_rwsplit, "SET GLOBAL max_allowed_packet=10000000000"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "SET GLOBAL max_allowed_packet=10000000000"); Test->stop_timeout(); Test->repl->connect(); - //test_longblob(Test, Test->conn_rwsplit, (char *) "LONGBLOB", 512 * 1024 / sizeof(long int), 17 * 2, 25); + //test_longblob(Test, Test->maxscales->conn_rwsplit[0], (char *) "LONGBLOB", 512 * 1024 / sizeof(long int), 17 * 2, 25); test_longblob(Test, Test->repl->nodes[0], (char *) "LONGBLOB", 512 * 1024 / sizeof(long int), 17 * 2, 5); Test->repl->close_connections(); @@ -380,15 +381,15 @@ int main(int argc, char *argv[]) exp_rows[6] = 1; exp_rows[7] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test07_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test07_sql); compare_expected(Test, "CALL multi()", 8, exp_rows); Test->tprintf("**** Test 8 ****\n"); exp_rows[0] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test08_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test08_sql); compare_expected(Test, "CALL multi()", 1, exp_rows); Test->tprintf("**** Test 9 ****\n"); @@ -401,8 +402,8 @@ int main(int argc, char *argv[]) exp_rows[0] = 1; exp_rows[1] = 4; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test10_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test10_sql); compare_expected(Test, "CALL multi()", 2, exp_rows); err_check(Test, 1096); @@ -418,7 +419,7 @@ int main(int argc, char *argv[]) Test->tprintf("**** Test 12 (C++) ****\n"); exp_rows[0] = 0; - stmt = mysql_stmt_init(Test->conn_rwsplit); + stmt = mysql_stmt_init(Test->maxscales->conn_rwsplit[0]); if (stmt == NULL) { Test->add_result(1, "stmt init error: %s\n", mysql_stmt_error(stmt)); @@ -435,17 +436,17 @@ int main(int argc, char *argv[]) Test->tprintf("**** Test 12 (MariaDB command line client) ****\n"); exp_rows[0] = 0; - Test->try_query(Test->conn_rwsplit, "SET @table = 't1'"); - Test->try_query(Test->conn_rwsplit, "SET @s = CONCAT('SELECT * FROM ', @table)"); - Test->try_query(Test->conn_rwsplit, "PREPARE stmt1 FROM @s"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "SET @table = 't1'"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "SET @s = CONCAT('SELECT * FROM ', @table)"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "PREPARE stmt1 FROM @s"); compare_expected(Test, "EXECUTE stmt1", 1, exp_rows); - Test->try_query(Test->conn_rwsplit, "DEALLOCATE PREPARE stmt1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DEALLOCATE PREPARE stmt1"); Test->tprintf("**** Test 13 (C++)****\n"); exp_rows[0] = 10; exp_rows[1] = 0; - stmt = mysql_stmt_init(Test->conn_rwsplit); + stmt = mysql_stmt_init(Test->maxscales->conn_rwsplit[0]); if (stmt == NULL) { Test->add_result(1, "stmt init error: %s\n", mysql_stmt_error(stmt)); @@ -457,25 +458,25 @@ int main(int argc, char *argv[]) mysql_stmt_close(stmt); Test->tprintf("**** Test 13 (MariaDB command line client) ****\n"); - Test->try_query(Test->conn_rwsplit, "SET @table = 't1'"); - Test->try_query(Test->conn_rwsplit, "SET @s = CONCAT('SELECT * FROM ', @table, ' LIMIT 10')"); - Test->try_query(Test->conn_rwsplit, "PREPARE stmt1 FROM @s"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "SET @table = 't1'"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "SET @s = CONCAT('SELECT * FROM ', @table, ' LIMIT 10')"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "PREPARE stmt1 FROM @s"); compare_expected(Test, "EXECUTE stmt1", 1, exp_rows); - Test->try_query(Test->conn_rwsplit, "DEALLOCATE PREPARE stmt1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DEALLOCATE PREPARE stmt1"); Test->tprintf("**** Test 14 ****\n"); exp_rows[0] = 1; exp_rows[1] = 18; exp_rows[2] = 1; exp_rows[3] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test14_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test14_sql); compare_expected(Test, "CALL multi()", 4, exp_rows); Test->tprintf("**** Test 15 ****\n"); exp_rows[0] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test15_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test15_sql); compare_expected(Test, "CALL multi()", 1, exp_rows); Test->tprintf("**** Test 16 ****\n"); @@ -488,8 +489,8 @@ int main(int argc, char *argv[]) exp_rows[1] = 1; exp_rows[2] = 1; exp_rows[3] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test17_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test17_sql); compare_expected(Test, "CALL multi()", 4, exp_rows); Test->tprintf("**** Test 18 ****\n"); @@ -514,39 +515,39 @@ int main(int argc, char *argv[]) exp_rows[18] = 1; exp_rows[19] = 1; exp_rows[20] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test18_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test18_sql); compare_expected(Test, "CALL multi()", 21, exp_rows); Test->tprintf("**** Test 19 ****\n"); exp_rows[0] = 0; - Test->try_query(Test->conn_rwsplit, "DROP PROCEDURE IF EXISTS multi"); - Test->try_query(Test->conn_rwsplit, test19_sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP PROCEDURE IF EXISTS multi"); + Test->try_query(Test->maxscales->conn_rwsplit[0], test19_sql); compare_expected(Test, "CALL multi()", 1, exp_rows); Test->tprintf("**** Test 20 ****\n"); exp_rows[0] = 2; exp_rows[1] = 0; - Test->try_query(Test->conn_rwsplit, "SET GLOBAL max_allowed_packet=10000000000"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "SET GLOBAL max_allowed_packet=10000000000"); compare_expected(Test, "SELECT * FROM long_blob_table limit 2;", 1, exp_rows); err_check(Test, 0); - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); - Test->ssh_maxscale(true, - "sed -i \"s/max_resultset_size=900000000/max_resultset_size=9000000/\" /etc/maxscale.cnf"); + Test->maxscales->ssh_node(0, + "sed -i \"s/max_resultset_size=900000000/max_resultset_size=9000000/\" /etc/maxscale.cnf", true); Test->set_timeout(100); - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); Test->tprintf("**** Test 21 ****\n"); exp_rows[0] = 0; - Test->try_query(Test->conn_rwsplit, "SET GLOBAL max_allowed_packet=10000000000"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "SET GLOBAL max_allowed_packet=10000000000"); compare_expected(Test, "SELECT * FROM long_blob_table limit 1;", 1, exp_rows); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs1073_binlog_enc.cpp b/maxscale-system-test/mxs1073_binlog_enc.cpp index d8b9f640c..cc4049191 100644 --- a/maxscale-system-test/mxs1073_binlog_enc.cpp +++ b/maxscale-system-test/mxs1073_binlog_enc.cpp @@ -102,8 +102,8 @@ int main(int argc, char *argv[]) Test->repl->ssh_node(i, (char *) "cp ~/mariadb_binlog_keys.txt /etc/", true); } - Test->copy_to_maxscale(str2, (char *) "~/"); - Test->ssh_maxscale(true, "cp ~/mariadb_binlog_keys.txt /etc/"); + Test->maxscales->copy_to_node(str2, (char *) "~/", 0); + Test->maxscales->ssh_node_f(0, true, "cp ~/mariadb_binlog_keys.txt /etc/"); Test->start_binlog(); @@ -129,7 +129,7 @@ int main(int argc, char *argv[]) execute_query(Test->repl->nodes[0], (char *) "FLUSH LOGS"); Test->tprintf("Running 'maxbinlogcheck' against Maxscale binlog file\n"); - char * maxscale_binlogcheck_output = Test->ssh_maxscale_output(true, + char * maxscale_binlogcheck_output = Test->maxscales->ssh_node_f(0, true, "maxbinlogcheck -M -K /etc/mariadb_binlog_keys.txt -H /var/lib/maxscale/Binlog_Service/mar-bin.000001 --aes_algo=%s 2> 1", alg); //puts(maxscale_binlogcheck_output); @@ -146,7 +146,7 @@ int main(int argc, char *argv[]) sprintf(str1, "mysqlbinlog -R -h %s -P %d -u%s -p%s mar-bin.000001 --stop-position=60000", - Test->maxscale_IP, Test->binlog_port, Test->maxscale_user, Test->maxscale_password); + Test->maxscales->IP[0], Test->maxscales->binlog_port[0], Test->maxscales->user_name, Test->maxscales->password); Test->tprintf("running mysqlbinlog on node_000 to connecto Maxscale: %s\n", str1); int exit_code; char * mysql_binlog_connect_output = Test->repl->ssh_node_output(0, str1, false, &exit_code); @@ -173,7 +173,7 @@ int main(int argc, char *argv[]) Test->tprintf("Copying binlogs from Maxscale to Master\n"); system("rm -rf binlogs"); system("mkdir binlogs"); - Test->copy_from_maxscale((char *) "/var/lib/maxscale/Binlog_Service/*", (char *) "binlogs/"); + Test->maxscales->copy_from_node((char *) "/var/lib/maxscale/Binlog_Service/*", (char *) "binlogs/", 0); Test->repl->ssh_node(0, "rm -rf binlogs", true); Test->repl->copy_to_node("-r binlogs", "./", 0); Test->repl->ssh_node(0, "chown mysql:mysql binlogs/*", true); diff --git a/maxscale-system-test/mxs1110_16mb.cpp b/maxscale-system-test/mxs1110_16mb.cpp index e31bd819b..2b6f208c9 100644 --- a/maxscale-system-test/mxs1110_16mb.cpp +++ b/maxscale-system-test/mxs1110_16mb.cpp @@ -13,50 +13,49 @@ int main(int argc, char *argv[]) { TestConnections::skip_maxscale_start(true); TestConnections * Test = new TestConnections(argc, argv); - Test->stop_maxscale(); + Test->maxscales->stop_maxscale(0); Test->set_timeout(60); int chunk_size = 2500000; int chunk_num = 5; - Test->copy_to_maxscale("./masking/masking_user/masking_rules.json", "~/"); + Test->maxscales->copy_to_node_legacy("./masking/masking_user/masking_rules.json", "~/", 0); - Test->copy_to_maxscale("./cache/cache_basic/cache_rules.json", "~/"); + Test->maxscales->copy_to_node_legacy("./cache/cache_basic/cache_rules.json", "~/", 0); - Test->ssh_maxscale(true, "cd %s;" + Test->maxscales->ssh_node_f(0, true, "cd %s;" "rm -rf rules;" "mkdir rules;" "chown vagrant:vagrant rules", - Test->maxscale_access_homedir); + Test->maxscales->access_homedir[0]); copy_rules(Test, (char *) "rules2", "./fw/"); - Test->start_maxscale(); + Test->maxscales->start_maxscale(0); Test->repl->execute_query_all_nodes( (char *) "set global max_allowed_packet=100000000"); Test->galera->execute_query_all_nodes( (char *) "set global max_allowed_packet=100000000"); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->repl->connect(); Test->tprintf("LONGBLOB: Trying send data via RWSplit\n"); - test_longblob(Test, Test->conn_rwsplit, (char *) "LONGBLOB", chunk_size, chunk_num, 2); + test_longblob(Test, Test->maxscales->conn_rwsplit[0], (char *) "LONGBLOB", chunk_size, chunk_num, 2); Test->repl->close_connections(); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->repl->sync_slaves(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Checking data via RWSplit\n"); - check_longblob_data(Test, Test->conn_rwsplit, chunk_size, chunk_num, 2); + check_longblob_data(Test, Test->maxscales->conn_rwsplit[0], chunk_size, chunk_num, 2); Test->tprintf("Checking data via ReadConn master\n"); - check_longblob_data(Test, Test->conn_master, chunk_size, chunk_num, 2); + check_longblob_data(Test, Test->maxscales->conn_master[0], chunk_size, chunk_num, 2); Test->tprintf("Checking data via ReadConn slave\n"); - check_longblob_data(Test, Test->conn_slave, chunk_size, chunk_num, 2); - Test->close_maxscale_connections(); + check_longblob_data(Test, Test->maxscales->conn_slave[0], chunk_size, chunk_num, 2); + Test->maxscales->close_maxscale_connections(0); - MYSQL * conn_galera = open_conn(4016, Test->maxscale_IP, Test->maxscale_user, - Test->maxscale_password, Test->ssl); + MYSQL * conn_galera = open_conn(4016, Test->maxscales->IP[0], Test->maxscales->user_name, + Test->maxscales->password, Test->ssl); mysql_close(conn_galera); int rval = Test->global_result; delete Test; return rval; } - diff --git a/maxscale-system-test/mxs1123.cpp b/maxscale-system-test/mxs1123.cpp index 19e32bbf6..4702811ad 100644 --- a/maxscale-system-test/mxs1123.cpp +++ b/maxscale-system-test/mxs1123.cpp @@ -7,17 +7,17 @@ int main(int argc, char** argv) { TestConnections test(argc, argv); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.tprintf("Waiting one second between queries, all queries should succeed"); sleep(1); - test.try_query(test.conn_rwsplit, "select 1"); + test.try_query(test.maxscales->conn_rwsplit[0], "select 1"); sleep(1); - test.try_query(test.conn_master, "select 1"); + test.try_query(test.maxscales->conn_master[0], "select 1"); sleep(1); - test.try_query(test.conn_slave, "select 1"); + test.try_query(test.maxscales->conn_slave[0], "select 1"); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/mxs118.cpp b/maxscale-system-test/mxs118.cpp index 56db9e613..3643ee72b 100644 --- a/maxscale-system-test/mxs118.cpp +++ b/maxscale-system-test/mxs118.cpp @@ -16,9 +16,9 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); - Test->check_log_err((char *) "Multiple monitors are monitoring server", true); + Test->check_log_err(0, (char *) "Multiple monitors are monitoring server", true); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs127.cpp b/maxscale-system-test/mxs127.cpp index dffd54bda..9ffe061ed 100644 --- a/maxscale-system-test/mxs127.cpp +++ b/maxscale-system-test/mxs127.cpp @@ -14,14 +14,14 @@ int main(int argc, char *argv[]) int i; char sql[256]; - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("RWSplit: Executing set @test=i 10000 times\n"); for (i = 0; i < 10000; i++) { Test->set_timeout(5); sprintf(sql, "set @test=%d", i); - Test->try_query(Test->conn_rwsplit, sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], sql); } Test->tprintf("done!\n"); @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { Test->set_timeout(5); sprintf(sql, "set @test=%d", i); - Test->try_query(Test->conn_master, sql); + Test->try_query(Test->maxscales->conn_master[0], sql); } Test->tprintf("done!\n"); @@ -39,11 +39,11 @@ int main(int argc, char *argv[]) { Test->set_timeout(5); sprintf(sql, "set @test=%d", i); - Test->try_query(Test->conn_slave, sql); + Test->try_query(Test->maxscales->conn_slave[0], sql); } Test->tprintf("done!\n"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/mxs1295_sp_call.cpp b/maxscale-system-test/mxs1295_sp_call.cpp index ae4292cf4..5e43dfda9 100644 --- a/maxscale-system-test/mxs1295_sp_call.cpp +++ b/maxscale-system-test/mxs1295_sp_call.cpp @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) { TestConnections test(argc, argv); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.repl->connect(); test.tprintf("Create the stored procedure and check that it works"); @@ -32,12 +32,12 @@ int main(int argc, char *argv[]) int master = get_server_id(test.repl->nodes[0]); int slave = get_server_id(test.repl->nodes[1]); - int result = get_server_id(test.conn_rwsplit); + int result = get_server_id(test.maxscales->conn_rwsplit[0]); test.add_result(result != slave, "The query should be routed to a slave(%d): %d", slave, result); - test.try_query(test.conn_rwsplit, "USE test"); - test.try_query(test.conn_rwsplit, "CALL multi()"); - result = get_server_id(test.conn_rwsplit); + test.try_query(test.maxscales->conn_rwsplit[0], "USE test"); + test.try_query(test.maxscales->conn_rwsplit[0], "CALL multi()"); + result = get_server_id(test.maxscales->conn_rwsplit[0]); test.add_result(result != master, "The query should be routed to the master(%d): %d", master, result); return test.global_result; diff --git a/maxscale-system-test/mxs1310_implicit_db.cpp b/maxscale-system-test/mxs1310_implicit_db.cpp index eafc3b7a2..2e511899e 100644 --- a/maxscale-system-test/mxs1310_implicit_db.cpp +++ b/maxscale-system-test/mxs1310_implicit_db.cpp @@ -27,22 +27,22 @@ int main(int argc, char *argv[]) test.repl->sync_slaves(); test.tprintf("Run test with sharded database as active database"); - test.connect_rwsplit(); - test.try_query(test.conn_rwsplit, "USE db2"); - execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, id FROM t2", server_id[1]); - execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, id FROM db1.t1", server_id[0]); - execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, a.id FROM t2 as a JOIN db1.t1 as b", + test.maxscales->connect_rwsplit(0); + test.try_query(test.maxscales->conn_rwsplit[0], "USE db2"); + execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id, id FROM t2", server_id[1]); + execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id, id FROM db1.t1", server_id[0]); + execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id, a.id FROM t2 as a JOIN db1.t1 as b", server_id[1]); - test.close_rwsplit(); + test.maxscales->close_rwsplit(0); test.tprintf("Run test with a common database as active database"); - test.connect_rwsplit(); - test.try_query(test.conn_rwsplit, "USE db1"); - execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, id FROM t1", server_id[0]); - execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, id FROM db2.t2", server_id[1]); - execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id, a.id FROM t1 as a JOIN db1.t1 as b", + test.maxscales->connect_rwsplit(0); + test.try_query(test.maxscales->conn_rwsplit[0], "USE db1"); + execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id, id FROM t1", server_id[0]); + execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id, id FROM db2.t2", server_id[1]); + execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id, a.id FROM t1 as a JOIN db1.t1 as b", server_id[0]); - test.close_rwsplit(); + test.maxscales->close_rwsplit(0); // Cleanup execute_query(test.repl->nodes[0], "DROP DATABASE db1"); diff --git a/maxscale-system-test/mxs1319.cpp b/maxscale-system-test/mxs1319.cpp index 04d3aeda5..f5f1c496d 100644 --- a/maxscale-system-test/mxs1319.cpp +++ b/maxscale-system-test/mxs1319.cpp @@ -11,12 +11,12 @@ int main(int argc, char *argv[]) test.tprintf("Changing SQL_MODE to PAD_CHAR_TO_FULL_LENGTH and restarting MaxScale"); test.repl->connect(); test.repl->execute_query_all_nodes("SET GLOBAL SQL_MODE='PAD_CHAR_TO_FULL_LENGTH'"); - test.restart_maxscale(); + test.maxscales->restart_maxscale(0); test.tprintf("Connecting to MaxScale and executing a query"); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "SELECT 1"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "SELECT 1"); + test.maxscales->close_maxscale_connections(0); test.repl->execute_query_all_nodes("SET GLOBAL SQL_MODE=DEFAULT"); return test.global_result; diff --git a/maxscale-system-test/mxs1323_retry_read.cpp b/maxscale-system-test/mxs1323_retry_read.cpp index 3bd64f621..246f9d088 100644 --- a/maxscale-system-test/mxs1323_retry_read.cpp +++ b/maxscale-system-test/mxs1323_retry_read.cpp @@ -16,7 +16,7 @@ void* async_block(void* data) std::string do_query(TestConnections& test) { - MYSQL* conn = test.open_rwsplit_connection(); + MYSQL* conn = test.maxscales->open_rwsplit_connection(0); const char* query = "SELECT SLEEP(15), @@server_id"; char output[512] = ""; diff --git a/maxscale-system-test/mxs1323_stress.cpp b/maxscale-system-test/mxs1323_stress.cpp index efae35e66..8f62d13f8 100644 --- a/maxscale-system-test/mxs1323_stress.cpp +++ b/maxscale-system-test/mxs1323_stress.cpp @@ -14,7 +14,7 @@ void* async_query(void* data) while (running && test->global_result == 0) { - MYSQL* conn = test->open_rwsplit_connection(); + MYSQL* conn = test->maxscales->open_rwsplit_connection(0); for (int i = 0; i < 50 && running && test->global_result == 0; i++) { @@ -37,8 +37,8 @@ int main(int argc, char *argv[]) std::stringstream ss; ss << "CREATE OR REPLACE TABLE test.t1 (id INT)"; - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, ss.str().c_str()); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], ss.str().c_str()); ss.str(""); ss << "INSERT INTO test.t1 VALUES (0)"; @@ -46,9 +46,9 @@ int main(int argc, char *argv[]) { ss << ",(" << i << ")"; } - test.try_query(test.conn_rwsplit, ss.str().c_str()); + test.try_query(test.maxscales->conn_rwsplit[0], ss.str().c_str()); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); if (test.global_result) { diff --git a/maxscale-system-test/mxs1418.cpp b/maxscale-system-test/mxs1418.cpp index 9bd11efe6..a1aa132ef 100644 --- a/maxscale-system-test/mxs1418.cpp +++ b/maxscale-system-test/mxs1418.cpp @@ -13,15 +13,15 @@ void* thr(void* data) while (running && test->global_result == 0) { test->set_timeout(60); - if (test->try_query(test->conn_rwsplit, "SELECT 1")) + if (test->try_query(test->maxscales->conn_rwsplit[0], "SELECT 1")) { test->tprintf("Failed to select via readwritesplit"); } - if (test->try_query(test->conn_master, "SELECT 1")) + if (test->try_query(test->maxscales->conn_master[0], "SELECT 1")) { test->tprintf("Failed to select via readconnroute master"); } - if (test->try_query(test->conn_slave, "SELECT 1")) + if (test->try_query(test->maxscales->conn_slave[0], "SELECT 1")) { test->tprintf("Failed to select via readconnroute slave"); } @@ -35,7 +35,7 @@ void* thr(void* data) int main(int argc, char *argv[]) { TestConnections test(argc, argv); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.tprintf("Connect to MaxScale and continuously execute queries"); pthread_t thread; @@ -46,9 +46,9 @@ int main(int argc, char *argv[]) for (int i = 3; i > -1; i--) { - test.ssh_maxscale(true, "maxadmin remove server server%d \"RW Split Router\"", i); - test.ssh_maxscale(true, "maxadmin remove server server%d \"Read Connection Router Slave\"", i); - test.ssh_maxscale(true, "maxadmin remove server server%d \"Read Connection Router Master\"", i); + test.maxscales->ssh_node_f(0, true, "maxadmin remove server server%d \"RW Split Router\"", i); + test.maxscales->ssh_node_f(0, true, "maxadmin remove server server%d \"Read Connection Router Slave\"", i); + test.maxscales->ssh_node_f(0, true, "maxadmin remove server server%d \"Read Connection Router Master\"", i); } sleep(5); @@ -56,18 +56,18 @@ int main(int argc, char *argv[]) test.tprintf("Stop queries and close the connections"); running = false; pthread_join(thread, NULL); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); test.tprintf("Add all servers to all services"); for (int i = 3; i > -1; i--) { - test.ssh_maxscale(true, "maxadmin add server server%d \"RW Split Router\"", i); - test.ssh_maxscale(true, "maxadmin add server server%d \"Read Connection Router Slave\"", i); - test.ssh_maxscale(true, "maxadmin add server server%d \"Read Connection Router Master\"", i); + test.maxscales->ssh_node_f(0, true, "maxadmin add server server%d \"RW Split Router\"", i); + test.maxscales->ssh_node_f(0, true, "maxadmin add server server%d \"Read Connection Router Slave\"", i); + test.maxscales->ssh_node_f(0, true, "maxadmin add server server%d \"Read Connection Router Master\"", i); } - test.check_maxscale_alive(); + test.check_maxscale_alive(0); return test.global_result; } diff --git a/maxscale-system-test/mxs1451_skip_auth.cpp b/maxscale-system-test/mxs1451_skip_auth.cpp index 972873ac9..68f7ce55a 100644 --- a/maxscale-system-test/mxs1451_skip_auth.cpp +++ b/maxscale-system-test/mxs1451_skip_auth.cpp @@ -13,10 +13,12 @@ int main(int argc, char *argv[]) test.set_timeout(60); test.tprintf("Creating users"); test.repl->connect(); - execute_query(test.repl->nodes[0], "CREATE USER 'auth_test'@'%s' IDENTIFIED BY 'test'", test.maxscale_ip()); - execute_query(test.repl->nodes[0], "GRANT ALL ON *.* to 'auth_test'@'%s'", test.maxscale_ip()); - execute_query(test.repl->nodes[0], "CREATE USER 'auth_test_nopw'@'%s'", test.maxscale_ip()); - execute_query(test.repl->nodes[0], "GRANT ALL ON *.* to 'auth_test_nopw'@'%s'", test.maxscale_ip()); + execute_query(test.repl->nodes[0], "CREATE USER 'auth_test'@'%s' IDENTIFIED BY 'test'", + test.maxscales->ip(0)); + execute_query(test.repl->nodes[0], "GRANT ALL ON *.* to 'auth_test'@'%s'", test.maxscales->ip(0)); + execute_query(test.repl->nodes[0], "CREATE USER 'auth_test_nopw'@'%s'", test.maxscales->ip(0)); + execute_query(test.repl->nodes[0], "GRANT ALL ON *.* to 'auth_test_nopw'@'%s'", + test.maxscales->ip(0)); test.repl->sync_slaves(); test.repl->close_connections(); @@ -24,38 +26,44 @@ int main(int argc, char *argv[]) test.set_timeout(60); test.tprintf("... with correct credentials"); - MYSQL* conn = open_conn_db(test.rwsplit_port, test.maxscale_ip(), "test", "auth_test", "test", false); + MYSQL* conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->ip(0), "test", "auth_test", + "test", false); test.try_query(conn, "SHOW DATABASES"); mysql_close(conn); test.set_timeout(60); test.tprintf("... without a password"); - conn = open_conn_db(test.rwsplit_port, test.maxscale_ip(), "test", "auth_test_nopw", "", false); + conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->ip(0), "test", "auth_test_nopw", "", + false); test.try_query(conn, "SHOW DATABASES"); mysql_close(conn); test.set_timeout(60); test.tprintf("... with wrong password"); - conn = open_conn_db(test.rwsplit_port, test.maxscale_ip(), "test", "auth_test", "wrong_password", false); + conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->ip(0), "test", "auth_test", + "wrong_password", false); test.add_result(mysql_errno(conn) == 0, "Connection with wrong password should fail"); mysql_close(conn); test.set_timeout(60); test.tprintf("... with a password for user without a password"); - conn = open_conn_db(test.rwsplit_port, test.maxscale_ip(), "test", "auth_test_nopw", "test", false); - test.add_result(mysql_errno(conn) == 0, "Connection with wrong password to user without a password should fail"); + conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->ip(0), "test", "auth_test_nopw", "test", + false); + test.add_result(mysql_errno(conn) == 0, + "Connection with wrong password to user without a password should fail"); mysql_close(conn); test.tprintf("... with bad credentials"); - conn = open_conn_db(test.rwsplit_port, test.maxscale_ip(), "test", "wrong_user", "wrong_password", false); + conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->ip(0), "test", "wrong_user", + "wrong_password", false); test.add_result(mysql_errno(conn) == 0, "Connection with bad credentials should fail"); mysql_close(conn); test.set_timeout(60); test.tprintf("Dropping users"); test.repl->connect(); - execute_query(test.repl->nodes[0], "DROP USER 'auth_test'@'%s'", test.maxscale_ip()); - execute_query(test.repl->nodes[0], "DROP USER 'auth_test_nopw'@'%s'", test.maxscale_ip()); + execute_query(test.repl->nodes[0], "DROP USER 'auth_test'@'%s'", test.maxscales->ip(0)); + execute_query(test.repl->nodes[0], "DROP USER 'auth_test_nopw'@'%s'", test.maxscales->ip(0)); test.repl->close_connections(); return test.global_result; diff --git a/maxscale-system-test/mxs1457_ignore_deleted.cpp b/maxscale-system-test/mxs1457_ignore_deleted.cpp index c7965aeda..e9c457a1d 100644 --- a/maxscale-system-test/mxs1457_ignore_deleted.cpp +++ b/maxscale-system-test/mxs1457_ignore_deleted.cpp @@ -21,7 +21,7 @@ int main(int argc, char *argv[]) * The monitor needs to be stopped before the slaves are stopped to prevent * it from detecting the broken replication. */ - test.ssh_maxscale(true, "maxadmin shutdown monitor MySQL-Monitor"); + test.maxscales->ssh_node(0, "maxadmin shutdown monitor \"MySQL Monitor\"", true); // Stop slaves and drop the user on the master test.repl->stop_slaves(); test.repl->connect(); @@ -29,12 +29,14 @@ int main(int argc, char *argv[]) test.repl->close_connections(); test.set_timeout(60); - MYSQL* conn = open_conn_db(test.rwsplit_port, test.maxscale_ip(), "test", "auth_test", "test", false); + MYSQL* conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->ip(0), "test", "auth_test", + "test", false); test.add_result(mysql_errno(conn) == 0, "Connection with users from master should fail"); mysql_close(conn); - test.ssh_maxscale(true, "maxadmin remove server server1 RW-Split-Router"); - conn = open_conn_db(test.rwsplit_port, test.maxscale_ip(), "test", "auth_test", "test", false); + test.maxscales->ssh_node(0, "maxadmin remove server server1 \"RW Split Router\"", true); + conn = open_conn_db(test.maxscales->rwsplit_port[0], test.maxscales->ip(0), "test", "auth_test", "test", + false); test.add_result(mysql_errno(conn), "Connection should be OK: %s", mysql_error(conn)); test.try_query(conn, "SELECT 1"); mysql_close(conn); diff --git a/maxscale-system-test/mxs1468.cpp b/maxscale-system-test/mxs1468.cpp index 70161fce7..17eedfc17 100644 --- a/maxscale-system-test/mxs1468.cpp +++ b/maxscale-system-test/mxs1468.cpp @@ -11,27 +11,27 @@ int main(int argc, char** argv) TestConnections test(argc, argv); test.verbose = true; - test.ssh_maxscale(true, - "maxadmin create monitor cluster-monitor mysqlmon;" - "maxadmin alter monitor cluster-monitor user=maxskysql password=skysql monitor_interval=1000;" - "maxadmin restart monitor cluster-monitor;" - "maxadmin create listener rwsplit-service rwsplit-listener 0.0.0.0 4006;" - "maxadmin create listener rwsplit-service rwsplit-listener2 0.0.0.0 4008;" - "maxadmin create listener rwsplit-service rwsplit-listener3 0.0.0.0 4009;" - "maxadmin list listeners;" - "maxadmin create server prod_mysql01 %s 3306;" - "maxadmin create server prod_mysql02 %s 3306;" - "maxadmin create server prod_mysql03 %s 3306;" - "maxadmin list servers;" - "maxadmin add server prod_mysql02 cluster-monitor rwsplit-service;" - "maxadmin add server prod_mysql01 cluster-monitor rwsplit-service;" - "maxadmin add server prod_mysql03 cluster-monitor rwsplit-service;" - "maxadmin list servers;", test.repl->IP[0], test.repl->IP[1], test.repl->IP[2]); + test.maxscales->ssh_node_f(0, true, + "maxadmin create monitor cluster-monitor mysqlmon;" + "maxadmin alter monitor cluster-monitor user=maxskysql password=skysql monitor_interval=1000;" + "maxadmin restart monitor cluster-monitor;" + "maxadmin create listener rwsplit-service rwsplit-listener 0.0.0.0 4006;" + "maxadmin create listener rwsplit-service rwsplit-listener2 0.0.0.0 4008;" + "maxadmin create listener rwsplit-service rwsplit-listener3 0.0.0.0 4009;" + "maxadmin list listeners;" + "maxadmin create server prod_mysql01 %s 3306;" + "maxadmin create server prod_mysql02 %s 3306;" + "maxadmin create server prod_mysql03 %s 3306;" + "maxadmin list servers;" + "maxadmin add server prod_mysql02 cluster-monitor rwsplit-service;" + "maxadmin add server prod_mysql01 cluster-monitor rwsplit-service;" + "maxadmin add server prod_mysql03 cluster-monitor rwsplit-service;" + "maxadmin list servers;", test.repl->IP[0], test.repl->IP[1], test.repl->IP[2]); test.verbose = false; test.tprintf("Restarting MaxScale"); - test.add_result(test.restart_maxscale(), "Restart should succeed"); - test.check_maxscale_alive(); + test.add_result(test.maxscales->restart_maxscale(0), "Restart should succeed"); + test.check_maxscale_alive(0); return test.global_result; } diff --git a/maxscale-system-test/mxs1476.cpp b/maxscale-system-test/mxs1476.cpp index 65ae63121..d4770de54 100644 --- a/maxscale-system-test/mxs1476.cpp +++ b/maxscale-system-test/mxs1476.cpp @@ -8,36 +8,37 @@ void do_test(TestConnections& test, int master, int slave) { - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "DROP TABLE IF EXISTS test.t1"); - test.try_query(test.conn_rwsplit, "CREATE TABLE test.t1 (id int)"); - test.try_query(test.conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS test.t1"); + test.try_query(test.maxscales->conn_rwsplit[0], "CREATE TABLE test.t1 (id int)"); + test.try_query(test.maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); test.tprintf("Stop a slave node and perform an insert"); test.galera->stop_node(slave); sleep(5); - test.try_query(test.conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); + test.try_query(test.maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); test.tprintf("Start the slave node and perform another insert"); - test.galera->start_node(slave); + test.galera->start_node(slave, (char *) ""); sleep(5); - test.try_query(test.conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); - test.close_maxscale_connections(); + test.try_query(test.maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); + test.maxscales->close_maxscale_connections(0); test.tprintf("Stop the master node and perform an insert"); test.galera->stop_node(master); sleep(5); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); test.tprintf("Start the master node and perform another insert (expecting failure)"); - test.galera->start_node(master); + test.galera->start_node(master, (char *) ""); sleep(5); - test.add_result(execute_query_silent(test.conn_rwsplit, "INSERT INTO test.t1 VALUES (1)") == 0, "Query should fail"); - test.close_maxscale_connections(); + test.add_result(execute_query_silent(test.maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)") == 0, + "Query should fail"); + test.maxscales->close_maxscale_connections(0); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "DROP TABLE test.t1"); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "DROP TABLE test.t1"); } int main(int argc, char** argv) @@ -49,15 +50,15 @@ int main(int argc, char** argv) do_test(test, 1, 0); test.tprintf("Swap the priorities around and run the test again"); - test.ssh_maxscale(true, "sed -i 's/priority=1/priority=3/' /etc/maxscale.cnf;" - "sed -i 's/priority=2/priority=1/' /etc/maxscale.cnf;" - "sed -i 's/priority=3/priority=2/' /etc/maxscale.cnf;"); - test.restart_maxscale(); + test.maxscales->ssh_node_f(0, true, "sed -i 's/priority=1/priority=3/' /etc/maxscale.cnf;" + "sed -i 's/priority=2/priority=1/' /etc/maxscale.cnf;" + "sed -i 's/priority=3/priority=2/' /etc/maxscale.cnf;"); + test.maxscales->restart_maxscale(0); do_test(test, 0, 1); - test.galera->start_node(2, ""); - test.galera->start_node(3, ""); + test.galera->start_node(2, (char *) ""); + test.galera->start_node(3, (char *) ""); test.galera->fix_replication(); return test.global_result; } diff --git a/maxscale-system-test/mxs1509.cpp b/maxscale-system-test/mxs1509.cpp new file mode 100644 index 000000000..4c495e217 --- /dev/null +++ b/maxscale-system-test/mxs1509.cpp @@ -0,0 +1,97 @@ +/** + * MXS-1509: Show correct server state for multisource replication + * + * https://jira.mariadb.org/browse/MXS-1509 + */ + +#include "testconnections.h" +#include +#include "maxscales.h" + +void change_master(TestConnections& test, int slave, int master, const char* name = NULL) +{ + std::string source; + + if (name) + { + source = "'"; + source += name; + source += "'"; + } + + execute_query(test.repl->nodes[slave], + "STOP ALL SLAVES;CHANGE MASTER %s TO master_host='%s', master_port=3306, " + "master_user='%s', master_password='%s', master_use_gtid=slave_pos;START ALL SLAVES", + source.c_str(), test.repl->IP[master], test.repl->user_name, test.repl->password, source.c_str()); +} + +const char* dump_status(const StringSet& current, const StringSet& expected) +{ + std::stringstream ss; + ss << "Current status: ("; + + for (const auto& a : current) + { + ss << a << ","; + } + + ss << ") Expected status: ("; + + for (const auto& a : expected) + { + ss << a << ","; + } + + ss << ")"; + + static std::string res = ss.str(); + return res.c_str(); +} + +void check_status(TestConnections& test, const StringSet& expected_master, const StringSet& expected_slave) +{ + sleep(2); + StringSet master = test.maxscales->get_server_status(0, "server1"); + StringSet slave = test.maxscales->get_server_status(0, "server2"); + test.add_result(master != expected_master, "Master status is not what was expected: %s", + dump_status(master, expected_master)); + test.add_result(slave != expected_slave, "Slave status is not what was expected: %s", + dump_status(slave, expected_slave)); +} + +int main(int argc, char** argv) +{ + TestConnections test(argc, argv); + + // Stop replication on nodes three and four + test.repl->connect(); + execute_query(test.repl->nodes[2], "STOP ALL SLAVES; RESET SLAVE ALL;"); + execute_query(test.repl->nodes[3], "STOP ALL SLAVES; RESET SLAVE ALL;"); + + // Point the master to an external server + change_master(test, 1, 0); + change_master(test, 0, 2); + check_status(test, {"Master", "Running"}, {"Slave", "Running"}); + + // Resetting the slave on master should have no effect + execute_query(test.repl->nodes[0], "STOP ALL SLAVES; RESET SLAVE ALL;"); + check_status(test, {"Master", "Running"}, {"Slave", "Running"}); + + // Configure multi-source replication, check that master status is as expected + change_master(test, 0, 2, "extra-slave"); + change_master(test, 1, 2, "extra-slave"); + check_status(test, {"Master", "Running"}, {"Slave", "Running", "Slave of External Server"}); + + // Stopping multi-source replication on slave should remove the Slave of External Server status + execute_query(test.repl->nodes[1], "STOP SLAVE 'extra-slave'; RESET SLAVE 'extra-slave';"); + check_status(test, {"Master", "Running"}, {"Slave", "Running"}); + + // Doing the same on the master should have no effect + execute_query(test.repl->nodes[0], "STOP ALL SLAVES; RESET SLAVE ALL;"); + check_status(test, {"Master", "Running"}, {"Slave", "Running"}); + + // Cleanup + test.repl->execute_query_all_nodes( "STOP ALL SLAVES; RESET SLAVE ALL;"); + test.repl->fix_replication(); + return test.global_result; +} diff --git a/maxscale-system-test/mxs244_prepared_stmt_loop.cpp b/maxscale-system-test/mxs244_prepared_stmt_loop.cpp index 31294fe83..896175ebe 100644 --- a/maxscale-system-test/mxs244_prepared_stmt_loop.cpp +++ b/maxscale-system-test/mxs244_prepared_stmt_loop.cpp @@ -1,5 +1,5 @@ /** - * @file mxs244_prepared_stmt_loop.cpp mxs244_prepared_stmt_loop executed following statements in the loop against all routers: + * @file mxs244_prepared_stmt_loop.cpp mxs244_prepared_stmt_loop executed following statements in the loop against all maxscales->routers[0]: * @verbatim SET NAMES "UTF8"; PREPARE s1 FROM 'SHOW GLOBAL STATUS WHERE variable_name = ?'; @@ -22,11 +22,11 @@ int main(int argc, char *argv[]) Test->set_timeout(5); Test->repl->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); MYSQL * router[3]; - router[0] = Test->conn_rwsplit; - router[1] = Test->conn_master; - router[2] = Test->conn_slave; + router[0] = Test->maxscales->conn_rwsplit[0]; + router[1] = Test->maxscales->conn_master[0]; + router[2] = Test->maxscales->conn_slave[0]; for (int ir = 0; ir < r; ir++) { @@ -50,8 +50,8 @@ int main(int argc, char *argv[]) Test->set_timeout(20); - Test->close_maxscale_connections(); - Test->check_maxscale_alive(); + Test->maxscales->close_maxscale_connections(0); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs280_select_outfile.cpp b/maxscale-system-test/mxs280_select_outfile.cpp index 4dc30c499..2ffe05359 100644 --- a/maxscale-system-test/mxs280_select_outfile.cpp +++ b/maxscale-system-test/mxs280_select_outfile.cpp @@ -19,19 +19,19 @@ int main(int argc, char *argv[]) int i; TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Create /tmp/t1.csv on all backend nodes\n"); for (i = 0; i < Test->repl->N; i++) { Test->set_timeout(30); - Test->repl->ssh_node(i, true, "touch /tmp/t1.csv"); + Test->repl->ssh_node(i, (char *) "touch /tmp/t1.csv", true); } - Test->add_result(create_t1(Test->conn_rwsplit), "Error creating t1\n"); - Test->try_query(Test->conn_rwsplit, (char *) "INSERT INTO t1 (x1, fl) VALUES (0, 0), (1, 0)"); + Test->add_result(create_t1(Test->maxscales->conn_rwsplit[0]), "Error creating t1\n"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "INSERT INTO t1 (x1, fl) VALUES (0, 0), (1, 0)"); - if ( (execute_query(Test->conn_rwsplit, (char *) "SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1;")) == 0 ) + if ( (execute_query(Test->maxscales->conn_rwsplit[0], (char *) "SELECT * INTO OUTFILE '/tmp/t1.csv' FROM t1;")) == 0 ) { Test->add_result(1, "SELECT INTO OUTFILE epected to fail, but it is OK\n"); } @@ -42,13 +42,13 @@ int main(int argc, char *argv[]) for (i = 0; i < Test->repl->N; i++) { Test->set_timeout(30); - Test->repl->ssh_node(i, true, "rm -rf /tmp/t1.csv"); + Test->repl->ssh_node(i, (char *) "rm -rf /tmp/t1.csv", true); } Test->set_timeout(30); sleep(5); - Test->check_log_err((char *) "Failed to execute session command in", true); - Test->check_log_err((char *) "File '/tmp/t1.csv' already exists", true); + Test->check_log_err(0, (char *) "Failed to execute session command in", true); + Test->check_log_err(0, (char *) "File '/tmp/t1.csv' already exists", true); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs314.cpp b/maxscale-system-test/mxs314.cpp index 55a103768..fd60824d9 100644 --- a/maxscale-system-test/mxs314.cpp +++ b/maxscale-system-test/mxs314.cpp @@ -28,9 +28,9 @@ int main(int argc, char *argv[]) } Test->set_timeout(50); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); - stmt = mysql_stmt_init(Test->conn_rwsplit); + stmt = mysql_stmt_init(Test->maxscales->conn_rwsplit[0]); for (int i = 0; i < start; i++) { @@ -45,14 +45,14 @@ int main(int argc, char *argv[]) Test->tprintf("%d\t", i); if (mysql_stmt_prepare(stmt, query.c_str(), query.length())) { - Test->add_result(1, "Error: %s\n", mysql_error(Test->conn_rwsplit)); + Test->add_result(1, "Error: %s\n", mysql_error(Test->maxscales->conn_rwsplit[0])); Test->add_result(1, "Failed at %d\n", i); // delete Test; // return 1; } if (mysql_stmt_reset(stmt)) { - Test->add_result(1, "Error: %s\n", mysql_error(Test->conn_rwsplit)); + Test->add_result(1, "Error: %s\n", mysql_error(Test->maxscales->conn_rwsplit[0])); Test->add_result(1, "Failed at %d\n", i); // delete Test; // return 1; @@ -67,7 +67,7 @@ int main(int argc, char *argv[]) cout << endl; Test->set_timeout(20); mysql_stmt_close(stmt); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/mxs321.cpp b/maxscale-system-test/mxs321.cpp index 76bf1670d..771bf45fb 100644 --- a/maxscale-system-test/mxs321.cpp +++ b/maxscale-system-test/mxs321.cpp @@ -24,7 +24,7 @@ int check_connection_count(TestConnections* test, int server) char cmd[1024]; test->set_timeout(30); sprintf(cmd, "show server server%d", server); - test->add_result(test->get_maxadmin_param(cmd, (char*) "Current no. of conns:", result), + test->add_result(test->maxscales->get_maxadmin_param(0, cmd, (char*) "Current no. of conns:", result), "maxadmin command %s failed\n", cmd); int result_d = 999; sscanf(result, "%d", &result_d); @@ -46,15 +46,15 @@ void create_and_check_connections(TestConnections* test, int target) switch (target) { case 1: - stmt[i] = test->open_rwsplit_connection(); + stmt[i] = test->maxscales->open_rwsplit_connection(0); break; case 2: - stmt[i] = test->open_readconn_master_connection(); + stmt[i] = test->maxscales->open_readconn_master_connection(0); break; case 3: - stmt[i] = test->open_readconn_master_connection(); + stmt[i] = test->maxscales->open_readconn_master_connection(0); break; } } @@ -92,9 +92,9 @@ int main(int argc, char *argv[]) Test->set_timeout(50); Test->repl->execute_query_all_nodes((char *) "SET GLOBAL max_connections=100"); - Test->connect_maxscale(); - execute_query(Test->conn_rwsplit, "SET GLOBAL max_connections=100"); - Test->close_maxscale_connections(); + Test->maxscales->connect_maxscale(0); + execute_query(Test->maxscales->conn_rwsplit[0], "SET GLOBAL max_connections=100"); + Test->maxscales->close_maxscale_connections(0); Test->stop_timeout(); /** Create connections to readwritesplit */ diff --git a/maxscale-system-test/mxs365.cpp b/maxscale-system-test/mxs365.cpp index b2cbb7703..2cc057ffb 100644 --- a/maxscale-system-test/mxs365.cpp +++ b/maxscale-system-test/mxs365.cpp @@ -49,38 +49,38 @@ int main(int argc, char *argv[]) /** Set max packet size and create test table */ test->set_timeout(20); test->tprintf("Connect to Maxscale\n"); - test->connect_maxscale(); + test->maxscales->connect_maxscale(0); test->tprintf("Setting max_allowed_packet, creating table\n"); - test->add_result(execute_query(test->conn_rwsplit, + test->add_result(execute_query(test->maxscales->conn_rwsplit[0], "set global max_allowed_packet=(1048576 * 60)"), "Setting max_allowed_packet failed."); - test->add_result(execute_query(test->conn_rwsplit, + test->add_result(execute_query(test->maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS test.dump"), "Dropping table failed."); - test->add_result(execute_query(test->conn_rwsplit, + test->add_result(execute_query(test->maxscales->conn_rwsplit[0], "CREATE TABLE test.dump(a int, b varchar(80), c varchar(80))"), "Creating table failed."); test->tprintf("Closing connection to Maxscale\n"); - test->close_maxscale_connections(); + test->maxscales->close_maxscale_connections(0); /** Reconnect, load the data and then read it */ test->tprintf("Re-connect to Maxscale\n"); test->set_timeout(20); - test->connect_maxscale(); + test->maxscales->connect_maxscale(0); char query[1024]; snprintf(query, sizeof (filename), "LOAD DATA LOCAL INFILE '%s' INTO TABLE test.dump FIELDS TERMINATED BY ','", filename); test->tprintf("Loading data\n"); test->set_timeout(100); - test->add_result(execute_query(test->conn_rwsplit, query), "Loading data failed."); + test->add_result(execute_query(test->maxscales->conn_rwsplit[0], query), "Loading data failed."); test->tprintf("Reading data\n"); test->set_timeout(100); - test->add_result(execute_query(test->conn_rwsplit, "SELECT * FROM test.dump"), + test->add_result(execute_query(test->maxscales->conn_rwsplit[0], "SELECT * FROM test.dump"), "Reading data failed."); - test->close_maxscale_connections(); + test->maxscales->close_maxscale_connections(0); test->tprintf("Cecking if Maxscale alive\n"); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); int rval = test->global_result; delete test; unlink(filename); diff --git a/maxscale-system-test/mxs37_table_privilege.cpp b/maxscale-system-test/mxs37_table_privilege.cpp index 14227bc22..a2e03f2a5 100644 --- a/maxscale-system-test/mxs37_table_privilege.cpp +++ b/maxscale-system-test/mxs37_table_privilege.cpp @@ -17,15 +17,15 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(60); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Create user with only SELECT priviledge to a table"); - execute_query_silent(Test->conn_rwsplit, "DROP USER 'table_privilege'@'%'"); - execute_query_silent(Test->conn_rwsplit, "DROP TABLE test.t1"); - execute_query(Test->conn_rwsplit, "CREATE TABLE test.t1 (id INT)"); - execute_query(Test->conn_rwsplit, "CREATE USER 'table_privilege'@'%%' IDENTIFIED BY 'pass'"); - execute_query(Test->conn_rwsplit, "GRANT SELECT ON test.t1 TO 'table_privilege'@'%%'"); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "DROP USER 'table_privilege'@'%'"); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "DROP TABLE test.t1"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE TABLE test.t1 (id INT)"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE USER 'table_privilege'@'%%' IDENTIFIED BY 'pass'"); + execute_query(Test->maxscales->conn_rwsplit[0], "GRANT SELECT ON test.t1 TO 'table_privilege'@'%%'"); Test->stop_timeout(); Test->repl->sync_slaves(); @@ -44,7 +44,7 @@ int main(int argc, char *argv[]) */ for (int i = 0; i < 5; i++) { - MYSQL *conn = open_conn_db(Test->rwsplit_port, Test->maxscale_IP, (char *) "test", + MYSQL *conn = open_conn_db(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "test", (char *) "table_privilege", (char *) "pass", Test->ssl); if (mysql_errno(conn) != 0) { @@ -70,10 +70,10 @@ int main(int argc, char *argv[]) } Test->set_timeout(20); - execute_query_silent(Test->conn_rwsplit, "DROP USER 'table_privilege'@'%'"); - execute_query_silent(Test->conn_rwsplit, "DROP TABLE test.t1"); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "DROP USER 'table_privilege'@'%'"); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "DROP TABLE test.t1"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs419_lots_of_connections.cpp b/maxscale-system-test/mxs419_lots_of_connections.cpp index 817ed394a..08ebf7aa1 100644 --- a/maxscale-system-test/mxs419_lots_of_connections.cpp +++ b/maxscale-system-test/mxs419_lots_of_connections.cpp @@ -14,9 +14,9 @@ int main(int argc, char *argv[]) Test->set_timeout(30); Test->tprintf("set global max_connections = 2000"); - Test->connect_maxscale(); - Test->try_query(Test->conn_rwsplit, (char *) "set global max_connections = 2000;\n"); - Test->close_maxscale_connections(); + Test->maxscales->connect_maxscale(0); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "set global max_connections = 2000;\n"); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Trying %d connections\n", connections); Test->add_result(Test->create_connections(connections, true, true, true, false), @@ -24,12 +24,12 @@ int main(int argc, char *argv[]) Test->set_timeout(30); Test->tprintf("set global max_connections = 100"); - Test->connect_maxscale(); - Test->try_query(Test->conn_rwsplit, (char *) "set global max_connections = 100;\n"); - Test->close_maxscale_connections(); + Test->maxscales->connect_maxscale(0); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "set global max_connections = 100;\n"); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checking if Maxscale alive\n"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs431.cpp b/maxscale-system-test/mxs431.cpp index 708f95ea5..9cf26ce77 100644 --- a/maxscale-system-test/mxs431.cpp +++ b/maxscale-system-test/mxs431.cpp @@ -20,7 +20,7 @@ int main(int argc, char *argv[]) Test->set_timeout(30); Test->repl->stop_slaves(); Test->set_timeout(30); - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); Test->set_timeout(30); Test->repl->connect(); Test->stop_timeout(); @@ -47,9 +47,9 @@ int main(int argc, char *argv[]) { sprintf(str, "shard_db%d", i); Test->set_timeout(15); - MYSQL *conn = open_conn_db(Test->rwsplit_port, Test->maxscale_IP, - str, Test->maxscale_user, - Test->maxscale_password, Test->ssl); + MYSQL *conn = open_conn_db(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], + str, Test->maxscales->user_name, + Test->maxscales->password, Test->ssl); Test->set_timeout(15); Test->tprintf("Trying DB %d\n", i); if (execute_query(conn, "SELECT 1")) diff --git a/maxscale-system-test/mxs47.cpp b/maxscale-system-test/mxs47.cpp index b64121481..7878205ba 100644 --- a/maxscale-system-test/mxs47.cpp +++ b/maxscale-system-test/mxs47.cpp @@ -13,7 +13,7 @@ int main(int argc, char *argv[]) int iterations = 5000; test.tprintf("Executing `SELECT REPEAT('a', X );` for X = 0..%d with a stride of 7", iterations); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); for (int i = 1; i < iterations; i += 7) { @@ -21,10 +21,10 @@ int main(int argc, char *argv[]) sprintf(str, "SELECT REPEAT('a',%d)", i); test.set_timeout(15); - test.try_query(test.conn_rwsplit, str); + test.try_query(test.maxscales->conn_rwsplit[0], str); } - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/mxs501_tee_usedb.cpp b/maxscale-system-test/mxs501_tee_usedb.cpp index cbd9bfee4..96bb813ee 100644 --- a/maxscale-system-test/mxs501_tee_usedb.cpp +++ b/maxscale-system-test/mxs501_tee_usedb.cpp @@ -37,7 +37,7 @@ passwd=skysql filters=QLA @endverbatim * - * try USE test command against all routers + * try USE test command against all maxscales->routers[0] */ #include @@ -51,25 +51,25 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->set_timeout(10); Test->tprintf("Trying USE db against RWSplit\n"); - Test->try_query(Test->conn_rwsplit, (char *) "USE mysql"); - Test->try_query(Test->conn_rwsplit, (char *) "USE test"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "USE mysql"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "USE test"); Test->set_timeout(10); Test->tprintf("Trying USE db against ReadConn master\n"); - Test->try_query(Test->conn_master, (char *) "USE mysql"); - Test->try_query(Test->conn_master, (char *) "USE test"); + Test->try_query(Test->maxscales->conn_master[0], (char *) "USE mysql"); + Test->try_query(Test->maxscales->conn_master[0], (char *) "USE test"); Test->set_timeout(10); Test->tprintf("Trying USE db against ReadConn slave\n"); - Test->try_query(Test->conn_master, (char *) "USE mysql"); - Test->try_query(Test->conn_slave, (char *) "USE test"); + Test->try_query(Test->maxscales->conn_master[0], (char *) "USE mysql"); + Test->try_query(Test->maxscales->conn_slave[0], (char *) "USE test"); Test->set_timeout(10); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/mxs548_short_session_change_user.cpp b/maxscale-system-test/mxs548_short_session_change_user.cpp index 6dd42d890..17878a9b7 100644 --- a/maxscale-system-test/mxs548_short_session_change_user.cpp +++ b/maxscale-system-test/mxs548_short_session_change_user.cpp @@ -4,7 +4,7 @@ * - create 'user' with password 'pass2' * - create load on Master (3 threads are inserting data into 't1' in the loop) * - in 40 parallel threads open connection, execute change_user to 'user', execute change_user to default user, close connection - * - repeat test first only for RWSplit and second for all routers + * - repeat test first only for RWSplit and second for all maxscales->routers[0] * - check logs for lack of "Unable to write to backend 'server2' due to authentication failure" errors * - check for lack of crashes in the log */ @@ -31,8 +31,8 @@ void *query_thread_master(void *ptr); int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); - Test->ssh_maxscale(true, "sysctl net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_tw_recycle=1 " - "net.core.somaxconn=10000 net.ipv4.tcp_max_syn_backlog=10000"); + Test->maxscales->ssh_node_f(0, true, "sysctl net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_tw_recycle=1 " + "net.core.somaxconn=10000 net.ipv4.tcp_max_syn_backlog=10000"); Test->set_timeout(20); int threads_num = 40; @@ -82,17 +82,17 @@ int main(int argc, char *argv[]) int iret_master[master_load_threads_num]; Test->repl->connect(); - Test->connect_maxscale(); - create_t1(Test->conn_rwsplit); + Test->maxscales->connect_maxscale(0); + create_t1(Test->maxscales->conn_rwsplit[0]); Test->repl->execute_query_all_nodes((char *) "set global max_connections = 2000;"); Test->repl->sync_slaves(); Test->tprintf("Creating user 'user' \n"); - execute_query(Test->conn_rwsplit, (char *) "DROP USER user@'%%'"); - execute_query(Test->conn_rwsplit, (char *) "CREATE USER user@'%%' IDENTIFIED BY 'pass2'"); - execute_query(Test->conn_rwsplit, (char *) "GRANT SELECT ON test.* TO user@'%%'"); - execute_query(Test->conn_rwsplit, (char *) "DROP TABLE IF EXISTS test.t1"); - execute_query(Test->conn_rwsplit, (char *) "CREATE TABLE test.t1 (x1 int, fl int)"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP USER user@'%%'"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE USER user@'%%' IDENTIFIED BY 'pass2'"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "GRANT SELECT ON test.* TO user@'%%'"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE IF EXISTS test.t1"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE TABLE test.t1 (x1 int, fl int)"); Test->repl->sync_slaves(); /* Create independent threads each of them will create some load on Master */ @@ -119,7 +119,7 @@ int main(int argc, char *argv[]) Test->repl->flush_hosts(); - Test->tprintf("all routers are involved, threads are running %d seconds more\n", run_time); + Test->tprintf("all maxscales->routers[0] are involved, threads are running %d seconds more\n", run_time); Test->set_timeout(run_time + 100); for (i = 0; i < threads_num; i++) @@ -151,21 +151,21 @@ int main(int argc, char *argv[]) Test->tprintf("Dropping tables and users\n"); Test->set_timeout(60); - execute_query(Test->conn_rwsplit, (char *) "DROP TABLE test.t1;"); - execute_query(Test->conn_rwsplit, (char *) "DROP USER user@'%%'"); - Test->close_maxscale_connections(); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE test.t1;"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP USER user@'%%'"); + Test->maxscales->close_maxscale_connections(0); Test->set_timeout(160); Test->tprintf("Trying to connect Maxscale\n"); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Closing Maxscale connections\n"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checking if Maxscale alive\n"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); Test->tprintf("Checking log for unwanted errors\n"); - Test->check_log_err((char *) "due to authentication failure", false); - Test->check_log_err((char *) "fatal signal 11", false); - Test->check_log_err((char *) "due to handshake failure", false); + Test->check_log_err(0, (char *) "due to authentication failure", false); + Test->check_log_err(0, (char *) "fatal signal 11", false); + Test->check_log_err(0, (char *) "due to handshake failure", false); // We need to wait for the TCP connections in TIME_WAIT state so that // later tests don't fail due to a lack of file descriptors @@ -183,7 +183,7 @@ void *query_thread1(void *ptr) while (data->exit_flag == 0) { - data->conn1 = data->Test->open_rwsplit_connection(); + data->conn1 = data->Test->maxscales->open_rwsplit_connection(0); if (data->conn1 != NULL) { @@ -195,7 +195,7 @@ void *query_thread1(void *ptr) } if (data->rwsplit_only == 0) { - data->conn2 = data->Test->open_readconn_master_connection(); + data->conn2 = data->Test->maxscales->open_readconn_master_connection(0); if (data->conn2 != NULL) { @@ -206,7 +206,7 @@ void *query_thread1(void *ptr) } } - data->conn3 = data->Test->open_readconn_slave_connection(); + data->conn3 = data->Test->maxscales->open_readconn_slave_connection(0); if (data->conn3 != NULL) { diff --git a/maxscale-system-test/mxs559_block_master.cpp b/maxscale-system-test/mxs559_block_master.cpp index 5f5d8c4c8..ba8a051f7 100644 --- a/maxscale-system-test/mxs559_block_master.cpp +++ b/maxscale-system-test/mxs559_block_master.cpp @@ -30,14 +30,14 @@ void *disconnect_thread(void *ptr); int main(int argc, char *argv[]) { TestConnections test(argc, argv); - test.ssh_maxscale(true, "sysctl net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_tw_recycle=1 " - "net.core.somaxconn=10000 net.ipv4.tcp_max_syn_backlog=10000"); + test.maxscales->ssh_node_f(0, true, "sysctl net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_tw_recycle=1 " + "net.core.somaxconn=10000 net.ipv4.tcp_max_syn_backlog=10000"); test.set_timeout(60); - test.connect_maxscale(); - create_t1(test.conn_rwsplit); - execute_query(test.conn_rwsplit, "set global max_connections=1000"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + create_t1(test.maxscales->conn_rwsplit[0]); + execute_query(test.maxscales->conn_rwsplit[0], "set global max_connections=1000"); + test.maxscales->close_maxscale_connections(0); test.tprintf("Create query load"); int load_threads_num = 10; @@ -48,10 +48,10 @@ int main(int argc, char *argv[]) for (int i = 0; i < load_threads_num; i++) { data_master[i].exit_flag = 0; - data_master[i].ip = test.maxscale_IP; - data_master[i].port = test.rwsplit_port; - data_master[i].user = test.maxscale_user; - data_master[i].password = test.maxscale_password; + data_master[i].ip = test.maxscales->IP[0]; + data_master[i].port = test.maxscales->rwsplit_port[0]; + data_master[i].user = test.maxscales->user_name; + data_master[i].password = test.maxscales->password; data_master[i].ssl = test.ssl; pthread_create(&thread_master[i], NULL, disconnect_thread, &data_master[i]); } @@ -100,7 +100,7 @@ int main(int argc, char *argv[]) { test.set_timeout(60); test.verbose = true; - int rc = test.connect_maxscale(); + int rc = test.maxscales->connect_maxscale(0); test.verbose = false; if (rc == 0) @@ -110,14 +110,14 @@ int main(int argc, char *argv[]) sleep(1); } - test.try_query(test.conn_rwsplit, "DROP TABLE IF EXISTS t1"); - test.close_maxscale_connections(); + test.try_query(test.maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS t1"); + test.maxscales->close_maxscale_connections(0); - test.check_maxscale_alive(); - test.check_log_err("due to authentication failure", false); - test.check_log_err("fatal signal 11", false); - test.check_log_err("due to handshake failure", false); - test.check_log_err("Refresh rate limit exceeded for load of users' table", false); + test.check_maxscale_alive(0); + test.check_log_err(0, "due to authentication failure", false); + test.check_log_err(0, "fatal signal 11", false); + test.check_log_err(0, "due to handshake failure", false); + test.check_log_err(0, "Refresh rate limit exceeded for load of users' table", false); return test.global_result; } @@ -142,4 +142,3 @@ void *disconnect_thread( void *ptr ) return NULL; } - diff --git a/maxscale-system-test/mxs564_big_dump.cpp b/maxscale-system-test/mxs564_big_dump.cpp index 9771181be..164e659a8 100644 --- a/maxscale-system-test/mxs564_big_dump.cpp +++ b/maxscale-system-test/mxs564_big_dump.cpp @@ -5,7 +5,7 @@ * - after a while block first slave * - after a while block second slave * - check that all INSERTs are ok - * - repeat with both RWSplit and ReadConn master routers + * - repeat with both RWSplit and ReadConn master maxscales->routers[0] * - check Maxscale is alive */ @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) //Test->repl->flush_hosts(); Test->set_timeout(20); - int master = Test->find_master_maxadmin(Test->galera); + int master = Test->maxscales->find_master_maxadmin(0, Test->galera); Test->stop_timeout(); Test->tprintf(("Master is %d\n"), master); int k = 0; @@ -82,14 +82,14 @@ int main(int argc, char *argv[]) Test->set_timeout(20); Test->repl->connect(); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->set_timeout(20); - create_t1(Test->conn_rwsplit); + create_t1(Test->maxscales->conn_rwsplit[0]); Test->repl->execute_query_all_nodes((char *) "set global max_connections = 2000;"); Test->set_timeout(20); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE IF EXISTS t1"); - Test->try_query(Test->conn_rwsplit, (char *) "CREATE TABLE t1 (x1 int, fl int)"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE IF EXISTS t1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "CREATE TABLE t1 (x1 int, fl int)"); for (i = 0; i < threads_num; i++) { @@ -124,7 +124,7 @@ int main(int argc, char *argv[]) Test->tprintf("exit %d\n", i); } - Test->tprintf("all routers are involved, threads are running %d seconds more\n", run_time); + Test->tprintf("all maxscales->routers[0] are involved, threads are running %d seconds more\n", run_time); for (i = 0; i < threads_num; i++) { @@ -162,16 +162,16 @@ int main(int argc, char *argv[]) Test->tprintf("set global max_connections = 100 for all backends\n"); Test->repl->execute_query_all_nodes((char *) "set global max_connections = 100;"); Test->tprintf("Drop t1\n"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE IF EXISTS t1;"); - Test->close_maxscale_connections(); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE IF EXISTS t1;"); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checking if Maxscale alive\n"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); //Test->tprintf("Checking log for unwanted errors\n"); - //Test->check_log_err((char *) "due to authentication failure", false); - //Test->check_log_err((char *) "fatal signal 11", false); - //Test->check_log_err((char *) "due to handshake failure", false); - //Test->check_log_err((char *) "Refresh rate limit exceeded for load of users' table", false); + //Test->check_log_err(0, (char *) "due to authentication failure", false); + //Test->check_log_err(0, (char *) "fatal signal 11", false); + //Test->check_log_err(0, (char *) "due to handshake failure", false); + //Test->check_log_err(0, (char *) "Refresh rate limit exceeded for load of users' table", false); int rval = Test->global_result; delete Test; @@ -185,7 +185,7 @@ void *query_thread1( void *ptr ) sleep(data->thread_id); create_insert_string(sql, 1000, 2); - data->conn1 = data->Test->open_rwsplit_connection(); + data->conn1 = data->Test->maxscales->open_rwsplit_connection(0); if ((data->conn1 == NULL) || (mysql_errno(data->conn1) != 0 )) { data->Test->add_result(1, "Error connecting to RWSplit\n"); @@ -196,7 +196,7 @@ void *query_thread1( void *ptr ) if (data->rwsplit_only == 0) { - data->conn2 = data->Test->open_readconn_master_connection(); + data->conn2 = data->Test->maxscales->open_readconn_master_connection(0); if ((data->conn2 == NULL) || (mysql_errno(data->conn2) != 0 )) { data->Test->add_result(1, "Error connecting to ReadConn Master\n"); diff --git a/maxscale-system-test/mxs585.py b/maxscale-system-test/mxs585.py new file mode 100755 index 000000000..49b1d094f --- /dev/null +++ b/maxscale-system-test/mxs585.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +### +## @file mxs585.py Regression case for MXS-585 "Intermittent connection failure with MaxScale 1.2/1.3 using MariaDB/J 1.3" +## - open connection, execute simple query and close connection in the loop + +import maxpython + +test1 = maxpython.MaxScaleTest("mxs585.py") + +for i in range(0,100): + if i % 10 == 0: + print(str(i)) + test1.maxscale['rwsplit'].query_and_close("select 1") + test1.maxscale['rcmaster'].query_and_close("select 1") + test1.maxscale['rcslave'].query_and_close("select 1") diff --git a/maxscale-system-test/mxs598.py b/maxscale-system-test/mxs598.py new file mode 100755 index 000000000..ddb07180f --- /dev/null +++ b/maxscale-system-test/mxs598.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python + + +### +## @file mxs598.py Regression case for MXS-598 "SSL RW Router / JDBC Exception" +## - use SSL for Maxscale client connection +## - simple transactions in the loop + +import maxpython + +test1 = maxpython.MaxScaleTest("mxs598.py") + +print("Connecting to MaxScale") +for i in test1.maxscale.values(): + i.connect("useSSL=true&requireSSL=true&verifyServerCert=false") + +print("Trying 100 simple transactions on all services") +for i in range(0,100): + for x in test1.maxscale.values(): + x.begin() + x.query("insert into test.t1 values (1)") + x.query("select * from test.t1") + x.commit() + +print("Closing connections") +for i in test1.maxscale.values(): + i.disconnect() diff --git a/maxscale-system-test/mxs621_unreadable_cnf.cpp b/maxscale-system-test/mxs621_unreadable_cnf.cpp index 9c302a27f..8c9e569a5 100644 --- a/maxscale-system-test/mxs621_unreadable_cnf.cpp +++ b/maxscale-system-test/mxs621_unreadable_cnf.cpp @@ -18,13 +18,13 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(30); - Test->ssh_maxscale(true, "chmod 400 /etc/maxscale.cnf"); + Test->maxscales->ssh_node_f(0, true, "chmod 400 /etc/maxscale.cnf"); Test->set_timeout(30); - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); Test->set_timeout(30); - Test->check_log_err((char *) "Opening file '/etc/maxscale.cnf' for reading failed", true); + Test->check_log_err(0, (char *) "Opening file '/etc/maxscale.cnf' for reading failed", true); Test->set_timeout(30); - Test->ssh_maxscale(true, "chmod 777 /etc/maxscale.cnf"); + Test->maxscales->ssh_node_f(0, true, "chmod 777 /etc/maxscale.cnf"); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs652_bad_ssl.cpp b/maxscale-system-test/mxs652_bad_ssl.cpp index 6a3dc8de2..253b8350a 100644 --- a/maxscale-system-test/mxs652_bad_ssl.cpp +++ b/maxscale-system-test/mxs652_bad_ssl.cpp @@ -2,7 +2,7 @@ * @file mxs652_bad_ssl.cpp mxs652 regression case ("ssl is configured in a wrong way, but Maxscale can be started and works") * * - Maxscale.cnf contains ssl configuration for all services in 'router' section instead of 'listener' with 'ssl=require' - * - trying to connect to all routers without ssl and expect error + * - trying to connect to all maxscales->routers[0] without ssl and expect error */ @@ -17,11 +17,11 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->check_log_err((char *) "Unexpected parameter 'ssl_version'", true); + Test->check_log_err(0, (char *) "Unexpected parameter 'ssl_version'", true); Test->tprintf("Trying RWSplit, expecting fault\n"); - MYSQL * conn = open_conn(Test->rwsplit_port, Test->maxscale_IP, Test->maxscale_user, Test->maxscale_password, + MYSQL * conn = open_conn(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], Test->maxscales->user_name, Test->maxscales->password, false); if (mysql_errno(conn) == 0) @@ -31,7 +31,7 @@ int main(int argc, char *argv[]) } Test->tprintf("Trying ReadConn master, expecting fault\n"); - conn = open_conn(Test->readconn_master_port, Test->maxscale_IP, Test->maxscale_user, Test->maxscale_password, + conn = open_conn(Test->maxscales->readconn_master_port[0], Test->maxscales->IP[0], Test->maxscales->user_name, Test->maxscales->password, false); if (mysql_errno(conn) == 0) @@ -41,7 +41,7 @@ int main(int argc, char *argv[]) } Test->tprintf("Trying ReadConn slave, expecting fault\n"); - conn = open_conn(Test->readconn_slave_port, Test->maxscale_IP, Test->maxscale_user, Test->maxscale_password, + conn = open_conn(Test->maxscales->readconn_slave_port[0][0], Test->maxscales->IP[0], Test->maxscales->user_name, Test->maxscales->password, false); if (mysql_errno(conn) == 0) diff --git a/maxscale-system-test/mxs657_restart.cpp b/maxscale-system-test/mxs657_restart.cpp index 5a8175f60..9f26758ee 100644 --- a/maxscale-system-test/mxs657_restart.cpp +++ b/maxscale-system-test/mxs657_restart.cpp @@ -29,7 +29,7 @@ int main(int argc, char *argv[]) int i, j; - Test->tprintf("Connecting to RWSplit %s\n", Test->maxscale_IP); + Test->tprintf("Connecting to RWSplit %s\n", Test->maxscales->IP[0]); Test->set_timeout(2000); @@ -44,13 +44,13 @@ int main(int argc, char *argv[]) for (i = 0; i < iter; i++) { Test->tprintf("i= %d\n", i); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); for (j = 0; j < iter; j++) { - execute_query_silent(Test->conn_rwsplit, "SELECT 1"); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "SELECT 1"); } - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); if (i > iter) { restart_flag = 1; @@ -94,7 +94,7 @@ int main(int argc, char *argv[]) pthread_join(restart_t, NULL); Test->tprintf("Checxking if MaxScale is still alive!\n"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; @@ -109,11 +109,11 @@ void *kill_vm_thread( void *ptr ) sleep(2); if (restart_flag == 0) { - Test->execute_maxadmin_command((char * ) "restart service \"RW Split Router\""); + Test->maxscales->execute_maxadmin_command(0, (char * ) "restart service \"RW Split Router\""); } else { - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); } } diff --git a/maxscale-system-test/mxs657_restart_service.cpp b/maxscale-system-test/mxs657_restart_service.cpp index 8086bd231..c46a3db41 100644 --- a/maxscale-system-test/mxs657_restart_service.cpp +++ b/maxscale-system-test/mxs657_restart_service.cpp @@ -80,8 +80,8 @@ int main(int argc, char *argv[]) sht_rst_service(); - Test->check_maxscale_alive(); - Test->check_log_err((char *) "received fatal signal", false); + Test->check_maxscale_alive(0); + Test->check_log_err(0, (char *) "received fatal signal", false); int rval = Test->global_result; delete Test; return rval; @@ -91,7 +91,7 @@ void *query_thread1( void *ptr ) { while (!exit_flag) { - Test->execute_maxadmin_command(shutdown_cmd); - Test->execute_maxadmin_command(restart_cmd); + Test->maxscales->execute_maxadmin_command(0, shutdown_cmd); + Test->maxscales->execute_maxadmin_command(0, restart_cmd); } } diff --git a/maxscale-system-test/mxs682_cyrillic.cpp b/maxscale-system-test/mxs682_cyrillic.cpp index 1561cfe86..7189cde5e 100644 --- a/maxscale-system-test/mxs682_cyrillic.cpp +++ b/maxscale-system-test/mxs682_cyrillic.cpp @@ -63,12 +63,12 @@ int main(int argc, char *argv[]) iconv_close(converter); */ - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->set_timeout(10); nodes->connect(); Test->set_timeout(10); - MYSQL * conn = Test->conn_rwsplit; + MYSQL * conn = Test->maxscales->conn_rwsplit[0]; //Test->try_query(conn, (char *) "set names utf8mb4;"); execute_query_silent(conn, (char *) "DROP TABLE t2;"); @@ -79,9 +79,9 @@ int main(int argc, char *argv[]) Test->stop_timeout(); sleep(5); - check_val(Test->conn_rwsplit, Test); - check_val(Test->conn_master, Test); - check_val(Test->conn_slave, Test); + check_val(Test->maxscales->conn_rwsplit[0], Test); + check_val(Test->maxscales->conn_master[0], Test); + check_val(Test->maxscales->conn_slave[0], Test); for (int i = 0; i < Test->repl->N; i++) { @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) //execute_query_silent(conn, (char *) "DROP TABLE t2;"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/mxs710_bad_socket.cpp b/maxscale-system-test/mxs710_bad_socket.cpp index e79013c18..b31c71538 100644 --- a/maxscale-system-test/mxs710_bad_socket.cpp +++ b/maxscale-system-test/mxs710_bad_socket.cpp @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->check_maxscale_processes(0); - Test->check_log_err("Fatal", false); + Test->check_log_err(0, "Fatal", false); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/mxs716.cpp b/maxscale-system-test/mxs716.cpp index 5d9c00cf9..a44dc3907 100644 --- a/maxscale-system-test/mxs716.cpp +++ b/maxscale-system-test/mxs716.cpp @@ -18,7 +18,7 @@ void run_test(TestConnections* Test, const char* database) Test->set_timeout(20); Test->tprintf("Trying to connect using 'table_privilege'@'%%' to database '%s'", database); - MYSQL* conn = open_conn_db(Test->rwsplit_port, Test->maxscale_IP, database, "table_privilege", "pass", + MYSQL* conn = open_conn_db(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], database, "table_privilege", "pass", Test->ssl); if (conn && mysql_errno(conn) == 0) @@ -39,30 +39,30 @@ int main(int argc, char *argv[]) { TestConnections* Test = new TestConnections(argc, argv); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Preparing test"); Test->set_timeout(180); - execute_query(Test->conn_rwsplit, "DROP DATABASE IF EXISTS db1"); - execute_query(Test->conn_rwsplit, "DROP DATABASE IF EXISTS db2"); - execute_query(Test->conn_rwsplit, "DROP DATABASE IF EXISTS db3"); - execute_query(Test->conn_rwsplit, "DROP DATABASE IF EXISTS db4"); - execute_query(Test->conn_rwsplit, "CREATE DATABASE db1"); - execute_query(Test->conn_rwsplit, "CREATE DATABASE db2"); - execute_query(Test->conn_rwsplit, "CREATE DATABASE db3"); - execute_query(Test->conn_rwsplit, "CREATE DATABASE db4"); - execute_query(Test->conn_rwsplit, "CREATE TABLE db1.t1 (id INT)"); - execute_query(Test->conn_rwsplit, "CREATE TABLE db2.t1 (id INT)"); - execute_query(Test->conn_rwsplit, "CREATE TABLE db3.t1 (id INT)"); - execute_query(Test->conn_rwsplit, "CREATE TABLE db4.t1 (id INT)"); - execute_query(Test->conn_rwsplit, "INSERT INTO db1.t1 VALUES (1)"); - execute_query(Test->conn_rwsplit, "INSERT INTO db2.t1 VALUES (1)"); - execute_query(Test->conn_rwsplit, "INSERT INTO db3.t1 VALUES (1)"); - execute_query(Test->conn_rwsplit, "INSERT INTO db4.t1 VALUES (1)"); - execute_query(Test->conn_rwsplit, "CREATE USER 'table_privilege'@'%%' IDENTIFIED BY 'pass'"); - execute_query(Test->conn_rwsplit, "GRANT SELECT ON db1.* TO 'table_privilege'@'%%'"); - execute_query(Test->conn_rwsplit, "GRANT SELECT ON db2.* TO 'table_privilege'@'%%'"); - execute_query(Test->conn_rwsplit, "GRANT SELECT ON db3.t1 TO 'table_privilege'@'%%'"); - execute_query(Test->conn_rwsplit, "GRANT SELECT ON db4.t1 TO 'table_privilege'@'%%'"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP DATABASE IF EXISTS db1"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP DATABASE IF EXISTS db2"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP DATABASE IF EXISTS db3"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP DATABASE IF EXISTS db4"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE DATABASE db1"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE DATABASE db2"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE DATABASE db3"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE DATABASE db4"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE TABLE db1.t1 (id INT)"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE TABLE db2.t1 (id INT)"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE TABLE db3.t1 (id INT)"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE TABLE db4.t1 (id INT)"); + execute_query(Test->maxscales->conn_rwsplit[0], "INSERT INTO db1.t1 VALUES (1)"); + execute_query(Test->maxscales->conn_rwsplit[0], "INSERT INTO db2.t1 VALUES (1)"); + execute_query(Test->maxscales->conn_rwsplit[0], "INSERT INTO db3.t1 VALUES (1)"); + execute_query(Test->maxscales->conn_rwsplit[0], "INSERT INTO db4.t1 VALUES (1)"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE USER 'table_privilege'@'%%' IDENTIFIED BY 'pass'"); + execute_query(Test->maxscales->conn_rwsplit[0], "GRANT SELECT ON db1.* TO 'table_privilege'@'%%'"); + execute_query(Test->maxscales->conn_rwsplit[0], "GRANT SELECT ON db2.* TO 'table_privilege'@'%%'"); + execute_query(Test->maxscales->conn_rwsplit[0], "GRANT SELECT ON db3.t1 TO 'table_privilege'@'%%'"); + execute_query(Test->maxscales->conn_rwsplit[0], "GRANT SELECT ON db4.t1 TO 'table_privilege'@'%%'"); Test->repl->sync_slaves(); @@ -73,12 +73,12 @@ int main(int argc, char *argv[]) Test->tprintf("Cleaning up..."); Test->set_timeout(60); - Test->connect_maxscale(); - execute_query(Test->conn_rwsplit, "DROP DATABASE db1"); - execute_query(Test->conn_rwsplit, "DROP DATABASE db2"); - execute_query(Test->conn_rwsplit, "DROP DATABASE db3"); - execute_query(Test->conn_rwsplit, "DROP DATABASE db4"); - execute_query(Test->conn_rwsplit, "DROP USER 'table_privilege'@'%%'"); + Test->maxscales->connect_maxscale(0); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP DATABASE db1"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP DATABASE db2"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP DATABASE db3"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP DATABASE db4"); + execute_query(Test->maxscales->conn_rwsplit[0], "DROP USER 'table_privilege'@'%%'"); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs720_line_with_no_equal.cpp b/maxscale-system-test/mxs720_line_with_no_equal.cpp index a601ced77..d304ff30c 100644 --- a/maxscale-system-test/mxs720_line_with_no_equal.cpp +++ b/maxscale-system-test/mxs720_line_with_no_equal.cpp @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(30); - Test->check_log_err((char *) "Failed to pre-parse configuration file", true); + Test->check_log_err(0, (char *) "Failed to pre-parse configuration file", true); Test->check_maxscale_processes(0); int rval = Test->global_result; diff --git a/maxscale-system-test/mxs720_wierd_line.cpp b/maxscale-system-test/mxs720_wierd_line.cpp index 02537257e..f42028010 100644 --- a/maxscale-system-test/mxs720_wierd_line.cpp +++ b/maxscale-system-test/mxs720_wierd_line.cpp @@ -16,8 +16,8 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(30); - Test->check_log_err((char *) "Unexpected parameter 'укпоукц'", true); - Test->check_log_err((char *) "Unexpected parameter 'hren'", true); + Test->check_log_err(0, (char *) "Unexpected parameter 'укпоукц'", true); + Test->check_log_err(0, (char *) "Unexpected parameter 'hren'", true); Test->check_maxscale_processes(0); int rval = Test->global_result; diff --git a/maxscale-system-test/mxs722.cpp b/maxscale-system-test/mxs722.cpp index bf114efb5..fbc91fd7d 100644 --- a/maxscale-system-test/mxs722.cpp +++ b/maxscale-system-test/mxs722.cpp @@ -19,39 +19,39 @@ int main(int argc, char *argv[]) { TestConnections* test = new TestConnections(argc, argv); test->stop_timeout(); - test->stop_maxscale(); + test->maxscales->stop_maxscale(0); /** Copy original config so we can easily reset the testing environment */ - test->ssh_maxscale(true, "cp /etc/maxscale.cnf /etc/maxscale.cnf.backup"); + test->maxscales->ssh_node_f(0, true, "cp /etc/maxscale.cnf /etc/maxscale.cnf.backup"); /** Get a baseline result with a good configuration */ - int baseline = test->ssh_maxscale(true, "maxscale -c --user=maxscale"); + int baseline = test->maxscales->ssh_node_f(0, true, "maxscale -c --user=maxscale"); /** Configure bad parameter for a listener */ - test->ssh_maxscale(true, "sed -i -e 's/service/ecivres/' /etc/maxscale.cnf"); - test->add_result(baseline == test->ssh_maxscale(true, "maxscale -c --user=maxscale"), + test->maxscales->ssh_node_f(0, true, "sed -i -e 's/service/ecivres/' /etc/maxscale.cnf"); + test->add_result(baseline == test->maxscales->ssh_node_f(0, true, "maxscale -c --user=maxscale"), "Bad parameter name should be detected.\n"); - test->ssh_maxscale(true, "cp /etc/maxscale.cnf.backup /etc/maxscale.cnf"); + test->maxscales->ssh_node_f(0, true, "cp /etc/maxscale.cnf.backup /etc/maxscale.cnf"); /** Set router_options to a bad value */ - test->ssh_maxscale(true, "sed -i -e 's/router_options.*/router_options=bad_option=true/' /etc/maxscale.cnf"); - test->add_result(baseline == test->ssh_maxscale(true, "maxscale -c --user=maxscale"), - "Bad router_options should be detected.\n"); + test->maxscales->ssh_node_f(0, true, + "sed -i -e 's/router_options.*/router_options=bad_option=true/' /etc/maxscale.cnf"); + test->add_result(baseline == test->maxscales->ssh_node_f(0, true, "maxscale -c --user=maxscale"), + "Bad router_options should be detected.\n"); - test->ssh_maxscale(true, "cp /etc/maxscale.cnf.backup /etc/maxscale.cnf"); + test->maxscales->ssh_node_f(0, true, "cp /etc/maxscale.cnf.backup /etc/maxscale.cnf"); /** Configure bad filter parameter */ - test->ssh_maxscale(true, "sed -i -e 's/filebase/basefile/' /etc/maxscale.cnf"); - test->add_result(baseline == test->ssh_maxscale(true, "maxscale -c --user=maxscale"), + test->maxscales->ssh_node_f(0, true, "sed -i -e 's/filebase/basefile/' /etc/maxscale.cnf"); + test->add_result(baseline == test->maxscales->ssh_node_f(0, true, "maxscale -c --user=maxscale"), "Bad filter parameter should be detected.\n"); /** Remove configuration file */ - test->ssh_maxscale(true, "rm -f /etc/maxscale.cnf"); - test->add_result(baseline == test->ssh_maxscale(true, "maxscale -c --user=maxscale"), + test->maxscales->ssh_node_f(0, true, "rm -f /etc/maxscale.cnf"); + test->add_result(baseline == test->maxscales->ssh_node_f(0, true, "maxscale -c --user=maxscale"), "Missing configuration file should be detected.\n"); int rval = test->global_result; delete test; return rval; } - diff --git a/maxscale-system-test/mxs729_maxadmin.cpp b/maxscale-system-test/mxs729_maxadmin.cpp index 2bd4e970e..2df74be27 100644 --- a/maxscale-system-test/mxs729_maxadmin.cpp +++ b/maxscale-system-test/mxs729_maxadmin.cpp @@ -27,11 +27,13 @@ const char * user_only = "Enabled Linux accounts (secure) : root, %s\n"; void add_remove_maxadmin_user(TestConnections* Test) { char str[1024]; + int exit_code; - Test->tprintf("enable account %s to maxadmin:\n", Test->maxscale_access_user); - char * st3 = Test->ssh_maxscale_output(true, "maxadmin enable account %s", Test->maxscale_access_user); + Test->tprintf("enable account %s to maxadmin:\n", Test->maxscales->access_user[0]); + char * st3 = Test->maxscales->ssh_node_output_f(0, true, &exit_code, "maxadmin enable account %s", + Test->maxscales->access_user[0]); Test->tprintf("Result: %s\n", st3); - sprintf(str, user_added, Test->maxscale_access_user); + sprintf(str, user_added, Test->maxscales->access_user[0]); if (strstr(st3, str) == NULL) { Test->add_result(1, "There is no proper '%s' message\n", str); @@ -42,9 +44,9 @@ void add_remove_maxadmin_user(TestConnections* Test) } Test->tprintf("trying maxadmin without 'root':\n"); - char * st4 = Test->ssh_maxscale_output(false, "maxadmin show users"); + char * st4 = Test->maxscales->ssh_node_output_f(0, false, &exit_code, "maxadmin show users"); Test->tprintf("Result: %s\n", st4); - sprintf(str, user_only, Test->maxscale_access_user); + sprintf(str, user_only, Test->maxscales->access_user[0]); if (strstr(st4, str) == NULL) { Test->add_result(1, "There is no proper '%s' message\n", str); @@ -55,7 +57,7 @@ void add_remove_maxadmin_user(TestConnections* Test) } Test->tprintf("trying maxadmin with 'root':\n"); - int st5 = Test->ssh_maxscale(true, "maxadmin show users"); + int st5 = Test->maxscales->ssh_node_f(0, true, "maxadmin show users"); if (st5 != 0) { Test->add_result(1, "User added and access to MaxAdmin as 'root' is not possible\n"); @@ -66,9 +68,9 @@ void add_remove_maxadmin_user(TestConnections* Test) } Test->tprintf("trying maxadmin without 'root'\n"); - char * st7 = Test->ssh_maxscale_output(false, "maxadmin show users"); + char * st7 = Test->maxscales->ssh_node_output_f(0, false, &exit_code, "maxadmin show users"); Test->tprintf("Result: %s\n", st7); - sprintf(str, user_and_root, Test->maxscale_access_user); + sprintf(str, user_and_root, Test->maxscales->access_user[0]); if (strstr(st7, str) == NULL) { Test->add_result(1, "There is no proper '%s' message\n", str); @@ -79,10 +81,11 @@ void add_remove_maxadmin_user(TestConnections* Test) } Test->tprintf("creating readonly user"); - Test->ssh_maxscale(false, "maxadmin add readonly-user test test"); + Test->maxscales->ssh_node_f(0, false, "maxadmin add readonly-user test test"); - Test->tprintf("trying to remove user '%s'\n", Test->maxscale_access_user); - char * st8 = Test->ssh_maxscale_output(false, "maxadmin disable account %s", Test->maxscale_access_user); + Test->tprintf("trying to remove user '%s'\n", Test->maxscales->access_user[0]); + char * st8 = Test->maxscales->ssh_node_output_f(0, false, &exit_code, "maxadmin disable account %s", + Test->maxscales->access_user[0]); if (strstr(st8, remove_last_admin)) { @@ -93,11 +96,11 @@ void add_remove_maxadmin_user(TestConnections* Test) Test->tprintf("OK\n"); } - Test->tprintf("Trying with removed user '%s'\n", Test->maxscale_access_user); - int st9 = Test->ssh_maxscale(false, "maxadmin show users"); + Test->tprintf("Trying with removed user '%s'\n", Test->maxscales->access_user[0]); + int st9 = Test->maxscales->ssh_node_f(0, false, "maxadmin show users"); if (st9 == 0) { - Test->add_result(1, "User '%s' should be removed", Test->maxscale_access_user); + Test->add_result(1, "User '%s' should be removed", Test->maxscales->access_user[0]); } else { @@ -107,15 +110,16 @@ void add_remove_maxadmin_user(TestConnections* Test) int main(int argc, char *argv[]) { + int exit_code; TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(600); - Test->ssh_maxscale(true, "rm -rf /var/lib/maxscale/passwd"); - Test->ssh_maxscale(true, "rm -rf /var/lib/maxscale/maxadmin-users"); - Test->restart_maxscale(); + Test->maxscales->ssh_node_f(0, true, "rm -rf /var/lib/maxscale/passwd"); + Test->maxscales->ssh_node_f(0, true, "rm -rf /var/lib/maxscale/maxadmin-users"); + Test->maxscales->restart_maxscale(0); Test->tprintf("trying maxadmin without 'root'\n"); - int st1 = Test->ssh_maxscale(false, "maxadmin show users"); + int st1 = Test->maxscales->ssh_node_f(0, false, "maxadmin show users"); Test->tprintf("exit code is: %d\n", st1); if (st1 == 0) { @@ -123,7 +127,7 @@ int main(int argc, char *argv[]) } Test->tprintf("trying maxadmin with 'root'\n"); - char * st2 = Test->ssh_maxscale_output(true, "maxadmin show users"); + char * st2 = Test->maxscales->ssh_node_output_f(0, true, &exit_code, "maxadmin show users"); Test->tprintf("Result: \n %s\n", st2); if (strstr(st2, only_root) == NULL) { @@ -133,17 +137,18 @@ int main(int argc, char *argv[]) add_remove_maxadmin_user(Test); Test->tprintf("trying long wierd user\n"); - char * st10 = Test->ssh_maxscale_output(true, - "maxadmin enable account yygrgtrпрекури6н33имн756ККККЕН:УИГГГГ*?:*:*fj34oru34h275g23457g2v90590+u764gv56837fbv62381§SDFERGtrg45ergfergergefewfergt456ty"); + char * st10 = Test->maxscales->ssh_node_output(0, + "maxadmin enable account yygrgtrпрекури6н33имн756ККККЕН:УИГГГГ*?:*:*fj34oru34h275g23457g2v90590+u764gv56837fbv62381§SDFERGtrg45ergfergergefewfergt456ty", + true, &exit_code); /*Test->tprintf("Result: %s\n", st10); if (strstr(st10, "has been successfully added") == NULL) { Test->add_result(1, "Wrong list of MaxAdmin users\n"); }*/ - Test->check_maxscale_alive(); - Test->ssh_maxscale(true, "rm -rf /var/lib/maxscale/passwd"); - Test->ssh_maxscale(true, "rm -rf /var/lib/maxscale/maxadmin-users"); + Test->check_maxscale_alive(0); + Test->maxscales->ssh_node_f(0, true, "rm -rf /var/lib/maxscale/passwd"); + Test->maxscales->ssh_node_f(0, true, "rm -rf /var/lib/maxscale/maxadmin-users"); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs781_binlog_wrong_passwrd.cpp b/maxscale-system-test/mxs781_binlog_wrong_passwrd.cpp index 72b93d32a..95a77c18a 100644 --- a/maxscale-system-test/mxs781_binlog_wrong_passwrd.cpp +++ b/maxscale-system-test/mxs781_binlog_wrong_passwrd.cpp @@ -31,11 +31,12 @@ int main(int argc, char *argv[]) Test->tprintf("Connecting to all backend nodes\n"); Test->add_result(Test->repl->connect(), "Connecting to backed failed\n"); - Test->prepare_binlog(); + Test->prepare_binlog(0); Test->tprintf("Connecting to MaxScale binlog router (with any DB)\n"); Test->set_timeout(30); - MYSQL * binlog = open_conn_no_db(Test->binlog_port, Test->maxscale_IP, Test->repl->user_name, + MYSQL * binlog = open_conn_no_db(Test->maxscales->binlog_port[0], Test->maxscales->IP[0], + Test->repl->user_name, Test->repl->password, Test->ssl); Test->add_result(mysql_errno(binlog), "Error connection to binlog router %s\n", mysql_error(binlog)); @@ -71,4 +72,3 @@ int main(int argc, char *argv[]) delete Test; return rval; } - diff --git a/maxscale-system-test/mxs812_1.cpp b/maxscale-system-test/mxs812_1.cpp index d1d564f6d..e3c95b5cc 100644 --- a/maxscale-system-test/mxs812_1.cpp +++ b/maxscale-system-test/mxs812_1.cpp @@ -15,7 +15,7 @@ void run_test(TestConnections *Test, size_t size, int chunks) { char *insert_stmt = (char *) "INSERT INTO long_blob_table(x, b) VALUES(1, ?)"; - MYSQL *conn = Test->conn_rwsplit; + MYSQL *conn = Test->maxscales->conn_rwsplit[0]; MYSQL_STMT * stmt = mysql_stmt_init(conn); Test->tprintf("Preparing statement"); @@ -51,7 +51,7 @@ void run_test(TestConnections *Test, size_t size, int chunks) Test->stop_timeout(); sleep(5); - Test->check_current_operations(0); + Test->check_current_operations(0, 0); Test->tprintf("Closing statement"); Test->add_result(mysql_stmt_close(stmt), "Error closing stmt\n"); } @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) Test->try_query(Test->repl->nodes[0], (char*)"DROP TABLE IF EXISTS long_blob_table"); Test->try_query(Test->repl->nodes[0], (char*)"CREATE TABLE long_blob_table(x INT, b LONGBLOB)"); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->tprintf("Starting test"); for (int i = 0; i < iter; i++) { diff --git a/maxscale-system-test/mxs812_2.cpp b/maxscale-system-test/mxs812_2.cpp index 7c99d47e8..a5b2309a5 100644 --- a/maxscale-system-test/mxs812_2.cpp +++ b/maxscale-system-test/mxs812_2.cpp @@ -45,7 +45,7 @@ void* test_thr(void *data) while (running) { - MYSQL *mysql = Test->open_rwsplit_connection(); + MYSQL *mysql = Test->maxscales->open_rwsplit_connection(0); for (int i = 0; i < 3; i++) { @@ -91,8 +91,8 @@ int main(int argc, char *argv[]) Test->stop_timeout(); sleep(5); - Test->check_maxscale_alive(); - Test->check_current_operations(0); + Test->check_maxscale_alive(0); + Test->check_current_operations(0, 0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs813_long_hostname.cpp b/maxscale-system-test/mxs813_long_hostname.cpp index b7ab8d63d..039868a77 100644 --- a/maxscale-system-test/mxs813_long_hostname.cpp +++ b/maxscale-system-test/mxs813_long_hostname.cpp @@ -20,9 +20,10 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); - Test->start_binlog(); + Test->start_binlog(0); - MYSQL * binlog = open_conn_no_db(Test->binlog_port, Test->maxscale_IP, Test->repl->user_name, + MYSQL * binlog = open_conn_no_db(Test->maxscales->binlog_port[0], Test->maxscales->IP[0], + Test->repl->user_name, Test->repl->password, Test->ssl); Test->tprintf("stop slave\n"); @@ -40,7 +41,7 @@ int main(int argc, char *argv[]) mysql_close(binlog); - Test->check_maxscale_processes(1); + Test->check_maxscale_processes(0, 1); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/mxs822_maxpasswd.cpp b/maxscale-system-test/mxs822_maxpasswd.cpp index 483fab4b7..6340c68ee 100644 --- a/maxscale-system-test/mxs822_maxpasswd.cpp +++ b/maxscale-system-test/mxs822_maxpasswd.cpp @@ -20,25 +20,26 @@ void try_password(TestConnections* Test, char * pass) /** * Create the user */ - Test->connect_maxscale(); - execute_query_silent(Test->conn_rwsplit, "DROP USER 'test'@'%'"); - execute_query(Test->conn_rwsplit, "CREATE USER 'test'@'%%' IDENTIFIED BY '%s'", pass); - execute_query(Test->conn_rwsplit, "GRANT ALL ON *.* TO 'test'@'%%'"); - Test->close_maxscale_connections(); + Test->maxscales->connect_maxscale(0); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "DROP USER 'test'@'%'"); + execute_query(Test->maxscales->conn_rwsplit[0], "CREATE USER 'test'@'%%' IDENTIFIED BY '%s'", pass); + execute_query(Test->maxscales->conn_rwsplit[0], "GRANT ALL ON *.* TO 'test'@'%%'"); + Test->maxscales->close_maxscale_connections(0); /** * Encrypt and change the password */ Test->tprintf("Encrypting password: %s", pass); Test->set_timeout(30); - int rc = Test->ssh_maxscale(true, "maxpasswd /var/lib/maxscale/ '%s' | tr -dc '[:xdigit:]' > /tmp/pw.txt && " - "sed -i 's/user=.*/user=test/' /etc/maxscale.cnf && " - "sed -i \"s/passwd=.*/passwd=$(cat /tmp/pw.txt)/\" /etc/maxscale.cnf && " - "service maxscale restart && " - "sleep 3 && " - "sed -i 's/user=.*/user=maxskysql/' /etc/maxscale.cnf && " - "sed -i 's/passwd=.*/passwd=skysql/' /etc/maxscale.cnf && " - "service maxscale restart", pass); + int rc = Test->maxscales->ssh_node_f(0, true, + "maxpasswd /var/lib/maxscale/ '%s' | tr -dc '[:xdigit:]' > /tmp/pw.txt && " + "sed -i 's/user=.*/user=test/' /etc/maxscale.cnf && " + "sed -i \"s/passwd=.*/passwd=$(cat /tmp/pw.txt)/\" /etc/maxscale.cnf && " + "service maxscale restart && " + "sleep 3 && " + "sed -i 's/user=.*/user=maxskysql/' /etc/maxscale.cnf && " + "sed -i 's/passwd=.*/passwd=skysql/' /etc/maxscale.cnf && " + "service maxscale restart", pass); Test->add_result(rc, "Failed to encrypt password '%s'", pass); sleep(3); @@ -49,14 +50,14 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(30); - Test->ssh_maxscale(true, "maxkeys"); - Test->ssh_maxscale(true, "sudo chown maxscale:maxscale /var/lib/maxscale/.secrets"); + Test->maxscales->ssh_node_f(0, true, "maxkeys"); + Test->maxscales->ssh_node_f(0, true, "sudo chown maxscale:maxscale /var/lib/maxscale/.secrets"); try_password(Test, (char *) "aaa$aaa"); try_password(Test, (char *) "#¤&"); try_password(Test, (char *) "пароль"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/mxs827_write_timeout.cpp b/maxscale-system-test/mxs827_write_timeout.cpp index 659c2d0d0..141a6837b 100644 --- a/maxscale-system-test/mxs827_write_timeout.cpp +++ b/maxscale-system-test/mxs827_write_timeout.cpp @@ -16,23 +16,23 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(10); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); - Test->try_query(Test->conn_rwsplit, "SET wait_timeout=20"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "SET wait_timeout=20"); - create_t1(Test->conn_rwsplit); + create_t1(Test->maxscales->conn_rwsplit[0]); for (int i = 0; i < 30; i++) { Test->tprintf("Trying query %d\n", i); Test->set_timeout(10); - Test->try_query(Test->conn_rwsplit, "SELECT 1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "SELECT 1"); sleep(1); } - Test->try_query(Test->conn_rwsplit, "INSERT INTO t1 VALUES (1, 1)"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "INSERT INTO t1 VALUES (1, 1)"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mxs874_slave_recovery.cpp b/maxscale-system-test/mxs874_slave_recovery.cpp index 0e6d60805..f6d976093 100644 --- a/maxscale-system-test/mxs874_slave_recovery.cpp +++ b/maxscale-system-test/mxs874_slave_recovery.cpp @@ -21,10 +21,10 @@ int main(int argc, char *argv[]) TestConnections test(argc, argv); test.set_timeout(10); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.set_timeout(10); - test.try_query(test.conn_rwsplit, (char *) "SET @a=1"); + test.try_query(test.maxscales->conn_rwsplit[0], (char *) "SET @a=1"); test.stop_timeout(); sleep(1); test.set_timeout(20); @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) for (retries = 0; retries < 10; retries++) { char server1_status[256]; - test.get_maxadmin_param((char *) "show server server2", (char *) "Status", server1_status); + test.maxscales->get_maxadmin_param(0, (char *) "show server server2", (char *) "Status", server1_status); if (strstr(server1_status, "Running")) { break; @@ -62,20 +62,20 @@ int main(int argc, char *argv[]) int real_id = test.repl->get_server_id(1); char server_id[200] = ""; - find_field(test.conn_rwsplit, "SELECT @@server_id", "@@server_id", server_id); + find_field(test.maxscales->conn_rwsplit[0], "SELECT @@server_id", "@@server_id", server_id); int queried_id = atoi(server_id); test.add_result(queried_id != real_id, "The query server ID '%d' does not match the one from server '%d'. " "Slave was not recovered.", queried_id, real_id); char userval[200] = ""; - find_field(test.conn_rwsplit, "SELECT @a", "@a", userval); + find_field(test.maxscales->conn_rwsplit[0], "SELECT @a", "@a", userval); test.add_result(atoi(userval) != 1, "User variable @a is not 1, it is '%s'", userval); test.tprintf("Unblocking second slave\n"); test.repl->unblock_node(2); - test.check_maxscale_alive(); + test.check_maxscale_alive(0); return test.global_result; } diff --git a/maxscale-system-test/mxs922_bad_server.cpp b/maxscale-system-test/mxs922_bad_server.cpp index a1411a946..066f49734 100644 --- a/maxscale-system-test/mxs922_bad_server.cpp +++ b/maxscale-system-test/mxs922_bad_server.cpp @@ -15,8 +15,8 @@ void add_servers(TestConnections *test) for (int i = 0; i < 4; i++) { - test->ssh_maxscale(true, "maxadmin add server server%d " MONITOR_NAME, i + 1); - test->ssh_maxscale(true, "maxadmin add server server%d " SERVICE_NAME, i + 1); + test->maxscales->ssh_node_f(0, true, "maxadmin add server server%d " MONITOR_NAME, i + 1); + test->maxscales->ssh_node_f(0, true, "maxadmin add server server%d " SERVICE_NAME, i + 1); } test->stop_timeout(); } @@ -28,8 +28,8 @@ void remove_servers(TestConnections *test) for (int i = 0; i < 4; i++) { - test->ssh_maxscale(true, "maxadmin remove server server%d " MONITOR_NAME, i + 1); - test->ssh_maxscale(true, "maxadmin remove server server%d " SERVICE_NAME, i + 1); + test->maxscales->ssh_node_f(0, true, "maxadmin remove server server%d " MONITOR_NAME, i + 1); + test->maxscales->ssh_node_f(0, true, "maxadmin remove server server%d " SERVICE_NAME, i + 1); } test->stop_timeout(); } @@ -41,7 +41,7 @@ void destroy_servers(TestConnections *test) for (int i = 0; i < 4; i++) { - test->ssh_maxscale(true, "maxadmin destroy server server%d", i + 1); + test->maxscales->ssh_node_f(0, true, "maxadmin destroy server server%d", i + 1); } test->stop_timeout(); } @@ -51,16 +51,16 @@ void do_query(TestConnections *test, bool should_fail) test->tprintf("Trying to query, expecting %s", should_fail ? "failure" : "success"); test->set_timeout(120); - test->connect_maxscale(); + test->maxscales->connect_maxscale(0); - bool failed = execute_query(test->conn_rwsplit, "select @@server_id") == 0; + bool failed = execute_query(test->maxscales->conn_rwsplit[0], "select @@server_id") == 0; const char *msg = should_fail ? "Query was successful when failure was expected." : "Query failed when success was expected."; test->add_result(failed == should_fail, msg); - test->close_maxscale_connections(); + test->maxscales->close_maxscale_connections(0); test->stop_timeout(); } @@ -73,8 +73,8 @@ int main(int argc, char *argv[]) for (int i = 0; i < 4; i++) { - test->ssh_maxscale(true, "maxadmin create server server%d 3306 %s", - i + 1, test->repl->IP[i]); + test->maxscales->ssh_node_f(0, true, "maxadmin create server server%d 3306 %s", + i + 1, test->repl->IP[i]); } /** Add the servers to the monitor and service */ @@ -89,7 +89,8 @@ int main(int argc, char *argv[]) test->tprintf("Create the servers with correct parameters"); for (int i = 0; i < 4; i++) { - test->ssh_maxscale(true, "maxadmin create server server%d %s %d", i + 1, test->repl->IP[i], test->repl->port[i]); + test->maxscales->ssh_node_f(0, true, "maxadmin create server server%d %s %d", i + 1, test->repl->IP[i], + test->repl->port[i]); } /** Add the servers again */ @@ -106,7 +107,7 @@ int main(int argc, char *argv[]) do_query(test, true); - test->check_maxscale_processes(1); + test->check_maxscale_processes(0, 1); int rval = test->global_result; delete test; return rval; diff --git a/maxscale-system-test/mxs922_double_listener.cpp b/maxscale-system-test/mxs922_double_listener.cpp index f9610d3a5..83d03889a 100644 --- a/maxscale-system-test/mxs922_double_listener.cpp +++ b/maxscale-system-test/mxs922_double_listener.cpp @@ -13,14 +13,14 @@ int main(int argc, char *argv[]) config.create_all_listeners(); config.create_all_listeners(); - test->check_maxscale_processes(1); + test->check_maxscale_processes(0, 1); config.create_monitor("mysql-monitor", "mysqlmon", 500); config.reset(); sleep(1); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); int rval = test->global_result; delete test; return rval; diff --git a/maxscale-system-test/mxs922_listener_ssl.cpp b/maxscale-system-test/mxs922_listener_ssl.cpp index 53fef7d73..92e5feb69 100644 --- a/maxscale-system-test/mxs922_listener_ssl.cpp +++ b/maxscale-system-test/mxs922_listener_ssl.cpp @@ -15,16 +15,17 @@ int main(int argc, char *argv[]) config.reset(); sleep(1); - test->connect_maxscale(); - test->try_query(test->conn_rwsplit, "select @@server_id") == 0; + test->maxscales->connect_maxscale(0); + test->try_query(test->maxscales->conn_rwsplit[0], "select @@server_id") == 0; config.create_ssl_listener(Config::SERVICE_RCONN_SLAVE); - MYSQL *conn = open_conn(test->readconn_master_port, test->maxscale_IP, test->maxscale_user, - test->maxscale_password, true); + 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"); mysql_close(conn); - test->check_maxscale_processes(1); + test->check_maxscale_processes(0, 1); int rval = test->global_result; delete test; return rval; diff --git a/maxscale-system-test/mxs922_monitor.cpp b/maxscale-system-test/mxs922_monitor.cpp index 0d3abb9fd..979d6037e 100644 --- a/maxscale-system-test/mxs922_monitor.cpp +++ b/maxscale-system-test/mxs922_monitor.cpp @@ -18,38 +18,38 @@ int main(int argc, char *argv[]) sleep(1); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); config.destroy_monitor("mysql-monitor"); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); - test->ssh_maxscale(true, "for i in 0 1 2 3; do maxadmin clear server server$i running; done"); + test->maxscales->ssh_node(0, "for i in 0 1 2 3; do maxadmin clear server server$i running; done", true); - test->add_result(test->connect_maxscale() == 0, "Should not be able to connect"); + test->add_result(test->maxscales->connect_maxscale(0) == 0, "Should not be able to connect"); config.create_monitor("mysql-monitor2", "mysqlmon", 500); config.add_created_servers("mysql-monitor2"); sleep(1); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); /** Try to alter the monitor user */ - test->connect_maxscale(); - execute_query(test->conn_rwsplit, "DROP USER 'test'@'%%'"); - execute_query(test->conn_rwsplit, "CREATE USER 'test'@'%%' IDENTIFIED BY 'test'"); - execute_query(test->conn_rwsplit, "GRANT ALL ON *.* TO 'test'@'%%'"); - test->close_maxscale_connections(); + test->maxscales->connect_maxscale(0); + execute_query(test->maxscales->conn_rwsplit[0], "DROP USER 'test'@'%%'"); + execute_query(test->maxscales->conn_rwsplit[0], "CREATE USER 'test'@'%%' IDENTIFIED BY 'test'"); + execute_query(test->maxscales->conn_rwsplit[0], "GRANT ALL ON *.* TO 'test'@'%%'"); + test->maxscales->close_maxscale_connections(0); config.alter_monitor("mysql-monitor2", "user", "test"); config.alter_monitor("mysql-monitor2", "password", "test"); sleep(1); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); /** Remove the user */ - test->connect_maxscale(); - execute_query(test->conn_rwsplit, "DROP USER 'test'@'%%'"); + test->maxscales->connect_maxscale(0); + execute_query(test->maxscales->conn_rwsplit[0], "DROP USER 'test'@'%%'"); config.restart_monitors(); @@ -58,12 +58,12 @@ int main(int argc, char *argv[]) * monitor is running if the states have changed and the query is * successful. */ - test->ssh_maxscale(true, "for i in 0 1 2 3; do maxadmin clear server server$i running; done"); + test->maxscales->ssh_node(0, "for i in 0 1 2 3; do maxadmin clear server server$i running; done", true); sleep(1); - test->add_result(execute_query_silent(test->conn_rwsplit, "SELECT 1") == 0, + test->add_result(execute_query_silent(test->maxscales->conn_rwsplit[0], "SELECT 1") == 0, "Query should fail when monitor has wrong credentials"); - test->close_maxscale_connections(); + test->maxscales->close_maxscale_connections(0); for (int i = 0; i < test->repl->N; i++) { @@ -73,9 +73,9 @@ int main(int argc, char *argv[]) config.restart_monitors(); sleep(1); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); - test->check_log_err("Fatal", false); + test->check_log_err(0, "Fatal", false); int rval = test->global_result; delete test; return rval; diff --git a/maxscale-system-test/mxs922_restart.cpp b/maxscale-system-test/mxs922_restart.cpp index 1ccca79d5..282f759ac 100644 --- a/maxscale-system-test/mxs922_restart.cpp +++ b/maxscale-system-test/mxs922_restart.cpp @@ -17,10 +17,10 @@ void add_servers(TestConnections *test) for (int i = 0; i < 4; i++) { test->set_timeout(120); - test->ssh_maxscale(true, "maxadmin add server server%d " MONITOR_NAME, i + 1); - test->ssh_maxscale(true, "maxadmin add server server%d " SERVICE_NAME1, i + 1); - test->ssh_maxscale(true, "maxadmin add server server%d " SERVICE_NAME2, i + 1); - test->ssh_maxscale(true, "maxadmin add server server%d " SERVICE_NAME3, i + 1); + test->maxscales->ssh_node_f(0, true, "maxadmin add server server%d " MONITOR_NAME, i + 1); + test->maxscales->ssh_node_f(0, true, "maxadmin add server server%d " SERVICE_NAME1, i + 1); + test->maxscales->ssh_node_f(0, true, "maxadmin add server server%d " SERVICE_NAME2, i + 1); + test->maxscales->ssh_node_f(0, true, "maxadmin add server server%d " SERVICE_NAME3, i + 1); test->stop_timeout(); } } @@ -30,16 +30,16 @@ void do_query(TestConnections *test, bool should_fail) test->tprintf("Trying to query, expecting %s", should_fail ? "failure" : "success"); test->set_timeout(120); - test->connect_maxscale(); + test->maxscales->connect_maxscale(0); - bool failed = execute_query(test->conn_rwsplit, "select @@server_id") == 0; + bool failed = execute_query(test->maxscales->conn_rwsplit[0], "select @@server_id") == 0; const char *msg = should_fail ? "Query was successful when failure was expected." : "Query failed when success was expected."; test->add_result(failed == should_fail, msg); - test->close_maxscale_connections(); + test->maxscales->close_maxscale_connections(0); test->stop_timeout(); } @@ -52,7 +52,7 @@ int main(int argc, char *argv[]) for (int i = 0; i < 4; i++) { - test->ssh_maxscale(true, "maxadmin create server server%d %s", i + 1, test->repl->IP[i]); + test->maxscales->ssh_node_f(0, true, "maxadmin create server server%d %s", i + 1, test->repl->IP[i]); } /** Add the servers again */ @@ -65,13 +65,13 @@ int main(int argc, char *argv[]) test->tprintf("Restarting MaxScale"); - test->restart_maxscale(); + test->maxscales->restart_maxscale(0); sleep(2); do_query(test, false); - test->check_maxscale_alive(); - test->check_log_err("Fatal", false); + test->check_maxscale_alive(0); + test->check_log_err(0, "Fatal", false); int rval = test->global_result; delete test; return rval; diff --git a/maxscale-system-test/mxs922_scaling.cpp b/maxscale-system-test/mxs922_scaling.cpp index 9f79d70c9..d8201051b 100644 --- a/maxscale-system-test/mxs922_scaling.cpp +++ b/maxscale-system-test/mxs922_scaling.cpp @@ -12,7 +12,7 @@ void* query_thread(void *data) { TestConnections *test = static_cast(data); - MYSQL *mysql = test->open_rwsplit_connection(); + MYSQL *mysql = test->maxscales->open_rwsplit_connection(0); my_bool yes = true; mysql_options(mysql, MYSQL_OPT_RECONNECT, &yes); @@ -85,8 +85,8 @@ int main(int argc, char *argv[]) sleep(1); - test->check_maxscale_alive(); - test->check_log_err("Fatal", false); + test->check_maxscale_alive(0); + test->check_log_err(0, "Fatal", false); int rval = test->global_result; delete test; return rval; diff --git a/maxscale-system-test/mxs922_server.cpp b/maxscale-system-test/mxs922_server.cpp index f5f150acf..d8009647b 100644 --- a/maxscale-system-test/mxs922_server.cpp +++ b/maxscale-system-test/mxs922_server.cpp @@ -8,14 +8,14 @@ int check_server_id(TestConnections *test, int idx) { - test->close_maxscale_connections(); - test->connect_maxscale(); + test->maxscales->close_maxscale_connections(0); + test->maxscales->connect_maxscale(0); int a = test->repl->get_server_id(idx); int b = -1; char str[1024]; - if (find_field(test->conn_rwsplit, "SELECT @@server_id", "@@server_id", str) == 0) + if (find_field(test->maxscales->conn_rwsplit[0], "SELECT @@server_id", "@@server_id", str) == 0) { b = atoi(str); } @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) config.destroy_server(1); config.destroy_server(1); config.check_server_count(0); - test->check_maxscale_processes(1); + test->check_maxscale_processes(0, 1); test->tprintf("Testing adding of server to service"); @@ -47,7 +47,7 @@ int main(int argc, char *argv[]) config.add_server(1); config.check_server_count(1); sleep(1); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); config.remove_server(1); config.destroy_server(1); config.check_server_count(0); @@ -58,11 +58,11 @@ int main(int argc, char *argv[]) config.add_server(1); config.alter_server(1, "address", test->repl->IP[1]); sleep(1); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); config.alter_server(1, "address", "This-is-not-the-address-you-are-looking-for"); config.alter_server(1, "port", 12345); - test->connect_maxscale(); - test->add_result(execute_query_silent(test->conn_rwsplit, "SELECT 1") == 0, + test->maxscales->connect_maxscale(0); + test->add_result(execute_query_silent(test->maxscales->conn_rwsplit[0], "SELECT 1") == 0, "Query with bad address should fail"); config.remove_server(1); @@ -92,7 +92,7 @@ int main(int argc, char *argv[]) config.reset(); sleep(1); - test->check_maxscale_alive(); + test->check_maxscale_alive(0); int rval = test->global_result; delete test; return rval; diff --git a/maxscale-system-test/mxs951_utfmb4.cpp b/maxscale-system-test/mxs951_utfmb4.cpp index 737a277a1..dd740c350 100644 --- a/maxscale-system-test/mxs951_utfmb4.cpp +++ b/maxscale-system-test/mxs951_utfmb4.cpp @@ -28,8 +28,8 @@ int main(int argc, char *argv[]) sprintf(cmd, "%s/utf64.cnf", test_dir); for (int i = 0; i < Test->repl->N; i++) { - Test->repl->copy_to_node(cmd, "./", i); - Test->repl->ssh_node(i, true, "cp ./utf64.cnf /etc/my.cnf.d/"); + Test->repl->copy_to_node_legacy(cmd, (char *) "./", i); + Test->repl->ssh_node(i, (char *) "cp ./utf64.cnf /etc/my.cnf.d/", true); } Test->repl->start_replication(); @@ -44,15 +44,15 @@ int main(int argc, char *argv[]) Test->set_timeout(120); Test->tprintf("Restart Maxscale"); - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); Test->stop_timeout(); Test->tprintf("Restore backend configuration\n"); for (int i = 0; i < Test->repl->N; i++) { - Test->repl->ssh_node(i, true, "rm /etc/my.cnf.d/utf64.cnf"); + Test->repl->ssh_node(i, (char *) "rm /etc/my.cnf.d/utf64.cnf", true); } Test->repl->start_replication(); diff --git a/maxscale-system-test/mxs957.cpp b/maxscale-system-test/mxs957.cpp index 0d9e653db..b9f6b40af 100644 --- a/maxscale-system-test/mxs957.cpp +++ b/maxscale-system-test/mxs957.cpp @@ -43,12 +43,12 @@ const char* queries[] = int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); for (int i = 0; queries[i]; i++) { Test->set_timeout(30); - Test->try_query(Test->conn_rwsplit, queries[i]); + Test->try_query(Test->maxscales->conn_rwsplit[0], queries[i]); } int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/mysqlmon_backup.cpp b/maxscale-system-test/mysqlmon_backup.cpp index 3fccd5e2f..49dcc1d6f 100644 --- a/maxscale-system-test/mysqlmon_backup.cpp +++ b/maxscale-system-test/mysqlmon_backup.cpp @@ -13,25 +13,25 @@ void check_master(TestConnections& test) { test.add_result(test.find_master_maxadmin(test.repl) != 0, "Node 0 is not the master"); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "INSERT INTO test.t1 VALUES (1)"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "INSERT INTO test.t1 VALUES (1)"); + test.maxscales->close_maxscale_connections(0); } void check_slave(TestConnections& test) { test.add_result(test.find_slave_maxadmin(test.repl) == -1, "No slaves found"); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "SELECT * FROM test.t1"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "SELECT * FROM test.t1"); + test.maxscales->close_maxscale_connections(0); } void kill_maxscale(TestConnections& test) { test.tprintf("Killing and restarting MaxScale"); - test.ssh_maxscale(true, "pkill -9 maxscale"); - test.start_maxscale(); + test.maxscales->ssh_node_f(0, true, "pkill -9 maxscale"); + test.maxscales->start_maxscale(0); test.tprintf("Waiting for MaxScale to start"); sleep(10); @@ -39,7 +39,7 @@ void kill_maxscale(TestConnections& test) void restart_maxscale(TestConnections& test) { - test.restart_maxscale(); + test.maxscales->restart_maxscale(0); test.tprintf("Waiting for MaxScale to start"); sleep(10); } @@ -48,9 +48,9 @@ int main(int argc, char** argv) { TestConnections test(argc, argv); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "CREATE OR REPLACE TABLE test.t1(id int)"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "CREATE OR REPLACE TABLE test.t1(id int)"); + test.maxscales->close_maxscale_connections(0); test.tprintf("Checking that node 0 is the master and slaves are OK"); check_master(test); diff --git a/maxscale-system-test/namedserverfilter.cpp b/maxscale-system-test/namedserverfilter.cpp index 0aac2c734..d83755aff 100644 --- a/maxscale-system-test/namedserverfilter.cpp +++ b/maxscale-system-test/namedserverfilter.cpp @@ -16,7 +16,7 @@ int compare_server_id(TestConnections* test, char *node_id) { char str[1024]; int rval = 0; - if (find_field(test->conn_rwsplit, "SELECT @@server_id", "@@server_id", str)) + if (find_field(test->maxscales->conn_rwsplit[0], "SELECT @@server_id", "@@server_id", str)) { test->tprintf("Failed to query for @@server_id.\n"); rval = 1; @@ -37,7 +37,7 @@ int main(int argc, char **argv) sprintf(server_id, "%d", test->repl->get_server_id(1)); test->tprintf("Server ID of server2 is: %s\n", server_id); - test->add_result(test->connect_rwsplit(), "Test failed to connect to MaxScale.\n"); + test->add_result(test->maxscales->connect_rwsplit(0), "Test failed to connect to MaxScale.\n"); test->add_result(compare_server_id(test, server_id), "Test failed, server ID was not correct.\n"); int rval = test->global_result; delete test; diff --git a/maxscale-system-test/no_password.cpp b/maxscale-system-test/no_password.cpp index 8eeac22d9..cfd36ff07 100644 --- a/maxscale-system-test/no_password.cpp +++ b/maxscale-system-test/no_password.cpp @@ -8,13 +8,13 @@ int main(int argc, char** argv) { TestConnections test(argc, argv); - MYSQL *mysql = open_conn(test.rwsplit_port, test.maxscale_IP, "testuser", NULL, false); + MYSQL *mysql = open_conn(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], "testuser", NULL, false); test.add_result(mysql_errno(mysql) == 0, "Connecting to MaxScale should fail"); test.add_result(strstr(mysql_error(mysql), "using password: NO") == NULL, "Missing (using password: NO) error message, got this instead: %s", mysql_error(mysql)); test.tprintf("MySQL error: %s", mysql_error(mysql)); mysql_close(mysql); - open_conn(test.rwsplit_port, test.maxscale_IP, "testuser", "testpassword", false); + open_conn(test.maxscales->rwsplit_port[0], test.maxscales->IP[0], "testuser", "testpassword", false); test.add_result(mysql_errno(mysql) == 0, "Connecting to MaxScale should fail"); test.add_result(strstr(mysql_error(mysql), "using password: YES") == NULL, "Missing (using password: YES) error message, got this instead: %s", mysql_error(mysql)); test.tprintf("MySQL error: %s", mysql_error(mysql)); diff --git a/maxscale-system-test/nodes.cpp b/maxscale-system-test/nodes.cpp new file mode 100644 index 000000000..c85b19dab --- /dev/null +++ b/maxscale-system-test/nodes.cpp @@ -0,0 +1,440 @@ +#include "nodes.h" +#include +#include + +Nodes::Nodes() +{ +} + +int Nodes::check_node_ssh(int node) +{ + int res = 0; + printf("Checking node %d\n", node); + fflush(stdout); + + if (ssh_node(node, (char *) "ls > /dev/null", false) != 0) + { + printf("Node %d is not available\n", node); + fflush(stdout); + res = 1; + } + else + { + printf("Node %d is OK\n", node); + fflush(stdout); + } + return res; +} + +int Nodes::check_nodes() +{ + int res = 0; + for (int i = 0; i < N; i++) + { + res += check_node_ssh(i); + } + return res; +} + +void Nodes::generate_ssh_cmd(char *cmd, int node, const char *ssh, bool sudo) +{ + if (strcmp(IP[node], "127.0.0.1") == 0) + { + if (sudo) + { + sprintf(cmd, "%s %s", + access_sudo[node], ssh); + } + else + { + sprintf(cmd, "%s", + ssh); + + } + } + else + { + + if (sudo) + { + sprintf(cmd, + "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s '%s %s\'", + sshkey[node], access_user[node], IP[node], access_sudo[node], ssh); + } + else + { + sprintf(cmd, + "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s '%s'", + sshkey[node], access_user[node], IP[node], ssh); + } + } +} + + +char* Nodes::ssh_node_output_f(int node, bool sudo, int * exit_code, const char* format, ...) +{ + va_list valist; + + va_start(valist, format); + int message_len = vsnprintf(NULL, 0, format, valist); + va_end(valist); + + if (message_len < 0) + { + return NULL; + } + + char *sys = (char*)malloc(message_len + 1); + + va_start(valist, format); + vsnprintf(sys, message_len + 1, format, valist); + va_end(valist); + + char * result = ssh_node_output(node, sys, sudo, exit_code); + free(sys); + + return result; +} + + +char * Nodes::ssh_node_output(int node, const char *ssh, bool sudo, int *exit_code) +{ + char *cmd = (char*)malloc(strlen(ssh) + 1024); + + generate_ssh_cmd(cmd, node, ssh, sudo); +//tprintf("############ssh smd %s\n:", cmd); + FILE *output = popen(cmd, "r"); + if (output == NULL) + { + printf("Error opening ssh %s\n", strerror(errno)); + return NULL; + } + char buffer[1024]; + size_t rsize = sizeof(buffer); + char* result = (char*)calloc(rsize, sizeof(char)); + + while (fgets(buffer, sizeof(buffer), output)) + { + result = (char*)realloc(result, sizeof(buffer) + rsize); + rsize += sizeof(buffer); + strcat(result, buffer); + } + + free(cmd); + int code = pclose(output); + if (WIFEXITED(code)) + { + * exit_code = WEXITSTATUS(code); + } + else + { + * exit_code = 256; + } + return result; +} + + +int Nodes::ssh_node(int node, const char *ssh, bool sudo) +{ + char *cmd = (char*)malloc(strlen(ssh) + 1024); + + if (strcmp(IP[node], "127.0.0.1") == 0) + { + printf("starting bash\n"); + sprintf(cmd, "bash"); + } + else + { + sprintf(cmd, + "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s%s", + sshkey[node], access_user[node], IP[node], verbose ? "" : " > /dev/null"); + } + 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", ssh); + rc = pclose(in); + } + + + free(cmd); + return rc; + + + if (WIFEXITED(rc)) + { + return WEXITSTATUS(rc); + } + else + { + return 256; + } +} + +int Nodes::ssh_node_f(int node, bool sudo, const char* format, ...) +{ + va_list valist; + + va_start(valist, format); + int message_len = vsnprintf(NULL, 0, format, valist); + va_end(valist); + + if (message_len < 0) + { + return -1; + } + + char *sys = (char*)malloc(message_len + 1); + + va_start(valist, format); + vsnprintf(sys, message_len + 1, format, valist); + va_end(valist); + + int result = ssh_node(node, sys, sudo); + free(sys); + return (result); + + +} + +int Nodes::copy_to_node(int i, const char* src, const char* dest) +{ + if (i >= N) + { + return 1; + } + char sys[strlen(src) + strlen(dest) + 1024]; + + if (strcmp(IP[i], "127.0.0.1") == 0) + { + sprintf(sys, "cp %s %s", + src, dest); + } + else + { + sprintf(sys, "scp -q -r -i %s -o UserKnownHostsFile=/dev/null " + "-o StrictHostKeyChecking=no -o LogLevel=quiet %s %s@%s:%s", + sshkey[i], src, access_user[i], IP[i], dest); + } + if (verbose) + { + printf("%s\n", sys); + } + + return system(sys); +} + + +int Nodes::copy_to_node_legacy(const char* src, const char* dest, int i) +{ + + return copy_to_node(i, src, dest); +} + +int Nodes::copy_from_node(int i, const char* src, const char* dest) +{ + if (i >= N) + { + return 1; + } + char sys[strlen(src) + strlen(dest) + 1024]; + if (strcmp(IP[i], "127.0.0.1") == 0) + { + sprintf(sys, "cp %s %s", + src, dest); + } + else + { + sprintf(sys, "scp -q -r -i %s -o UserKnownHostsFile=/dev/null " + "-o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s:%s %s", + sshkey[i], access_user[i], IP[i], src, dest); + } + if (verbose) + { + printf("%s\n", sys); + } + + return system(sys); +} + +int Nodes::copy_from_node_legacy(const char* src, const char* dest, int i) +{ + return copy_from_node(i, src, dest); +} + +int Nodes::read_basic_env() +{ + char * env; + char env_name[64]; + sprintf(env_name, "%s_N", prefix); + env = getenv(env_name); + if (env != NULL) + { + sscanf(env, "%d", &N); + } + else + { + N = 1; + } + + sprintf(env_name, "%s_user", prefix); + env = getenv(env_name); + if (env != NULL) + { + sscanf(env, "%s", user_name); + } + else + { + sprintf(user_name, "skysql"); + } + sprintf(env_name, "%s_password", prefix); + env = getenv(env_name); + if (env != NULL) + { + sscanf(env, "%s", password); + } + else + { + sprintf(password, "skysql"); + } + + if ((N > 0) && (N < 255)) + { + for (int i = 0; i < N; i++) + { + //reading IPs + sprintf(env_name, "%s_%03d_network", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_network", prefix); + env = getenv(env_name); + + } + if (env != NULL) + { + sprintf(IP[i], "%s", env); + } + + //reading private IPs + sprintf(env_name, "%s_%03d_private_ip", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_private_ip", prefix); + env = getenv(env_name); + } + if (env != NULL) + { + sprintf(IP_private[i], "%s", env); + } + else + { + sprintf(IP_private[i], "%s", IP[i]); + } + + //reading IPv6 + sprintf(env_name, "%s_%03d_network6", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_network6", prefix); + env = getenv(env_name); + } + if (env != NULL) + { + sprintf(IP6[i], "%s", env); + } + else + { + sprintf(IP6[i], "%s", IP[i]); + } + //reading sshkey + sprintf(env_name, "%s_%03d_keyfile", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_keyfile", prefix); + env = getenv(env_name); + } + if (env != NULL) + { + sprintf(sshkey[i], "%s", env); + } + + sprintf(env_name, "%s_%03d_whoami", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_whoami", prefix); + env = getenv(env_name); + } + + if (env != NULL) + { + sprintf(access_user[i], "%s", env); + } + else + { + sprintf(access_user[i], "vagrant"); + } + + sprintf(env_name, "%s_%03d_access_sudo", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_access_sudo", prefix); + env = getenv(env_name); + } + if (env != NULL) + { + sprintf(access_sudo[i], "%s", env); + } + else + { + sprintf(access_sudo[i], " "); + } + + if (strcmp(access_user[i], "root") == 0) + { + sprintf(access_homedir[i], "/%s/", access_user[i]); + } + else + { + sprintf(access_homedir[i], "/home/%s/", access_user[i]); + } + + sprintf(env_name, "%s_%03d_hostname", prefix, i); + env = getenv(env_name); + if (env == NULL) + { + sprintf(env_name, "%s_hostname", prefix); + env = getenv(env_name); + } + + if (env != NULL) + { + sprintf(hostname[i], "%s", env); + } + else + { + sprintf(hostname[i], "%s", IP[i]); + } + } + } + + return 0; +} + +char* Nodes::ip(int i) const +{ + return use_ipv6 ? (char*)IP6[i] : (char*)IP[i]; +} diff --git a/maxscale-system-test/nodes.h b/maxscale-system-test/nodes.h new file mode 100644 index 000000000..b961e226f --- /dev/null +++ b/maxscale-system-test/nodes.h @@ -0,0 +1,156 @@ +#ifndef NODES_H +#define NODES_H + +#include +#include +#include "mariadb_func.h" +#include +#include + +typedef std::set StringSet; + + +class Nodes +{ +public: + Nodes(); + + char IP[256][1024]; + /** + * @brief private IP address strings for every backend node (for AWS) + */ + + char IP_private[256][1024]; + /** + * @brief IP address strings for every backend node (IPv6) + */ + char IP6[256][1024]; + + /** + * @brief use_ipv6 If true IPv6 addresses will be used to connect Maxscale and backed + * Also IPv6 addresses go to maxscale.cnf + */ + bool use_ipv6; + + /** + * @brief Path to ssh key for every backend node + */ + char sshkey[256][4096]; + + /** + * @brief Number of backend nodes + */ + int N; + + /** + * @brief name of backend setup (like 'repl' or 'galera') + */ + char prefix[16]; + + /** + * @brief access_user Unix users name to access nodes via ssh + */ + char access_user[256][256]; + + /** + * @brief access_sudo empty if sudo is not needed or "sudo " if sudo is needed. + */ + char access_sudo[256][64]; + + /** + * @brief access_homedir home directory of access_user + */ + char access_homedir[256][256]; + + char hostname[256][1024]; + + /** + * @brief User name to access backend nodes + */ + char user_name[256]; + /** + * @brief Password to access backend nodes + */ + char password[256]; + + /** + * @brief Verbose command output + */ + bool verbose; + + /** + * @brief Get IP address + * + * @return The current IP address + */ + char* ip(int i) const; + + /** + * @brief Generate command line to execute command on the node via ssh + * @param cmd result + * @param index index number of the node (index) + * @param ssh command to execute + * @param sudo if true the command is executed with root privelegues + */ + void generate_ssh_cmd(char * cmd, int node, const char *ssh, bool sudo); + + /** + * @brief executes shell command on the node using ssh + * @param index number of the node (index) + * @param ssh command to execute + * @param sudo if true the command is executed with root privelegues + * @param pointer to variable to store process exit code + * @return output of the command + */ + char *ssh_node_output_f(int node, bool sudo, int * exit_code, const char* format, ...); + char *ssh_node_output(int node, const char *ssh, bool sudo, int *exit_code); + + /** + * @brief executes shell command on the node using ssh + * @param index number of the node (index) + * @param ssh command to execute + * @param sudo if true the command is executed with root privelegues + * @return exit code of the coomand + */ + int ssh_node(int node, const char *ssh, bool sudo); + int ssh_node_f(int node, bool sudo, const char* format, ...); + + /** + * @brief Copy a local file to the Node i machine + * @param src Source file on the local filesystem + * @param dest Destination file on the remote file system + * @param i Node index + * @return exit code of the system command or 1 in case of i > N + */ + int copy_to_node_legacy(const char* src, const char* dest, int i); + int copy_to_node(int i, const char* src, const char* dest); + + /** + * @brief Copy a local file to the Node i machine + * @param src Source file on the remote filesystem + * @param dest Destination file on the local file system + * @param i Node index + * @return exit code of the system command or 1 in case of i > N + */ + int copy_from_node_legacy(const char* src, const char* dest, int i); + int copy_from_node(int i, const char* src, const char* dest); + + /** + * @brief Check node via ssh and restart it if it is not resposible + * @param node Node index + * @return 0 if node is ok, 1 if start failed + */ + int check_nodes(); + + /** + * @brief read_basic_env Read IP, sshkey, etc - common parameters for all kinds of nodes + * @return 0 in case of success + */ + int read_basic_env(); + +private: + int check_node_ssh(int node); + +}; + +#endif // NODES_H diff --git a/maxscale-system-test/nsfilter.py b/maxscale-system-test/nsfilter.py new file mode 100755 index 000000000..329be7886 --- /dev/null +++ b/maxscale-system-test/nsfilter.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python + +import maxpython + +test = maxpython.MaxScaleTest("nsfilter") + +server_id = [] + +for conn in test.repl: + server_id[conn] = conn.query("SELECT @@server_id") + +nomatch = test.maxscale['rwsplit'].query("SELECT @@server_id") +match = test.maxscale['rwsplit'].query("SELECT \"test\", @@server_id") + +print(nomatch) +print(match) diff --git a/maxscale-system-test/open_close_connections.cpp b/maxscale-system-test/open_close_connections.cpp index 6dca01fa5..ec7e9da75 100644 --- a/maxscale-system-test/open_close_connections.cpp +++ b/maxscale-system-test/open_close_connections.cpp @@ -34,8 +34,8 @@ int main(int argc, char *argv[]) // Tuning these kernel parameters removes any system limitations on how many // connections can be created within a short period - Test->ssh_maxscale(true, "sysctl net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_tw_recycle=1 " - "net.core.somaxconn=10000 net.ipv4.tcp_max_syn_backlog=10000"); + Test->maxscales->ssh_node_f(0, true, "sysctl net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_tw_recycle=1 " + "net.core.somaxconn=10000 net.ipv4.tcp_max_syn_backlog=10000"); Test->repl->execute_query_all_nodes((char *) "set global max_connections = 50000;"); Test->repl->sync_slaves(); @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) pthread_join(thread1[i], NULL); } - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; @@ -73,15 +73,15 @@ void *query_thread1( void *ptr ) while (data->exit_flag == 0 && data->Test->global_result == 0) { - MYSQL *conn1 = data->Test->open_rwsplit_connection(); + MYSQL *conn1 = data->Test->maxscales->open_rwsplit_connection(0); data->Test->add_result(mysql_errno(conn1), "Error opening RWsplit conn, thread num is %d, iteration %d, error is: %s\n", data->thread_id, data->i, mysql_error(conn1)); - MYSQL *conn2 = data->Test->open_readconn_master_connection(); + MYSQL *conn2 = data->Test->maxscales->open_readconn_master_connection(0); data->Test->add_result(mysql_errno(conn2), "Error opening ReadConn master conn, thread num is %d, iteration %d, error is: %s\n", data->thread_id, data->i, mysql_error(conn2)); - MYSQL *conn3 = data->Test->open_readconn_slave_connection(); + MYSQL *conn3 = data->Test->maxscales->open_readconn_slave_connection(0); data->Test->add_result(mysql_errno(conn3), "Error opening ReadConn master conn, thread num is %d, iteration %d, error is: %s\n", data->thread_id, data->i, mysql_error(conn3)); diff --git a/maxscale-system-test/pers_01.cpp b/maxscale-system-test/pers_01.cpp index b894875c9..b859868d7 100644 --- a/maxscale-system-test/pers_01.cpp +++ b/maxscale-system-test/pers_01.cpp @@ -41,7 +41,7 @@ void check_pers_conn(TestConnections* Test, int pers_conn_expected[], char * ser for (int i = 0; i < 4; i++) { sprintf(str, "show server %s%d", server, i + 1); - Test->get_maxadmin_param(str, (char *) "Persistent measured pool size:", result); + Test->maxscales->get_maxadmin_param(0, str, (char *) "Persistent measured pool size:", result); Test->tprintf("%s: %s\n", str, result); sscanf(result, "%d", &pers_conn[i]); if (pers_conn[i] != pers_conn_expected[i]) @@ -69,7 +69,7 @@ int main(int argc, char *argv[]) galera_pers_conn_expected[2] = 0; galera_pers_conn_expected[3] = 0; - Test->add_result(Test->create_connections(70, true, true, true, true), + Test->add_result(Test->create_connections(0, 70, true, true, true, true), "Error creating connections"); sleep(5); Test->set_timeout(20); diff --git a/maxscale-system-test/pers_02.cpp b/maxscale-system-test/pers_02.cpp index 511e12497..d626c6019 100644 --- a/maxscale-system-test/pers_02.cpp +++ b/maxscale-system-test/pers_02.cpp @@ -22,22 +22,21 @@ int main(int argc, char *argv[]) Test->set_timeout(60); Test->repl->execute_query_all_nodes((char *) "set global max_connections = 20;"); - Test->create_connections(75, true, true, true, true); + Test->create_connections(0, 75, true, true, true, true); Test->stop_timeout(); - Test->repl->close_connections(); Test->repl->stop_nodes(); Test->repl->start_replication(); - Test->repl->connect(); + Test->repl->close_connections(); Test->repl->sync_slaves(); Test->set_timeout(60); Test->repl->execute_query_all_nodes((char *) "set global max_connections = 2000;"); - Test->add_result(Test->create_connections(70 , true, true, true, true), + Test->add_result(Test->create_connections(0, 70 , true, true, true, true), "Connections creation error \n"); - Test->check_log_err((char *) "fatal signal 11", false); - Test->check_maxscale_alive(); + Test->check_log_err(0, (char *) "fatal signal 11", false); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; diff --git a/maxscale-system-test/prepared_statement.cpp b/maxscale-system-test/prepared_statement.cpp index d98b00bc7..5b4d34bfe 100644 --- a/maxscale-system-test/prepared_statement.cpp +++ b/maxscale-system-test/prepared_statement.cpp @@ -22,19 +22,19 @@ void test_basic(TestConnections& test) int N = 4; test.repl->connect(); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); - create_t1(test.conn_rwsplit); - insert_into_t1(test.conn_rwsplit, N); + create_t1(test.maxscales->conn_rwsplit[0]); + insert_into_t1(test.maxscales->conn_rwsplit[0], N); test.set_timeout(20); - test.try_query(test.conn_rwsplit, "PREPARE stmt FROM 'SELECT * FROM t1 WHERE fl=@x;';"); - test.try_query(test.conn_rwsplit, "SET @x = 3;"); - test.try_query(test.conn_rwsplit, "EXECUTE stmt"); - test.try_query(test.conn_rwsplit, "SET @x = 4;"); - test.try_query(test.conn_rwsplit, "EXECUTE stmt"); + test.try_query(test.maxscales->conn_rwsplit[0], "PREPARE stmt FROM 'SELECT * FROM t1 WHERE fl=@x;';"); + test.try_query(test.maxscales->conn_rwsplit[0], "SET @x = 3;"); + test.try_query(test.maxscales->conn_rwsplit[0], "EXECUTE stmt"); + test.try_query(test.maxscales->conn_rwsplit[0], "SET @x = 4;"); + test.try_query(test.maxscales->conn_rwsplit[0], "EXECUTE stmt"); - test.check_maxscale_alive(); + test.check_maxscale_alive(0); test.stop_timeout(); } @@ -43,12 +43,12 @@ void test_routing(TestConnections& test) test.set_timeout(60); test.repl->connect(); int server_id = test.repl->get_server_id(0); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); // Test that reads are routed to slaves char buf[1024] = "-1"; - test.try_query(test.conn_rwsplit, "PREPARE ps1 FROM 'SELECT @@server_id'"); - test.add_result(find_field(test.conn_rwsplit, "EXECUTE ps1", "@@server_id", buf), + test.try_query(test.maxscales->conn_rwsplit[0], "PREPARE ps1 FROM 'SELECT @@server_id'"); + test.add_result(find_field(test.maxscales->conn_rwsplit[0], "EXECUTE ps1", "@@server_id", buf), "Execute should succeed"); int res = atoi(buf); test.add_result(res == server_id, "Query should be routed to a slave (got %d, master is %d)", res, server_id); @@ -56,36 +56,36 @@ void test_routing(TestConnections& test) // Test reads inside transactions are routed to master strcpy(buf, "-1"); - test.try_query(test.conn_rwsplit, "BEGIN"); - test.add_result(find_field(test.conn_rwsplit, "EXECUTE ps1", "@@server_id", buf), + test.try_query(test.maxscales->conn_rwsplit[0], "BEGIN"); + test.add_result(find_field(test.maxscales->conn_rwsplit[0], "EXECUTE ps1", "@@server_id", buf), "Execute should succeed"); res = atoi(buf); test.add_result(res != server_id, "Query should be routed to master inside a transaction (got %d, master is %d)", res, server_id); - test.try_query(test.conn_rwsplit, "COMMIT"); + test.try_query(test.maxscales->conn_rwsplit[0], "COMMIT"); // Test reads inside read-only transactions are routed slaves strcpy(buf, "-1"); - test.try_query(test.conn_rwsplit, "START TRANSACTION READ ONLY"); - test.add_result(find_field(test.conn_rwsplit, "EXECUTE ps1", "@@server_id", buf), + test.try_query(test.maxscales->conn_rwsplit[0], "START TRANSACTION READ ONLY"); + test.add_result(find_field(test.maxscales->conn_rwsplit[0], "EXECUTE ps1", "@@server_id", buf), "Execute should succeed"); res = atoi(buf); test.add_result(res == server_id, "Query should be routed to a slave inside a read-only transaction (got %d, master is %d)", res, server_id); - test.try_query(test.conn_rwsplit, "COMMIT"); + test.try_query(test.maxscales->conn_rwsplit[0], "COMMIT"); // Test prepared statements that modify data strcpy(buf, "-1"); - test.try_query(test.conn_rwsplit, "CREATE OR REPLACE TABLE test.t1 (id INT)"); - test.try_query(test.conn_rwsplit, "PREPARE ps2 FROM 'INSERT INTO test.t1 VALUES (?)'"); - test.try_query(test.conn_rwsplit, "SET @a = 1"); - test.try_query(test.conn_rwsplit, "EXECUTE ps2 USING @a"); + test.try_query(test.maxscales->conn_rwsplit[0], "CREATE OR REPLACE TABLE test.t1 (id INT)"); + test.try_query(test.maxscales->conn_rwsplit[0], "PREPARE ps2 FROM 'INSERT INTO test.t1 VALUES (?)'"); + test.try_query(test.maxscales->conn_rwsplit[0], "SET @a = 1"); + test.try_query(test.maxscales->conn_rwsplit[0], "EXECUTE ps2 USING @a"); test.repl->sync_slaves(); - test.add_result(find_field(test.conn_rwsplit, "SELECT id FROM test.t1", "id", buf), + test.add_result(find_field(test.maxscales->conn_rwsplit[0], "SELECT id FROM test.t1", "id", buf), "Read should succeed"); res = atoi(buf); test.add_result(res != server_id, "Writes should be routed to the master (got %d, master is %d)", res, server_id); // Cleanup - test.check_maxscale_alive(); + test.check_maxscale_alive(0); test.stop_timeout(); } diff --git a/maxscale-system-test/readconnrouter_master.cpp b/maxscale-system-test/readconnrouter_master.cpp index 5c974e1aa..19d1eaeb8 100644 --- a/maxscale-system-test/readconnrouter_master.cpp +++ b/maxscale-system-test/readconnrouter_master.cpp @@ -30,7 +30,7 @@ int check_connnections_only_to_master(TestConnections * Test, int master) printf("Checking number of connections to each node\n"); for (int i = 0; i < Test->repl->N; i++) { - conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscale_ip(), Test->maxscale_hostname, (char *) "test"); + conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscales->ip(0), Test->maxscales->hostname[0], (char *) "test"); printf("Connections to node %d (%s):\t%d\n", i, Test->repl->IP[i], conn_num); if (((i == master) && (conn_num != 1)) || ((i != master) && (conn_num != 0))) { @@ -49,13 +49,13 @@ int main(int argc, char *argv[]) Test->repl->connect(); Test->tprintf("Connecting to ReadConnnRouter in 'master' mode\n"); - Test->connect_readconn_master(); + Test->maxscales->connect_readconn_master(0); printf("Sleeping 10 seconds\n"); Test->stop_timeout(); sleep(10); Test->set_timeout(50); Test->add_result(check_connnections_only_to_master(Test, 0), "connections are not only to Master\n"); - Test->close_readconn_master(); + Test->maxscales->close_readconn_master(0); Test->tprintf("Changing master to node 1\n"); Test->set_timeout(50); Test->repl->change_master(1, 0); @@ -64,18 +64,18 @@ int main(int argc, char *argv[]) sleep(10); Test->set_timeout(50); printf("Connecting to ReadConnnRouter in 'master' mode\n"); - Test->connect_readconn_master(); + Test->maxscales->connect_readconn_master(0); printf("Sleeping 10 seconds\n"); Test->stop_timeout(); sleep(10); Test->set_timeout(50); Test->add_result(check_connnections_only_to_master(Test, 1), "connections are not only to master"); - Test->close_readconn_master(); + Test->maxscales->close_readconn_master(0); Test->set_timeout(50); printf("Changing master back to node 0\n"); Test->repl->change_master(0, 1); - Test->check_log_err((char *) "The service 'CLI' is missing a definition of the servers", false); + Test->check_log_err(0, (char *) "The service 'CLI' is missing a definition of the servers", false); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/readconnrouter_slave.cpp b/maxscale-system-test/readconnrouter_slave.cpp index 38b8d74fd..bdf86bf60 100644 --- a/maxscale-system-test/readconnrouter_slave.cpp +++ b/maxscale-system-test/readconnrouter_slave.cpp @@ -25,7 +25,7 @@ int main(int argc, char *argv[]) Test->tprintf("Creating %d connections to ReadConnRouter in 'slave' mode\n", TestConnNum); for (i = 0; i < TestConnNum; i++) { - conn[i] = Test->open_readconn_slave_connection(); + conn[i] = Test->maxscales->open_readconn_slave_connection(0); } Test->tprintf("Waiting 5 seconds\n"); sleep(5); @@ -35,14 +35,14 @@ int main(int argc, char *argv[]) int TotalConn = 0; Test->tprintf("Checking connections to Master: should be 0\n"); - conn_num = get_conn_num(Test->repl->nodes[0], Test->maxscale_ip(), Test->maxscale_hostname, (char *) "test"); + conn_num = get_conn_num(Test->repl->nodes[0], Test->maxscales->ip(0), Test->maxscales->hostname[0], (char *) "test"); Test->add_result(conn_num, "number of connections to Master is %d\n", conn_num); Test->tprintf("Number of connections to each slave should be between %d and %d\n", ConnFloor, ConnCell); Test->tprintf("Checking connections to each node\n"); for (int i = 1; i < Test->repl->N; i++) { - conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscale_ip(), Test->maxscale_hostname, (char *) "test"); + conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscales->ip(0), Test->maxscales->hostname[0], (char *) "test"); TotalConn += conn_num; printf("Connections to node %d (%s):\t%d\n", i, Test->repl->IP[i], conn_num); if ((conn_num > ConnCell) || (conn_num < ConnFloor)) diff --git a/maxscale-system-test/regexfilter1.cpp b/maxscale-system-test/regexfilter1.cpp index d01ab6698..76dbee34f 100644 --- a/maxscale-system-test/regexfilter1.cpp +++ b/maxscale-system-test/regexfilter1.cpp @@ -13,14 +13,14 @@ int main(int argc, char *argv[]) { TestConnections * test = new TestConnections(argc, argv); - test->connect_maxscale(); - test->add_result(execute_query_check_one(test->conn_rwsplit, "SELECT 123", "0"), + test->maxscales->connect_maxscale(0); + test->add_result(execute_query_check_one(test->maxscales->conn_rwsplit[0], "SELECT 123", "0"), "Query to first service should have replaced the query.\n"); - test->add_result(execute_query_check_one(test->conn_slave, "SELECT 123", "123"), + test->add_result(execute_query_check_one(test->maxscales->conn_slave[0], "SELECT 123", "123"), "Query to second service should not have replaced the query.\n"); - test->add_result(execute_query_check_one(test->conn_master, "SELECT 123", "123"), + test->add_result(execute_query_check_one(test->maxscales->conn_master[0], "SELECT 123", "123"), "Query to third service should not have replaced the query.\n"); - test->close_maxscale_connections(); + test->maxscales->close_maxscale_connections(0); int rval = test->global_result; delete test; return rval; diff --git a/maxscale-system-test/replication_manager.cpp b/maxscale-system-test/replication_manager.cpp index 0d25228cb..221c0f76c 100644 --- a/maxscale-system-test/replication_manager.cpp +++ b/maxscale-system-test/replication_manager.cpp @@ -17,13 +17,13 @@ void prepare() void get_output(TestConnections& test) { test.tprintf("Maxadmin output:"); - char *output = test.ssh_maxscale_output(true, "maxadmin list servers"); + char *output = test.maxscales->ssh_node_f(0, true, "maxadmin list servers"); test.tprintf("%s", output); free(output); - test.tprintf("MaxScale output:"); - output = test.ssh_maxscale_output(true, - "cat /var/log/maxscale/maxscale.log && sudo truncate -s 0 /var/log/maxscale/maxscale.log"); + test.tprintf("replication-manager output:"); + output = test.maxscales->ssh_node_f(0, true, + "cat /var/log/replication-manager.log && sudo truncate -s 0 /var/log/replication-manager.log"); test.tprintf("%s", output); free(output); } @@ -32,7 +32,7 @@ static int inserts = 0; void check(TestConnections& test) { - MYSQL *conn = test.open_rwsplit_connection(); + MYSQL *conn = test.maxscales->open_rwsplit_connection(0); const char *query1 = "INSERT INTO test.t1 VALUES (%d)"; const char *query2 = "SELECT * FROM test.t1"; @@ -66,21 +66,6 @@ void check(TestConnections& test) mysql_close(conn); } -int get_server_id(TestConnections& test) -{ - MYSQL *conn = test.open_rwsplit_connection(); - int id = -1; - char str[1024]; - - if (find_field(conn, "SELECT @@server_id", "@@server_id", str) == 0) - { - id = atoi(str); - } - - mysql_close(conn); - return id; -} - static bool interactive = false; void get_input() @@ -98,9 +83,8 @@ int main(int argc, char** argv) prepare(); TestConnections test(argc, argv); - test.tprintf("Installing replication-manager"); - int rc = system("new_replication_manager=yes ./manage_mrm.sh install > manage_mrm.log"); + int rc = system("./manage_mrm.sh install > manage_mrm.log"); if (!WIFEXITED(rc) || WEXITSTATUS(rc) != 0) { test.tprintf("Failed to install replication-manager, see manage_mrm.log for more details"); @@ -112,9 +96,8 @@ int main(int argc, char** argv) test.tprintf("Creating table and inserting data"); get_input(); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "CREATE OR REPLACE TABLE test.t1(id INT)"); - test.repl->sync_slaves(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "CREATE OR REPLACE TABLE test.t1(id INT)"); check(test); get_output(test); @@ -144,34 +127,31 @@ int main(int argc, char** argv) check(test); get_output(test); + test.tprintf("Starting all nodes and wait for replication-manager to fix the replication"); + get_input(); - test.tprintf("Fix replication and recreate table"); - test.close_maxscale_connections(); - test.repl->fix_replication(); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "CREATE OR REPLACE TABLE test.t1(id INT)"); - test.repl->sync_slaves(); - inserts = 0; + test.repl->start_node(0, (char*)""); + sleep(5); + test.repl->start_node(1, (char*)""); + sleep(5); + test.repl->start_node(2, (char*)""); + sleep(5); check(test); get_output(test); - test.tprintf("Disable replication on a slave and kill master, check that it is not promoted"); - execute_query(test.repl->nodes[1], "STOP SLAVE; RESET SLAVE; RESET SLAVE ALL;"); - test.repl->stop_node(0); - sleep(10); + test.tprintf("Dropping tables"); + get_input(); + test.maxscales->close_maxscale_connections(0); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "DROP TABLE test.t1"); + test.maxscales->close_maxscale_connections(0); - check(test); get_output(test); - int id = get_server_id(test); - test.add_result(id == test.repl->get_server_id(1), "Invalid slave should not be used"); - - // TODO: Figure this also out, remove the component if it's not needed - // test.tprintf("Removing replication-manager"); - // get_input(); - // system("./manage_mrm.sh remove >> manage_mrm.log"); - + test.tprintf("Removing replication-manager"); + get_input(); + system("./manage_mrm.sh remove >> manage_mrm.log"); test.repl->fix_replication(); return test.global_result; } diff --git a/maxscale-system-test/replication_manager_2nodes.cpp b/maxscale-system-test/replication_manager_2nodes.cpp index 3ce636c9d..04ca6e385 100644 --- a/maxscale-system-test/replication_manager_2nodes.cpp +++ b/maxscale-system-test/replication_manager_2nodes.cpp @@ -13,27 +13,27 @@ void prepare(TestConnections& test) t.c_iflag &= ~ECHO; tcsetattr(STDIN_FILENO, TCSANOW, &t); - test.ssh_maxscale(true, "pcs resource disable maxscale-clone; pcs resource disable replication-manager"); + test.maxscales->ssh_node_f(0, true, "pcs resource disable maxscale-clone; pcs resource disable replication-manager"); test.repl->fix_replication(); system("./manage_mrm.sh configure 2"); - test.copy_from_maxscale((char*)"/etc/maxscale.cnf", (char*)"."); - test.copy_to_maxscale("./config.toml", "~"); - test.ssh_maxscale(false, "sudo cp ~/maxscale.cnf /etc/; sudo cp ~/config.toml /etc/replication-manager/"); + test.maxscales->copy_from_node((char*)"/etc/maxscale.cnf", (char*)".", 0); + test.maxscales->copy_to_node("./config.toml", "~", 0); + test.maxscales->ssh_node_f(0, false, "sudo cp ~/maxscale.cnf /etc/; sudo cp ~/config.toml /etc/replication-manager/"); system("sed -i 's/version_string=.*/version_string=10.1.19-maxscale-standby/' ./maxscale.cnf"); test.galera->copy_to_node("./maxscale.cnf", "~", 0); test.galera->copy_to_node("./config.toml", "~", 0); test.galera->ssh_node(0, "sudo cp ~/config.toml /etc/replication-manager", false); test.galera->ssh_node(0, "sudo cp ~/maxscale.cnf /etc/", false); - test.ssh_maxscale(true, "replication-manager bootstrap --clean-all;pcs resource enable maxscale-clone; pcs resource enable replication-manager"); + test.maxscales->ssh_node_f(0, true, "replication-manager bootstrap --clean-all;pcs resource enable maxscale-clone; pcs resource enable replication-manager"); sleep(5); } void get_output(TestConnections& test) { test.tprintf("Maxadmin output:"); - char *output = test.ssh_maxscale_output(true, "maxadmin list servers"); + char *output = test.maxscales->ssh_node_f(0, true, "maxadmin list servers"); test.tprintf("%s", output); free(output); } @@ -42,7 +42,7 @@ static int inserts = 0; void check(TestConnections& test) { - MYSQL *conn = test.open_rwsplit_connection(); + MYSQL *conn = test.maxscales->open_rwsplit_connection(0); const char *query1 = "INSERT INTO test.t1 VALUES (%d)"; const char *query2 = "SELECT * FROM test.t1"; @@ -146,9 +146,9 @@ int main(int argc, char** argv) test.tprintf("Creating table and inserting data"); get_input(); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "CREATE OR REPLACE TABLE test.t1(id INT)"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "CREATE OR REPLACE TABLE test.t1(id INT)"); + test.maxscales->close_maxscale_connections(0); check(test); @@ -194,9 +194,9 @@ int main(int argc, char** argv) check(test); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "DROP TABLE test.t1"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "DROP TABLE test.t1"); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/replication_manager_3nodes.cpp b/maxscale-system-test/replication_manager_3nodes.cpp index 83332d7c8..776e80d25 100644 --- a/maxscale-system-test/replication_manager_3nodes.cpp +++ b/maxscale-system-test/replication_manager_3nodes.cpp @@ -13,27 +13,27 @@ void prepare(TestConnections& test) t.c_iflag &= ~ECHO; tcsetattr(STDIN_FILENO, TCSANOW, &t); - test.ssh_maxscale(true, "pcs resource disable maxscale-clone; pcs resource disable replication-manager"); + test.maxscales->ssh_node_f(0, true, "pcs resource disable maxscale-clone; pcs resource disable replication-manager"); test.repl->fix_replication(); system("./manage_mrm.sh configure 3"); - test.copy_from_maxscale((char*)"/etc/maxscale.cnf", (char*)"."); - test.copy_to_maxscale("./config.toml", "~"); - test.ssh_maxscale(false, "sudo cp ~/maxscale.cnf /etc/; sudo cp ~/config.toml /etc/replication-manager/"); + test.maxscales->copy_from_node((char*)"/etc/maxscale.cnf", (char*)".", 0); + test.maxscales->copy_to_node("./config.toml", "~", 0); + test.maxscales->ssh_node_f(0, false, "sudo cp ~/maxscale.cnf /etc/; sudo cp ~/config.toml /etc/replication-manager/"); system("sed -i 's/version_string=.*/version_string=10.1.19-maxscale-standby/' ./maxscale.cnf"); test.galera->copy_to_node("./maxscale.cnf", "~", 0); test.galera->copy_to_node("./config.toml", "~", 0); test.galera->ssh_node(0, "sudo cp ~/config.toml /etc/replication-manager", false); test.galera->ssh_node(0, "sudo cp ~/maxscale.cnf /etc/", false); - test.ssh_maxscale(true, "replication-manager bootstrap --clean-all;pcs resource enable maxscale-clone; pcs resource enable replication-manager"); + test.maxscales->ssh_node_f(0, true, "replication-manager bootstrap --clean-all;pcs resource enable maxscale-clone; pcs resource enable replication-manager"); sleep(5); } void get_output(TestConnections& test) { test.tprintf("Maxadmin output:"); - char *output = test.ssh_maxscale_output(true, "maxadmin list servers"); + char *output = test.maxscales->ssh_node_f(0, true, "maxadmin list servers"); test.tprintf("%s", output); free(output); } @@ -42,7 +42,7 @@ static int inserts = 0; void check(TestConnections& test) { - MYSQL *conn = test.open_rwsplit_connection(); + MYSQL *conn = test.maxscales->open_rwsplit_connection(0); const char *query1 = "INSERT INTO test.t1 VALUES (%d)"; const char *query2 = "SELECT * FROM test.t1"; @@ -146,9 +146,9 @@ int main(int argc, char** argv) test.tprintf("Creating table and inserting data"); get_input(); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "CREATE OR REPLACE TABLE test.t1(id INT)"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "CREATE OR REPLACE TABLE test.t1(id INT)"); + test.maxscales->close_maxscale_connections(0); check(test); @@ -216,9 +216,9 @@ int main(int argc, char** argv) // check(test); - test.connect_maxscale(); - test.try_query(test.conn_rwsplit, "DROP TABLE test.t1"); - test.close_maxscale_connections(); + test.maxscales->connect_maxscale(0); + test.try_query(test.maxscales->conn_rwsplit[0], "DROP TABLE test.t1"); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/rw_galera_select_insert.cpp b/maxscale-system-test/rw_galera_select_insert.cpp index ed2ff8c34..2c282491d 100644 --- a/maxscale-system-test/rw_galera_select_insert.cpp +++ b/maxscale-system-test/rw_galera_select_insert.cpp @@ -25,11 +25,11 @@ int main(int argc, char *argv[]) tolerance = 0; // connect to the MaxScale server (rwsplit) - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); - Test->execute_maxadmin_command((char *) "shutdown monitor \"Galera Monitor\""); + Test->maxscales->execute_maxadmin_command(0, (char *) "shutdown monitor \"Galera Monitor\""); - if (Test->conn_rwsplit == NULL ) + if (Test->maxscales->conn_rwsplit[0] == NULL ) { Test->add_result(1, "Can't connect to MaxScale\n"); int rval = Test->global_result; @@ -39,20 +39,20 @@ int main(int argc, char *argv[]) else { - Test->try_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS t1;"); - Test->try_query(Test->conn_rwsplit, "create table t1 (x1 int);"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS t1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "create table t1 (x1 int);"); get_global_status_allnodes(&selects[0], &inserts[0], Test->galera, silent); - Test->try_query(Test->conn_rwsplit, "select * from t1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "select * from t1;"); get_global_status_allnodes(&new_selects[0], &new_inserts[0], Test->galera, silent); print_delta(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], Test->galera->N); - Test->try_query(Test->conn_rwsplit, "insert into t1 values(1);"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "insert into t1 values(1);"); get_global_status_allnodes(&new_selects[0], &new_inserts[0], Test->galera, silent); print_delta(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], Test->galera->N); // close connections - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); } Test->galera->close_connections(); diff --git a/maxscale-system-test/rw_select_insert.cpp b/maxscale-system-test/rw_select_insert.cpp index fd31594a6..13b47c635 100644 --- a/maxscale-system-test/rw_select_insert.cpp +++ b/maxscale-system-test/rw_select_insert.cpp @@ -129,24 +129,24 @@ int main(int argc, char *argv[]) Test->set_timeout(120); Test->repl->connect(); - Test->tprintf("Connecting to RWSplit %s\n", Test->maxscale_IP); - Test->connect_rwsplit(); + Test->tprintf("Connecting to RWSplit %s\n", Test->maxscales->IP[0]); + Test->maxscales->connect_rwsplit(0); - Test->execute_maxadmin_command((char *) "shutdown monitor MySQL-Monitor"); + Test->maxscales->execute_maxadmin_command(0, (char *) "shutdown monitor MySQL-Monitor"); get_global_status_allnodes(&selects[0], &inserts[0], Test->repl, silent); Test->tprintf("Creating table t1\n"); fflush(stdout); - Test->try_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS t1;"); - Test->try_query(Test->conn_rwsplit, "create table t1 (x1 int);"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS t1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "create table t1 (x1 int);"); Test->repl->sync_slaves(); printf("Trying SELECT * FROM t1\n"); fflush(stdout); get_global_status_allnodes(&selects[0], &inserts[0], Test->repl, silent); - Test->try_query(Test->conn_rwsplit, "select * from t1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "select * from t1;"); get_global_status_allnodes(&new_selects[0], &new_inserts[0], Test->repl, silent); Test->add_result(check_com_select(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], Test->repl, 1), "Wrong check_com_select result\n"); @@ -154,7 +154,7 @@ int main(int argc, char *argv[]) printf("Trying INSERT INTO t1 VALUES(1);\n"); fflush(stdout); get_global_status_allnodes(&selects[0], &inserts[0], Test->repl, silent); - Test->try_query(Test->conn_rwsplit, "insert into t1 values(1);"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "insert into t1 values(1);"); get_global_status_allnodes(&new_selects[0], &new_inserts[0], Test->repl, silent); Test->add_result(check_com_insert(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], Test->repl, 1), "Wrong check_com_insert result\n"); @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) printf("Trying SELECT * FROM t1\n"); fflush(stdout); get_global_status_allnodes(&selects[0], &inserts[0], Test->repl, silent); - execute_query(Test->conn_rwsplit, "select * from t1;"); + execute_query(Test->maxscales->conn_rwsplit[0], "select * from t1;"); get_global_status_allnodes(&new_selects[0], &new_inserts[0], Test->repl, silent); Test->add_result(check_com_select(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], Test->repl, 1), "Wrong check_com_select result\n"); @@ -173,7 +173,7 @@ int main(int argc, char *argv[]) printf("Trying INSERT INTO t1 VALUES(1);\n"); fflush(stdout); get_global_status_allnodes(&selects[0], &inserts[0], Test->repl, silent); - execute_query(Test->conn_rwsplit, "insert into t1 values(1);"); + execute_query(Test->maxscales->conn_rwsplit[0], "insert into t1 values(1);"); get_global_status_allnodes(&new_selects[0], &new_inserts[0], Test->repl, silent); Test->add_result(check_com_insert(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], Test->repl, 1), "Wrong check_com_insert result\n"); @@ -187,7 +187,7 @@ int main(int argc, char *argv[]) for (i = 0; i < 100; i++) { Test->set_timeout(20); - Test->try_query(Test->conn_rwsplit, "select * from t1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "select * from t1;"); } Test->stop_timeout(); @@ -206,7 +206,7 @@ int main(int argc, char *argv[]) for (i = 0; i < 100; i++) { Test->set_timeout(20); - Test->try_query(Test->conn_rwsplit, "insert into t1 values(1);"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "insert into t1 values(1);"); } Test->stop_timeout(); @@ -216,7 +216,7 @@ int main(int argc, char *argv[]) 100), "Wrong check_com_insert result\n"); - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/rwsplit_conn_num.cpp b/maxscale-system-test/rwsplit_conn_num.cpp index cf7437840..9322f3d69 100644 --- a/maxscale-system-test/rwsplit_conn_num.cpp +++ b/maxscale-system-test/rwsplit_conn_num.cpp @@ -36,7 +36,7 @@ int main(int argc, char *argv[]) Test->tprintf("Creating %d connections to RWSplit router\n", TestConnNum); for (i = 0; i < TestConnNum; i++) { - conn[i] = Test->open_rwsplit_connection(); + conn[i] = Test->maxscales->open_rwsplit_connection(0); } Test->tprintf("Waiting 5 seconds\n"); sleep(5); @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) int TotalConn = 0; Test->tprintf("Checking connections to Master: should be %d\n", TestConnNum); - conn_num = get_conn_num(Test->repl->nodes[0], Test->maxscale_ip(), Test->maxscale_hostname, (char *) "test"); + conn_num = get_conn_num(Test->repl->nodes[0], Test->maxscales->ip(0), Test->maxscales->hostname[0], (char *) "test"); if (conn_num != TestConnNum) { Test->add_result(1, "number of connections to Master is %d\n", conn_num); @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) Test->tprintf("Checking connections to each node\n"); for (int i = 1; i < Test->repl->N; i++) { - conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscale_ip(), Test->maxscale_hostname, (char *) "test"); + conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscales->ip(0), Test->maxscales->hostname[0], (char *) "test"); TotalConn += conn_num; Test->tprintf("Connections to node %d (%s):\t%d\n", i, Test->repl->IP[i], conn_num); if ((conn_num > ConnCell) || (conn_num < ConnFloor)) diff --git a/maxscale-system-test/rwsplit_connect.cpp b/maxscale-system-test/rwsplit_connect.cpp index e94381753..1ce74dada 100644 --- a/maxscale-system-test/rwsplit_connect.cpp +++ b/maxscale-system-test/rwsplit_connect.cpp @@ -12,8 +12,8 @@ int main(int argc, char *argv[]) Test->set_timeout(20); Test->repl->connect(); - Test->tprintf("Connecting to RWSplit %s\n", Test->maxscale_ip()); - Test->connect_rwsplit(); + Test->tprintf("Connecting to RWSplit %s\n", Test->maxscales->ip(0)); + Test->maxscales->connect_rwsplit(0); unsigned int conn_num; unsigned int all_conn = 0; @@ -22,7 +22,7 @@ int main(int argc, char *argv[]) Test->tprintf("Checking number of connections ot backend servers\n"); for (int i = 0; i < Test->repl->N; i++) { - conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscale_ip(), Test->maxscale_hostname, (char *) "test"); + conn_num = get_conn_num(Test->repl->nodes[i], Test->maxscales->ip(0), Test->maxscales->hostname[0], (char *) "test"); Test->tprintf("connections: %u\n", conn_num); if ((i == 0) && (conn_num != 1)) { @@ -37,7 +37,7 @@ int main(int argc, char *argv[]) all_conn); } - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); Test->repl->close_connections(); int rval = Test->global_result; diff --git a/maxscale-system-test/rwsplit_multi_stmt.cpp b/maxscale-system-test/rwsplit_multi_stmt.cpp index 8f5715a03..162fd54e4 100644 --- a/maxscale-system-test/rwsplit_multi_stmt.cpp +++ b/maxscale-system-test/rwsplit_multi_stmt.cpp @@ -23,49 +23,50 @@ int main(int argc, char** argv) sprintf(master_id, "%d", test.repl->get_server_id(0)); sprintf(slave_id, "%d", test.repl->get_server_id(1)); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.tprintf("Configuration: strict_multi_stmt=true"); - test.add_result(execute_query_check_one(test.conn_rwsplit, + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id", slave_id), "Query should be routed to slave"); - test.add_result(execute_query_check_one(test.conn_rwsplit, + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "USE test; SELECT @@server_id", master_id), "Query should be routed to master"); - test.add_result(execute_query_check_one(test.conn_rwsplit, + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id", master_id), "All queries should be routed to master"); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); // Reconfigure MaxScale - test.ssh_maxscale(true, "sed -i 's/strict_multi_stmt=true/strict_multi_stmt=false/' /etc/maxscale.cnf"); - test.restart_maxscale(); + test.maxscales->ssh_node(0, "sed -i 's/strict_multi_stmt=true/strict_multi_stmt=false/' /etc/maxscale.cnf", + true); + test.maxscales->restart_maxscale(0); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.tprintf("Configuration: strict_multi_stmt=false"); - test.add_result(execute_query_check_one(test.conn_rwsplit, + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id", slave_id), "Query should be routed to slave"); - test.add_result(execute_query_check_one(test.conn_rwsplit, + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "USE test; SELECT @@server_id", master_id), "Query should be routed to master"); - test.add_result(execute_query_check_one(test.conn_rwsplit, + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id", slave_id), "Query should be routed to slave"); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/rwsplit_read_only_trx.cpp b/maxscale-system-test/rwsplit_read_only_trx.cpp index 644dc002c..3c1771f4e 100644 --- a/maxscale-system-test/rwsplit_read_only_trx.cpp +++ b/maxscale-system-test/rwsplit_read_only_trx.cpp @@ -18,39 +18,39 @@ int main(int argc, char** argv) sprintf(master_id, "%d", test.repl->get_server_id(0)); sprintf(slave_id, "%d", test.repl->get_server_id(1)); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); - execute_query_silent(test.conn_rwsplit, "DROP TABLE test.t1"); - execute_query_silent(test.conn_rwsplit, "CREATE TABLE test.t1(id int)"); + execute_query_silent(test.maxscales->conn_rwsplit[0], "DROP TABLE test.t1"); + execute_query_silent(test.maxscales->conn_rwsplit[0], "CREATE TABLE test.t1(id int)"); // Test read-only transaction with commit - test.try_query(test.conn_rwsplit, "START TRANSACTION READ ONLY"); - test.add_result(execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id", slave_id), + test.try_query(test.maxscales->conn_rwsplit[0], "START TRANSACTION READ ONLY"); + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id", slave_id), "Query should be routed to slave"); - test.try_query(test.conn_rwsplit, "COMMIT"); + test.try_query(test.maxscales->conn_rwsplit[0], "COMMIT"); // Test read-only transaction with rollback - test.try_query(test.conn_rwsplit, "START TRANSACTION READ ONLY"); - test.add_result(execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id", slave_id), + test.try_query(test.maxscales->conn_rwsplit[0], "START TRANSACTION READ ONLY"); + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id", slave_id), "Query should be routed to slave"); - test.try_query(test.conn_rwsplit, "ROLLBACK"); + test.try_query(test.maxscales->conn_rwsplit[0], "ROLLBACK"); // Test normal transaction - test.try_query(test.conn_rwsplit, "START TRANSACTION"); - test.add_result(execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id", master_id), + test.try_query(test.maxscales->conn_rwsplit[0], "START TRANSACTION"); + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id", master_id), "Query should be routed to master"); - test.try_query(test.conn_rwsplit, "COMMIT"); + test.try_query(test.maxscales->conn_rwsplit[0], "COMMIT"); // Test writes in read-only transaction - test.try_query(test.conn_rwsplit, "START TRANSACTION READ ONLY"); - test.add_result(execute_query_check_one(test.conn_rwsplit, "SELECT @@server_id", slave_id), + test.try_query(test.maxscales->conn_rwsplit[0], "START TRANSACTION READ ONLY"); + test.add_result(execute_query_check_one(test.maxscales->conn_rwsplit[0], "SELECT @@server_id", slave_id), "Query should be routed to slave"); - test.add_result(execute_query(test.conn_rwsplit, "UPDATE test.t1 SET id=0") == 0, + test.add_result(execute_query(test.maxscales->conn_rwsplit[0], "UPDATE test.t1 SET id=0") == 0, "Query should fail"); - test.try_query(test.conn_rwsplit, "COMMIT"); + test.try_query(test.maxscales->conn_rwsplit[0], "COMMIT"); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/rwsplit_readonly.cpp b/maxscale-system-test/rwsplit_readonly.cpp index fcb92569d..d405fc435 100644 --- a/maxscale-system-test/rwsplit_readonly.cpp +++ b/maxscale-system-test/rwsplit_readonly.cpp @@ -18,32 +18,35 @@ void test_all_ok(TestConnections *Test) /** Insert should work */ Test->set_timeout(30); Test->tprintf("Testing that writes and reads to all services work\n"); - Test->add_result(execute_query_silent(Test->conn_rwsplit, + Test->add_result(execute_query_silent(Test->maxscales->conn_rwsplit[0], "INSERT INTO test.readonly VALUES (1) -- fail_instantly"), "Query to service with 'fail_instantly' should succeed\n"); Test->set_timeout(30); - Test->add_result(execute_query_silent(Test->conn_master, + Test->add_result(execute_query_silent(Test->maxscales->conn_master[0], "INSERT INTO test.readonly VALUES (1) -- fail_on_write"), "Query to service with 'fail_on_write' should succeed\n"); Test->set_timeout(30); - Test->add_result(execute_query_silent(Test->conn_slave, + Test->add_result(execute_query_silent(Test->maxscales->conn_slave[0], "INSERT INTO test.readonly VALUES (1) -- error_on_write"), "Query to service with 'error_on_write' should succeed\n"); Test->set_timeout(30); - Test->add_result(execute_query_silent(Test->conn_rwsplit, "SELECT * FROM test.readonly -- fail_instantly"), + Test->add_result(execute_query_silent(Test->maxscales->conn_rwsplit[0], + "SELECT * FROM test.readonly -- fail_instantly"), "Query to service with 'fail_instantly' should succeed\n"); Test->set_timeout(30); - Test->add_result(execute_query_silent(Test->conn_master, "SELECT * FROM test.readonly -- fail_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_master[0], + "SELECT * FROM test.readonly -- fail_on_write"), "Query to service with 'fail_on_write' should succeed\n"); Test->set_timeout(30); - Test->add_result(execute_query_silent(Test->conn_slave, "SELECT * FROM test.readonly -- error_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_slave[0], + "SELECT * FROM test.readonly -- error_on_write"), "Query to service with 'error_on_write' should succeed\n"); } void test_basic(TestConnections *Test) { /** Check that everything is OK before blocking the master */ - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); test_all_ok(Test); /** Block master */ @@ -54,76 +57,84 @@ void test_basic(TestConnections *Test) /** Select to service with 'fail_instantly' should close the connection */ Test->set_timeout(30); Test->tprintf("SELECT to 'fail_instantly'\n"); - Test->add_result(!execute_query_silent(Test->conn_rwsplit, "SELECT * FROM test.readonly -- fail_instantly"), + Test->add_result(!execute_query_silent(Test->maxscales->conn_rwsplit[0], + "SELECT * FROM test.readonly -- fail_instantly"), "SELECT to service with 'fail_instantly' should fail\n"); /** Other services should still work */ Test->set_timeout(30); Test->tprintf("SELECT to 'fail_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_master, "SELECT * FROM test.readonly -- fail_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_master[0], + "SELECT * FROM test.readonly -- fail_on_write"), "SELECT to service with 'fail_on_write' should succeed\n"); Test->set_timeout(30); Test->tprintf("SELECT to 'error_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_slave, "SELECT * FROM test.readonly -- error_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_slave[0], + "SELECT * FROM test.readonly -- error_on_write"), "SELECT to service with 'error_on_write' should succeed\n"); /** Insert to 'fail_on_write' should fail and close the connection */ Test->set_timeout(30); Test->tprintf("INSERT to 'fail_on_write'\n"); - Test->add_result(!execute_query_silent(Test->conn_master, + Test->add_result(!execute_query_silent(Test->maxscales->conn_master[0], "INSERT INTO test.readonly VALUES (1) -- fail_on_write"), "INSERT to service with 'fail_on_write' should succeed\n"); Test->set_timeout(30); Test->tprintf("SELECT to 'fail_on_write'\n"); - Test->add_result(!execute_query_silent(Test->conn_master, "SELECT * FROM test.readonly -- fail_on_write"), + Test->add_result(!execute_query_silent(Test->maxscales->conn_master[0], + "SELECT * FROM test.readonly -- fail_on_write"), "SELECT to service with 'fail_on_write' should fail after an INSERT\n"); /** Insert to 'error_on_write' should fail but subsequent SELECTs should work */ Test->set_timeout(30); Test->tprintf("INSERT to 'error_on_write'\n"); - Test->add_result(!execute_query_silent(Test->conn_slave, + Test->add_result(!execute_query_silent(Test->maxscales->conn_slave[0], "INSERT INTO test.readonly VALUES (1) -- error_on_write"), "INSERT to service with 'error_on_write' should fail\n"); Test->tprintf("SELECT to 'error_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_slave, "SELECT * FROM test.readonly -- error_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_slave[0], + "SELECT * FROM test.readonly -- error_on_write"), "SELECT to service with 'fail_on_write' should succeed after an INSERT\n"); /** Close connections and try to create new ones */ Test->set_timeout(30); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Opening connections while master is blocked\n"); - Test->add_result(Test->connect_rwsplit() == 0, "Connection to 'fail_instantly' service should fail\n"); - Test->add_result(Test->connect_readconn_master() != 0, + Test->add_result(Test->maxscales->connect_rwsplit(0) == 0, + "Connection to 'fail_instantly' service should fail\n"); + Test->add_result(Test->maxscales->connect_readconn_master(0) != 0, "Connection to 'fail_on_write' service should succeed\n"); - Test->add_result(Test->connect_readconn_slave() != 0, + Test->add_result(Test->maxscales->connect_readconn_slave(0) != 0, "Connection to 'error_on_write' service should succeed\n"); /** The {fail|error}_on_write services should work and allow reads */ Test->set_timeout(30); Test->tprintf("SELECT to 'fail_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_master, "SELECT * FROM test.readonly -- fail_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_master[0], + "SELECT * FROM test.readonly -- fail_on_write"), "SELECT to service with 'fail_on_write' should succeed\n"); Test->set_timeout(30); Test->tprintf("SELECT to 'error_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_slave, "SELECT * FROM test.readonly -- error_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_slave[0], + "SELECT * FROM test.readonly -- error_on_write"), "SELECT to service with 'error_on_write' should succeed\n"); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->stop_timeout(); Test->repl->unblock_node(0); sleep(10); /** Check that everything is OK after unblocking */ - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); test_all_ok(Test); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); } void test_complex(TestConnections *Test) { /** Check that everything works before test */ - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); test_all_ok(Test); /** Block master */ @@ -134,17 +145,20 @@ void test_complex(TestConnections *Test) /** Select to service with 'fail_instantly' should close the connection */ Test->set_timeout(30); Test->tprintf("SELECT to 'fail_instantly'\n"); - Test->add_result(!execute_query_silent(Test->conn_rwsplit, "SELECT * FROM test.readonly -- fail_instantly"), + Test->add_result(!execute_query_silent(Test->maxscales->conn_rwsplit[0], + "SELECT * FROM test.readonly -- fail_instantly"), "SELECT to service with 'fail_instantly' should fail\n"); /** The {fail|error}_on_write services should allow reads */ Test->set_timeout(30); Test->tprintf("SELECT to 'fail_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_master, "SELECT * FROM test.readonly -- fail_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_master[0], + "SELECT * FROM test.readonly -- fail_on_write"), "SELECT to service with 'fail_on_write' should succeed\n"); Test->set_timeout(30); Test->tprintf("SELECT to 'error_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_slave, "SELECT * FROM test.readonly -- error_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_slave[0], + "SELECT * FROM test.readonly -- error_on_write"), "SELECT to service with 'error_on_write' should succeed\n"); /** Unblock node and try to read */ @@ -154,16 +168,18 @@ void test_complex(TestConnections *Test) Test->set_timeout(30); Test->tprintf("SELECT to 'fail_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_master, "SELECT * FROM test.readonly -- fail_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_master[0], + "SELECT * FROM test.readonly -- fail_on_write"), "SELECT to service with 'fail_on_write' should succeed\n"); Test->set_timeout(30); Test->tprintf("SELECT to 'error_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_slave, "SELECT * FROM test.readonly -- error_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_slave[0], + "SELECT * FROM test.readonly -- error_on_write"), "SELECT to service with 'error_on_write' should succeed\n"); /** Block slaves */ Test->stop_timeout(); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->repl->block_node(1); Test->repl->block_node(2); Test->repl->block_node(3); @@ -171,15 +187,17 @@ void test_complex(TestConnections *Test) /** Reconnect to MaxScale */ Test->set_timeout(30); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->set_timeout(30); Test->tprintf("SELECT to 'fail_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_master, "SELECT * FROM test.readonly -- fail_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_master[0], + "SELECT * FROM test.readonly -- fail_on_write"), "SELECT to service with 'fail_on_write' should succeed\n"); Test->set_timeout(30); Test->tprintf("SELECT to 'error_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_slave, "SELECT * FROM test.readonly -- error_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_slave[0], + "SELECT * FROM test.readonly -- error_on_write"), "SELECT to service with 'error_on_write' should succeed\n"); Test->stop_timeout(); @@ -191,11 +209,13 @@ void test_complex(TestConnections *Test) Test->set_timeout(30); Test->tprintf("SELECT to 'fail_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_master, "SELECT * FROM test.readonly -- fail_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_master[0], + "SELECT * FROM test.readonly -- fail_on_write"), "SELECT to service with 'fail_on_write' should succeed\n"); Test->set_timeout(30); Test->tprintf("SELECT to 'error_on_write'\n"); - Test->add_result(execute_query_silent(Test->conn_slave, "SELECT * FROM test.readonly -- error_on_write"), + Test->add_result(execute_query_silent(Test->maxscales->conn_slave[0], + "SELECT * FROM test.readonly -- error_on_write"), "SELECT to service with 'error_on_write' should succeed\n"); /** Block all nodes */ @@ -209,11 +229,13 @@ void test_complex(TestConnections *Test) /** SELECTs should fail*/ Test->set_timeout(30); Test->tprintf("SELECT to 'fail_on_write'\n"); - Test->add_result(!execute_query_silent(Test->conn_master, "SELECT * FROM test.readonly -- fail_on_write"), + Test->add_result(!execute_query_silent(Test->maxscales->conn_master[0], + "SELECT * FROM test.readonly -- fail_on_write"), "SELECT to service with 'fail_on_write' should fail\n"); Test->set_timeout(30); Test->tprintf("SELECT to 'error_on_write'\n"); - Test->add_result(!execute_query_silent(Test->conn_slave, "SELECT * FROM test.readonly -- error_on_write"), + Test->add_result(!execute_query_silent(Test->maxscales->conn_slave[0], + "SELECT * FROM test.readonly -- error_on_write"), "SELECT to service with 'error_on_write' should fail\n"); Test->stop_timeout(); Test->repl->unblock_node(0); @@ -223,10 +245,10 @@ void test_complex(TestConnections *Test) sleep(10); /** Reconnect and check that everything works after the test */ - Test->close_maxscale_connections(); - Test->connect_maxscale(); + Test->maxscales->close_maxscale_connections(0); + Test->maxscales->connect_maxscale(0); test_all_ok(Test); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); } int main(int argc, char *argv[]) @@ -236,10 +258,10 @@ int main(int argc, char *argv[]) /** Prepare for tests */ Test->stop_timeout(); - Test->connect_maxscale(); - execute_query_silent(Test->conn_rwsplit, "DROP TABLE IF EXISTS test.readonly\n"); - execute_query_silent(Test->conn_rwsplit, "CREATE TABLE test.readonly(id int)\n"); - Test->close_maxscale_connections(); + Test->maxscales->connect_maxscale(0); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "DROP TABLE IF EXISTS test.readonly\n"); + execute_query_silent(Test->maxscales->conn_rwsplit[0], "CREATE TABLE test.readonly(id int)\n"); + Test->maxscales->close_maxscale_connections(0); /** Basic tests */ test_basic(Test); diff --git a/maxscale-system-test/rwsplit_readonly_stress.cpp b/maxscale-system-test/rwsplit_readonly_stress.cpp index c0b0c37c2..c9908390f 100644 --- a/maxscale-system-test/rwsplit_readonly_stress.cpp +++ b/maxscale-system-test/rwsplit_readonly_stress.cpp @@ -33,12 +33,12 @@ void* query_thread(void *data) if (iter % 2 == 0) { - mysql = Test->open_readconn_slave_connection(); + mysql = Test->maxscales->open_readconn_slave_connection(0); type = "master_failure_mode=error_on_write"; } else { - mysql = Test->open_readconn_master_connection(); + mysql = Test->maxscales->open_readconn_master_connection(0); type = "master_failure_mode=fail_on_write"; } diff --git a/maxscale-system-test/schemarouter_duplicate_db.cpp b/maxscale-system-test/schemarouter_duplicate_db.cpp index 882fb5da2..079a36d58 100644 --- a/maxscale-system-test/schemarouter_duplicate_db.cpp +++ b/maxscale-system-test/schemarouter_duplicate_db.cpp @@ -17,17 +17,17 @@ int main(int argc, char *argv[]) TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(30); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); /** Create a database on all nodes */ - execute_query(Test->conn_master, "DROP DATABASE IF EXISTS duplicate;"); - execute_query(Test->conn_master, "CREATE DATABASE duplicate;"); + execute_query(Test->maxscales->conn_master[0], "DROP DATABASE IF EXISTS duplicate;"); + execute_query(Test->maxscales->conn_master[0], "CREATE DATABASE duplicate;"); - Test->add_result(execute_query(Test->conn_rwsplit, "SELECT 1") == 0, + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], "SELECT 1") == 0, "Query should fail when duplicate database is found."); Test->stop_timeout(); sleep(10); - Test->check_log_err((char *) "Duplicate databases found", true); + Test->check_log_err(0, (char *) "Duplicate databases found", true); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/script.cpp b/maxscale-system-test/script.cpp index 03359f899..50e3e07f4 100644 --- a/maxscale-system-test/script.cpp +++ b/maxscale-system-test/script.cpp @@ -20,7 +20,7 @@ @endverbatim * - make script non-executable * - block and unblock node1 - * - check error log for 'The file cannot be executed: /home/$maxscale_access_user/script.sh' error + * - check error log for 'The file cannot be executed: /home/$maxscales->access_user[0]/script.sh' error * - check if Maxscale still alive */ @@ -31,10 +31,10 @@ void test_script_monitor(TestConnections* Test, Mariadb_nodes* nodes, char * expected_filename) { Test->set_timeout(200); - Test->ssh_maxscale(true, "cd %s;" - "truncate -s 0 script_output;" - "chown maxscale:maxscale script_output", - Test->maxscale_access_homedir); + Test->maxscales->ssh_node_f(0, true, "cd %s;" + "truncate -s 0 script_output;" + "chown maxscale:maxscale script_output", + Test->maxscales->access_homedir[0]); sleep(10); Test->tprintf("Block master node"); @@ -63,10 +63,10 @@ void test_script_monitor(TestConnections* Test, Mariadb_nodes* nodes, char * exp Test->tprintf("Comparing results"); - if (Test->ssh_maxscale(false, "diff %s/script_output %s", Test->maxscale_access_homedir, - expected_filename) != 0) + if (Test->maxscales->ssh_node_f(0, false, "diff %s/script_output %s", Test->maxscales->access_homedir[0], + expected_filename) != 0) { - Test->ssh_maxscale(true, "cat %s/script_output", Test->maxscale_access_homedir); + Test->maxscales->ssh_node_f(0, true, "cat %s/script_output", Test->maxscales->access_homedir[0]); Test->add_result(1, "Wrong script output!"); } else @@ -83,16 +83,16 @@ int main(int argc, char *argv[]) Test->tprintf("Creating script on Maxscale machine"); - Test->ssh_maxscale(false, - "%s rm -rf %s/script; mkdir %s/script; echo \"echo \\$* >> %s/script_output\" > %s/script/script.sh; \ + Test->maxscales->ssh_node_f(0, false, + "%s rm -rf %s/script; mkdir %s/script; echo \"echo \\$* >> %s/script_output\" > %s/script/script.sh; \ chmod a+x %s/script/script.sh; chmod a+x %s; %s chown maxscale:maxscale %s/script -R", - Test->maxscale_access_sudo, Test->maxscale_access_homedir, - Test->maxscale_access_homedir, Test->maxscale_access_homedir, - Test->maxscale_access_homedir, Test->maxscale_access_homedir, Test->maxscale_access_homedir, - Test->maxscale_access_sudo, - Test->maxscale_access_homedir); + Test->maxscales->access_sudo[0], Test->maxscales->access_homedir[0], + Test->maxscales->access_homedir[0], Test->maxscales->access_homedir[0], + Test->maxscales->access_homedir[0], Test->maxscales->access_homedir[0], Test->maxscales->access_homedir[0], + Test->maxscales->access_sudo[0], + Test->maxscales->access_homedir[0]); - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); FILE * f; f = fopen("script_output_expected", "w"); @@ -144,18 +144,19 @@ int main(int argc, char *argv[]) char str[2048]; sprintf(str, "scp -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet script_output_expected* %s@%s:%s/", - Test->maxscale_keyfile, Test->maxscale_access_user, Test->maxscale_IP, Test->maxscale_access_homedir); + Test->maxscales->sshkey[0], Test->maxscales->access_user[0], Test->maxscales->IP[0], + Test->maxscales->access_homedir[0]); system(str); - sprintf(str, "%s/script_output_expected", Test->maxscale_access_homedir); + sprintf(str, "%s/script_output_expected", Test->maxscales->access_homedir[0]); test_script_monitor(Test, Test->repl, str); - sprintf(str, "%s/script_output_expected_galera", Test->maxscale_access_homedir); + sprintf(str, "%s/script_output_expected_galera", Test->maxscales->access_homedir[0]); test_script_monitor(Test, Test->galera, str); Test->set_timeout(200); Test->tprintf("Making script non-executable"); - Test->ssh_maxscale(true, "chmod a-x %s/script/script.sh", Test->maxscale_access_homedir); + Test->maxscales->ssh_node_f(0, true, "chmod a-x %s/script/script.sh", Test->maxscales->access_homedir[0]); sleep(3); @@ -171,10 +172,10 @@ int main(int argc, char *argv[]) sleep(15); Test->tprintf("Cheching Maxscale logs"); - Test->check_log_err((char *) "Cannot execute file" , true); + Test->check_log_err(0, (char *) "Cannot execute file" , true); Test->tprintf("checking if Maxscale is alive"); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/server_weight.cpp b/maxscale-system-test/server_weight.cpp index d358c9118..c10978d70 100644 --- a/maxscale-system-test/server_weight.cpp +++ b/maxscale-system-test/server_weight.cpp @@ -65,7 +65,8 @@ void check_conn_num(TestConnections* Test, int * Nc, unsigned int conn_num) { for (int i = 0; i < 4; i++) { - conn_num = get_conn_num(Test->galera->nodes[i], Test->maxscale_IP, Test->maxscale_hostname, (char *) "test"); + conn_num = get_conn_num(Test->galera->nodes[i], Test->maxscales->IP[0], Test->maxscales->hostname[0], + (char *) "test"); Test->tprintf("connections to node %d: %u (expected: %u)\n", i, conn_num, Nc[i]); if ((i < 4) && (Nc[i] != conn_num)) { @@ -78,17 +79,17 @@ int main(int argc, char *argv[]) { int maxscale_conn_num = 60; MYSQL *conn_read[maxscale_conn_num]; - MYSQL *conn_rwsplit[maxscale_conn_num]; + MYSQL *conn_rwsplit[0][maxscale_conn_num]; TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(30); int i; Test->galera->connect(); - Test->tprintf("Connecting to ReadConnMaster on %s\n", Test->maxscale_IP); + Test->tprintf("Connecting to ReadConnMaster on %s\n", Test->maxscales->IP[0]); for (i = 0; i < maxscale_conn_num; i++) { - conn_read[i] = Test->open_readconn_master_connection(); + conn_read[i] = Test->maxscales->open_readconn_master_connection(0); } Test->stop_timeout(); @@ -116,10 +117,10 @@ int main(int argc, char *argv[]) sleep(15); Test->set_timeout(30); - Test->tprintf("Connecting to RWSplit on %s\n", Test->maxscale_IP); + Test->tprintf("Connecting to RWSplit on %s\n", Test->maxscales->IP[0]); for (i = 0; i < maxscale_conn_num; i++) { - conn_rwsplit[i] = Test->open_rwsplit_connection(); + conn_rwsplit[0][i] = Test->maxscales->open_rwsplit_connection(0); } Test->stop_timeout(); @@ -140,16 +141,16 @@ int main(int argc, char *argv[]) for (i = 0; i < maxscale_conn_num; i++) { - mysql_close(conn_rwsplit[i]); + mysql_close(conn_rwsplit[0][i]); } Test->galera->close_connections(); - Test->check_log_err((char *) "Unexpected parameter 'weightby'", false); - Test->check_log_err((char *) + Test->check_log_err(0, (char *) "Unexpected parameter 'weightby'", false); + Test->check_log_err(0, (char *) "Weighting parameter 'serversize' with a value of 0 for server 'server4' rounds down to zero", true); // Pre-1.3.0 failure message - //Test->check_log_err((char *) "Server 'server4' has no value for weighting parameter 'serversize', no queries will be routed to this server", true); + //Test->check_log_err(0, (char *) "Server 'server4' has no value for weighting parameter 'serversize', no queries will be routed to this server", true); int rval = Test->global_result; diff --git a/maxscale-system-test/ses_bigmem.cpp b/maxscale-system-test/ses_bigmem.cpp index 560a42196..e218908e6 100644 --- a/maxscale-system-test/ses_bigmem.cpp +++ b/maxscale-system-test/ses_bigmem.cpp @@ -17,7 +17,7 @@ int main(int argc, char *argv[]) Test->set_timeout(10); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); int iterations = Test->smoke ? 100000 : 1000000; int r = Test->smoke ? 1 : 3; @@ -26,17 +26,17 @@ int main(int argc, char *argv[]) for (int i = 0; i < iterations; i++) { Test->set_timeout(10); - Test->try_query(Test->routers[j], (char*) "set autocommit=0;"); - Test->try_query(Test->routers[j], (char*) "select 1;"); - Test->try_query(Test->routers[j], (char*) "set autocommit=1;"); - Test->try_query(Test->routers[j], (char*) "select 2;"); + Test->try_query(Test->maxscales->routers[0][j], (char*) "set autocommit=0;"); + Test->try_query(Test->maxscales->routers[0][j], (char*) "select 1;"); + Test->try_query(Test->maxscales->routers[0][j], (char*) "set autocommit=1;"); + Test->try_query(Test->maxscales->routers[0][j], (char*) "select 2;"); if ((i / 1000) * 1000 == i) { Test->tprintf("i=%d\n", i); } } - maxscale_mem = Test->get_maxscale_memsize(); + maxscale_mem = Test->maxscales->get_maxscale_memsize(0); Test->tprintf("Maxscale process uses %lu KBytes\n", maxscale_mem); if (maxscale_mem > 2000000) @@ -45,9 +45,8 @@ int main(int argc, char *argv[]) } } - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; } - diff --git a/maxscale-system-test/session_limits.cpp b/maxscale-system-test/session_limits.cpp index 165d2a6e5..c162db948 100644 --- a/maxscale-system-test/session_limits.cpp +++ b/maxscale-system-test/session_limits.cpp @@ -25,29 +25,29 @@ int main(int argc, char *argv[]) test.set_timeout(200); test.tprintf("Open session, wait %d seconds and execute a query", first_sleep); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); sleep(first_sleep); - test.try_query(test.conn_rwsplit, "SELECT 1"); + test.try_query(test.maxscales->conn_rwsplit[0], "SELECT 1"); test.tprintf("Wait %d seconds and execute query, expecting failure", second_sleep); sleep(second_sleep); - test.add_result(execute_query(test.conn_rwsplit, "SELECT 1") == 0, + test.add_result(execute_query(test.maxscales->conn_rwsplit[0], "SELECT 1") == 0, "Session was not closed after %d seconds", second_sleep); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); test.tprintf("Open session and execute 10 session commands"); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); for (int i = 0; i < 10; i++) { - test.try_query(test.conn_rwsplit, "set @test=1"); + test.try_query(test.maxscales->conn_rwsplit[0], "set @test=1"); } test.tprintf("Execute one more session command and expect message in error log"); - execute_query(test.conn_rwsplit, "set @test=1"); + execute_query(test.maxscales->conn_rwsplit[0], "set @test=1"); sleep(1); - test.check_log_err("Router session exceeded session command history limit", true); - test.close_maxscale_connections(); + test.check_log_err(0, "Router session exceeded session command history limit", true); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/setup_binlog.cpp b/maxscale-system-test/setup_binlog.cpp index d03cc3384..4c500c62d 100644 --- a/maxscale-system-test/setup_binlog.cpp +++ b/maxscale-system-test/setup_binlog.cpp @@ -41,12 +41,12 @@ int main(int argc, char *argv[]) TestConnections test(argc, argv); test.binlog_cmd_option = 1; - test.start_binlog(); + test.start_binlog(0); test_binlog(&test); - test.check_log_err("SET NAMES utf8mb4", false); - test.check_log_err("set autocommit=1", false); - test.check_log_err("select USER()", false); + test.check_log_err(0, "SET NAMES utf8mb4", false); + test.check_log_err(0, "set autocommit=1", false); + test.check_log_err(0, "select USER()", false); return test.global_result; } diff --git a/maxscale-system-test/setup_binlog_gtid.cpp b/maxscale-system-test/setup_binlog_gtid.cpp index 361e59289..b580ac72e 100644 --- a/maxscale-system-test/setup_binlog_gtid.cpp +++ b/maxscale-system-test/setup_binlog_gtid.cpp @@ -1,23 +1,47 @@ /** - * @file setup_binlog_gtid.cpp - Basic GTID testing of binlogrouter + * @file setup_binlog_gtid.cpp test of simple binlog router setup + */ + +#include #include "testconnections.h" +#include "maxadmin_operations.h" +#include "sql_t1.h" + #include "test_binlog_fnc.h" + int main(int argc, char *argv[]) { - TestConnections test(argc, argv); - test.binlog_master_gtid = true; - test.binlog_slave_gtid = true; + TestConnections * Test = new TestConnections(argc, argv); + Test->set_timeout(3000); + int options_set = 3; + if (Test->smoke) + { + options_set = 1; + } - test.start_binlog(); - test_binlog(&test); + Test->repl->connect(); + execute_query(Test->repl->nodes[0], (char *) "DROP TABLE IF EXISTS t1;"); + Test->repl->close_connections(); + sleep(5); - test.check_log_err("SET NAMES utf8mb4", false); - test.check_log_err("set autocommit=1", false); - test.check_log_err("select USER()", false); + Test->binlog_master_gtid = true; + Test->binlog_slave_gtid = true; +// for (int option = 0; option < options_set; option++) + //{ + // Test->binlog_cmd_option = option; + Test->start_binlog(0); + test_binlog(Test); + //} - return test.global_result; + Test->check_log_err(0, "SET NAMES utf8mb4", false); + Test->check_log_err(0, "set autocommit=1", false); + Test->check_log_err(0, "select USER()", false); + + int rval = Test->global_result; + delete Test; + return rval; } diff --git a/maxscale-system-test/sharding.cpp b/maxscale-system-test/sharding.cpp index 1b6cc3812..0a4d29e35 100644 --- a/maxscale-system-test/sharding.cpp +++ b/maxscale-system-test/sharding.cpp @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) sprintf(user_str, "user%d", i); sprintf(pass_str, "pass%d", i); Test->tprintf("Open connection to Sharding router using %s %s\n", user_str, pass_str); - conn = open_conn_db(Test->rwsplit_port, Test->maxscale_IP, (char *) "shard_db", user_str, pass_str, + conn = open_conn_db(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "shard_db", user_str, pass_str, Test->ssl); Test->add_result(execute_query(conn, "CREATE TABLE table%d (x1 int, fl int);", i), "Query should succeed."); } @@ -97,7 +97,7 @@ int main(int argc, char *argv[]) sprintf(user_str, "user%d", i); sprintf(pass_str, "pass%d", i); Test->tprintf("Open connection to Sharding router using %s %s\n", user_str, pass_str); - conn = open_conn_db(Test->rwsplit_port, Test->maxscale_IP, (char *) "shard_db", user_str, pass_str, + conn = open_conn_db(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "shard_db", user_str, pass_str, Test->ssl); sprintf(str, "SHOW TABLES;"); @@ -109,26 +109,26 @@ int main(int argc, char *argv[]) mysql_close(conn); } - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); Test->tprintf("Trying USE shard_db\n"); - execute_query(Test->conn_rwsplit, "USE shard_db"); + execute_query(Test->maxscales->conn_rwsplit[0], "USE shard_db"); for (i = 0; i < Test->repl->N; i++) { - Test->add_result(execute_query(Test->conn_rwsplit, "USE shard_db%d", i), "Query should succeed."); + Test->add_result(execute_query(Test->maxscales->conn_rwsplit[0], "USE shard_db%d", i), "Query should succeed."); } - mysql_close(Test->conn_rwsplit); + mysql_close(Test->maxscales->conn_rwsplit[0]); Test->tprintf("Trying to connect with empty database name\n"); - conn = open_conn_db(Test->rwsplit_port, Test->maxscale_IP, (char *) "", user_str, pass_str, Test->ssl); + conn = open_conn_db(Test->maxscales->rwsplit_port[0], Test->maxscales->IP[0], (char *) "", user_str, pass_str, Test->ssl); mysql_close(conn); Test->stop_timeout(); - Test->check_log_err((char *) "Length (0) is 0", false); - Test->check_log_err((char *) "Unable to parse query", false); - Test->check_log_err((char *) "query string allocation failed", false); + Test->check_log_err(0, (char *) "Length (0) is 0", false); + Test->check_log_err(0, (char *) "Unable to parse query", false); + Test->check_log_err(0, (char *) "query string allocation failed", false); Test->repl->connect(); /** Cleanup */ diff --git a/maxscale-system-test/sharding_load_data.cpp b/maxscale-system-test/sharding_load_data.cpp index 385a6f507..9e4ba10a9 100644 --- a/maxscale-system-test/sharding_load_data.cpp +++ b/maxscale-system-test/sharding_load_data.cpp @@ -28,23 +28,23 @@ int main(int argc, char** argv) test.repl->connect(); execute_query(test.repl->nodes[0], "CREATE DATABASE db1"); execute_query(test.repl->nodes[0], "CREATE TABLE db1.t1(id INT)"); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.tprintf("Loading local data file"); - test.try_query(test.conn_rwsplit, "LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE db1.t1"); + test.try_query(test.maxscales->conn_rwsplit[0], "LOAD DATA LOCAL INFILE 'data.csv' INTO TABLE db1.t1"); test.tprintf("Verifying that data was loaded"); - long total = execute_query_count_rows(test.conn_rwsplit, "SELECT * FROM db1.t1"); + long total = execute_query_count_rows(test.maxscales->conn_rwsplit[0], "SELECT * FROM db1.t1"); test.add_result(total != 100, "Expected 100 rows, got %ld", total); test.tprintf("Dropping tables and databases"); - test.try_query(test.conn_rwsplit, "DROP TABLE db1.t1"); - test.try_query(test.conn_rwsplit, "DROP DATABASE db1"); + test.try_query(test.maxscales->conn_rwsplit[0], "DROP TABLE db1.t1"); + test.try_query(test.maxscales->conn_rwsplit[0], "DROP DATABASE db1"); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); // Remove the test data unlink("data.csv"); diff --git a/maxscale-system-test/short_sessions.cpp b/maxscale-system-test/short_sessions.cpp index 3b7df1ee5..cf698899c 100644 --- a/maxscale-system-test/short_sessions.cpp +++ b/maxscale-system-test/short_sessions.cpp @@ -23,7 +23,7 @@ int main(int argc, char *argv[]) test.set_timeout(20); test.repl->connect(); - MYSQL *conn = test.open_rwsplit_connection(); + MYSQL *conn = test.maxscales->open_rwsplit_connection(0); execute_query(conn, "USE test;"); create_t1(conn); mysql_close(conn); @@ -36,32 +36,32 @@ int main(int argc, char *argv[]) sprintf(sql, "INSERT INTO t1 (x1, fl) VALUES(%d, 1);", i); test.set_timeout(15); - conn = test.open_rwsplit_connection(); + conn = test.maxscales->open_rwsplit_connection(0); execute_query(conn, sql); mysql_close(conn); } test.set_timeout(20); - test.add_result(test.connect_maxscale(), "Failed to connect to MaxScale"); + test.add_result(test.maxscales->connect_maxscale(0), "Failed to connect to MaxScale"); test.tprintf("Checking t1 table using RWSplit router"); test.set_timeout(240); - test.add_result(execute_select_query_and_check(test.conn_rwsplit, (char *) "SELECT * FROM t1;", + test.add_result(execute_select_query_and_check(test.maxscales->conn_rwsplit[0], (char *) "SELECT * FROM t1;", iterations), "t1 is wrong"); test.tprintf("Checking t1 table using ReadConn router in master mode"); test.set_timeout(240); - test.add_result(execute_select_query_and_check(test.conn_master, (char *) "SELECT * FROM t1;", + test.add_result(execute_select_query_and_check(test.maxscales->conn_master[0], (char *) "SELECT * FROM t1;", iterations), "t1 is wrong"); test.tprintf("Checking t1 table using ReadConn router in slave mode"); test.set_timeout(240); - test.add_result(execute_select_query_and_check(test.conn_slave, (char *) "SELECT * FROM t1;", iterations), + test.add_result(execute_select_query_and_check(test.maxscales->conn_slave[0], (char *) "SELECT * FROM t1;", iterations), "t1 is wrong"); test.set_timeout(20); - test.close_maxscale_connections(); - test.check_maxscale_alive(); + test.maxscales->close_maxscale_connections(0); + test.check_maxscale_alive(0); return test.global_result; } diff --git a/maxscale-system-test/show_monitor_crash.cpp b/maxscale-system-test/show_monitor_crash.cpp index 6a31e46fb..fd51fcefd 100644 --- a/maxscale-system-test/show_monitor_crash.cpp +++ b/maxscale-system-test/show_monitor_crash.cpp @@ -18,12 +18,12 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->set_timeout(100); - Test->execute_maxadmin_command((char *) "show monitors"); + Test->maxscales->execute_maxadmin_command(0, (char *) "show monitors"); sleep(5); - Test->check_log_err((char *) "Failed to start monitor", true); - Test->check_log_err((char *) "fatal signal 11", false); + Test->check_log_err(0, (char *) "Failed to start monitor", true); + Test->check_log_err(0, (char *) "fatal signal 11", false); - Test->check_maxscale_processes(1); + Test->check_maxscale_processes(0, 1); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/slave_failover.cpp b/maxscale-system-test/slave_failover.cpp index 901bc7c05..28982f093 100644 --- a/maxscale-system-test/slave_failover.cpp +++ b/maxscale-system-test/slave_failover.cpp @@ -19,12 +19,12 @@ int main(int argc, char *argv[]) TestConnections test(argc, argv); printf("Connecting to RWSplit"); test.set_timeout(60); - test.add_result(test.connect_rwsplit(), "Error connection to RWSplit! Exiting"); + test.add_result(test.maxscales->connect_rwsplit(0), "Error connection to RWSplit! Exiting"); sleep(5); test.tprintf("Checking current slave"); int res = 0; - int old_slave = test.find_connected_slave(&res); + int old_slave = test.find_connected_slave(0, &res); test.add_result(res, "no current slave"); test.tprintf("Setup firewall to block mysql on old slave (oldslave is node %d)", old_slave); @@ -37,14 +37,14 @@ int main(int argc, char *argv[]) sleep(10); test.set_timeout(20); - int current_slave = test.find_connected_slave(&res); + int current_slave = test.find_connected_slave(0, &res); test.add_result((current_slave == old_slave) || (current_slave < 0), "No failover happened"); test.tprintf("Unblock old node"); test.repl->unblock_node(old_slave); - test.close_rwsplit(); + test.maxscales->close_rwsplit(0); - test.check_maxscale_alive(); + test.check_maxscale_alive(0); test.stop_timeout(); test.repl->fix_replication(); diff --git a/maxscale-system-test/slave_lag.cpp b/maxscale-system-test/slave_lag.cpp index a0ffb9be2..7f0bfe2b3 100644 --- a/maxscale-system-test/slave_lag.cpp +++ b/maxscale-system-test/slave_lag.cpp @@ -38,7 +38,7 @@ int check_lag(int * min_lag) for (i = 1; i < Test->repl->N; i++ ) { sprintf(ma_cmd, "show server server%d", i + 1); - get_maxadmin_param(Test->maxscale_IP, (char *) "admin", Test->maxadmin_password, ma_cmd, + maxscales->get_maxadmin_param(0, Test->maxscales->IP[0], (char *) "admin", Test->maxscales->maxadmin_password[0], ma_cmd, (char *) "Slave delay:", result); sscanf(result, "%d", &res_d); Test->tprintf("server%d lag: %d\n", i + 1, res_d); @@ -52,10 +52,10 @@ int check_lag(int * min_lag) } } Test->tprintf("Minimum lag: %d\n", *min_lag); - Test->connect_rwsplit(); - find_field(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale max_slave_replication_lag=20", + Test->maxscales->connect_rwsplit(0); + find_field(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale max_slave_replication_lag=20", (char *) "@@server_id", &server_id[0]); - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); sscanf(server_id, "%d", &server_id_d); Test->tprintf("Connected to the server with server_id %d\n", server_id_d); if ((server1_id_d == server_id_d)) @@ -84,11 +84,11 @@ int main(int argc, char *argv[]) Test->set_timeout(2000); Test->repl->connect(); - Test->connect_rwsplit(); + Test->maxscales->connect_rwsplit(0); // connect to the MaxScale server (rwsplit) - if (Test->conn_rwsplit == NULL ) + if (Test->maxscales->conn_rwsplit[0] == NULL ) { printf("Can't connect to MaxScale\n"); int rval = Test->global_result; @@ -103,13 +103,13 @@ int main(int argc, char *argv[]) execute_query(Test->repl->nodes[i], (char *) "set global max_connections = 200;"); } - create_t1(Test->conn_rwsplit); - create_t2(Test->conn_rwsplit); + create_t1(Test->maxscales->conn_rwsplit[0]); + create_t2(Test->maxscales->conn_rwsplit[0]); create_insert_string(sql, 50000, 1); Test->tprintf("sql_len=%lu\n", strlen(sql)); /* for ( i = 0; i < 100; i++) { - Test->try_query(Test->conn_rwsplit, sql); + Test->try_query(Test->maxscales->conn_rwsplit[0], sql); }*/ pthread_t threads[1000]; @@ -124,13 +124,13 @@ int main(int argc, char *argv[]) iret[j] = pthread_create( &threads[j], NULL, query_thread, &sql); } - execute_query(Test->conn_rwsplit, (char *) "select @@server_id; -- maxscale max_slave_replication_lag=10"); + execute_query(Test->maxscales->conn_rwsplit[0], (char *) "select @@server_id; -- maxscale max_slave_replication_lag=10"); find_field(Test->repl->nodes[0], (char *) "select @@server_id;", (char *) "@@server_id", &server1_id[0]); sscanf(server1_id, "%d", &server1_id_d); Test->tprintf("Master server_id: %d\n", server1_id_d); - Test->close_rwsplit(); + Test->maxscales->close_rwsplit(0); for (i = 0; i < 1000; i++) { @@ -180,13 +180,13 @@ void *checks_thread( void *ptr ) char result[1024]; for (int i = 0; i < 1000; i++) { - get_maxadmin_param(Test->maxscale_IP, (char *) "admin", Test->maxadmin_password, + maxscales->get_maxadmin_param(0, Test->maxscales->IP[0], (char *) "admin", Test->maxscales->maxadmin_password[0], (char *) "show server server2", (char *) "Slave delay:", result); printf("server2: %s\n", result); - get_maxadmin_param(Test->maxscale_IP, (char *) "admin", Test->maxadmin_password, + maxscales->get_maxadmin_param(0, Test->maxscales->IP[0], (char *) "admin", Test->maxscales->maxadmin_password[0], (char *) "show server server3", (char *) "Slave delay:", result); printf("server3: %s\n", result); - get_maxadmin_param(Test->maxscale_IP, (char *) "admin", Test->maxadmin_password, + maxscales->get_maxadmin_param(0, Test->maxscales->IP[0], (char *) "admin", Test->maxscales->maxadmin_password[0], (char *) "show server server4", (char *) "Slave delay:", result); printf("server4: %s\n", result); } diff --git a/maxscale-system-test/sql_queries.cpp b/maxscale-system-test/sql_queries.cpp index 729560af1..a97adc167 100644 --- a/maxscale-system-test/sql_queries.cpp +++ b/maxscale-system-test/sql_queries.cpp @@ -65,46 +65,46 @@ int main(int argc, char *argv[]) Test->tprintf("Connection to backend\n"); Test->repl->connect(); Test->tprintf("Connection to Maxscale\n"); - if (Test->connect_maxscale() != 0) + if (Test->maxscales->connect_maxscale(0) != 0) { Test->add_result(1, "Error connecting to MaxScale"); break; } Test->tprintf("Filling t1 with data\n"); - Test->add_result(Test->insert_select(N), "insert-select check failed\n"); + Test->add_result(Test->insert_select(0, N), "insert-select check failed\n"); Test->tprintf("Creating database test1\n"); - Test->try_query(Test->conn_rwsplit, "DROP TABLE t1"); - Test->try_query(Test->conn_rwsplit, "DROP DATABASE IF EXISTS test1;"); - Test->try_query(Test->conn_rwsplit, "CREATE DATABASE test1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP TABLE t1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "DROP DATABASE IF EXISTS test1;"); + Test->try_query(Test->maxscales->conn_rwsplit[0], "CREATE DATABASE test1;"); Test->repl->sync_slaves(); Test->tprintf("Testing with database 'test1'\n"); - Test->add_result(Test->use_db( (char *) "test1"), "use_db failed\n"); - Test->add_result(Test->insert_select(N), "insert-select check failed\n"); + Test->add_result(Test->use_db(0, (char *) "test1"), "use_db failed\n"); + Test->add_result(Test->insert_select(0, N), "insert-select check failed\n"); - Test->add_result(Test->check_t1_table(false, (char *) "test"), "t1 is found in 'test'\n"); - Test->add_result(Test->check_t1_table(true, (char *) "test1"), "t1 is not found in 'test1'\n"); + Test->add_result(Test->check_t1_table(0, false, (char *) "test"), "t1 is found in 'test'\n"); + Test->add_result(Test->check_t1_table(0, true, (char *) "test1"), "t1 is not found in 'test1'\n"); Test->tprintf("Trying queries with syntax errors\n"); for (j = 0; j < 3; j++) { - execute_query(Test->routers[j], "DROP DATABASE I EXISTS test1;"); - execute_query(Test->routers[j], "CREATE TABLE "); + execute_query(Test->maxscales->routers[0][j], "DROP DATABASE I EXISTS test1;"); + execute_query(Test->maxscales->routers[0][j], "CREATE TABLE "); } // close connections - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->repl->close_connections(); } Test->stop_timeout(); - Test->check_log_err((char *) "Length (0) is 0", false); - Test->check_log_err((char *) "Unable to parse query", false); - Test->check_log_err((char *) "query string allocation failed", false); + Test->check_log_err(0, (char *) "Length (0) is 0", false); + Test->check_log_err(0, (char *) "Unable to parse query", false); + Test->check_log_err(0, (char *) "query string allocation failed", false); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; diff --git a/maxscale-system-test/stale_slaves.cpp b/maxscale-system-test/stale_slaves.cpp index fc91649e7..114a467e4 100644 --- a/maxscale-system-test/stale_slaves.cpp +++ b/maxscale-system-test/stale_slaves.cpp @@ -27,9 +27,9 @@ int main(int argc, char **argv) test->tprintf("Block the master and try a read query\n"); test->repl->block_node(0); sleep(15); - test->connect_readconn_slave(); + test->maxscales->connect_readconn_slave(0); char first_slave[1024]; - find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", first_slave); + find_field(test->maxscales->conn_slave[0], "SELECT @@server_id", "@@server_id", first_slave); int found = -1; @@ -49,9 +49,9 @@ int main(int argc, char **argv) sleep(15); test->tprintf("Blocked the slave that replied to us, expecting a different slave\n"); - test->connect_readconn_slave(); + test->maxscales->connect_readconn_slave(0); char second_slave[1024]; - find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave); + find_field(test->maxscales->conn_slave[0], "SELECT @@server_id", "@@server_id", second_slave); test->add_result(strcmp(first_slave, second_slave) == 0, "Server IDs match when they shouldn't: %s - %s", first_slave, second_slave); @@ -61,8 +61,8 @@ int main(int argc, char **argv) sleep(15); test->tprintf("Unblocked the slave, still expecting a different slave\n"); - test->connect_readconn_slave(); - find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave); + test->maxscales->connect_readconn_slave(0); + find_field(test->maxscales->conn_slave[0], "SELECT @@server_id", "@@server_id", second_slave); test->add_result(strcmp(first_slave, second_slave) == 0, "Server IDs match when they shouldn't: %s - %s", first_slave, second_slave); @@ -72,8 +72,8 @@ int main(int argc, char **argv) sleep(15); test->tprintf("Unblocked all nodes, expecting the server ID of the first slave server\n"); - test->connect_readconn_slave(); - find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave); + test->maxscales->connect_readconn_slave(0); + find_field(test->maxscales->conn_slave[0], "SELECT @@server_id", "@@server_id", second_slave); test->add_result(strcmp(first_slave, second_slave) != 0, "Server IDs don't match when they should: %s - %s", first_slave, second_slave); @@ -83,8 +83,8 @@ int main(int argc, char **argv) sleep(15); test->tprintf("Stopped replication, expecting a different slave\n"); - test->connect_readconn_slave(); - find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave); + test->maxscales->connect_readconn_slave(0); + find_field(test->maxscales->conn_slave[0], "SELECT @@server_id", "@@server_id", second_slave); test->add_result(strcmp(first_slave, second_slave) == 0, "Server IDs match when they shouldn't: %s - %s", first_slave, second_slave); @@ -94,8 +94,8 @@ int main(int argc, char **argv) sleep(15); test->tprintf("Started replication, expecting the server ID of the first slave server\n"); - test->connect_readconn_slave(); - find_field(test->conn_slave, "SELECT @@server_id", "@@server_id", second_slave); + test->maxscales->connect_readconn_slave(0); + find_field(test->maxscales->conn_slave[0], "SELECT @@server_id", "@@server_id", second_slave); test->add_result(strcmp(first_slave, second_slave) != 0, "Server IDs don't match when they should: %s - %s", first_slave, second_slave); diff --git a/maxscale-system-test/sysbench_example.cpp b/maxscale-system-test/sysbench_example.cpp index a15062222..7bbdb45f0 100644 --- a/maxscale-system-test/sysbench_example.cpp +++ b/maxscale-system-test/sysbench_example.cpp @@ -17,11 +17,11 @@ int main(int argc, char *argv[]) char sys1[4096]; - Test->ssh_maxscale(false, "maxscale --version-full"); + Test->maxscales->ssh_node(0, "maxscale --version-full", false); fflush(stdout); - Test->tprintf("Connecting to RWSplit %s\n", Test->maxscale_IP); + Test->tprintf("Connecting to RWSplit %s\n", Test->maxscales->IP[0]); - sprintf(&sys1[0], sysbench_prepare_short, Test->sysbench_dir, Test->sysbench_dir, Test->maxscale_IP); + sprintf(&sys1[0], sysbench_prepare_short, Test->sysbench_dir, Test->sysbench_dir, Test->maxscales->IP[0]); Test->tprintf("Preparing sysbench tables\n%s\n", sys1); Test->set_timeout(10000); @@ -29,8 +29,8 @@ int main(int argc, char *argv[]) Test->stop_timeout(); - sprintf(&sys1[0], sysbench_command_short, Test->sysbench_dir, Test->sysbench_dir, Test->maxscale_IP, - Test->rwsplit_port, "off"); + sprintf(&sys1[0], sysbench_command_short, Test->sysbench_dir, Test->sysbench_dir, Test->maxscales->IP[0], + Test->maxscales->rwsplit_port[0], "off"); Test->set_log_copy_interval(300); Test->tprintf("Executing sysbench \n%s\n", sys1); if (system(sys1) != 0) @@ -38,32 +38,31 @@ int main(int argc, char *argv[]) Test->tprintf("Error executing sysbench test\n"); } - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); printf("Dropping sysbanch tables!\n"); fflush(stdout); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest1"); if (!Test->smoke) { - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest2"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest3"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest4"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest2"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest3"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest4"); } - //global_result += execute_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest"); + //global_result += execute_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest"); printf("closing connections to MaxScale!\n"); fflush(stdout); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checking if MaxScale is still alive!\n"); fflush(stdout); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; return rval; } - diff --git a/maxscale-system-test/sysbench_kill_slave.cpp b/maxscale-system-test/sysbench_kill_slave.cpp index a3dad48f4..012b2e029 100644 --- a/maxscale-system-test/sysbench_kill_slave.cpp +++ b/maxscale-system-test/sysbench_kill_slave.cpp @@ -27,19 +27,19 @@ int main(int argc, char *argv[]) char sys1[4096]; int port[3]; - port[0] = Test->rwsplit_port; - port[1] = Test->readconn_master_port; - port[2] = Test->readconn_slave_port; + port[0] = Test->maxscales->rwsplit_port[0]; + port[1] = Test->maxscales->readconn_master_port[0]; + port[2] = Test->maxscales->readconn_slave_port[0]; - Test->tprintf("Connecting to RWSplit %s\n", Test->maxscale_IP); + Test->tprintf("Connecting to RWSplit %s\n", Test->maxscales->IP[0]); if (Test->smoke) { - sprintf(&sys1[0], sysbench_prepare1, Test->sysbench_dir, Test->sysbench_dir, Test->maxscale_IP); + sprintf(&sys1[0], sysbench_prepare1, Test->sysbench_dir, Test->sysbench_dir, Test->maxscales->IP[0]); } else { - sprintf(&sys1[0], sysbench_prepare, Test->sysbench_dir, Test->sysbench_dir, Test->maxscale_IP); + sprintf(&sys1[0], sysbench_prepare, Test->sysbench_dir, Test->sysbench_dir, Test->maxscales->IP[0]); } Test->tprintf("Preparing sysbench tables\n%s\n", sys1); @@ -55,7 +55,7 @@ int main(int argc, char *argv[]) Test->tprintf("Trying test with port %d\n", port[k]); check_iret = pthread_create( &kill_vm_thread1, NULL, kill_vm_thread, NULL); - if (port[k] == Test->readconn_slave_port ) + if (port[k] == Test->maxscales->readconn_slave_port[0] ) { readonly = ro_on; } @@ -65,12 +65,12 @@ int main(int argc, char *argv[]) } if (Test->smoke) { - sprintf(&sys1[0], sysbench_command1, Test->sysbench_dir, Test->sysbench_dir, Test->maxscale_IP, port[k], + sprintf(&sys1[0], sysbench_command1, Test->sysbench_dir, Test->sysbench_dir, Test->maxscales->IP[0], port[k], readonly); } else { - sprintf(&sys1[0], sysbench_command, Test->sysbench_dir, Test->sysbench_dir, Test->maxscale_IP, port[k], + sprintf(&sys1[0], sysbench_command, Test->sysbench_dir, Test->sysbench_dir, Test->maxscales->IP[0], port[k], readonly); } Test->tprintf("Executing sysbench tables\n%s\n", sys1); @@ -90,27 +90,27 @@ int main(int argc, char *argv[]) sleep(30); } - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); printf("Dropping sysbanch tables!\n"); fflush(stdout); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest1"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest1"); if (!Test->smoke) { - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest2"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest3"); - Test->try_query(Test->conn_rwsplit, (char *) "DROP TABLE sbtest4"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest2"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest3"); + Test->try_query(Test->maxscales->conn_rwsplit[0], (char *) "DROP TABLE sbtest4"); } printf("closing connections to MaxScale!\n"); fflush(stdout); - Test->close_maxscale_connections(); + Test->maxscales->close_maxscale_connections(0); Test->tprintf("Checxking if MaxScale is still alive!\n"); fflush(stdout); - Test->check_maxscale_alive(); + Test->check_maxscale_alive(0); int rval = Test->global_result; delete Test; @@ -124,7 +124,7 @@ void *kill_vm_thread( void *ptr ) sleep(20); printf("Checking current slave\n"); fflush(stdout); - old_slave = Test->find_connected_slave1(); + old_slave = Test->find_connected_slave1(0); if ((old_slave >= 1) && (old_slave <= Test->repl->N)) { diff --git a/maxscale-system-test/temporal_tables.cpp b/maxscale-system-test/temporal_tables.cpp index 79cf1f81c..beaded2e9 100644 --- a/maxscale-system-test/temporal_tables.cpp +++ b/maxscale-system-test/temporal_tables.cpp @@ -19,44 +19,44 @@ using namespace std; int main(int argc, char *argv[]) { TestConnections test(argc, argv); - test.connect_maxscale(); + test.maxscales->connect_maxscale(0); test.tprintf("Create a table and insert two rows into it"); test.set_timeout(30); - execute_query(test.conn_rwsplit, "USE test"); - create_t1(test.conn_rwsplit); - execute_query(test.conn_rwsplit, "INSERT INTO t1 (x1, fl) VALUES(0, 1)"); - execute_query(test.conn_rwsplit, "INSERT INTO t1 (x1, fl) VALUES(1, 1)"); + execute_query(test.maxscales->conn_rwsplit[0], "USE test"); + create_t1(test.maxscales->conn_rwsplit[0]); + execute_query(test.maxscales->conn_rwsplit[0], "INSERT INTO t1 (x1, fl) VALUES(0, 1)"); + execute_query(test.maxscales->conn_rwsplit[0], "INSERT INTO t1 (x1, fl) VALUES(1, 1)"); test.tprintf("Create temporary table and insert one row"); test.set_timeout(30); - execute_query(test.conn_rwsplit, "create temporary table t1 as (SELECT * FROM t1 WHERE fl=3)"); - execute_query(test.conn_rwsplit, "INSERT INTO t1 (x1, fl) VALUES(0, 1)"); + execute_query(test.maxscales->conn_rwsplit[0], "create temporary table t1 as (SELECT * FROM t1 WHERE fl=3)"); + execute_query(test.maxscales->conn_rwsplit[0], "INSERT INTO t1 (x1, fl) VALUES(0, 1)"); test.tprintf("Check that the temporary table has one row"); test.set_timeout(90); - test.add_result(execute_select_query_and_check(test.conn_rwsplit, "SELECT * FROM t1", 1), + test.add_result(execute_select_query_and_check(test.maxscales->conn_rwsplit[0], "SELECT * FROM t1", 1), "Current connection should show one row"); - test.add_result(execute_select_query_and_check(test.conn_master, "SELECT * FROM t1", 2), + test.add_result(execute_select_query_and_check(test.maxscales->conn_master[0], "SELECT * FROM t1", 2), "New connection should show two rows"); - test.add_result(execute_select_query_and_check(test.conn_slave, "SELECT * FROM t1", 2), + test.add_result(execute_select_query_and_check(test.maxscales->conn_slave[0], "SELECT * FROM t1", 2), "New connection should show two rows"); printf("Drop temporary table and check that the real table has two rows"); test.set_timeout(90); - execute_query(test.conn_rwsplit, "DROP TABLE t1"); - test.add_result(execute_select_query_and_check(test.conn_rwsplit, "SELECT * FROM t1", 2), + execute_query(test.maxscales->conn_rwsplit[0], "DROP TABLE t1"); + test.add_result(execute_select_query_and_check(test.maxscales->conn_rwsplit[0], "SELECT * FROM t1", 2), "check failed"); - test.add_result(execute_select_query_and_check(test.conn_master, "SELECT * FROM t1", 2), + test.add_result(execute_select_query_and_check(test.maxscales->conn_master[0], "SELECT * FROM t1", 2), "check failed"); - test.add_result(execute_select_query_and_check(test.conn_slave, "SELECT * FROM t1", 2), + test.add_result(execute_select_query_and_check(test.maxscales->conn_slave[0], "SELECT * FROM t1", 2), "check failed"); - test.close_maxscale_connections(); + test.maxscales->close_maxscale_connections(0); return test.global_result; } diff --git a/maxscale-system-test/test_binlog_fnc.cpp b/maxscale-system-test/test_binlog_fnc.cpp index b3414e1d7..01c0d2c57 100644 --- a/maxscale-system-test/test_binlog_fnc.cpp +++ b/maxscale-system-test/test_binlog_fnc.cpp @@ -19,10 +19,10 @@ int check_sha1(TestConnections* Test) Test->set_timeout(50); Test->tprintf("ls before FLUSH LOGS"); Test->tprintf("Maxscale"); - Test->ssh_maxscale(true, "ls -la %s/mar-bin.0000*", Test->maxscale_binlog_dir); + Test->maxscales->ssh_node_f(0, true, "ls -la %s/mar-bin.0000*", Test->maxscales->maxscale_binlog_dir); Test->tprintf("Master"); Test->set_timeout(50); - Test->ssh_maxscale(false, "ls -la /var/lib/mysql/mar-bin.0000*"); + Test->maxscales->ssh_node(0, "ls -la /var/lib/mysql/mar-bin.0000*", false); Test->tprintf("FLUSH LOGS"); Test->set_timeout(100); @@ -33,11 +33,11 @@ int check_sha1(TestConnections* Test) Test->tprintf("ls after first FLUSH LOGS"); Test->tprintf("Maxscale"); Test->set_timeout(50); - Test->ssh_maxscale(true, "ls -la %s/mar-bin.0000*", Test->maxscale_binlog_dir); + Test->maxscales->ssh_node_f(0, true, "ls -la %s/mar-bin.0000*", Test->maxscales->maxscale_binlog_dir); Test->tprintf("Master"); Test->set_timeout(50); - Test->ssh_maxscale(false, "ls -la /var/lib/mysql/mar-bin.0000*"); + Test->maxscales->ssh_node(0, "ls -la /var/lib/mysql/mar-bin.0000*", false); Test->set_timeout(100); Test->tprintf("FLUSH LOGS"); @@ -50,18 +50,19 @@ int check_sha1(TestConnections* Test) Test->tprintf("ls before FLUSH LOGS"); Test->tprintf("Maxscale"); - Test->ssh_maxscale(true, "ls -la %s/mar-bin.0000*", Test->maxscale_binlog_dir); + Test->maxscales->ssh_node_f(0, true, "ls -la %s/mar-bin.0000*", Test->maxscales->maxscale_binlog_dir); Test->tprintf("Master"); Test->set_timeout(50); - Test->ssh_maxscale(false, "ls -la /var/lib/mysql/mar-bin.0000*"); + Test->maxscales->ssh_node(0, "ls -la /var/lib/mysql/mar-bin.0000*", false); for (i = 1; i < 3; i++) { Test->tprintf("FILE: 000000%d", i); Test->set_timeout(50); - s_maxscale = Test->ssh_maxscale_output(true, "sha1sum %s/mar-bin.00000%d", Test->maxscale_binlog_dir, i); + s_maxscale = Test->maxscales->ssh_node_output_f(0, true, &exit_code, "sha1sum %s/mar-bin.00000%d", + Test->maxscales->maxscale_binlog_dir, i); if (s_maxscale != NULL) { x = strchr(s_maxscale, ' '); @@ -144,7 +145,7 @@ void test_binlog(TestConnections* Test) Test->tprintf("SELECT * FROM t1 WHERE fl=10, checking inserted values"); Test->add_result(execute_query_check_one(Test->repl->nodes[0], (char *) "SELECT * FROM t1 WHERE fl=10", - "111"), "SELECT check failed"); + "111"), "SELECT check failed"); Test->tprintf("ROLLBACK"); @@ -158,11 +159,11 @@ void test_binlog(TestConnections* Test) Test->set_timeout(20); Test->tprintf("SELECT * FROM t1 WHERE fl=10, checking inserted values"); Test->add_result(execute_query_check_one(Test->repl->nodes[0], (char *) "SELECT * FROM t1 WHERE fl=10", - "112"), "SELECT check failed"); + "112"), "SELECT check failed"); Test->tprintf("SELECT * FROM t1 WHERE fl=10, checking inserted values from slave"); Test->add_result(execute_query_check_one(Test->repl->nodes[2], (char *) "SELECT * FROM t1 WHERE fl=10", - "112"), "SELECT check failed"); + "112"), "SELECT check failed"); Test->tprintf("DELETE FROM t1 WHERE fl=10"); Test->try_query(Test->repl->nodes[0], (char *) "DELETE FROM t1 WHERE fl=10"); Test->tprintf("Checking t1"); @@ -176,11 +177,11 @@ void test_binlog(TestConnections* Test) Test->tprintf("SELECT, checking inserted values"); Test->add_result(execute_query_check_one(Test->repl->nodes[0], (char *) "SELECT * FROM t1 WHERE fl=10", - "111"), "SELECT check failed"); + "111"), "SELECT check failed"); Test->tprintf("SELECT, checking inserted values from slave"); Test->add_result(execute_query_check_one(Test->repl->nodes[2], (char *) "SELECT * FROM t1 WHERE fl=10", - "111"), "SELECT check failed"); + "111"), "SELECT check failed"); Test->tprintf("DELETE FROM t1 WHERE fl=10"); Test->try_query(Test->repl->nodes[0], (char *) "DELETE FROM t1 WHERE fl=10"); @@ -202,7 +203,8 @@ void test_binlog(TestConnections* Test) create_t1(Test->repl->nodes[0]); Test->tprintf("Connecting to MaxScale binlog router"); - binlog = open_conn(Test->binlog_port, Test->maxscale_IP, Test->repl->user_name, Test->repl->password, + binlog = open_conn(Test->maxscales->binlog_port[0], Test->maxscales->IP[0], Test->repl->user_name, + Test->repl->password, Test->ssl); Test->tprintf("STOP SLAVE against Maxscale binlog"); @@ -234,4 +236,3 @@ void test_binlog(TestConnections* Test) Test->repl->close_connections(); Test->stop_timeout(); } - diff --git a/maxscale-system-test/test_ctrl_c/test_ctrl_c.sh b/maxscale-system-test/test_ctrl_c/test_ctrl_c.sh index 01e9574e4..85e0952d6 100755 --- a/maxscale-system-test/test_ctrl_c/test_ctrl_c.sh +++ b/maxscale-system-test/test_ctrl_c/test_ctrl_c.sh @@ -10,7 +10,7 @@ fi T="$(date +%s)" -$maxscale_access_sudo maxscale -d -U maxscale +$maxscale_access_sudo maxscale -d if [ $? -ne 0 ] ; then exit 1 fi diff --git a/maxscale-system-test/test_hints.cpp b/maxscale-system-test/test_hints.cpp index 9e5be74f7..8fd30d373 100644 --- a/maxscale-system-test/test_hints.cpp +++ b/maxscale-system-test/test_hints.cpp @@ -74,7 +74,7 @@ int main(int argc, char** argv) { TestConnections* test = new TestConnections(argc, argv); test->repl->connect(); - test->connect_maxscale(); + test->maxscales->connect_maxscale(0); char server_id[test->repl->N][1024]; @@ -87,7 +87,7 @@ int main(int argc, char** argv) for (int i = 0; queries[i].query; i++) { char str[1024]; - find_field(test->conn_rwsplit, queries[i].query, "@@server_id", str); + find_field(test->maxscales->conn_rwsplit[0], queries[i].query, "@@server_id", str); if (strcmp(server_id[queries[i].reply], str) != 0) { test->add_result(1, "%s: Expected %s but got %s.\n", diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index fcc411239..52d472af7 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -16,7 +16,6 @@ namespace maxscale { static bool start = true; static bool check_nodes = true; -static bool multiple_maxscales = false; static std::string required_repl_version; static std::string required_galera_version; } @@ -63,40 +62,9 @@ void TestConnections::require_galera_version(const char *version) maxscale::required_galera_version = version; } -void TestConnections::multiple_maxscales(bool value) -{ - maxscale::multiple_maxscales = value; -} - -void TestConnections::set_secondary_maxscale(const char* ip_var, const char* ip6_var) -{ - const char* ip = getenv(ip_var); - const char* ip6 = getenv(ip6_var); - - if (ip || ip6) - { - TestConnections::multiple_maxscales(true); - if (ip) - { - setenv("maxscale2_IP", ip, 1); - } - if (ip6) - { - setenv("maxscale2_network6", ip6, 1); - } - } -} - TestConnections::TestConnections(int argc, char *argv[]): enable_timeouts(true), global_result(0), - rwsplit_port(4006), - readconn_master_port(4008), - readconn_slave_port(4009), - binlog_port(5306), - conn_rwsplit(NULL), - conn_master(NULL), - conn_slave(NULL), use_ipv6(false), use_snapshots(false), no_backend_log_copy(false), @@ -118,12 +86,8 @@ TestConnections::TestConnections(int argc, char *argv[]): #ifdef SIGBUS signal_set(SIGBUS, sigfatal_handler); #endif - chdir(test_dir); gettimeofday(&start_time, NULL); - ports[0] = rwsplit_port; - ports[1] = readconn_master_port; - ports[2] = readconn_slave_port; read_env(); @@ -247,6 +211,10 @@ TestConnections::TestConnections(int argc, char *argv[]): repl->use_ipv6 = use_ipv6; + maxscales = new Maxscales("maxscale", test_dir, verbose); + + maxscales->use_ipv6 = use_ipv6; + maxscales->ssl = ssl; if (maxscale::required_repl_version.length()) { @@ -288,7 +256,7 @@ TestConnections::TestConnections(int argc, char *argv[]): if (use_snapshots) { - snapshot_reverted = revert_snapshot("clean"); + snapshot_reverted = revert_snapshot((char *) "clean"); } if (!snapshot_reverted && maxscale::check_nodes) @@ -308,14 +276,7 @@ TestConnections::TestConnections(int argc, char *argv[]): if (maxscale_init) { - init_maxscale(); - - if (maxscale::multiple_maxscales && !secondary_maxscale_IP.empty()) - { - set_active_maxscale(MXS_SECONDARY); - init_maxscale(); - set_active_maxscale(MXS_PRIMARY); - } + init_maxscale(0); } if (backend_ssl) @@ -406,68 +367,6 @@ int TestConnections::read_env() printf("Reading test setup configuration from environmental variables\n"); } - env = getenv("maxscale_IP"); - if (env != NULL) - { - sprintf(maxscale_IP, "%s", env); - primary_maxscale_IP = env; - } - - env = getenv("maxscale_network6"); - if (env != NULL) - { - sprintf(maxscale_IP6, "%s", env); - primary_maxscale_IP6 = env; - } - - env = getenv("maxscale2_IP"); - if (env != NULL) - { - secondary_maxscale_IP = env; - } - - env = getenv("maxscale2_network6"); - if (env != NULL) - { - secondary_maxscale_IP = env; - } - - env = getenv("maxscale_user"); - if (env != NULL) - { - sprintf(maxscale_user, "%s", env); - } - else - { - sprintf(maxscale_user, "skysql"); - } - env = getenv("maxscale_password"); - if (env != NULL) - { - sprintf(maxscale_password, "%s", env); - } - else - { - sprintf(maxscale_password, "skysql"); - } - env = getenv("maxadmin_password"); - if (env != NULL) - { - sprintf(maxadmin_password, "%s", env); - } - else - { - sprintf(maxadmin_password, "mariadb"); - } - env = getenv("maxscale_keyfile"); - if (env != NULL) - { - sprintf(maxscale_keyfile, "%s", env); - } - else - { - sprintf(maxscale_keyfile, "skysql"); - } //env = getenv("get_logs_command"); if (env != NULL) {sprintf(get_logs_command, "%s", env);} @@ -477,45 +376,9 @@ int TestConnections::read_env() sprintf(sysbench_dir, "%s", env); } - env = getenv("maxscale_cnf"); - if (env != NULL) - { - sprintf(maxscale_cnf, "%s", env); - } - else - { - sprintf(maxscale_cnf, "/etc/maxscale.cnf"); - } - env = getenv("maxscale_log_dir"); - if (env != NULL) - { - sprintf(maxscale_log_dir, "%s", env); - } - else - { - sprintf(maxscale_log_dir, "/var/log/maxscale/"); - } - env = getenv("maxscale_binlog_dir"); - if (env != NULL) - { - sprintf(maxscale_binlog_dir, "%s", env); - } - else - { - sprintf(maxscale_binlog_dir, "/var/lib/maxscale/Binlog_Service/"); - } //env = getenv("test_dir"); if (env != NULL) {sprintf(test_dir, "%s", env);} - env = getenv("maxscale_whoami"); - if (env != NULL) - { - sprintf(maxscale_access_user, "%s", env); - } - env = getenv("maxscale_access_sudo"); - if (env != NULL) - { - sprintf(maxscale_access_sudo, "%s", env); - } + ssl = false; env = getenv("ssl"); if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0) )) { @@ -543,49 +406,45 @@ int TestConnections::read_env() use_ipv6 = true; } - env = getenv("maxscale_hostname"); - if (env != NULL) - { - sprintf(maxscale_hostname, "%s", env); - } - else - { - sprintf(maxscale_hostname, "%s", maxscale_IP); - } - env = getenv("backend_ssl"); if (env != NULL && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0) )) { backend_ssl = true; } - - if (strcmp(maxscale_access_user, "root") == 0) + else { - sprintf(maxscale_access_homedir, "/%s/", maxscale_access_user); + backend_ssl = false; + } + + + env = getenv("smoke"); + if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0) )) + { + smoke = true; } else { - sprintf(maxscale_access_homedir, "/home/%s/", maxscale_access_user); + smoke = false; } - - env = getenv("smoke"); - if (env) - { - smoke = strcasecmp(env, "yes") == 0 || strcasecmp(env, "true") == 0 || - strcasecmp(env, "1") == 0 || strcasecmp(env, "on") == 0; - } - env = getenv("threads"); if ((env != NULL)) { sscanf(env, "%d", &threads); } + else + { + threads = 4; + } env = getenv("use_snapshots"); if (env != NULL && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0) )) { use_snapshots = true; } + else + { + use_snapshots = false; + } env = getenv("take_snapshot_command"); if (env != NULL) { @@ -621,12 +480,12 @@ int TestConnections::read_env() int TestConnections::print_env() { int i; - printf("Maxscale IP\t%s\n", maxscale_IP); - printf("Maxscale User name\t%s\n", maxscale_user); - printf("Maxscale Password\t%s\n", maxscale_password); - printf("Maxscale SSH key\t%s\n", maxscale_keyfile); - printf("Maxadmin password\t%s\n", maxadmin_password); - printf("Access user\t%s\n", maxscale_access_user); + printf("Maxscale IP\t%s\n", maxscales->IP[0]); + printf("Maxscale User name\t%s\n", maxscales->user_name); + printf("Maxscale Password\t%s\n", maxscales->password); + printf("Maxscale SSH key\t%s\n", maxscales->sshkey[0]); + printf("Maxadmin password\t%s\n", maxscales->maxadmin_password[0]); + printf("Access user\t%s\n", maxscales->access_user[0]); repl->print_env(); galera->print_env(); } @@ -649,7 +508,7 @@ const char * get_template_name(char * test_name) return default_template; } -void TestConnections::process_template(const char *template_name, const char *dest) +void TestConnections::process_template(int m, const char *template_name, const char *dest) { char str[4096]; char template_file[1024]; @@ -699,53 +558,56 @@ void TestConnections::process_template(const char *template_name, const char *de } mdn[j]->connect(); - execute_query(mdn[j]->nodes[0], "CREATE DATABASE IF NOT EXISTS test"); + execute_query(mdn[j]->nodes[0], (char *) "CREATE DATABASE IF NOT EXISTS test"); mdn[j]->close_connections(); } - sprintf(str, "sed -i \"s/###access_user###/%s/g\" maxscale.cnf", maxscale_access_user); + sprintf(str, "sed -i \"s/###access_user###/%s/g\" maxscale.cnf", maxscales->access_user[m]); system(str); - sprintf(str, "sed -i \"s|###access_homedir###|%s|g\" maxscale.cnf", maxscale_access_homedir); + sprintf(str, "sed -i \"s|###access_homedir###|%s|g\" maxscale.cnf", maxscales->access_homedir[m]); system(str); if (repl->v51) { system("sed -i \"s/###repl51###/mysql51_replication=true/g\" maxscale.cnf"); } - copy_to_maxscale("maxscale.cnf", (char *) dest); + maxscales->copy_to_node_legacy((char *) "maxscale.cnf", (char *) dest, m); } -int TestConnections::init_maxscale() +int TestConnections::init_maxscale(int m) { const char * template_name = get_template_name(test_name); tprintf("Template is %s\n", template_name); + process_template(m, template_name, maxscales->access_homedir[m]); - process_template(template_name, maxscale_access_homedir); - - ssh_maxscale(true, "cp maxscale.cnf %s;rm -rf %s/certs;mkdir -m a+wrx %s/certs;", maxscale_cnf, - maxscale_access_homedir, maxscale_access_homedir); + maxscales->ssh_node_f(m, true, + "cp maxscale.cnf %s;rm -rf %s/certs;mkdir -m a+wrx %s/certs;", + maxscales->maxscale_cnf[m], + maxscales->access_homedir[m], maxscales->access_homedir[m]); char str[4096]; char dtr[4096]; sprintf(str, "%s/ssl-cert/*", test_dir); - sprintf(dtr, "%s/certs/", maxscale_access_homedir); - copy_to_maxscale(str, dtr); + sprintf(dtr, "%s/certs/", maxscales->access_homedir[m]); + maxscales->copy_to_node_legacy(str, dtr, m); sprintf(str, "cp %s/ssl-cert/* .", test_dir); system(str); - ssh_maxscale(true, "chown maxscale:maxscale -R %s/certs;" - "chmod 664 %s/certs/*.pem;" - " chmod a+x %s;" - "%s" - "iptables -I INPUT -p tcp --dport 4001 -j ACCEPT;" - "rm -f %s/maxscale.log %s/maxscale1.log;" - "rm -f /var/log/maxscale/.secrets;" // Needs to be explicitly deleted - "rm -rf /tmp/core* /dev/shm/* /var/lib/maxscale/maxscale.cnf.d/ /var/lib/maxscale/*;" - "%s", - maxscale_access_homedir, maxscale_access_homedir, maxscale_access_homedir, - maxscale::start ? "killall -9 maxscale;" : "", - maxscale_log_dir, maxscale_log_dir, maxscale::start ? "service maxscale restart" : ""); + + maxscales->ssh_node_f(m, true, + "chown maxscale:maxscale -R %s/certs;" + "chmod 664 %s/certs/*.pem;" + " chmod a+x %s;" + "%s" + "iptables -I INPUT -p tcp --dport 4001 -j ACCEPT;" + "rm -f %s/maxscale.log %s/maxscale1.log;" + "rm -rf /tmp/core* /dev/shm/* /var/lib/maxscale/maxscale.cnf.d/ /var/lib/maxscale/*;" + "%s", + maxscales->access_homedir[m], maxscales->access_homedir[m], maxscales->access_homedir[m], + maxscale::start ? "killall -9 maxscale;" : "", + maxscales->maxscale_log_dir[m], maxscales->maxscale_log_dir[m], + maxscale::start ? "service maxscale restart" : ""); fflush(stdout); @@ -755,7 +617,7 @@ int TestConnections::init_maxscale() for (waits = 0; waits < 15; waits++) { - if (ssh_maxscale(true, "/bin/sh -c \"maxadmin help > /dev/null || exit 1\"") == 0) + if (maxscales->ssh_node(m, "/bin/sh -c \"maxadmin help > /dev/null || exit 1\"", true) == 0); { break; } @@ -769,43 +631,8 @@ int TestConnections::init_maxscale() } } -int TestConnections::connect_maxscale() -{ - return connect_rwsplit() + - connect_readconn_master() + - connect_readconn_slave(); -} -int TestConnections::close_maxscale_connections() -{ - mysql_close(conn_master); - mysql_close(conn_slave); - mysql_close(conn_rwsplit); -} - -int TestConnections::restart_maxscale() -{ - int res = ssh_maxscale(true, "service maxscale restart"); - fflush(stdout); - return res; -} - -int TestConnections::start_maxscale() -{ - int res = ssh_maxscale(true, "service maxscale start"); - fflush(stdout); - return res; -} - -int TestConnections::stop_maxscale() -{ - int res = ssh_maxscale(true, "service maxscale stop"); - check_maxscale_processes(0); - fflush(stdout); - return res; -} - -int TestConnections::copy_mariadb_logs(Mariadb_nodes * repl, const char* prefix) +int TestConnections::copy_mariadb_logs(Mariadb_nodes * repl, char * prefix) { int local_result = 0; char * mariadb_log; @@ -820,7 +647,7 @@ int TestConnections::copy_mariadb_logs(Mariadb_nodes * repl, const char* prefix) { 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, "cat /var/lib/mysql/*.err", true, &exit_code); + mariadb_log = repl->ssh_node_output(i, (char *) "cat /var/lib/mysql/*.err", true, &exit_code); sprintf(str, "LOGS/%s/%s%d_mariadb_log", test_name, prefix, i); f = fopen(str, "w"); if (f != NULL) @@ -841,54 +668,72 @@ int TestConnections::copy_mariadb_logs(Mariadb_nodes * repl, const char* prefix) int TestConnections::copy_all_logs() { - char str[4096]; set_timeout(300); if (!no_backend_log_copy) { - copy_mariadb_logs(repl, "node"); - copy_mariadb_logs(galera, "galera"); + copy_mariadb_logs(repl, (char *) "node"); + copy_mariadb_logs(galera, (char *) "galera"); } - sprintf(str, "%s/copy_logs.sh %s", test_dir, test_name); - tprintf("Executing %s\n", str); - if (system(str) != 0) + return (copy_maxscale_logs(0)); +} +int TestConnections::copy_maxscale_logs(double timestamp) +{ + char log_dir[1024]; + char log_dir_i[1024]; + char sys[1024]; + if (timestamp == 0) { - tprintf("copy_logs.sh executing FAILED!\n"); - return 1; + sprintf(log_dir, "LOGS/%s", test_name); } else { - tprintf("copy_logs.sh OK!\n"); - return 0; + sprintf(log_dir, "LOGS/%s/%04f", test_name, timestamp); } + for (int i = 0; i < maxscales->N; i++) + { + sprintf(log_dir_i, "%s/%03d", log_dir, i); + sprintf(sys, "mkdir -p %s", log_dir_i); + system(sys); + if (strcmp(maxscales->IP[i], "127.0.0.1") != 0) + { + maxscales->ssh_node_f(i, true, + "rm -rf %s/logs; mkdir %s/logs; \ + %s cp %s/*.log %s/logs/; \ + %s cp /tmp/core* %s/logs/;\ + %s cp %s %s/logs/;\ + %s chmod 777 -R %s/logs", + maxscales->access_homedir[i], maxscales->access_homedir[i], + maxscales->access_sudo[i], maxscales->maxscale_log_dir[i], maxscales->access_homedir[i], + maxscales->access_sudo[i], maxscales->access_homedir[i], + maxscales->access_sudo[i], maxscales->maxscale_cnf[i], maxscales->access_homedir[i], + maxscales->access_homedir[i]); + sprintf(sys, "%s/logs/*", maxscales->access_homedir[i]); + maxscales->copy_from_node(i, sys, log_dir_i); + } + else + { + maxscales->ssh_node_f(i, true, "cp %s/*.logs %s/", maxscales->maxscale_log_dir[i], log_dir_i); + maxscales->ssh_node_f(i, true, "cp /tmp/core* %s/", log_dir_i); + maxscales->ssh_node_f(i, true, "cp %s %s/", maxscales->maxscale_cnf[i], log_dir_i); + maxscales->ssh_node_f(i, true, "chmod a+r -R %s", log_dir_i); + } + } + return 0; } int TestConnections::copy_all_logs_periodic() { - char str[4096]; - //set_timeout(300); - timeval t2; gettimeofday(&t2, NULL); double elapsedTime = (t2.tv_sec - start_time.tv_sec); elapsedTime += (double) (t2.tv_usec - start_time.tv_usec) / 1000000.0; - sprintf(str, "%s/copy_logs.sh %s %04f", test_dir, test_name, elapsedTime); - tprintf("Executing %s\n", str); - if (system(str) != 0) - { - tprintf("copy_logs.sh executing FAILED!\n"); - return 1; - } - else - { - tprintf("copy_logs.sh OK!\n"); - return 0; - } + return (copy_maxscale_logs(elapsedTime)); } -int TestConnections::prepare_binlog() +int TestConnections::prepare_binlog(int m) { char version_str[1024] = ""; @@ -901,28 +746,28 @@ int TestConnections::prepare_binlog() strstr(version_str, "10.1") == NULL && strstr(version_str, "10.2") == NULL) { - add_result(ssh_maxscale(true, - "sed -i \"s/,mariadb10-compatibility=1//\" %s", - maxscale_cnf), "Error editing maxscale.cnf"); + add_result(maxscales->ssh_node_f(m, true, + "sed -i \"s/,mariadb10-compatibility=1//\" %s", + maxscales->maxscale_cnf[m]), "Error editing maxscale.cnf"); } tprintf("Removing all binlog data from Maxscale node"); - add_result(ssh_maxscale(true, "rm -rf %s", maxscale_binlog_dir), + add_result(maxscales->ssh_node_f(m, true, "rm -rf %s", maxscales->maxscale_binlog_dir[m]), "Removing binlog data failed"); tprintf("Creating binlog dir"); - add_result(ssh_maxscale(true, "mkdir -p %s", maxscale_binlog_dir), + add_result(maxscales->ssh_node_f(m, true, "mkdir -p %s", maxscales->maxscale_binlog_dir[m]), "Creating binlog data dir failed"); tprintf("Set 'maxscale' as a owner of binlog dir"); - add_result(ssh_maxscale(false, - "%s mkdir -p %s; %s chown maxscale:maxscale -R %s", - maxscale_access_sudo, maxscale_binlog_dir, - maxscale_access_sudo, maxscale_binlog_dir), + add_result(maxscales->ssh_node_f(m, false, + "%s mkdir -p %s; %s chown maxscale:maxscale -R %s", + maxscales->access_sudo[m], maxscales->maxscale_binlog_dir[m], + maxscales->access_sudo[m], maxscales->maxscale_binlog_dir[m]), "directory ownership change failed"); return 0; } -int TestConnections::start_binlog() +int TestConnections::start_binlog(int m) { char sys1[4096]; MYSQL * binlog; @@ -950,14 +795,14 @@ int TestConnections::start_binlog() repl->stop_nodes(); - binlog = open_conn_no_db(binlog_port, maxscale_IP, repl->user_name, repl->password, ssl); - execute_query(binlog, "stop slave"); - execute_query(binlog, "reset slave all"); - execute_query(binlog, "reset master"); + binlog = open_conn_no_db(maxscales->binlog_port[m], maxscales->IP[m], repl->user_name, repl->password, ssl); + execute_query(binlog, (char *) "stop slave"); + execute_query(binlog, (char *) "reset slave all"); + execute_query(binlog, (char *) "reset master"); mysql_close(binlog); tprintf("Stopping maxscale\n"); - add_result(stop_maxscale(), "Maxscale stopping failed\n"); + add_result(maxscales->stop_maxscale(m), "Maxscale stopping failed\n"); for (i = 0; i < repl->N; i++) { @@ -976,12 +821,12 @@ int TestConnections::start_binlog() execute_query(repl->nodes[i], "reset master"); } - prepare_binlog(); + prepare_binlog(m); tprintf("Testing binlog when MariaDB is started with '%s' option\n", cmd_opt); tprintf("ls binlog data dir on Maxscale node\n"); - add_result(ssh_maxscale(true, "ls -la %s/", maxscale_binlog_dir), "ls failed\n"); + add_result(maxscales->ssh_node_f(m, true, "ls -la %s/", maxscales->maxscale_binlog_dir[m]), "ls failed\n"); if (binlog_master_gtid) { @@ -989,7 +834,8 @@ int TestConnections::start_binlog() tprintf("GTID for connection 1st slave to master!\n"); try_query(repl->nodes[1], (char *) "stop slave"); try_query(repl->nodes[1], (char *) "SET @@global.gtid_slave_pos=''"); - sprintf(sys1, "CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d, MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_USE_GTID=Slave_pos", + sprintf(sys1, + "CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d, MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_USE_GTID=Slave_pos", repl->IP[0], repl->port[0]); try_query(repl->nodes[1], sys1); try_query(repl->nodes[1], (char *) "start slave"); @@ -1011,10 +857,10 @@ int TestConnections::start_binlog() } tprintf("Starting back Maxscale\n"); - add_result(start_maxscale(), "Maxscale start failed\n"); + add_result(maxscales->start_maxscale(m), "Maxscale start failed\n"); tprintf("Connecting to MaxScale binlog router (with any DB)\n"); - binlog = open_conn_no_db(binlog_port, maxscale_IP, repl->user_name, repl->password, ssl); + binlog = open_conn_no_db(maxscales->binlog_port[m], maxscales->IP[m], repl->user_name, repl->password, ssl); add_result(mysql_errno(binlog), "Error connection to binlog router %s\n", mysql_error(binlog)); @@ -1024,7 +870,8 @@ int TestConnections::start_binlog() tprintf("GTID for connection binlog router to master!\n"); try_query(binlog, (char *) "stop slave"); try_query(binlog, (char *) "SET @@global.gtid_slave_pos=''"); - sprintf(sys1, "CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d, MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_USE_GTID=Slave_pos", + sprintf(sys1, + "CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d, MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_USE_GTID=Slave_pos", repl->IP[0], repl->port[0]); try_query(binlog, sys1); } @@ -1041,7 +888,7 @@ int TestConnections::start_binlog() { sprintf(sys1, "CHANGE MASTER TO master_ssl_cert='%s/certs/client-cert.pem', master_ssl_ca='%s/certs/ca.pem', master_ssl=1, master_ssl_key='%s/certs/client-key.pem'", - maxscale_access_homedir, maxscale_access_homedir, maxscale_access_homedir); + maxscales->access_homedir[m], maxscales->access_homedir[m], maxscales->access_homedir[m]); tprintf("Configuring Master ssl: %s\n", sys1); try_query(binlog, sys1); } @@ -1057,8 +904,9 @@ int TestConnections::start_binlog() { try_query(repl->nodes[i], (char *) "stop slave"); try_query(repl->nodes[i], (char *) "SET @@global.gtid_slave_pos=''"); - sprintf(sys1, "CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d, MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_USE_GTID=Slave_pos", - maxscale_IP, binlog_port); + sprintf(sys1, + "CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d, MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_USE_GTID=Slave_pos", + maxscales->IP[m], maxscales->binlog_port[m]); try_query(repl->nodes[i], sys1); try_query(repl->nodes[i], (char *) "start slave"); } @@ -1069,21 +917,18 @@ int TestConnections::start_binlog() // get Master status from Maxscale binlog tprintf("show master status\n"); - fflush(stdout); find_field(binlog, (char *) "show master status", (char *) "File", &log_file[0]); find_field(binlog, (char *) "show master status", (char *) "Position", &log_pos[0]); tprintf("Maxscale binlog master file: %s\n", log_file); - fflush(stdout); tprintf("Maxscale binlog master pos : %s\n", log_pos); - fflush(stdout); tprintf("Setup all backend nodes except first one to be slaves of binlog Maxscale node\n"); fflush(stdout); for (i = 2; i < repl->N; i++) { - try_query(repl->nodes[i], "stop slave;"); - repl->set_slave(repl->nodes[i], maxscale_IP, binlog_port, log_file, log_pos); + try_query(repl->nodes[i], (char *) "stop slave"); + repl->set_slave(repl->nodes[i], maxscales->IP[m], maxscales->binlog_port[m], log_file, log_pos); } } @@ -1094,12 +939,13 @@ int TestConnections::start_binlog() return global_result; } -bool TestConnections::replicate_from_master() +bool TestConnections::replicate_from_master(int m) { bool rval = true; /** Stop the binlogrouter */ - MYSQL* conn = open_conn_no_db(binlog_port, maxscale_IP, repl->user_name, repl->password, ssl); + MYSQL* conn = open_conn_no_db(maxscales->binlog_port[m], maxscales->IP[m], repl->user_name, repl->password, + ssl); if (execute_query(conn, "stop slave")) { @@ -1110,9 +956,9 @@ bool TestConnections::replicate_from_master() repl->execute_query_all_nodes("STOP SLAVE"); /** Clean up MaxScale directories */ - ssh_maxscale(true, "service maxscale stop"); - prepare_binlog(); - ssh_maxscale(true, "service maxscale start"); + maxscales->ssh_node(m, "service maxscale stop", true); + prepare_binlog(m); + maxscales->ssh_node(m, "service maxscale start", true); char log_file[256] = ""; char log_pos[256] = "4"; @@ -1120,7 +966,7 @@ bool TestConnections::replicate_from_master() repl->connect(); execute_query(repl->nodes[0], "RESET MASTER"); - conn = open_conn_no_db(binlog_port, maxscale_IP, repl->user_name, repl->password, ssl); + conn = open_conn_no_db(maxscales->binlog_port[m], maxscales->IP[m], repl->user_name, repl->password, ssl); if (find_field(repl->nodes[0], "show master status", "File", log_file) || repl->set_slave(conn, repl->IP[0], repl->port[0], log_file, log_pos) || @@ -1134,7 +980,7 @@ bool TestConnections::replicate_from_master() return rval; } -int TestConnections::start_mm() +int TestConnections::start_mm(int m) { int i; char log_file1[256]; @@ -1143,33 +989,31 @@ int TestConnections::start_mm() char log_pos2[256]; tprintf("Stopping maxscale\n"); - fflush(stdout); - int global_result = stop_maxscale(); + int global_result = maxscales->stop_maxscale(m); tprintf("Stopping all backend nodes\n"); - fflush(stdout); global_result += repl->stop_nodes(); for (i = 0; i < 2; i++) { tprintf("Starting back node %d\n", i); - global_result += repl->start_node(i, ""); + global_result += repl->start_node(i, (char *) ""); } repl->connect(); for (i = 0; i < 2; i++) { - execute_query(repl->nodes[i], "stop slave"); - execute_query(repl->nodes[i], "reset master"); + execute_query(repl->nodes[i], (char *) "stop slave"); + execute_query(repl->nodes[i], (char *) "reset master"); } - execute_query(repl->nodes[0], "SET GLOBAL READ_ONLY=ON"); + execute_query(repl->nodes[0], (char *) "SET GLOBAL READ_ONLY=ON"); - find_field(repl->nodes[0], "show master status", "File", log_file1); - find_field(repl->nodes[0], "show master status", "Position", log_pos1); + find_field(repl->nodes[0], (char *) "show master status", (char *) "File", log_file1); + find_field(repl->nodes[0], (char *) "show master status", (char *) "Position", log_pos1); - find_field(repl->nodes[1], "show master status", "File", log_file2); - find_field(repl->nodes[1], "show master status", "Position", log_pos2); + find_field(repl->nodes[1], (char *) "show master status", (char *) "File", log_file2); + find_field(repl->nodes[1], (char *) "show master status", (char *) "Position", 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); @@ -1177,46 +1021,53 @@ int TestConnections::start_mm() repl->close_connections(); tprintf("Starting back Maxscale\n"); - fflush(stdout); - global_result += start_maxscale(); + global_result += maxscales->start_maxscale(m); return global_result; } -bool TestConnections::log_matches(const char* pattern) +bool TestConnections::log_matches(int m, const char* pattern) { - return ssh_maxscale(true, "grep '%s' /var/log/maxscale/maxscale*.log", pattern) == 0; + return maxscales->ssh_node_f(m, true, "grep '%s' /var/log/maxscale/maxscale*.log", pattern) == 0; } -void TestConnections::log_includes(const char* pattern) +void TestConnections::log_includes(int m, const char* pattern) { - add_result(!log_matches(pattern), "Log does not match pattern '%s'", pattern); + add_result(!log_matches(m, pattern), "Log does not match pattern '%s'", pattern); } -void TestConnections::log_excludes(const char* pattern) +void TestConnections::log_excludes(int m, const char* pattern) { - add_result(log_matches(pattern), "Log matches pattern '%s'", pattern); + add_result(log_matches(m, pattern), "Log matches pattern '%s'", pattern); } -void TestConnections::check_log_err(const char * err_msg, bool expected) +void TestConnections::check_log_err(int m, const char * err_msg, bool expected) { char * err_log_content; tprintf("Getting logs\n"); char sys1[4096]; + char dest[1024]; + char log_file[64]; set_timeout(100); - sprintf(&sys1[0], "rm -f *.log; %s %s", get_logs_command, maxscale_IP); + sprintf(dest, "maxscale_log_%03d/", m); + sprintf(&sys1[0], "mkdir -p maxscale_log_%03d; rm -f %s*.log", + m, dest); //tprintf("Executing: %s\n", sys1); system(sys1); set_timeout(50); + sprintf(sys1, "%s/*", maxscales->maxscale_log_dir[m]); + maxscales->copy_from_node(m, sys1, dest); tprintf("Reading maxscale.log\n"); - if ( ( read_log("maxscale.log", &err_log_content) != 0) || (strlen(err_log_content) < 2) ) + sprintf(log_file, "maxscale_log_%03d/maxscale.log", m); + if ( ( read_log(log_file, &err_log_content) != 0) || (strlen(err_log_content) < 2) ) { tprintf("Reading maxscale1.log\n"); + sprintf(log_file, "maxscale_log_%03d/maxscale1.log", m); free(err_log_content); - if (read_log("maxscale1.log", &err_log_content) != 0) + if (read_log(log_file, &err_log_content) != 0) { add_result(1, "Error reading log\n"); } @@ -1251,7 +1102,7 @@ void TestConnections::check_log_err(const char * err_msg, bool expected) } } -int TestConnections::find_connected_slave(int * global_result) +int TestConnections::find_connected_slave(int m, int * global_result) { int conn_num; int all_conn = 0; @@ -1259,7 +1110,7 @@ int TestConnections::find_connected_slave(int * global_result) repl->connect(); for (int i = 0; i < repl->N; i++) { - conn_num = get_conn_num(repl->nodes[i], maxscale_ip(), maxscale_hostname, "test"); + conn_num = get_conn_num(repl->nodes[i], maxscales->ip(m), maxscales->hostname[m], (char *) "test"); tprintf("connections to %d: %u\n", i, conn_num); if ((i == 0) && (conn_num != 1)) { @@ -1282,7 +1133,7 @@ int TestConnections::find_connected_slave(int * global_result) return current_slave; } -int TestConnections::find_connected_slave1() +int TestConnections::find_connected_slave1(int m) { int conn_num; int all_conn = 0; @@ -1290,7 +1141,7 @@ int TestConnections::find_connected_slave1() repl->connect(); for (int i = 0; i < repl->N; i++) { - conn_num = get_conn_num(repl->nodes[i], maxscale_ip(), maxscale_hostname, "test"); + conn_num = get_conn_num(repl->nodes[i], maxscales->ip(m), maxscales->hostname[m], (char *) "test"); tprintf("connections to %d: %u\n", i, conn_num); all_conn += conn_num; if ((i != 0) && (conn_num != 0)) @@ -1303,10 +1154,12 @@ int TestConnections::find_connected_slave1() return current_slave; } -int TestConnections::check_maxscale_processes(int expected) +int TestConnections::check_maxscale_processes(int m, int expected) { - char* maxscale_num = ssh_maxscale_output(false, "ps -C maxscale | grep maxscale | wc -l"); - if (maxscale_num == NULL) + int exit_code; + char* maxscale_num = maxscales->ssh_node_output(m, "ps -C maxscale | grep maxscale | wc -l", false, + &exit_code); + if ((maxscale_num == NULL) || (exit_code != 0)) { return -1; } @@ -1320,49 +1173,58 @@ int TestConnections::check_maxscale_processes(int expected) { tprintf("%s maxscale processes detected, trying agin in 5 seconds\n", maxscale_num); sleep(5); - maxscale_num = ssh_maxscale_output(false, "ps -C maxscale | grep maxscale | wc -l"); + maxscale_num = maxscales->ssh_node_output(m, "ps -C maxscale | grep maxscale | wc -l", false, &exit_code); if (atoi(maxscale_num) != expected) { add_result(1, "Number of MaxScale processes is not %d, it is %s\n", expected, maxscale_num); } } - return 0; + return exit_code; } -int TestConnections::check_maxscale_alive() +int TestConnections::stop_maxscale(int m) +{ + int res = maxscales->ssh_node(m, "service maxscale stop", true); + check_maxscale_processes(m, 0); + fflush(stdout); + return res; +} + + +int TestConnections::check_maxscale_alive(int m) { int gr = global_result; set_timeout(10); tprintf("Connecting to Maxscale\n"); - add_result(connect_maxscale(), "Can not connect to Maxscale\n"); + add_result(maxscales->connect_maxscale(m), "Can not connect to Maxscale\n"); tprintf("Trying simple query against all sevices\n"); tprintf("RWSplit \n"); set_timeout(10); - try_query(conn_rwsplit, "show databases;"); + try_query(maxscales->conn_rwsplit[m], (char *) "show databases;"); tprintf("ReadConn Master \n"); set_timeout(10); - try_query(conn_master, "show databases;"); + try_query(maxscales->conn_master[m], (char *) "show databases;"); tprintf("ReadConn Slave \n"); set_timeout(10); - try_query(conn_slave, "show databases;"); + try_query(maxscales->conn_slave[m], (char *) "show databases;"); set_timeout(10); - close_maxscale_connections() ; + maxscales->close_maxscale_connections(m); add_result(global_result - gr, "Maxscale is not alive\n"); stop_timeout(); - check_maxscale_processes(1); + check_maxscale_processes(m, 1); return global_result - gr; } -int TestConnections::test_maxscale_connections(bool rw_split, bool rc_master, bool rc_slave) +int TestConnections::test_maxscale_connections(int m, bool rw_split, bool rc_master, bool rc_slave) { int rval = 0; int rc; tprintf("Testing RWSplit, expecting %s\n", (rw_split ? "success" : "failure")); - rc = execute_query(conn_rwsplit, "select 1"); + rc = execute_query(maxscales->conn_rwsplit[m], "select 1"); if ((rc == 0) != rw_split) { tprintf("Error: Query %s\n", (rw_split ? "failed" : "succeeded")); @@ -1370,7 +1232,7 @@ int TestConnections::test_maxscale_connections(bool rw_split, bool rc_master, bo } tprintf("Testing ReadConnRoute Master, expecting %s\n", (rc_master ? "success" : "failure")); - rc = execute_query(conn_master, "select 1"); + rc = execute_query(maxscales->conn_master[m], "select 1"); if ((rc == 0) != rc_master) { tprintf("Error: Query %s", (rc_master ? "failed" : "succeeded")); @@ -1378,7 +1240,7 @@ int TestConnections::test_maxscale_connections(bool rw_split, bool rc_master, bo } tprintf("Testing ReadConnRoute Slave, expecting %s\n", (rc_slave ? "success" : "failure")); - rc = execute_query(conn_slave, "select 1"); + rc = execute_query(maxscales->conn_slave[m], "select 1"); if ((rc == 0) != rc_slave) { tprintf("Error: Query %s", (rc_slave ? "failed" : "succeeded")); @@ -1387,177 +1249,9 @@ int TestConnections::test_maxscale_connections(bool rw_split, bool rc_master, bo return rval; } -void TestConnections::generate_ssh_cmd(char * cmd, char * ssh, bool sudo) -{ - if (strcmp(maxscale_IP, "127.0.0.1") == 0) - { - if (sudo) - { - sprintf(cmd, - "%s %s", - maxscale_access_sudo, ssh); - } - else - { - sprintf(cmd, - "%s", - ssh); - } - } - else - { - if (sudo) - { - sprintf(cmd, - "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s '%s %s'", - maxscale_keyfile, maxscale_access_user, maxscale_IP, maxscale_access_sudo, ssh); - } - else - { - sprintf(cmd, - "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s '%s\'", - maxscale_keyfile, maxscale_access_user, maxscale_IP, ssh); - } - } -} - - -char* TestConnections::ssh_maxscale_output(bool sudo, const char* format, ...) -{ - va_list valist; - - va_start(valist, format); - int message_len = vsnprintf(NULL, 0, format, valist); - va_end(valist); - - if (message_len < 0) - { - return NULL; - } - - 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); - generate_ssh_cmd(cmd, sys, sudo); -//tprintf("############ssh smd %s\n:", cmd); - FILE *output = popen(cmd, "r"); - if (output == NULL) - { - printf("Error opening ssh %s\n", strerror(errno)); - return NULL; - } - char buffer[1024]; - size_t rsize = sizeof(buffer); - char* result = (char*)calloc(rsize, sizeof(char)); - - while (fgets(buffer, sizeof(buffer), output)) - { - result = (char*)realloc(result, sizeof(buffer) + rsize); - rsize += sizeof(buffer); - strcat(result, buffer); - } - - free(sys); - free(cmd); - pclose(output); - - return result; -} - -int TestConnections::ssh_maxscale(bool sudo, const char* format, ...) -{ - va_list valist; - - va_start(valist, format); - int message_len = vsnprintf(NULL, 0, format, valist); - va_end(valist); - - if (message_len < 0) - { - 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(maxscale_IP, "127.0.0.1") == 0) - { - tprintf("starting bash\n"); - sprintf(cmd, "bash"); - } - else - { - sprintf(cmd, - "ssh -i %s -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s%s", - maxscale_keyfile, maxscale_access_user, maxscale_IP, verbose ? "" : " > /dev/null"); - } - int rc = 1; - FILE *in = popen(cmd, "w"); - - if (in) - { - if (sudo) - { - fprintf(in, "sudo su -\n"); - fprintf(in, "cd /home/%s\n", maxscale_access_user); - } - - fprintf(in, "%s\n", sys); - rc = pclose(in); - } - - free(sys); - free(cmd); - return WEXITSTATUS(rc); -} - -int TestConnections::copy_to_maxscale(const char* src, const char* dest) -{ - char sys[strlen(src) + strlen(dest) + 1024]; - if (strcmp(maxscale_IP, "127.0.0.1") == 0) - { - sprintf(sys, "cp %s %s", - src, dest); - } - else - { - - sprintf(sys, "scp -q -i %s -o UserKnownHostsFile=/dev/null " - "-o StrictHostKeyChecking=no -o LogLevel=quiet %s %s@%s:%s", - maxscale_keyfile, src, maxscale_access_user, maxscale_IP, dest); - } - return system(sys); -} - - -int TestConnections::copy_from_maxscale(char* src, char* dest) -{ - char sys[strlen(src) + strlen(dest) + 1024]; - if (strcmp(maxscale_IP, "127.0.0.1") == 0) - { - sprintf(sys, "cp %s %s", - src, dest); - } - else - { - sprintf(sys, "scp -i %s -o UserKnownHostsFile=/dev/null " - "-o StrictHostKeyChecking=no -o LogLevel=quiet %s@%s:%s %s", - maxscale_keyfile, maxscale_access_user, maxscale_IP, src, dest); - } - return system(sys); -} - -int TestConnections::create_connections(int conn_N, bool rwsplit_flag, bool master_flag, bool slave_flag, +int TestConnections::create_connections(int m, int conn_N, bool rwsplit_flag, bool master_flag, + bool slave_flag, bool galera_flag) { int i; @@ -1585,7 +1279,7 @@ int TestConnections::create_connections(int conn_N, bool rwsplit_flag, bool mast printf("RWSplit \t"); } - rwsplit_conn[i] = open_rwsplit_connection(); + rwsplit_conn[i] = maxscales->open_rwsplit_connection(m); if (!rwsplit_conn[i]) { local_result++; @@ -1599,7 +1293,7 @@ int TestConnections::create_connections(int conn_N, bool rwsplit_flag, bool mast printf("ReadConn master \t"); } - master_conn[i] = open_readconn_master_connection(); + master_conn[i] = maxscales->open_readconn_master_connection(m); if ( mysql_errno(master_conn[i]) != 0 ) { local_result++; @@ -1613,7 +1307,7 @@ int TestConnections::create_connections(int conn_N, bool rwsplit_flag, bool mast printf("ReadConn slave \t"); } - slave_conn[i] = open_readconn_slave_connection(); + slave_conn[i] = maxscales->open_readconn_slave_connection(m); if ( mysql_errno(slave_conn[i]) != 0 ) { local_result++; @@ -1627,7 +1321,7 @@ int TestConnections::create_connections(int conn_N, bool rwsplit_flag, bool mast printf("Galera \n"); } - galera_conn[i] = open_conn(4016, maxscale_IP, maxscale_user, maxscale_password, ssl); + galera_conn[i] = open_conn(4016, maxscales->IP[m], maxscales->user_name, maxscales->password, ssl); if ( mysql_errno(galera_conn[i]) != 0) { local_result++; @@ -1705,7 +1399,7 @@ int TestConnections::create_connections(int conn_N, bool rwsplit_flag, bool mast return local_result; } -int TestConnections::get_client_ip(char * ip) +int TestConnections::get_client_ip(int m, char * ip) { MYSQL * conn; MYSQL_RES *res; @@ -1717,14 +1411,16 @@ int TestConnections::get_client_ip(char * ip) unsigned long long int i; unsigned int conn_num = 0; - connect_rwsplit(); - if (execute_query(conn_rwsplit, "CREATE DATABASE IF NOT EXISTS db_to_check_client_ip") != 0 ) + maxscales->connect_rwsplit(m); + if (execute_query(maxscales->conn_rwsplit[m], + (char *) "CREATE DATABASE IF NOT EXISTS db_to_check_client_ip") != 0 ) { return ret; } - close_rwsplit(); - conn = open_conn_db(rwsplit_port, maxscale_IP, "db_to_check_client_ip", maxscale_user, - maxscale_password, ssl); + maxscales->close_rwsplit(m); + conn = open_conn_db(maxscales->rwsplit_port[m], maxscales->IP[m], (char *) "db_to_check_client_ip", + maxscales->user_name, + maxscales->password, ssl); if (conn != NULL) { @@ -1761,7 +1457,7 @@ int TestConnections::get_client_ip(char * ip) } mysql_free_result(res); } - execute_query(conn_rwsplit, "DROP DATABASE db_to_check_client_ip"); + execute_query(maxscales->conn_rwsplit[m], "DROP DATABASE db_to_check_client_ip"); } mysql_close(conn); @@ -1853,36 +1549,36 @@ void *log_copy_thread( void *ptr ) } } -int TestConnections::insert_select(int N) +int TestConnections::insert_select(int m, int N) { int result = 0; tprintf("Create t1\n"); set_timeout(30); - create_t1(conn_rwsplit); + create_t1(maxscales->conn_rwsplit[m]); tprintf("Insert data into t1\n"); set_timeout(N * 16 + 30); - insert_into_t1(conn_rwsplit, N); + insert_into_t1(maxscales->conn_rwsplit[m], N); stop_timeout(); repl->sync_slaves(); tprintf("SELECT: rwsplitter\n"); set_timeout(30); - result += select_from_t1(conn_rwsplit, N); + result += select_from_t1(maxscales->conn_rwsplit[m], N); tprintf("SELECT: master\n"); set_timeout(30); - result += select_from_t1(conn_master, N); + result += select_from_t1(maxscales->conn_master[m], N); tprintf("SELECT: slave\n"); set_timeout(30); - result += select_from_t1(conn_slave, N); + result += select_from_t1(maxscales->conn_slave[m], N); return result; } -int TestConnections::use_db(char * db) +int TestConnections::use_db(int m, char * db) { int local_result = 0; char sql[100]; @@ -1890,11 +1586,11 @@ int TestConnections::use_db(char * db) sprintf(sql, "USE %s;", db); set_timeout(20); tprintf("selecting DB '%s' for rwsplit\n", db); - local_result += execute_query(conn_rwsplit, sql); + local_result += execute_query(maxscales->conn_rwsplit[m], sql); tprintf("selecting DB '%s' for readconn master\n", db); - local_result += execute_query(conn_slave, sql); + local_result += execute_query(maxscales->conn_slave[m], sql); tprintf("selecting DB '%s' for readconn slave\n", db); - local_result += execute_query(conn_master, sql); + local_result += execute_query(maxscales->conn_master[m], sql); for (int i = 0; i < repl->N; i++) { tprintf("selecting DB '%s' for direct connection to node %d\n", db, i); @@ -1903,19 +1599,19 @@ int TestConnections::use_db(char * db) return local_result; } -int TestConnections::check_t1_table(bool presence, char * db) +int TestConnections::check_t1_table(int m, bool presence, char * db) { const char *expected = presence ? "" : "NOT"; const char *actual = presence ? "NOT" : ""; int start_result = global_result; - add_result(use_db(db), "use db failed\n"); + add_result(use_db(m, db), "use db failed\n"); stop_timeout(); repl->sync_slaves(); tprintf("Checking: table 't1' should %s be found in '%s' database\n", expected, db); set_timeout(30); - int exists = check_if_t1_exists(conn_rwsplit); + int exists = check_if_t1_exists(maxscales->conn_rwsplit[m]); if (exists == presence) { @@ -1927,7 +1623,7 @@ int TestConnections::check_t1_table(bool presence, char * db) } set_timeout(30); - exists = check_if_t1_exists(conn_master); + exists = check_if_t1_exists(maxscales->conn_master[m]); if (exists == presence) { @@ -1940,7 +1636,7 @@ int TestConnections::check_t1_table(bool presence, char * db) } set_timeout(30); - exists = check_if_t1_exists(conn_slave); + exists = check_if_t1_exists(maxscales->conn_slave[m]); if (exists == presence) { @@ -1992,167 +1688,28 @@ int TestConnections::try_query(MYSQL *conn, const char *format, ...) return res; } -int TestConnections::try_query_all(const char *sql) +int TestConnections::try_query_all(int m, const char *sql) { - return try_query(conn_rwsplit, sql) + - try_query(conn_master, sql) + - try_query(conn_slave, sql); + return try_query(maxscales->conn_rwsplit[m], sql) + + try_query(maxscales->conn_master[m], sql) + + try_query(maxscales->conn_slave[m], sql); } -int TestConnections::find_master_maxadmin(Mariadb_nodes * nodes) -{ - bool found = false; - int master = -1; - - for (int i = 0; i < nodes->N; i++) - { - char show_server[256]; - char res[256]; - sprintf(show_server, "show server server%d", i + 1); - get_maxadmin_param(show_server, "Status", res); - - if (strstr(res, "Master")) - { - if (found) - { - master = -1; - } - else - { - master = i; - found = true; - } - } - } - - return master; -} - -int TestConnections::find_slave_maxadmin(Mariadb_nodes * nodes) -{ - int slave = -1; - - for (int i = 0; i < nodes->N; i++) - { - char show_server[256]; - char res[256]; - sprintf(show_server, "show server server%d", i + 1); - get_maxadmin_param(show_server, "Status", res); - - if (strstr(res, "Slave")) - { - slave = i; - } - } - - return slave; -} - -int TestConnections::execute_maxadmin_command(char * cmd) -{ - return ssh_maxscale(true, "maxadmin %s", cmd); -} -int TestConnections::execute_maxadmin_command_print(char * cmd) -{ - printf("%s\n", ssh_maxscale_output(true, "maxadmin %s", cmd)); - return 0; -} - -int TestConnections::check_maxadmin_param(const char *command, const char *param, const char *value) -{ - char result[1024]; - int rval = 1; - - if (get_maxadmin_param((char*)command, (char*)param, (char*)result) == 0) - { - char *end = strchr(result, '\0') - 1; - - while (isspace(*end)) - { - *end-- = '\0'; - } - - char *start = result; - - while (isspace(*start)) - { - start++; - } - - if (strcmp(start, value) == 0) - { - rval = 0; - } - else - { - printf("Expected %s, got %s\n", value, start); - } - } - - return rval; -} - -int TestConnections::get_maxadmin_param(const char* command, const char* param, char* result) -{ - char* buf = ssh_maxscale_output(true, "maxadmin %s", command); - char *x = strstr(buf, param); - - if (x == NULL) - { - return 1; - } - - x += strlen(param); - - // Skip any trailing parts of the parameter name - while (!isspace(*x)) - { - x++; - } - - // Trim leading whitespace - while (!isspace(*x)) - { - x++; - } - - char *end = strchr(x, '\n'); - - // Trim trailing whitespace - while (isspace(*end)) - { - *end-- = '\0'; - } - - strcpy(result, x); - - return 0; -} - -int TestConnections::list_dirs() +int TestConnections::list_dirs(int m) { for (int i = 0; i < repl->N; i++) { tprintf("ls on node %d\n", i); - repl->ssh_node(i, true, "ls -la /var/lib/mysql"); + repl->ssh_node(i, (char *) "ls -la /var/lib/mysql", true); fflush(stdout); } tprintf("ls maxscale \n"); - ssh_maxscale(true, "ls -la /var/lib/maxscale/"); + maxscales->ssh_node(m, "ls -la /var/lib/maxscale/", true); fflush(stdout); return 0; } -long unsigned TestConnections::get_maxscale_memsize() -{ - char * ps_out = ssh_maxscale_output(false, "ps -e -o pid,vsz,comm= | grep maxscale"); - long unsigned mem = 0; - pid_t pid; - sscanf(ps_out, "%d %lu", &pid, &mem); - return mem; -} - -void TestConnections::check_current_operations(int value) +void TestConnections::check_current_operations(int m, int value) { char value_str[512]; sprintf(value_str, "%d", value); @@ -2161,12 +1718,12 @@ void TestConnections::check_current_operations(int value) { char command[512]; sprintf(command, "show server server%d", i + 1); - add_result(check_maxadmin_param(command, "Current no. of operations:", value_str), + add_result(maxscales->check_maxadmin_param(m, command, "Current no. of operations:", value_str), "Current no. of operations is not %s", value_str); } } -void TestConnections::check_current_connections(int value) +void TestConnections::check_current_connections(int m, int value) { char value_str[512]; sprintf(value_str, "%d", value); @@ -2175,7 +1732,7 @@ void TestConnections::check_current_connections(int value) { char command[512]; sprintf(command, "show server server%d", i + 1); - add_result(check_maxadmin_param(command, "Current no. of conns:", value_str), + add_result(maxscales->check_maxadmin_param(m, command, "Current no. of conns:", value_str), "Current no. of conns is not %s", value_str); } } @@ -2187,129 +1744,22 @@ int TestConnections::take_snapshot(char * snapshot_name) return system(str); } -int TestConnections::revert_snapshot(const char* snapshot_name) +int TestConnections::revert_snapshot(char * snapshot_name) { char str[4096]; sprintf(str, "%s %s", revert_snapshot_command, snapshot_name); return system(str); } -bool TestConnections::test_bad_config(const char *config) +bool TestConnections::test_bad_config(int m, const char *config) { char src[PATH_MAX]; - process_template(config, "./"); + process_template(m, config, "./"); // Set the timeout to prevent hangs with configurations that work set_timeout(20); - return ssh_maxscale(true, "cp maxscale.cnf /etc/maxscale.cnf; service maxscale stop; " - "maxscale -U maxscale -lstdout &> /dev/null && sleep 1 && pkill -9 maxscale") == 0; -} - -int TestConnections::connect_rwsplit() -{ - if (use_ipv6) - { - conn_rwsplit = open_conn(rwsplit_port, maxscale_IP6, maxscale_user, maxscale_password, ssl); - } - else - { - conn_rwsplit = open_conn(rwsplit_port, maxscale_IP, maxscale_user, maxscale_password, ssl); - } - routers[0] = conn_rwsplit; - - int rc = 0; - int my_errno = mysql_errno(conn_rwsplit); - - if (my_errno) - { - if (verbose) - { - tprintf("Failed to connect to readwritesplit: %d, %s", my_errno, mysql_error(conn_rwsplit)); - } - rc = my_errno; - } - - return rc; -} - -int TestConnections::connect_readconn_master() -{ - if (use_ipv6) - { - conn_master = open_conn(readconn_master_port, maxscale_IP6, maxscale_user, maxscale_password, ssl); - } - else - { - conn_master = open_conn(readconn_master_port, maxscale_IP, maxscale_user, maxscale_password, ssl); - } - routers[1] = conn_master; - - int rc = 0; - int my_errno = mysql_errno(conn_master); - - if (my_errno) - { - if (verbose) - { - tprintf("Failed to connect to readwritesplit: %d, %s", my_errno, mysql_error(conn_master)); - } - rc = my_errno; - } - - return rc; -} - -int TestConnections::connect_readconn_slave() -{ - if (use_ipv6) - { - conn_slave = open_conn(readconn_slave_port, maxscale_IP6, maxscale_user, maxscale_password, ssl); - } - else - { - conn_slave = open_conn(readconn_slave_port, maxscale_IP, maxscale_user, maxscale_password, ssl); - } - routers[2] = conn_slave; - - int rc = 0; - int my_errno = mysql_errno(conn_slave); - - if (my_errno) - { - if (verbose) - { - tprintf("Failed to connect to readwritesplit: %d, %s", my_errno, mysql_error(conn_slave)); - } - rc = my_errno; - } - - return rc; -} - -char* TestConnections::maxscale_ip() const -{ - return use_ipv6 ? (char*)maxscale_IP6 : (char*)maxscale_IP; -} - -void TestConnections::set_active_maxscale(enum test_target target) -{ - switch (target) - { - case MXS_PRIMARY: - strcpy(maxscale_IP, primary_maxscale_IP.c_str()); - strcpy(maxscale_IP6, primary_maxscale_IP6.c_str()); - break; - - case MXS_SECONDARY: - strcpy(maxscale_IP, secondary_maxscale_IP.c_str()); - strcpy(maxscale_IP6, secondary_maxscale_IP6.c_str()); - break; - - default: - tprintf("Wrong enum value for 'set_active_maxscale': 0x%02x", target); - exit(1); - break; - } + return maxscales->ssh_node(m, "cp maxscale.cnf /etc/maxscale.cnf; service maxscale stop; " + "maxscale -U maxscale -lstdout &> /dev/null && sleep 1 && pkill -9 maxscale", false) == 0; } diff --git a/maxscale-system-test/testconnections.h b/maxscale-system-test/testconnections.h index cd2dfb202..6ac25658a 100644 --- a/maxscale-system-test/testconnections.h +++ b/maxscale-system-test/testconnections.h @@ -2,16 +2,14 @@ #define TESTCONNECTIONS_H #include "mariadb_nodes.h" +#include "maxscales.h" #include "templates.h" #include #include #include +#include +#include -enum test_target -{ - MXS_PRIMARY, - MXS_SECONDARY -}; /** * @brief Class contains references to Master/Slave and Galera test setups @@ -43,7 +41,7 @@ class TestConnections private: /** Whether timeouts are enabled or not */ bool enable_timeouts; - bool log_matches(const char* pattern); + bool log_matches(int m, const char* pattern); public: /** * @brief TestConnections constructor: reads environmental variables, copies MaxScale.cnf for MaxScale machine @@ -63,51 +61,6 @@ public: */ char * test_name; - /** - * @brief rwsplit_port RWSplit service port - */ - int rwsplit_port; - - /** - * @brief readconn_master_port ReadConnection in master mode service port - */ - int readconn_master_port; - - /** - * @brief readconn_slave_port ReadConnection in slave mode service port - */ - int readconn_slave_port; - - /** - * @brief binlog_port binlog router service port - */ - int binlog_port; - - /** - * @brief conn_rwsplit MYSQL connection struct to RWSplit service - */ - MYSQL *conn_rwsplit; - - /** - * @brief conn_master MYSQL connection struct to ReadConnection in master mode service - */ - MYSQL *conn_master; - - /** - * @brief conn_slave MYSQL connection struct to ReadConnection in slave mode service - */ - MYSQL *conn_slave; - - /** - * @brief routers Array of 3 MYSQL handlers which contains copies of conn_rwsplit, conn_master, conn_slave - */ - MYSQL *routers[3]; - - /** - * @brief ports of 3 int which contains copies of rwsplit_port, readconn_master_port, readconn_slave_port - */ - int ports[3]; - /** * @brief galera Mariadb_nodes object containing references to Galera setuo */ @@ -119,58 +72,9 @@ public: Mariadb_nodes * repl; /** - * @brief Get MaxScale IP address - * - * @return The current IP address of MaxScale + * @brief maxscales Maxscale object containing referebces to all Maxscale machines */ - char* maxscale_ip() const; - - /** - * @brief Maxscale_IP Maxscale machine IP address - */ - char maxscale_IP[1024]; - - /** IPv4 and IPv6 addresses for the primary and secondary instances */ - std::string primary_maxscale_IP; - std::string primary_maxscale_IP6; - std::string secondary_maxscale_IP; - std::string secondary_maxscale_IP6; - - /** - * @brief Maxscale_IP6 Maxscale machine IP address (IPv6) - */ - char maxscale_IP6[1024]; - - /** - * @brief use_ipv6 If true IPv6 addresses will be used to connect Maxscale and backed - * Also IPv6 addresses go to maxscale.cnf - */ - bool use_ipv6; - - /** - * @brief maxscale_hostname Maxscale machine 'hostname' value - */ - char maxscale_hostname[1024]; - - /** - * @brief Maxscale_User User name to access Maxscale services - */ - char maxscale_user[256]; - - /** - * @brief Maxscale_Password Password to access Maxscale services - */ - char maxscale_password[256]; - - /** - * @brief maxadmin_Password Password to access Maxadmin tool - */ - char maxadmin_password[256]; - - /** - * @brief Maxscale_sshkey ssh key for Maxscale machine - */ - char maxscale_keyfile[4096]; + Maxscales * maxscales; /** * @brief GetLogsCommand Command to copy log files from node virtual machines (should handle one parameter: IP address of virtual machine to kill) @@ -197,43 +101,13 @@ public: */ char sysbench_dir[4096]; - /** - * @brief maxscale_cnf full name of Maxscale configuration file - */ - char maxscale_cnf[4096]; - - /** - * @brief maxscale_log_dir name of log files directory - */ - char maxscale_log_dir[4096]; - - /** - * @brief maxscale_lbinog_dir name of binlog files (for binlog router) directory - */ - char maxscale_binlog_dir[4096]; - - /** - * @brief maxscale_access_user username to access test machines - */ - char maxscale_access_user[256]; - - /** - * @brief maxscale_access_homedir home directory of access_user - */ - char maxscale_access_homedir[256]; - - /** - * @brief maxscale_access_sudo empty if sudo is not needed or "sudo " if sudo is needed. - */ - char maxscale_access_sudo[64]; - /** * @brief copy_mariadb_logs copies MariaDB logs from backend * @param repl Mariadb_nodes object * @param prefix file name prefix * @return 0 if success */ - int copy_mariadb_logs(Mariadb_nodes *repl, const char* prefix); + int copy_mariadb_logs(Mariadb_nodes *repl, char * prefix); /** * @brief no_backend_log_copy if true logs from backends are not copied (needed if case of Aurora RDS backend or similar) @@ -258,7 +132,7 @@ public: /** * @brief ssl if true ssl will be used */ - bool ssl; + int ssl; /** * @brief backend_ssl if true ssl configuratio for all servers will be added @@ -328,6 +202,12 @@ public: */ timeval start_time; + /** + * @brief use_ipv6 If true IPv6 addresses will be used to connect Maxscale and backed + * Also IPv6 addresses go to maxscale.cnf + */ + bool use_ipv6; + /** Check whether all nodes are in a valid state */ static void check_nodes(bool value); @@ -338,12 +218,6 @@ public: static void require_repl_version(const char *version); static void require_galera_version(const char *version); - /** Initialize multiple MaxScale instances */ - static void multiple_maxscales(bool value); - - /** Set secondary MaxScale address */ - static void set_secondary_maxscale(const char* ip_var, const char* ip6_var); - /** * @brief add_result adds result to global_result and prints error message if result is not 0 * @param result 0 if step PASSED @@ -367,134 +241,32 @@ public: * @brief InitMaxscale Copies MaxSclae.cnf and start MaxScale * @return 0 if case of success */ - int init_maxscale(); + int init_maxscale(int m); - /** - * @brief ConnectMaxscale Opens connections to RWSplit, ReadConn master and ReadConn slave Maxscale services - * Opens connections to RWSplit, ReadConn master and ReadConn slave Maxscale services - * Connections stored in conn_rwsplit, conn_master and conn_slave MYSQL structs - * @return 0 in case of success - */ - int connect_maxscale(); - /** - * @brief CloseMaxscaleConn Closes connection that were opened by ConnectMaxscale() - * @return 0 - */ - int close_maxscale_connections(); - - /** - * @brief ConnectRWSplit Opens connections to RWSplit and store MYSQL struct in conn_rwsplit - * @return 0 in case of success - */ - int connect_rwsplit(); - - /** - * @brief ConnectReadMaster Opens connections to ReadConn master and store MYSQL struct in conn_master - * @return 0 in case of success - */ - int connect_readconn_master(); - - /** - * @brief ConnectReadSlave Opens connections to ReadConn slave and store MYSQL struct in conn_slave - * @return 0 in case of success - */ - int connect_readconn_slave(); - - /** - * @brief OpenRWSplitConn Opens new connections to RWSplit and returns MYSQL struct - * To close connection mysql_close() have to be called - * @return MYSQL struct - */ - MYSQL * open_rwsplit_connection() - { - return open_conn(rwsplit_port, maxscale_IP, maxscale_user, maxscale_password, ssl); - } - - /** - * @brief OpenReadMasterConn Opens new connections to ReadConn master and returns MYSQL struct - * To close connection mysql_close() have to be called - * @return MYSQL struct - */ - MYSQL * open_readconn_master_connection() - { - return open_conn(readconn_master_port, maxscale_IP, maxscale_user, maxscale_password, ssl); - } - - /** - * @brief OpenReadSlaveConn Opens new connections to ReadConn slave and returns MYSQL struct - * To close connection mysql_close() have to be called - * @return MYSQL struct - */ - MYSQL * open_readconn_slave_connection() - { - return open_conn(readconn_slave_port, maxscale_IP, maxscale_user, maxscale_password, ssl); - } - - /** - * @brief CloseRWSplit Closes RWplit connections stored in conn_rwsplit - */ - void close_rwsplit() - { - mysql_close(conn_rwsplit); - conn_rwsplit = NULL; - } - - /** - * @brief CloseReadMaster Closes ReadConn master connections stored in conn_master - */ - void close_readconn_master() - { - mysql_close(conn_master); - conn_master = NULL; - } - - /** - * @brief CloseReadSlave Closes ReadConn slave connections stored in conn_slave - */ - void close_readconn_slave() - { - mysql_close(conn_slave); - conn_slave = NULL; - } - - /** - * @brief restart_maxscale Issues 'service maxscale restart' command - */ - int restart_maxscale(); - - /** - * @brief start_maxscale Issues 'service maxscale start' command - */ - int start_maxscale(); - - /** - * @brief stop_maxscale Issues 'service maxscale stop' command - */ - int stop_maxscale(); /** * @brief start_binlog configure first node as Master, Second as slave connected to Master and others as slave connected to MaxScale binlog router * @return 0 in case of success */ - int start_binlog(); + int start_binlog(int m); /** * @brief Start binlogrouter replication from master */ - bool replicate_from_master(); + bool replicate_from_master(int m); /** * @brief prepare_binlog clean up binlog directory, set proper access rights to it * @return 0 */ - int prepare_binlog(); + int prepare_binlog(int m); /** * @brief start_mm configure first node as Master for second, Second as Master for first * @return 0 in case of success */ - int start_mm(); + int start_mm(int m); /** * @brief copy_all_logs Copies all MaxScale logs and (if happens) core to current workspace @@ -507,43 +279,11 @@ public: int copy_all_logs_periodic(); /** - * @brief Generate command line to execute command on the Maxscale ode via ssh - * @param cmd result - * @param ssh command to execute - * @param sudo if true the command is executed with root privelegues + * @brief copy_maxscale_logs Copies logs from all Maxscale nodes + * @param timestamp + * @return 0 */ - void generate_ssh_cmd(char * cmd, char * ssh, bool sudo); - - /** - * @brief Execute a command via ssh on the MaxScale machine - * @param ssh ssh command to execute on the MaxScale machine - * @return Output of the command or NULL if the command failed to execute - */ - char* ssh_maxscale_output(bool sudo, const char* format, ...); - - /** - * @brief Execute a shell command on Maxscale - * @param sudo Use root - * @param format printf style format string - * @return 0 on success - */ - int ssh_maxscale(bool sudo, const char* format, ...); - - /** - * @brief Copy a local file to the MaxScale machine - * @param src Source file on the local filesystem - * @param dest Destination file on the MaxScale machine's file system - * @return exit code of the system command - */ - int copy_to_maxscale(const char* src, const char* dest); - - /** - * @brief Copy a remote file from the MaxScale machine - * @param src Source file on the remote filesystem - * @param dest Destination file on the local file system - * @return exit code of the system command - */ - int copy_from_maxscale(char* src, char* dest); + int copy_maxscale_logs(double timestamp); /** * @brief Test that connections to MaxScale are in the expected state @@ -552,7 +292,7 @@ public: * @param rc_slave State of the MaxScale connection to Readconnroute Slave. True for working connection, false for no connection. * @return 0 if connections are in the expected state */ - int test_maxscale_connections(bool rw_split, + int test_maxscale_connections(int m, bool rw_split, bool rc_master, bool rc_slave); @@ -565,7 +305,8 @@ public: * @param galera_flag if true connections to RWSplit router with Galera backend will be created, if false - no connections to RWSplit with Galera backend * @return 0 in case of success */ - int create_connections(int conn_N, bool rwsplit_flag, bool master_flag, bool slave_flag, bool galera_flag); + int create_connections(int m, int conn_N, bool rwsplit_flag, bool master_flag, bool slave_flag, + bool galera_flag); /** * Trying to get client IP address by connection to DB via RWSplit and execution 'show processlist' @@ -573,7 +314,7 @@ public: * @param ip client IP address as it visible by Maxscale * @return 0 in case of success */ - int get_client_ip(char * ip); + int get_client_ip(int m, char * ip); /** * @brief set_timeout startes timeout thread which terminates test application after timeout_seconds @@ -608,7 +349,7 @@ public: * @param N number of INSERTs; every next INSERT is longer 16 times in compare with previous one: for N=4 last INSERT is about 700kb long * @return 0 in case of no error and all checks are ok */ - int insert_select(int N); + int insert_select(int m, int N); /** * @brief Executes USE command for all Maxscale service and all Master/Slave backend nodes @@ -616,7 +357,7 @@ public: * @param db Name of DB in 'USE' command * @return 0 in case of success */ - int use_db(char * db); + int use_db(int m, char * db); /** * @brief Checks if table t1 exists in DB @@ -625,7 +366,7 @@ public: * @return 0 if (t1 table exists AND presence=TRUE) OR (t1 table does not exist AND presence=false) */ - int check_t1_table(bool presence, char * db); + int check_t1_table(int m, bool presence, char * db); /** * @brief CheckLogErr Reads error log and tried to search for given string @@ -633,23 +374,23 @@ public: * @param expected TRUE if err_msg is expedted in the log, false if err_msg should NOT be in the log * @return 0 if (err_msg is found AND expected is TRUE) OR (err_msg is NOT found in the log AND expected is false) */ - void check_log_err(const char * err_msg, bool expected); + void check_log_err(int m, const char * err_msg, bool expected); /** - * @brief Check whether logs match a pattern - * - * The patterns are interpreted as `grep` compatible patterns (BRE regular expressions). If the - * log file does not match the pattern, it is considered an error. - */ - void log_includes(const char* pattern); + * @brief Check whether logs match a pattern + * + * The patterns are interpreted as `grep` compatible patterns (BRE regular expressions). If the + * log file does not match the pattern, it is considered an error. + */ + void log_includes(int m, const char* pattern); /** - * @brief Check whether logs do not match a pattern - * - * The patterns are interpreted as `grep` compatible patterns (BRE regular expressions). If the - * log file match the pattern, it is considered an error. - */ - void log_excludes(const char* pattern); + * @brief Check whether logs do not match a pattern + * + * The patterns are interpreted as `grep` compatible patterns (BRE regular expressions). If the + * log file match the pattern, it is considered an error. + */ + void log_excludes(int m, const char* pattern); /** * @brief FindConnectedSlave Finds slave node which has connections from MaxScale @@ -657,14 +398,14 @@ public: * @param global_result pointer to variable which is increased in case of error * @return index of found slave node */ - int find_connected_slave(int * global_result); + int find_connected_slave(int m, int * global_result); /** * @brief FindConnectedSlave1 same as FindConnectedSlave() but does not increase global_result * @param Test TestConnections object which contains info about test setup * @return index of found slave node */ - int find_connected_slave1(); + int find_connected_slave1(int m); /** * @brief CheckMaxscaleAlive Checks if MaxScale is alive @@ -672,7 +413,7 @@ public: * Also 'show processlist' query is executed using all services * @return 0 in case if success */ - int check_maxscale_alive(); + int check_maxscale_alive(int m); /** * @brief try_query Executes SQL query and repors error @@ -687,41 +428,22 @@ public: * @param sql SQL string * @return 0 if ok */ - int try_query_all(const char *sql); - - /** - * @brief find_master_maxadmin Tries to find node with 'Master' status using Maxadmin connand 'show server' - * @param nodes Mariadb_nodes object - * @return node index if one master found, -1 if no master found or several masters found - */ - int find_master_maxadmin(Mariadb_nodes * nodes); - int find_slave_maxadmin(Mariadb_nodes * nodes); - - int execute_maxadmin_command(char * cmd); - int execute_maxadmin_command_print(char * cmd); - int check_maxadmin_param(const char *command, const char *param, const char *value); - int get_maxadmin_param(const char *command, const char *param, char *result); - void check_current_operations(int value); - void check_current_connections(int value); + int try_query_all(int m, const char *sql); /** * @brief check_maxscale_processes Check if number of running Maxscale processes is equal to 'expected' * @param expected expected number of Maxscale processes * @return 0 if check is done */ - int check_maxscale_processes(int expected); + int check_maxscale_processes(int m, int expected); /** * @brief list_dirs Execute 'ls' on binlog directory on all repl nodes and on Maxscale node * @return 0 */ - int list_dirs(); + int list_dirs(int m); + - /** - * @brief get_maxscale_memsize Gets size of the memory consumed by Maxscale process - * @return memory size in kilobytes - */ - long unsigned get_maxscale_memsize(); /** * @brief make_snapshot Makes a snapshot for all running VMs @@ -735,28 +457,27 @@ public: * @param snapshot_name name of snapshot to revert * @return 0 in case of success or mdbci error code in case of error */ - int revert_snapshot(const char* snapshot_name); + int revert_snapshot(char * snapshot_name); /** * @brief Test a bad configuration * @param config Name of the config template * @return Always false, the test will time out if the loading is successful */ - bool test_bad_config(const char *config); + bool test_bad_config(int m, const char *config); /** * @brief Process a template configuration file * * @param dest Destination file name for actual configuration file */ - void process_template(const char *src, const char *dest = "/etc/maxscale.cnf"); + void process_template(int m, const char *src, const char *dest = "/etc/maxscale.cnf"); + + + void check_current_operations(int m, int value); + void check_current_connections(int m, int value); + int stop_maxscale(int m); - /** - * @brief Change the target MaxScale - * - * @param target Either MXS_PRIMARY or MXS_SECONDARY - */ - void set_active_maxscale(enum test_target target); }; /** diff --git a/maxscale-system-test/user_cache.cpp b/maxscale-system-test/user_cache.cpp index f35e775a7..b7b321c3a 100644 --- a/maxscale-system-test/user_cache.cpp +++ b/maxscale-system-test/user_cache.cpp @@ -16,7 +16,7 @@ int main(int argc, char *argv[]) { TestConnections * Test = new TestConnections(argc, argv); Test->stop_timeout(); - Test->stop_maxscale(); + Test->maxscales->stop_maxscale(0); /** Create the test user and give required grants */ Test->tprintf("Creating 'testuser'@'%'\n"); @@ -33,8 +33,8 @@ int main(int argc, char *argv[]) /** Test that MaxScale works and initialize the cache */ Test->tprintf("Test that MaxScale works and initialize the cache\n"); - Test->start_maxscale(); - Test->connect_maxscale(); + Test->maxscales->start_maxscale(0); + Test->maxscales->connect_maxscale(0); Test->set_timeout(30); Test->add_result(Test->try_query_all("SHOW DATABASES"), "Initial query without user cache should work\n"); Test->stop_timeout(); @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) /** Restart MaxScale and check that the user cache works */ Test->tprintf("Restarting MaxScale\n"); - Test->restart_maxscale(); + Test->maxscales->restart_maxscale(0); sleep(5); Test->tprintf("Unblocking all nodes\n"); @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) Test->tprintf("Checking that the user cache works and queries are accepted\n"); Test->set_timeout(30); - Test->connect_maxscale(); + Test->maxscales->connect_maxscale(0); Test->add_result(Test->try_query_all("SHOW DATABASES"), "Second query with user cache should work\n"); Test->stop_timeout(); diff --git a/maxscale-system-test/utilities.cmake b/maxscale-system-test/utilities.cmake index 4f5a3aaef..c284958c7 100644 --- a/maxscale-system-test/utilities.cmake +++ b/maxscale-system-test/utilities.cmake @@ -94,8 +94,6 @@ add_test_executable_notest(sysbench_example.cpp sysbench_example replication) set(CONNECTOR_C_VERSION "3.0" CACHE STRING "The Connector-C version to use") include(ExternalProject) -include(GNUInstallDirs) - ExternalProject_Add(connector-c GIT_REPOSITORY "https://github.com/MariaDB/mariadb-connector-c.git" GIT_TAG ${CONNECTOR_C_VERSION} @@ -105,19 +103,13 @@ ExternalProject_Add(connector-c include_directories(${CMAKE_BINARY_DIR}/include) set(MYSQL_CLIENT ${CMAKE_BINARY_DIR}/lib/mariadb/libmariadbclient.a CACHE INTERNAL "") -# Build Jansson -include(cmake/BuildJansson.cmake) -include_directories(${JANSSON_INCLUDE_DIR}) - # Build the CDC connector ExternalProject_Add(cdc_connector - GIT_REPOSITORY "https://github.com/mariadb-corporation/maxscale-cdc-connector" - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/cdc_connector/ -DJANSSON_INCLUDE_DIR=${JANSSON_INCLUDE_DIR} + SOURCE_DIR ${CMAKE_SOURCE_DIR}/cdc_connector/ + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/cdc_connector/ BUILD_COMMAND make - INSTALL_COMMAND make install - UPDATE_COMMAND "") -add_dependencies(cdc_connector jansson) + INSTALL_COMMAND make install) set(CDC_CONNECTOR_INCLUDE ${CMAKE_BINARY_DIR}/cdc_connector/include/ CACHE INTERNAL "") -set(CDC_CONNECTOR_LIBRARIES ${CMAKE_BINARY_DIR}/cdc_connector/${CMAKE_INSTALL_LIBDIR}/libcdc_connector.a CACHE INTERNAL "") +set(CDC_CONNECTOR_LIBRARIES ${CMAKE_BINARY_DIR}/cdc_connector/lib/libcdc_connector.so CACHE INTERNAL "") include_directories(${CMAKE_BINARY_DIR}/cdc_connector/include) diff --git a/maxscale-system-test/verify_master_failure.cpp b/maxscale-system-test/verify_master_failure.cpp index d4614d6ae..4b3106ea4 100644 --- a/maxscale-system-test/verify_master_failure.cpp +++ b/maxscale-system-test/verify_master_failure.cpp @@ -13,12 +13,12 @@ int main(int argc, char *argv[]) test.tprintf("Blocking master and checking that master failure is delayed at least once."); test.repl->block_node(0); sleep(5); - test.log_includes("delaying.*failover"); + test.log_includes(0, "delaying.*failover"); test.tprintf("Waiting to see if failover is performed."); sleep(10); - test.log_includes("Performing.*failover"); + test.log_includes(0, "Performing.*failover"); // TODO: Extend the test