diff --git a/maxscale-system-test/maxtest/include/maxtest/testconnections.h b/maxscale-system-test/maxtest/include/maxtest/testconnections.h index e81395f3c..50139d868 100644 --- a/maxscale-system-test/maxtest/include/maxtest/testconnections.h +++ b/maxscale-system-test/maxtest/include/maxtest/testconnections.h @@ -17,9 +17,6 @@ typedef std::set 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. @@ -86,24 +83,24 @@ 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}; Clustrix_nodes * clustrix; /** * @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) @@ -118,8 +115,6 @@ public: */ int copy_mariadb_logs(Mariadb_nodes* nrepl, const char* prefix, std::vector& threads); - std::string network_config; /**< Content of MDBCI network_config file */ - /** * @brief verbose if true more printing activated */ @@ -128,50 +123,40 @@ 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; + bool binlog_slave_gtid {false}; /** * @brief no_clustrix Do not check, restart and use Clustrix setup */ bool no_clustrix; - /** - * @brief ssl_options string with ssl configuration for command line client - */ - char ssl_options[1024]; - - /** - * @brief threads Number of Maxscale threads - */ - int threads; - /** * @brief timeout seconds until test termination */ @@ -197,30 +182,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); @@ -632,6 +593,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 @@ -641,6 +604,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. */ @@ -657,6 +622,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); }; diff --git a/maxscale-system-test/maxtest/src/testconnections.cpp b/maxscale-system-test/maxtest/src/testconnections.cpp index 720423bfc..d04995d24 100644 --- a/maxscale-system-test/maxtest/src/testconnections.cpp +++ b/maxscale-system-test/maxtest/src/testconnections.cpp @@ -41,6 +41,9 @@ const string label_clx_be = "CLUSTRIX_BACKEND"; const StringSet recognized_mdbci_labels = {label_repl_be, label_big_be, label_galera_be, label_2nd_mxs, label_cs_be, label_clx_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 @@ -140,16 +143,7 @@ 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) - , no_clustrix(false) - , threads(4) - , use_ipv6(false) + : no_clustrix(false) { std::ios::sync_with_stdio(true); signal_set(SIGSEGV, sigfatal_handler); @@ -159,12 +153,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(); @@ -268,17 +257,17 @@ TestConnections::TestConnections(int argc, char* argv[]) std::regex regex1("maxscale_000_network=[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+"); std::string replace1("maxscale_000_network=127.0.0.1"); - network_config = regex_replace(network_config, regex1, replace1); + m_network_config = regex_replace(m_network_config, regex1, replace1); std::regex regex2("maxscale_000_private_ip=[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+"); std::string replace2("maxscale_000_private_ip=127.0.0.1"); - network_config = regex_replace(network_config, regex2, replace2); + m_network_config = regex_replace(m_network_config, regex2, replace2); } break; case 'm': printf("Maxscale will be reinstalled"); - reinstall_maxscale = true; + m_reinstall_maxscale = true; break; default: @@ -325,7 +314,7 @@ TestConnections::TestConnections(int argc, char* argv[]) { if (call_mdbci("")) { - exit(MDBCI_FAUILT); + exit(MDBCI_FAIL); } } @@ -358,11 +347,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) { @@ -375,9 +364,9 @@ TestConnections::TestConnections(int argc, char* argv[]) if (!no_repl) { - repl = new Mariadb_nodes("node", test_dir, verbose, network_config); + repl = new Mariadb_nodes("node", test_dir, verbose, m_network_config); repl->setup(); - repl->use_ipv6 = use_ipv6; + 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); @@ -389,7 +378,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->setup(); galera->use_ipv6 = false; galera->take_snapshot_command = m_take_snapshot_command.c_str(); @@ -403,7 +392,7 @@ TestConnections::TestConnections(int argc, char* argv[]) if (!no_clustrix) { - clustrix = new Clustrix_nodes("clustrix", test_dir, verbose, network_config); + clustrix = new Clustrix_nodes("clustrix", test_dir, verbose, m_network_config); clustrix->setup(); clustrix->use_ipv6 = false; clustrix->take_snapshot_command = m_take_snapshot_command.c_str(); @@ -415,7 +404,7 @@ TestConnections::TestConnections(int argc, char* argv[]) clustrix = NULL; } - maxscales = new Maxscales("maxscale", test_dir, verbose, network_config); + maxscales = new Maxscales("maxscale", test_dir, verbose, m_network_config); maxscales->setup(); bool maxscale_ok = maxscales->check_nodes(); @@ -431,18 +420,18 @@ TestConnections::TestConnections(int argc, char* argv[]) if (call_mdbci("--recreate")) { - exit(MDBCI_FAUILT); + exit(MDBCI_FAIL); } } - if (reinstall_maxscale) + if (m_reinstall_maxscale) { initialize = true; if (reinstall_maxscales()) { tprintf("Failed to install Maxscale: target is %s", m_target.c_str()); - exit(MDBCI_FAUILT); + exit(MDBCI_FAIL); } } @@ -455,7 +444,7 @@ TestConnections::TestConnections(int argc, char* argv[]) } - 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 @@ -477,11 +466,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); } } @@ -554,7 +543,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() @@ -623,8 +612,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; @@ -668,24 +657,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()); @@ -698,7 +687,7 @@ void TestConnections::read_mdbci_info() } if (verbose) { - tprintf(network_config.c_str()); + tprintf(m_network_config.c_str()); } } @@ -724,10 +713,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 ", @@ -822,7 +811,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\\nssl_cert_verify_depth=9\\nssl_version=MAX|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[3]; @@ -1071,8 +1060,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); } @@ -1844,8 +1833,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); @@ -2220,19 +2209,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; @@ -2282,26 +2266,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;