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

@ -16,9 +16,6 @@
typedef std::set<std::string> StringSet;
#define MDBCI_FAUILT 200// Exit code for the case when failure caused by MDBCI non-zero exit
#define BROKEN_VM_FAUILT 201// Exit code for the case when failure caused by screwed VMs
/**
* @brief Class contains references to Master/Slave and Galera test setups
* Test setup should consist of two setups: one Master/Slave and one Galera.
@ -85,22 +82,22 @@ public:
/**
* @brief global_result Result of test, 0 if PASSED
*/
int global_result;
int global_result {0};
/**
* @brief galera Mariadb_nodes object containing references to Galera setuo
*/
Galera_nodes* galera;
Galera_nodes* galera {nullptr};
/**
* @brief repl Mariadb_nodes object containing references to Master/Slave setuo
*/
Mariadb_nodes* repl;
Mariadb_nodes* repl {nullptr};
/**
* @brief maxscales Maxscale object containing referebces to all Maxscale machines
*/
Maxscales* maxscales;
Maxscales* maxscales {nullptr};
/**
* @brief SysbenchDir path to SysBench directory (sysbanch should be >= 0.5)
@ -115,8 +112,6 @@ public:
*/
int copy_mariadb_logs(Mariadb_nodes* nrepl, const char* prefix, std::vector<std::thread>& threads);
std::string network_config; /**< Content of MDBCI network_config file */
/**
* @brief verbose if true more printing activated
*/
@ -125,44 +120,34 @@ public:
/**
* @brief smoke if true all tests are executed in quick mode
*/
bool smoke;
bool smoke {true};
/**
* @brief binlog_cmd_option index of mariadb start option
*/
int binlog_cmd_option;
int binlog_cmd_option {0};
/**
* @brief ssl if true ssl will be used
*/
int ssl;
int ssl {false};
/**
* @brief backend_ssl if true ssl configuratio for all servers will be added
*/
bool backend_ssl;
bool backend_ssl {false};
/**
* @brief binlog_master_gtid If true start_binlog() function configures Maxscale
* binlog router to use GTID to connect to Master
*/
bool binlog_master_gtid;
bool binlog_master_gtid {false};
/**
* @brief binlog_slave_gtid If true start_binlog() function configures slaves
* to use GTID to connect to Maxscale binlog router
*/
bool binlog_slave_gtid;
/**
* @brief ssl_options string with ssl configuration for command line client
*/
char ssl_options[1024];
/**
* @brief threads Number of Maxscale threads
*/
int threads;
bool binlog_slave_gtid {false};
/**
* @brief timeout seconds until test termination
@ -189,30 +174,6 @@ public:
*/
pthread_t log_copy_thread_p;
/**
* @brief start_time time when test was started (used by printf to print Timestamp)
*/
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;
/**
* @brief vm_path Path to the VM Vagrant directory
*/
std::string vm_path;
/**
* @brief reinstall_maxscale Flag that is set when 'reinstall_maxscale'
* option is provided;
* if true Maxscale will be removed and re-installed on all Maxscale nodes
* Used for 'run_test_snapshot'
*/
bool reinstall_maxscale;
/** Check whether all nodes are in a valid state */
static void check_nodes(bool value);
@ -619,6 +580,8 @@ private:
std::string m_mdbci_vm_path; /**< Path to directory with MDBCI VMs descriptions */
std::string m_mdbci_template; /**< Name of mdbci VMs tempate file */
std::string m_target; /**< Name of Maxscale repository in the CI */
std::string m_network_config; /**< Content of MDBCI network_config file */
std::string m_vm_path; /**< Path to the VM Vagrant directory */
/**
* Command to copy log files from node virtual machines (should handle one parameter: IP address of
@ -628,6 +591,8 @@ private:
std::string m_take_snapshot_command; /**< Command line to create a snapshot of all VMs */
std::string m_revert_snapshot_command; /**< Command line to revert a snapshot of all VMs */
char m_ssl_options[1024]; /**< String with ssl configuration for command line client */
bool m_enable_timeouts {true}; /**< Whether timeouts are enabled or not */
bool m_local_maxscale {false}; /**< MaxScale runs locally, specified using -l. */
@ -644,6 +609,21 @@ private:
/** If true tests do not revert VMs after the test even if test failed (use it for debugging) */
bool no_vm_revert {true};
int m_threads {4}; /**< Number of Maxscale threads */
timeval m_start_time {0, 0}; /**< time when test was started (used by printf to print Timestamp) */
/**
* If true IPv6 addresses will be used to connect Maxscale and backed Also IPv6 addresses go to
* maxscale.cnf. */
bool m_use_ipv6 {false};
/**
* Flag that is set when 'reinstall_maxscale'-option is provided. If true, Maxscale will be removed
* and re-installed on all Maxscale nodes. Used for 'run_test_snapshot'.
*/
bool m_reinstall_maxscale {false};
std::string flatten_stringset(const StringSet& set);
StringSet parse_to_stringset(const std::string& source);
};

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;