MXS-2900 Move more TestConnection fields to private

This commit is contained in:
Esa Korhonen
2020-04-01 16:47:08 +03:00
parent 2420ccf9a8
commit 5ed99b2f5b
2 changed files with 71 additions and 117 deletions

View File

@ -39,6 +39,9 @@ const string label_cs_be = "COLUMNSTORE_BACKEND";
const StringSet recognized_mdbci_labels =
{label_repl_be, label_big_be, label_galera_be, label_2nd_mxs, label_cs_be};
const int MDBCI_FAIL = 200; // Exit code when failure caused by MDBCI non-zero exit
const int BROKEN_VM_FAIL = 201; // Exit code when failure caused by broken VMs
}
namespace maxscale
@ -126,15 +129,6 @@ void TestConnections::restart_galera(bool value)
bool TestConnections::verbose = false;
TestConnections::TestConnections(int argc, char* argv[])
: global_result(0)
, smoke(true)
, binlog_cmd_option(0)
, ssl(false)
, backend_ssl(false)
, binlog_master_gtid(false)
, binlog_slave_gtid(false)
, threads(4)
, use_ipv6(false)
{
std::ios::sync_with_stdio(true);
signal_set(SIGSEGV, sigfatal_handler);
@ -144,12 +138,7 @@ TestConnections::TestConnections(int argc, char* argv[])
#ifdef SIGBUS
signal_set(SIGBUS, sigfatal_handler);
#endif
gettimeofday(&start_time, NULL);
repl = NULL;
galera = NULL;
maxscales = NULL;
reinstall_maxscale = false;
gettimeofday(&m_start_time, NULL);
read_env();
@ -256,7 +245,7 @@ TestConnections::TestConnections(int argc, char* argv[])
case 'm':
printf("Maxscale will be reinstalled");
reinstall_maxscale = true;
m_reinstall_maxscale = true;
break;
default:
@ -297,7 +286,7 @@ TestConnections::TestConnections(int argc, char* argv[])
{
if (call_mdbci(""))
{
exit(MDBCI_FAUILT);
exit(MDBCI_FAIL);
}
}
@ -322,11 +311,11 @@ TestConnections::TestConnections(int argc, char* argv[])
m_get_logs_command = (string)test_dir + "/get_logs.sh";
sprintf(ssl_options,
sprintf(m_ssl_options,
"--ssl-cert=%s/ssl-cert/client-cert.pem --ssl-key=%s/ssl-cert/client-key.pem",
test_dir,
test_dir);
setenv("ssl_options", ssl_options, 1);
setenv("ssl_options", m_ssl_options, 1);
if (maxscale::require_columnstore)
{
@ -339,8 +328,8 @@ TestConnections::TestConnections(int argc, char* argv[])
if (!no_repl)
{
repl = new Mariadb_nodes("node", test_dir, verbose, network_config);
repl->use_ipv6 = use_ipv6;
repl = new Mariadb_nodes("node", test_dir, verbose, m_network_config);
repl->use_ipv6 = m_use_ipv6;
repl->take_snapshot_command = m_take_snapshot_command.c_str();
repl->revert_snapshot_command = m_revert_snapshot_command.c_str();
repl_future = std::async(std::launch::async, &Mariadb_nodes::check_nodes, repl);
@ -352,7 +341,7 @@ TestConnections::TestConnections(int argc, char* argv[])
if (!no_galera)
{
galera = new Galera_nodes("galera", test_dir, verbose, network_config);
galera = new Galera_nodes("galera", test_dir, verbose, m_network_config);
// galera->use_ipv6 = use_ipv6;
galera->use_ipv6 = false;
galera->take_snapshot_command = m_take_snapshot_command.c_str();
@ -364,7 +353,7 @@ TestConnections::TestConnections(int argc, char* argv[])
galera = NULL;
}
maxscales = new Maxscales("maxscale", test_dir, verbose, network_config);
maxscales = new Maxscales("maxscale", test_dir, verbose, m_network_config);
bool maxscale_ok = maxscales->check_nodes();
bool repl_ok = no_repl || repl_future.get();
@ -377,14 +366,14 @@ TestConnections::TestConnections(int argc, char* argv[])
if (call_mdbci("--recreate"))
{
exit(MDBCI_FAUILT);
exit(MDBCI_FAIL);
}
}
if (reinstall_maxscale && reinstall_maxscales())
if (m_reinstall_maxscale && reinstall_maxscales())
{
tprintf("Failed to install Maxscale: target is %s", m_target.c_str());
exit(MDBCI_FAUILT);
exit(MDBCI_FAIL);
}
std::string src = std::string(test_dir) + "/mdbci/add_core_cnf.sh";
@ -393,7 +382,7 @@ TestConnections::TestConnections(int argc, char* argv[])
verbose ? "verbose" : "");
maxscales->use_ipv6 = use_ipv6;
maxscales->use_ipv6 = m_use_ipv6;
maxscales->ssl = ssl;
// Stop MaxScale to prevent it from interfering with the replication setup process
@ -415,11 +404,11 @@ TestConnections::TestConnections(int argc, char* argv[])
{
if (repl && !repl->fix_replication())
{
exit(BROKEN_VM_FAUILT);
exit(BROKEN_VM_FAIL);
}
if (galera && !galera->fix_replication())
{
exit(BROKEN_VM_FAUILT);
exit(BROKEN_VM_FAIL);
}
}
@ -492,7 +481,7 @@ TestConnections::TestConnections(int argc, char* argv[])
pthread_create(&timeout_thread_p, NULL, timeout_thread, this);
pthread_create(&log_copy_thread_p, NULL, log_copy_thread, this);
tprintf("Starting test");
gettimeofday(&start_time, NULL);
gettimeofday(&m_start_time, NULL);
}
TestConnections::~TestConnections()
@ -561,8 +550,8 @@ void TestConnections::report_result(const char* format, va_list argp)
{
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;
double elapsedTime = (t2.tv_sec - m_start_time.tv_sec);
elapsedTime += (double) (t2.tv_usec - m_start_time.tv_usec) / 1000000.0;
global_result += 1;
@ -606,24 +595,24 @@ void TestConnections::read_mdbci_info()
if (system(cmd.c_str()))
{
tprintf("Unable to create MDBCI VMs direcory '%s', exiting", m_mdbci_vm_path.c_str());
exit(MDBCI_FAUILT);
exit(MDBCI_FAIL);
}
m_mdbci_template = envvar_read_write_def_str("template", "default");
m_target = envvar_read_write_def_str("target", "develop");
m_mdbci_config_name = envvar_read_write_def_str("mdbci_config_name", "local");
vm_path = m_mdbci_vm_path + "/" + m_mdbci_config_name;
m_vm_path = m_mdbci_vm_path + "/" + m_mdbci_config_name;
if (!m_mdbci_config_name.empty())
{
std::ifstream nc_file;
nc_file.open(vm_path + "_network_config");
nc_file.open(m_vm_path + "_network_config");
std::stringstream strStream;
strStream << nc_file.rdbuf();
network_config = strStream.str();
m_network_config = strStream.str();
nc_file.close();
nc_file.open(vm_path + "_configured_labels");
nc_file.open(m_vm_path + "_configured_labels");
std::stringstream strStream1;
strStream1 << nc_file.rdbuf();
m_configured_mdbci_labels = parse_to_stringset(strStream1.str());
@ -636,7 +625,7 @@ void TestConnections::read_mdbci_info()
}
if (verbose)
{
tprintf(network_config.c_str());
tprintf(m_network_config.c_str());
}
}
@ -662,10 +651,10 @@ void TestConnections::read_env()
m_no_backend_log_copy = readenv_bool("no_backend_log_copy", false);
m_no_maxscale_log_copy = readenv_bool("no_maxscale_log_copy", false);
use_ipv6 = readenv_bool("use_ipv6", false);
m_use_ipv6 = readenv_bool("use_ipv6", false);
backend_ssl = readenv_bool("backend_ssl", false);
smoke = readenv_bool("smoke", false);
threads = readenv_int("threads", 4);
m_threads = readenv_int("threads", 4);
m_use_snapshots = readenv_bool("use_snapshots", false);
m_take_snapshot_command = envvar_read_write_def_str(
"take_snapshot_command", "mdbci snapshot take --path-to-nodes %s --snapshot-name ",
@ -760,7 +749,7 @@ void TestConnections::process_template(int m, const string& cnf_template_path, c
system("sed -i \"s|type=server|type=server\\nssl=required\\nssl_cert=/###access_homedir###/certs/client-cert.pem\\nssl_key=/###access_homedir###/certs/client-key.pem\\nssl_ca_cert=/###access_homedir###/certs/ca.pem|g\" maxscale.cnf");
}
sprintf(str, "sed -i \"s/###threads###/%d/\" maxscale.cnf", threads);
sprintf(str, "sed -i \"s/###threads###/%d/\" maxscale.cnf", m_threads);
system(str);
Mariadb_nodes * mdn[2];
@ -1004,8 +993,8 @@ int TestConnections::copy_all_logs_periodic()
{
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;
double elapsedTime = (t2.tv_sec - m_start_time.tv_sec);
elapsedTime += (double) (t2.tv_usec - m_start_time.tv_usec) / 1000000.0;
return copy_maxscale_logs(elapsedTime);
}
@ -1825,8 +1814,8 @@ void TestConnections::tprintf(const char* format, ...)
{
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;
double elapsedTime = (t2.tv_sec - m_start_time.tv_sec);
elapsedTime += (double) (t2.tv_usec - m_start_time.tv_usec) / 1000000.0;
struct tm tm_now;
localtime_r(&t2.tv_sec, &tm_now);
@ -2185,19 +2174,14 @@ int TestConnections::call_mdbci(const char * options)
tprintf("Failed to generate MDBCI virtual machines template");
return 1;
}
if (system((std::string("mdbci --override --template ") +
vm_path +
std::string(".json generate ") +
m_mdbci_config_name).c_str() ))
if (system((std::string("mdbci --override --template ") + m_vm_path +
".json generate " + m_mdbci_config_name).c_str() ))
{
tprintf("MDBCI failed to generate virtual machines description");
return 1;
}
if (system((std::string("cp -r ") +
std::string(test_dir) +
std::string("/mdbci/cnf ") +
std::string(vm_path) +
std::string("/")).c_str()))
if (system((std::string("cp -r ") + test_dir + std::string("/mdbci/cnf ") +
m_vm_path + "/").c_str()))
{
tprintf("Failed to copy my.cnf files");
return 1;
@ -2248,26 +2232,16 @@ int TestConnections::process_mdbci_template()
if (strcmp(product, "mysql") == 0 )
{
setenv("cnf_path",
(vm_path + std::string("/cnf/mysql56/")).c_str(),
(m_vm_path + "/cnf/mysql56/").c_str(),
1);
}
else
{
setenv("cnf_path",
(vm_path + std::string("/cnf/")).c_str(),
1);
setenv("cnf_path", (m_vm_path + "/cnf/").c_str(), 1);
}
std::string name = std::string(test_dir) +
std::string("/mdbci/templates/") +
m_mdbci_template +
std::string(".json.template");
std::string sys = std::string("envsubst < ") +
name +
std::string(" > ") +
vm_path +
std::string(".json");
std::string name = std::string(test_dir) + "/mdbci/templates/" + m_mdbci_template + ".json.template";
std::string sys = std::string("envsubst < ") + name + " > " + m_vm_path + ".json";
if (verbose)
{
std::cout << sys << std::endl;