Test: Provide additional control of local MaxScale

When running BLR locally, you need to be able to specify what
IP the BLR is visible at (127.0.0.1 does not work for VM nodes)
and also to perform cleanup etc. action when needed.
This commit is contained in:
Johan Wikman 2018-10-03 09:46:58 +03:00
parent 661bdd5b82
commit 9ecd027ea0
2 changed files with 83 additions and 35 deletions

View File

@ -7,6 +7,7 @@
#include <signal.h>
#include <execinfo.h>
#include <sys/stat.h>
#include <iostream>
#include <sstream>
#include <maxbase/stacktrace.hh>
@ -19,6 +20,7 @@ using namespace mxb;
namespace maxscale
{
static bool start = true;
static bool check_nodes = true;
static bool manual_debug = false;
@ -26,6 +28,15 @@ static std::string required_repl_version;
static std::string required_galera_version;
static bool restart_galera = false;
static bool multiple_maxscales = false;
}
static void perform_manual_action(const char* zMessage)
{
std::cout << zMessage << " (press enter when done)." << std::endl;
std::string not_used;
std::getline(std::cin, not_used);
std::cout << "Ok" << std::endl;
}
static void signal_set(int sig, void (* handler)(int))
@ -82,6 +93,7 @@ TestConnections::TestConnections(int argc, char* argv[])
: enable_timeouts(true)
, global_result(0)
, use_snapshots(false)
, local_maxscale(false)
, no_backend_log_copy(false)
, no_maxscale_log_copy(false)
, verbose(false)
@ -129,14 +141,14 @@ TestConnections::TestConnections(int argc, char* argv[])
{"restart-galera", no_argument, 0, 'g' },
{"no-timeouts", no_argument, 0, 'z' },
{"no-galera", no_argument, 0, 'y' },
{"local-maxscale", no_argument, 0, 'l' },
{"local-maxscale", optional_argument, 0, 'l' },
{0, 0, 0, 0 }
};
int c;
int option_index = 0;
while ((c = getopt_long(argc, argv, "hvnqsirgzyl", long_options, &option_index)) != -1)
while ((c = getopt_long(argc, argv, "hvnqsirgzyl::", long_options, &option_index)) != -1)
{
switch (c)
{
@ -198,12 +210,18 @@ TestConnections::TestConnections(int argc, char* argv[])
break;
case 'l':
printf("MaxScale assumed to be running locally; not started and logs not downloaded.\n");
maxscale_init = false;
no_maxscale_log_copy = true;
setenv("maxscale_IP", "127.0.0.1", true);
setenv("maxscale_network", "127.0.0.1", true);
setenv("maxscale_private_ip", "127.0.0.1", true);
{
const char* local_ip = optarg ? optarg : "127.0.0.1";
printf("MaxScale assumed to be running locally; not started and logs not downloaded. IP: %s\n", local_ip);
maxscale_init = false;
no_maxscale_log_copy = true;
local_maxscale=true;
setenv("maxscale_IP", local_ip, true);
setenv("maxscale_network", local_ip, true);
setenv("maxscale_private_ip", local_ip, true);
}
break;
default:
@ -899,22 +917,30 @@ int TestConnections::prepare_binlog(int m)
"Error editing maxscale.cnf");
}
tprintf("Removing all binlog data from Maxscale node");
add_result(maxscales->ssh_node_f(m, true, "rm -rf %s", maxscales->maxscale_binlog_dir[m]),
"Removing binlog data failed");
if (!local_maxscale)
{
tprintf("Removing all binlog data from Maxscale node");
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(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(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");
}
else
{
perform_manual_action("Remove all local binlog data");
}
tprintf("Creating 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(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;
}
@ -948,14 +974,21 @@ int TestConnections::start_binlog(int m)
repl->stop_nodes();
binlog =
open_conn_no_db(maxscales->binlog_port[m], maxscales->IP[m], repl->user_name, repl->password, ssl);
execute_query(binlog, "stop slave");
execute_query(binlog, "reset slave all");
mysql_close(binlog);
if (!local_maxscale)
{
binlog =
open_conn_no_db(maxscales->binlog_port[m], maxscales->IP[m], repl->user_name, repl->password, ssl);
execute_query(binlog, "stop slave");
execute_query(binlog, "reset slave all");
mysql_close(binlog);
tprintf("Stopping maxscale\n");
add_result(maxscales->stop_maxscale(m), "Maxscale stopping failed\n");
tprintf("Stopping maxscale\n");
add_result(maxscales->stop_maxscale(m), "Maxscale stopping failed\n");
}
else
{
perform_manual_action("Perform the equivalent of 'STOP SLAVE; RESET SLAVE ALL' and stop local Maxscale");
}
for (i = 0; i < repl->N; i++)
{
@ -978,9 +1011,12 @@ int TestConnections::start_binlog(int 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(maxscales->ssh_node_f(m, true, "ls -la %s/", maxscales->maxscale_binlog_dir[m]),
"ls failed\n");
if (!local_maxscale)
{
tprintf("ls binlog data dir on Maxscale node\n");
add_result(maxscales->ssh_node_f(m, true, "ls -la %s/", maxscales->maxscale_binlog_dir[m]),
"ls failed\n");
}
if (binlog_master_gtid)
{
@ -1011,8 +1047,15 @@ int TestConnections::start_binlog(int m)
repl->set_slave(repl->nodes[1], repl->IP[0], repl->port[0], log_file, log_pos);
}
tprintf("Starting back Maxscale\n");
add_result(maxscales->start_maxscale(m), "Maxscale start failed\n");
if (!local_maxscale)
{
tprintf("Starting back Maxscale\n");
add_result(maxscales->start_maxscale(m), "Maxscale start failed\n");
}
else
{
perform_manual_action("Start Maxscale");
}
tprintf("Connecting to MaxScale binlog router (with any DB)\n");
binlog =

View File

@ -140,6 +140,11 @@ public:
*/
int copy_mariadb_logs(Mariadb_nodes* repl, const char* prefix, std::vector<std::thread>& threads);
/**
* @brief MaxScale runs locally, specified using -l.
*/
bool local_maxscale;
/**
* @brief no_backend_log_copy if true logs from backends are not copied
* (needed if case of Aurora RDS backend or similar)