MXS-2900 Move more TestConnections fields to private

This commit is contained in:
Esa Korhonen 2020-03-24 18:35:23 +02:00
parent 2630cc930f
commit 480c57c122
2 changed files with 95 additions and 151 deletions

View File

@ -16,8 +16,8 @@
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
#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
@ -50,10 +50,6 @@ typedef std::set<std::string> StringSet;
*/
class TestConnections
{
private:
/** Whether timeouts are enabled or not */
bool enable_timeouts;
bool log_matches(int m, const char* pattern);
public:
/**
* @brief TestConnections constructor: reads environmental variables, copies MaxScale.cnf for MaxScale
@ -92,7 +88,7 @@ public:
/**
* @brief galera Mariadb_nodes object containing references to Galera setuo
*/
Galera_nodes * galera;
Galera_nodes* galera;
/**
* @brief repl Mariadb_nodes object containing references to Master/Slave setuo
@ -104,47 +100,6 @@ public:
*/
Maxscales* maxscales;
/**
* @brief mdbci_config_name Name of MDBCI VMs set
*/
char * mdbci_config_name;
/**
* @brief mdbci_vm_path Path to directory with MDBCI VMs descriptions
*/
char * mdbci_vm_path;
/**
* @brief mdbci_temlate Name of mdbci VMs tempate file
*/
char * mdbci_template;
/**
* @brief target Name of Maxscale repository in the CI
*/
char * target;
/**
* @brief GetLogsCommand Command to copy log files from node virtual machines (should handle one
* parameter: IP address of virtual machine to kill)
*/
char * get_logs_command;
/**
* @brief make_snapshot_command Command line to create a snapshot of all VMs
*/
char * take_snapshot_command;
/**
* @brief revert_snapshot_command Command line to revert a snapshot of all VMs
*/
char * revert_snapshot_command;
/**
* @brief use_snapshots if TRUE every test is trying to revert snapshot before running the test
*/
bool use_snapshots;
/**
* @brief SysbenchDir path to SysBench directory (sysbanch should be >= 0.5)
*/
@ -158,26 +113,8 @@ public:
*/
int copy_mariadb_logs(Mariadb_nodes* nrepl, const char* prefix, std::vector<std::thread>& threads);
/**
* @brief MaxScale runs locally, specified using -l.
*/
bool local_maxscale;
std::string network_config; /**< Content of MDBCI network_config file */
/**
* @brief network_config Content of MDBCI network_config file
*/
std::string network_config;
/**
* @brief no_backend_log_copy if true logs from backends are not copied
* (needed if case of Aurora RDS backend or similar)
*/
bool no_backend_log_copy;
/**
* @brief Do not download MaxScale logs.
*/
bool no_maxscale_log_copy;
/**
* @brief verbose if true more printing activated
*/
@ -215,22 +152,6 @@ public:
*/
bool binlog_slave_gtid;
/**
* @brief no_repl Do not check, restart and use Maxster/Slave setup;
*/
bool no_repl;
/**
* @brief no_galera Do not check, restart and use Galera setup; all Galera tests will fail
*/
bool no_galera;
/**
* @brief no_vm_revert If true tests do not revert VMs after the test even if test failed
* (use it for debugging)
*/
bool no_vm_revert;
/**
* @brief ssl_options string with ssl configuration for command line client
*/
@ -283,8 +204,8 @@ public:
std::string configured_labels;
/**
* @brief vm_path Path to the VM Vagrant directory
*/
* @brief vm_path Path to the VM Vagrant directory
*/
std::string vm_path;
/**
@ -633,7 +554,6 @@ public:
void check_current_connections(int m, int value);
int stop_maxscale(int m = 0);
int start_maxscale(int m = 0);
void process_template(const char* src, const char* dest = "/etc/maxscale.cnf");
/**
* Get the current master server id from the cluster, as seen by rwsplit.
@ -648,7 +568,7 @@ public:
*
* @param func Function to call
*/
void on_destroy(std::function<void (void)> func)
void on_destroy(std::function<void(void)> func)
{
m_on_destroy.push_back(func);
}
@ -664,7 +584,7 @@ public:
* @brief call_mdbci Execute MDBCI to bring up nodes
* @return 0 if success
*/
int call_mdbci(const char *options);
int call_mdbci(const char* options);
/**
* @brief resinstall_maxscales Remove Maxscale form all nodes and installs new ones
@ -679,19 +599,45 @@ private:
void set_template_and_labels();
void set_mdbci_labels();
bool log_matches(int m, const char* pattern);
bool too_many_maxscales() const
{
return maxscales->N < 2
&& m_mdbci_labels.find("SECOND_MAXSCALE") != std::string::npos;
}
bool too_many_maxscales() const;
std::vector<std::function<void(void)>> m_on_destroy;
std::string m_test_name; /**< Test name */
std::string m_config_template; /**< MaxScale config file template used by test */
std::string m_labels; /**< Test labels */
std::string m_mdbci_labels; /**< Labels for MDBCI */
std::string m_test_name; /**< Test name */
std::string m_config_template; /**< MaxScale config file template used by test */
std::string m_labels; /**< Test labels */
std::string m_mdbci_labels; /**< Labels for MDBCI */
char* m_mdbci_config_name; /**< Name of MDBCI VMs set */
char* m_mdbci_vm_path; /**< Path to directory with MDBCI VMs descriptions */
char* m_mdbci_template; /**< Name of mdbci VMs tempate file */
char* m_target; /**< Name of Maxscale repository in the CI */
/**
* Command to copy log files from node virtual machines (should handle one parameter: IP address of
* virtual machine to kill) */
char* m_get_logs_command;
char* m_take_snapshot_command; /**< Command line to create a snapshot of all VMs */
char* m_revert_snapshot_command; /**< Command line to revert a snapshot of all VMs */
bool m_enable_timeouts {true}; /**< Whether timeouts are enabled or not */
bool m_local_maxscale {false}; /**< MaxScale runs locally, specified using -l. */
/**< If true, every test is trying to revert snapshot before running the test. Unused for now. */
bool m_use_snapshots {false};
/* If true, logs from backends are not copied (needed if case of Aurora RDS backend or similar) */
bool m_no_backend_log_copy {false};
bool m_no_maxscale_log_copy {false}; /**< Do not download MaxScale logs. */
bool no_repl {false}; /**< Do not check, restart and use Master/Slave setup */
bool no_galera {false}; /**< Do not check, restart and use Galera setup; all Galera tests will fail */
/** If true tests do not revert VMs after the test even if test failed (use it for debugging) */
bool no_vm_revert {true};
};
/**

View File

@ -112,20 +112,13 @@ void TestConnections::restart_galera(bool value)
bool TestConnections::verbose = false;
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)
: global_result(0)
, smoke(true)
, binlog_cmd_option(0)
, ssl(false)
, backend_ssl(false)
, binlog_master_gtid(false)
, binlog_slave_gtid(false)
, no_galera(false)
, no_vm_revert(true)
, threads(4)
, use_ipv6(false)
{
@ -222,7 +215,7 @@ TestConnections::TestConnections(int argc, char* argv[])
break;
case 'z':
enable_timeouts = false;
m_enable_timeouts = false;
break;
case 'y':
@ -238,8 +231,8 @@ TestConnections::TestConnections(int argc, char* argv[])
local_ip);
maxscale_init = false;
no_maxscale_log_copy = true;
local_maxscale = true;
m_no_maxscale_log_copy = true;
m_local_maxscale = true;
setenv("maxscale_IP", local_ip, true);
setenv("maxscale_network", local_ip, true);
@ -312,8 +305,8 @@ TestConnections::TestConnections(int argc, char* argv[])
}
}
get_logs_command = (char *) malloc(strlen(test_dir) + 14);
sprintf(get_logs_command, "%s/get_logs.sh", test_dir);
m_get_logs_command = (char *) malloc(strlen(test_dir) + 14);
sprintf(m_get_logs_command, "%s/get_logs.sh", test_dir);
sprintf(ssl_options,
"--ssl-cert=%s/ssl-cert/client-cert.pem --ssl-key=%s/ssl-cert/client-key.pem",
@ -334,8 +327,8 @@ TestConnections::TestConnections(int argc, char* argv[])
{
repl = new Mariadb_nodes("node", test_dir, verbose, network_config);
repl->use_ipv6 = use_ipv6;
repl->take_snapshot_command = take_snapshot_command;
repl->revert_snapshot_command = revert_snapshot_command;
repl->take_snapshot_command = m_take_snapshot_command;
repl->revert_snapshot_command = m_revert_snapshot_command;
repl_future = std::async(std::launch::async, &Mariadb_nodes::check_nodes, repl);
}
else
@ -348,8 +341,8 @@ TestConnections::TestConnections(int argc, char* argv[])
galera = new Galera_nodes("galera", test_dir, verbose, network_config);
//galera->use_ipv6 = use_ipv6;
galera->use_ipv6 = false;
galera->take_snapshot_command = take_snapshot_command;
galera->revert_snapshot_command = revert_snapshot_command;
galera->take_snapshot_command = m_take_snapshot_command;
galera->revert_snapshot_command = m_revert_snapshot_command;
galera_future = std::async(std::launch::async, &Galera_nodes::check_nodes, galera);
}
else
@ -376,7 +369,7 @@ TestConnections::TestConnections(int argc, char* argv[])
if (reinstall_maxscale && reinstall_maxscales())
{
tprintf("Failed to install Maxscale: target is %s", target);
tprintf("Failed to install Maxscale: target is %s", m_target);
exit(MDBCI_FAUILT);
}
@ -593,21 +586,21 @@ void TestConnections::expect(bool result, const char* format, ...)
void TestConnections::read_mdbci_info()
{
mdbci_vm_path = readenv("MDBCI_VM_PATH", "%s/vms/", getenv("HOME"));
m_mdbci_vm_path = readenv("MDBCI_VM_PATH", "%s/vms/", getenv("HOME"));
if (system((std::string("mkdir -p ") +
std::string(mdbci_vm_path)).c_str()))
std::string(m_mdbci_vm_path)).c_str()))
{
tprintf("Unable to create MDBCI VMs direcory '%s', exiting", mdbci_vm_path);
tprintf("Unable to create MDBCI VMs direcory '%s', exiting", m_mdbci_vm_path);
exit(MDBCI_FAUILT);
}
mdbci_template = readenv("template", "default");
target = readenv("target", "develop");
m_mdbci_template = readenv("template", "default");
m_target = readenv("target", "develop");
mdbci_config_name = readenv("mdbci_config_name", "local");
vm_path = std::string(mdbci_vm_path) + "/" + std::string(mdbci_config_name);
m_mdbci_config_name = readenv("mdbci_config_name", "local");
vm_path = std::string(m_mdbci_vm_path) + "/" + std::string(m_mdbci_config_name);
if (mdbci_config_name != NULL)
if (m_mdbci_config_name != NULL)
{
std::ifstream nc_file;
nc_file.open(vm_path + "_network_config");
@ -653,17 +646,17 @@ void TestConnections::read_env()
maxscale::start = false;
}
no_backend_log_copy = readenv_bool("no_backend_log_copy", false);
no_maxscale_log_copy = readenv_bool("no_maxscale_log_copy", false);
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);
backend_ssl = readenv_bool("backend_ssl", false);
smoke = readenv_bool("smoke", false);
threads = readenv_int("threads", 4);
use_snapshots = readenv_bool("use_snapshots", false);
take_snapshot_command = readenv("take_snapshot_command",
"mdbci snapshot take --path-to-nodes %s --snapshot-name ", mdbci_config_name);
revert_snapshot_command = readenv("revert_snapshot_command",
"mdbci snapshot revert --path-to-nodes %s --snapshot-name ", mdbci_config_name);
m_use_snapshots = readenv_bool("use_snapshots", false);
m_take_snapshot_command = readenv("take_snapshot_command",
"mdbci snapshot take --path-to-nodes %s --snapshot-name ", m_mdbci_config_name);
m_revert_snapshot_command = readenv("revert_snapshot_command",
"mdbci snapshot revert --path-to-nodes %s --snapshot-name ", m_mdbci_config_name);
no_vm_revert = readenv_bool("no_vm_revert", true);
}
@ -928,7 +921,7 @@ int TestConnections::copy_all_logs()
std::vector<std::thread> threads;
if (!no_backend_log_copy)
if (!m_no_backend_log_copy)
{
copy_mariadb_logs(repl, "node", threads);
copy_mariadb_logs(galera, "galera", threads);
@ -936,7 +929,7 @@ int TestConnections::copy_all_logs()
int rv = 0;
if (!no_maxscale_log_copy)
if (!m_no_maxscale_log_copy)
{
rv = copy_maxscale_logs(0);
}
@ -1028,7 +1021,7 @@ int TestConnections::prepare_binlog(int m)
"Error editing maxscale.cnf");
}
if (!local_maxscale)
if (!m_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]),
@ -1085,7 +1078,7 @@ int TestConnections::start_binlog(int m)
repl->stop_nodes();
if (!local_maxscale)
if (!m_local_maxscale)
{
binlog =
open_conn_no_db(maxscales->binlog_port[m], maxscales->IP[m], repl->user_name, repl->password,
@ -1122,7 +1115,7 @@ int TestConnections::start_binlog(int m)
prepare_binlog(m);
tprintf("Testing binlog when MariaDB is started with '%s' option\n", cmd_opt);
if (!local_maxscale)
if (!m_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]),
@ -1158,7 +1151,7 @@ int TestConnections::start_binlog(int m)
repl->set_slave(repl->nodes[1], repl->IP_private[0], repl->port[0], log_file, log_pos);
}
if (!local_maxscale)
if (!m_local_maxscale)
{
tprintf("Starting back Maxscale\n");
add_result(maxscales->start_maxscale(m), "Maxscale start failed\n");
@ -1800,7 +1793,7 @@ int TestConnections::get_client_ip(int m, char* ip)
int TestConnections::set_timeout(long int timeout_seconds)
{
if (enable_timeouts)
if (m_enable_timeouts)
{
timeout = timeout_seconds;
}
@ -2148,15 +2141,15 @@ void TestConnections::check_current_connections(int m, int value)
int TestConnections::take_snapshot(char* snapshot_name)
{
char str[strlen(take_snapshot_command) + strlen(snapshot_name) + 2];
sprintf(str, "%s %s", take_snapshot_command, snapshot_name);
char str[strlen(m_take_snapshot_command) + strlen(snapshot_name) + 2];
sprintf(str, "%s %s", m_take_snapshot_command, snapshot_name);
return system(str);
}
int TestConnections::revert_snapshot(char* snapshot_name)
{
char str[strlen(revert_snapshot_command) + strlen(snapshot_name) + 2];
sprintf(str, "%s %s", revert_snapshot_command, snapshot_name);
char str[strlen(m_revert_snapshot_command) + strlen(snapshot_name) + 2];
sprintf(str, "%s %s", m_revert_snapshot_command, snapshot_name);
return system(str);
}
@ -2177,7 +2170,7 @@ int TestConnections::call_mdbci(const char * options)
{
struct stat buf;
if (stat(
(mdbci_vm_path + std::string("/") + mdbci_config_name).c_str(),
(m_mdbci_vm_path + std::string("/") + m_mdbci_config_name).c_str(),
&buf)
)
{
@ -2189,7 +2182,7 @@ int TestConnections::call_mdbci(const char * options)
if (system((std::string("mdbci --override --template ") +
vm_path +
std::string(".json generate ") +
std::string(mdbci_config_name)).c_str() ))
std::string(m_mdbci_config_name)).c_str() ))
{
tprintf("MDBCI failed to generate virtual machines description");
return 1;
@ -2206,7 +2199,7 @@ int TestConnections::call_mdbci(const char * options)
}
if (system((std::string("mdbci up ") +
std::string(mdbci_config_name) +
std::string(m_mdbci_config_name) +
std::string(" --labels ") +
m_mdbci_labels +
std::string(" ") +
@ -2220,7 +2213,7 @@ int TestConnections::call_mdbci(const char * options)
system((std::string("mdbci public_keys --key ") +
team_keys +
std::string(" ") +
std::string(mdbci_config_name)).c_str() );
std::string(m_mdbci_config_name)).c_str() );
read_env();
if (repl)
@ -2263,7 +2256,7 @@ int TestConnections::process_mdbci_template()
std::string name = std::string(test_dir) +
std::string("/mdbci/templates/") +
std::string(mdbci_template) +
std::string(m_mdbci_template) +
std::string(".json.template");
std::string sys = std::string("envsubst < ") +
@ -2301,10 +2294,10 @@ std::string dump_status(const StringSet& current, const StringSet& expected)
}
int TestConnections::reinstall_maxscales()
{
char sys[strlen(target) +
strlen(mdbci_config_name) +
strlen(maxscales->prefix) +
70];
char sys[strlen(m_target) +
strlen(m_mdbci_config_name) +
strlen(maxscales->prefix) +
70];
for (int i = 0; i < maxscales->N; i++)
{
printf("Installing Maxscale on node %d\n", i);
@ -2313,7 +2306,7 @@ int TestConnections::reinstall_maxscales()
maxscales->ssh_node(i, "yum clean all", true);
sprintf(sys, "mdbci install_product --product maxscale_ci --product-version %s %s/%s_%03d",
target, mdbci_config_name, maxscales->prefix, i);
m_target, m_mdbci_config_name, maxscales->prefix, i);
if (system(sys))
{
return 1;
@ -2321,3 +2314,8 @@ int TestConnections::reinstall_maxscales()
}
return 0;
}
bool TestConnections::too_many_maxscales() const
{
return maxscales->N < 2 && m_mdbci_labels.find("SECOND_MAXSCALE") != std::string::npos;
}