Merge commit '09cb4a885f88d30b5108d215dcdaa5163229a230' into develop
This commit is contained in:
@ -9,13 +9,17 @@
|
||||
#include <sys/stat.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <maxbase/stacktrace.hh>
|
||||
|
||||
#include "mariadb_func.h"
|
||||
#include "maxadmin_operations.h"
|
||||
#include "sql_t1.h"
|
||||
#include "testconnections.h"
|
||||
#include "labels_table.h"
|
||||
#include "envv.h"
|
||||
|
||||
using namespace mxb;
|
||||
using std::cout;
|
||||
@ -145,14 +149,12 @@ TestConnections::TestConnections(int argc, char* argv[])
|
||||
#endif
|
||||
gettimeofday(&start_time, NULL);
|
||||
|
||||
read_env();
|
||||
repl = NULL;
|
||||
galera = NULL;
|
||||
maxscales = NULL;
|
||||
reinstall_maxscale = false;
|
||||
|
||||
char* gal_env = getenv("galera_000_network");
|
||||
if ((gal_env == NULL) || (strcmp(gal_env, "") == 0 ))
|
||||
{
|
||||
no_galera = true;
|
||||
tprintf("Galera backend variables are not defined, Galera won't be used\n");
|
||||
}
|
||||
read_env();
|
||||
|
||||
bool maxscale_init = true;
|
||||
|
||||
@ -170,6 +172,7 @@ TestConnections::TestConnections(int argc, char* argv[])
|
||||
{"no-timeouts", no_argument, 0, 'z' },
|
||||
{"no-galera", no_argument, 0, 'y' },
|
||||
{"local-maxscale", optional_argument, 0, 'l' },
|
||||
{"reinstall-maxscale",no_argument, 0, 'm' },
|
||||
{0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
@ -257,21 +260,77 @@ TestConnections::TestConnections(int argc, char* argv[])
|
||||
}
|
||||
break;
|
||||
|
||||
case 'm':
|
||||
printf("Maxscale will be reinstalled");
|
||||
reinstall_maxscale = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("UNKNOWN OPTION: %c\n", c);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (optind < argc)
|
||||
test_name = basename(argv[0]);
|
||||
if (!strcmp(test_name, "non_native_setup"))
|
||||
{
|
||||
test_name = argv[optind];
|
||||
}
|
||||
else
|
||||
{
|
||||
test_name = basename(argv[0]);
|
||||
test_name = argv[1];
|
||||
}
|
||||
|
||||
const char * labels_string = NULL;
|
||||
template_name = get_template_name(test_name, &labels_string);
|
||||
labels = strstr(labels_string, "LABELS;");
|
||||
if (!labels)
|
||||
{
|
||||
labels = (char* ) "LABELS;REPL_BACKEND";
|
||||
}
|
||||
|
||||
mdbci_labels = get_mdbci_lables(labels);
|
||||
|
||||
std::string delimiter = std::string (",");
|
||||
size_t pos_start = 0, pos_end, delim_len = delimiter.length();
|
||||
std::string label;
|
||||
std::string mdbci_labels_c = mdbci_labels + delimiter;
|
||||
|
||||
bool mdbci_call_needed = false;
|
||||
|
||||
while ((pos_end = mdbci_labels_c.find (delimiter, pos_start)) != std::string::npos)
|
||||
{
|
||||
label = mdbci_labels_c.substr (pos_start, pos_end - pos_start);
|
||||
pos_start = pos_end + delim_len;
|
||||
if (configured_labels.find(label, 0) == std::string::npos)
|
||||
{
|
||||
mdbci_call_needed = true;
|
||||
tprintf("Machines with label '%s' are not running, MDBCI UP call is needed", label.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
tprintf("Machines with label '%s' are running, MDBCI UP call is not needed", label.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
if (mdbci_call_needed)
|
||||
{
|
||||
if (call_mdbci(""))
|
||||
{
|
||||
exit(MDBCI_FAUILT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (mdbci_labels.find(std::string("REPL_BACKEND")) == std::string::npos)
|
||||
{
|
||||
no_repl = true;
|
||||
tprintf("No need to use Master/Slave");
|
||||
}
|
||||
|
||||
if (mdbci_labels.find(std::string("GALERA_BACKEND")) == std::string::npos)
|
||||
{
|
||||
no_galera = true;
|
||||
tprintf("No need to use Galera");
|
||||
}
|
||||
|
||||
get_logs_command = (char *) malloc(strlen(test_dir) + 14);
|
||||
sprintf(get_logs_command, "%s/get_logs.sh", test_dir);
|
||||
|
||||
sprintf(ssl_options,
|
||||
@ -280,102 +339,146 @@ TestConnections::TestConnections(int argc, char* argv[])
|
||||
test_dir);
|
||||
setenv("ssl_options", ssl_options, 1);
|
||||
|
||||
if (no_galera && maxscale::require_galera)
|
||||
{
|
||||
cout << "Galera not in use, skipping test" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
if (maxscale::require_columnstore)
|
||||
{
|
||||
cout << "ColumnStore testing is not yet implemented, skipping test" << endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
repl = new Mariadb_nodes("node", test_dir, verbose);
|
||||
if (!no_repl)
|
||||
{
|
||||
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;
|
||||
if (repl->check_nodes())
|
||||
{
|
||||
if (call_mdbci("--recreate"))
|
||||
{
|
||||
exit(MDBCI_FAUILT);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
repl = NULL;
|
||||
}
|
||||
|
||||
if (!no_galera)
|
||||
{
|
||||
galera = new Galera_nodes("galera", test_dir, verbose);
|
||||
// galera->use_ipv6 = use_ipv6;
|
||||
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;
|
||||
if (galera->check_nodes())
|
||||
{
|
||||
if (call_mdbci("--recreate"))
|
||||
{
|
||||
exit(MDBCI_FAUILT);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
galera = NULL;
|
||||
}
|
||||
|
||||
repl->use_ipv6 = use_ipv6;
|
||||
repl->take_snapshot_command = take_snapshot_command;
|
||||
repl->revert_snapshot_command = revert_snapshot_command;
|
||||
maxscales = new Maxscales("maxscale", test_dir, verbose, use_valgrind, network_config);
|
||||
if (maxscales->check_nodes() ||
|
||||
((maxscales->N < 2) && (mdbci_labels.find(std::string("SECOND_MAXSCALE")) != std::string::npos))
|
||||
)
|
||||
{
|
||||
if (call_mdbci("--recreate"))
|
||||
{
|
||||
exit(MDBCI_FAUILT);
|
||||
}
|
||||
}
|
||||
|
||||
if (reinstall_maxscale)
|
||||
{
|
||||
if (reinstall_maxscales())
|
||||
{
|
||||
tprintf("Failed to install Maxscale: target is %s", target);
|
||||
exit(MDBCI_FAUILT);
|
||||
}
|
||||
}
|
||||
|
||||
std::string src = std::string(test_dir) + "/mdbci/add_core_cnf.sh";
|
||||
maxscales->copy_to_node(0, src.c_str(), maxscales->access_homedir[0]);
|
||||
maxscales->ssh_node_f(0, true, "%s/add_core_cnf.sh %s", maxscales->access_homedir[0],
|
||||
verbose ? "verbose" : "");
|
||||
|
||||
maxscales = new Maxscales("maxscale", test_dir, verbose, use_valgrind);
|
||||
|
||||
maxscales->use_ipv6 = use_ipv6;
|
||||
maxscales->ssl = ssl;
|
||||
|
||||
if (maxscale::required_repl_version.length())
|
||||
// Stop MaxScale to prevent it from interfering with the replication setup process
|
||||
if (!maxscale::manual_debug)
|
||||
{
|
||||
int ver_repl_required = get_int_version(maxscale::required_repl_version);
|
||||
std::string ver_repl = repl->get_lowest_version();
|
||||
int int_ver_repl = get_int_version(ver_repl);
|
||||
|
||||
if (int_ver_repl < ver_repl_required)
|
||||
for (int i = 0; i < maxscales->N; i++)
|
||||
{
|
||||
tprintf("Test requires a higher version of backend servers, skipping test.");
|
||||
tprintf("Required version: %s", maxscale::required_repl_version.c_str());
|
||||
tprintf("Master-slave version: %s", ver_repl.c_str());
|
||||
exit(0);
|
||||
maxscales->stop(i);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxscale::required_galera_version.length())
|
||||
if (repl)
|
||||
{
|
||||
int ver_galera_required = get_int_version(maxscale::required_galera_version);
|
||||
std::string ver_galera = galera->get_lowest_version();
|
||||
int int_ver_galera = get_int_version(ver_galera);
|
||||
|
||||
if (int_ver_galera < ver_galera_required)
|
||||
if (maxscale::required_repl_version.length())
|
||||
{
|
||||
tprintf("Test requires a higher version of backend servers, skipping test.");
|
||||
tprintf("Required version: %s", maxscale::required_galera_version.c_str());
|
||||
tprintf("Galera version: %s", ver_galera.c_str());
|
||||
exit(0);
|
||||
int ver_repl_required = get_int_version(maxscale::required_repl_version);
|
||||
std::string ver_repl = repl->get_lowest_version();
|
||||
int int_ver_repl = get_int_version(ver_repl);
|
||||
|
||||
if (int_ver_repl < ver_repl_required)
|
||||
{
|
||||
tprintf("Test requires a higher version of backend servers, skipping test.");
|
||||
tprintf("Required version: %s", maxscale::required_repl_version.c_str());
|
||||
tprintf("Master-slave version: %s", ver_repl.c_str());
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((maxscale::restart_galera) && (!no_galera))
|
||||
if (galera)
|
||||
{
|
||||
if (maxscale::required_galera_version.length())
|
||||
{
|
||||
int ver_galera_required = get_int_version(maxscale::required_galera_version);
|
||||
std::string ver_galera = galera->get_lowest_version();
|
||||
int int_ver_galera = get_int_version(ver_galera);
|
||||
|
||||
if (int_ver_galera < ver_galera_required)
|
||||
{
|
||||
tprintf("Test requires a higher version of backend servers, skipping test.");
|
||||
tprintf("Required version: %s", maxscale::required_galera_version.c_str());
|
||||
tprintf("Galera version: %s", ver_galera.c_str());
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((maxscale::restart_galera) && (galera))
|
||||
{
|
||||
galera->stop_nodes();
|
||||
galera->start_replication();
|
||||
}
|
||||
|
||||
bool snapshot_reverted = false;
|
||||
|
||||
if (use_snapshots)
|
||||
if (maxscale::check_nodes)
|
||||
{
|
||||
snapshot_reverted = revert_snapshot((char*) "clean");
|
||||
}
|
||||
|
||||
if (!snapshot_reverted && maxscale::check_nodes
|
||||
&& (repl->check_replication() || (!no_galera && galera->check_replication())))
|
||||
{
|
||||
// Stop MaxScale to prevent it from interfering with the replication setup process
|
||||
if (!maxscale::manual_debug)
|
||||
if (repl)
|
||||
{
|
||||
maxscales->stop_all();
|
||||
if (!repl->fix_replication() )
|
||||
{
|
||||
exit(BROKEN_VM_FAUILT);
|
||||
}
|
||||
}
|
||||
|
||||
if (!repl->fix_replication())
|
||||
{
|
||||
exit(200);
|
||||
}
|
||||
if (!no_galera)
|
||||
if (galera)
|
||||
{
|
||||
if (!galera->fix_replication())
|
||||
{
|
||||
exit(200);
|
||||
exit(BROKEN_VM_FAUILT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -389,7 +492,7 @@ TestConnections::TestConnections(int argc, char* argv[])
|
||||
{
|
||||
tprintf("Configuring backends for ssl \n");
|
||||
repl->configure_ssl(true);
|
||||
if (!no_galera)
|
||||
if (galera)
|
||||
{
|
||||
galera->configure_ssl(false);
|
||||
galera->start_replication();
|
||||
@ -448,8 +551,11 @@ TestConnections::~TestConnections()
|
||||
* }
|
||||
*/
|
||||
|
||||
delete repl;
|
||||
if (!no_galera)
|
||||
if (repl)
|
||||
{
|
||||
delete repl;
|
||||
}
|
||||
if (galera)
|
||||
{
|
||||
delete galera;
|
||||
}
|
||||
@ -507,129 +613,80 @@ void TestConnections::expect(bool result, const char* format, ...)
|
||||
}
|
||||
}
|
||||
|
||||
void TestConnections::read_mdbci_info()
|
||||
{
|
||||
mdbci_vm_path = readenv("MDBCI_VM_PATH", "%s/vms/", getenv("HOME"));
|
||||
|
||||
if (system((std::string("mkdir -p ") +
|
||||
std::string(mdbci_vm_path)).c_str()))
|
||||
{
|
||||
tprintf("Unable to create MDBCI VMs direcory '%s', exiting", mdbci_vm_path);
|
||||
exit(MDBCI_FAUILT);
|
||||
}
|
||||
mdbci_template = readenv("template", "default");
|
||||
target = readenv("target", "develop");
|
||||
|
||||
mdbci_config_name = readenv("mdbci_config_name", "local");
|
||||
vm_path = std::string(mdbci_vm_path) + std::string(mdbci_config_name);
|
||||
if (mdbci_config_name != NULL)
|
||||
{
|
||||
std::ifstream nc_file;
|
||||
nc_file.open(vm_path + "_network_config");
|
||||
std::stringstream strStream;
|
||||
strStream << nc_file.rdbuf();
|
||||
network_config = strStream.str();
|
||||
nc_file.close();
|
||||
|
||||
nc_file.open(vm_path + "_configured_labels");
|
||||
std::stringstream strStream1;
|
||||
strStream1 << nc_file.rdbuf();
|
||||
configured_labels = strStream1.str();
|
||||
nc_file.close();
|
||||
}
|
||||
else
|
||||
{
|
||||
tprintf("The name of MDBCI configuration is not defined, exiting!");
|
||||
exit(1);
|
||||
}
|
||||
if (verbose)
|
||||
{
|
||||
tprintf(network_config.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
void TestConnections::read_env()
|
||||
{
|
||||
char* env;
|
||||
|
||||
read_mdbci_info();
|
||||
if (verbose)
|
||||
{
|
||||
printf("Reading test setup configuration from environmental variables\n");
|
||||
}
|
||||
|
||||
// env = getenv("get_logs_command"); if (env != NULL) {sprintf(get_logs_command, "%s", env);}
|
||||
ssl = readenv_bool("ssl", true);
|
||||
|
||||
env = getenv("sysbench_dir");
|
||||
if (env != NULL)
|
||||
{
|
||||
sprintf(sysbench_dir, "%s", env);
|
||||
}
|
||||
|
||||
// env = getenv("test_dir"); if (env != NULL) {sprintf(test_dir, "%s", env);}
|
||||
|
||||
ssl = false;
|
||||
env = getenv("ssl");
|
||||
if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
{
|
||||
ssl = true;
|
||||
}
|
||||
env = getenv("mysql51_only");
|
||||
if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
if (readenv_bool("mysql51_only", false) || readenv_bool("no_nodes_check", false))
|
||||
{
|
||||
maxscale::check_nodes = false;
|
||||
}
|
||||
|
||||
env = getenv("no_nodes_check");
|
||||
if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
{
|
||||
maxscale::check_nodes = false;
|
||||
}
|
||||
env = getenv("no_backend_log_copy");
|
||||
if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
{
|
||||
no_backend_log_copy = true;
|
||||
}
|
||||
env = getenv("no_maxscale_log_copy");
|
||||
if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
{
|
||||
no_maxscale_log_copy = true;
|
||||
}
|
||||
env = getenv("use_ipv6");
|
||||
if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
{
|
||||
use_ipv6 = true;
|
||||
}
|
||||
|
||||
env = getenv("backend_ssl");
|
||||
if (env != NULL && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
{
|
||||
backend_ssl = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
backend_ssl = false;
|
||||
}
|
||||
|
||||
env = getenv("smoke");
|
||||
if (env)
|
||||
{
|
||||
smoke = strcasecmp(env, "yes") == 0 || strcasecmp(env, "true") == 0;
|
||||
}
|
||||
|
||||
env = getenv("threads");
|
||||
if ((env != NULL))
|
||||
{
|
||||
sscanf(env, "%d", &threads);
|
||||
}
|
||||
else
|
||||
{
|
||||
threads = 4;
|
||||
}
|
||||
|
||||
env = getenv("use_snapshots");
|
||||
if (env != NULL && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
{
|
||||
use_snapshots = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
use_snapshots = false;
|
||||
}
|
||||
env = getenv("take_snapshot_command");
|
||||
if (env != NULL)
|
||||
{
|
||||
sprintf(take_snapshot_command, "%s", env);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(take_snapshot_command, "exit 1");
|
||||
}
|
||||
env = getenv("revert_snapshot_command");
|
||||
if (env != NULL)
|
||||
{
|
||||
sprintf(revert_snapshot_command, "%s", env);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(revert_snapshot_command, "exit 1");
|
||||
}
|
||||
|
||||
env = getenv("no_maxscale_start");
|
||||
if (env != NULL && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
if (readenv_bool("no_maxscale_start", false))
|
||||
{
|
||||
maxscale::start = false;
|
||||
}
|
||||
|
||||
env = getenv("no_vm_revert");
|
||||
if ((env != NULL) && ((strcasecmp(env, "no") == 0) || (strcasecmp(env, "false") == 0)))
|
||||
{
|
||||
no_vm_revert = false;
|
||||
}
|
||||
|
||||
env = getenv("use_valgrind");
|
||||
if ((env != NULL) && ((strcasecmp(env, "yes") == 0) || (strcasecmp(env, "true") == 0)))
|
||||
{
|
||||
use_valgrind = true;
|
||||
}
|
||||
no_backend_log_copy = readenv_bool("no_backend_log_copy", false);
|
||||
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);
|
||||
no_vm_revert = readenv_bool("no_vm_revert", true);
|
||||
use_valgrind = readenv_bool("use_valgrind", false);
|
||||
}
|
||||
|
||||
void TestConnections::print_env()
|
||||
@ -650,9 +707,10 @@ void TestConnections::print_env()
|
||||
}
|
||||
}
|
||||
|
||||
const char* get_template_name(char* test_name)
|
||||
const char * get_template_name(char * test_name, const char ** labels)
|
||||
{
|
||||
int i = 0;
|
||||
*labels = NULL;
|
||||
while (cnf_templates[i].test_name && strcmp(cnf_templates[i].test_name, test_name) != 0)
|
||||
{
|
||||
i++;
|
||||
@ -660,6 +718,7 @@ const char* get_template_name(char* test_name)
|
||||
|
||||
if (cnf_templates[i].test_name)
|
||||
{
|
||||
*labels = (char *) cnf_templates[i].test_labels;
|
||||
return cnf_templates[i].test_template;
|
||||
}
|
||||
|
||||
@ -680,72 +739,79 @@ void TestConnections::process_template(int m, const char* template_name, const c
|
||||
sprintf(template_file, "%s/cnf/maxscale.cnf.template.%s", test_dir, template_name);
|
||||
sprintf(extended_template_file, "%s.%03d", template_file, m);
|
||||
|
||||
if (stat(extended_template_file, &stb) == 0)
|
||||
if (stat((char*)extended_template_file, &stb) == 0)
|
||||
{
|
||||
strcpy(template_file, extended_template_file);
|
||||
}
|
||||
tprintf("Template file is %s\n", template_file);
|
||||
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "sed ";
|
||||
sprintf(str, "cp %s maxscale.cnf", template_file);
|
||||
if (verbose)
|
||||
{
|
||||
tprintf("Executing '%s' command\n", str);
|
||||
}
|
||||
if (system(str) != 0)
|
||||
{
|
||||
tprintf("Error copying maxscale.cnf template\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (backend_ssl)
|
||||
{
|
||||
ss
|
||||
<<
|
||||
" -e \"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\" ";
|
||||
tprintf("Adding ssl settings\n");
|
||||
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");
|
||||
}
|
||||
|
||||
ss << " -e \"s/###threads###/" << threads << "/\" ";
|
||||
sprintf(str, "sed -i \"s/###threads###/%d/\" maxscale.cnf", threads);
|
||||
system(str);
|
||||
|
||||
Mariadb_nodes* mdn[2] {repl, galera};
|
||||
char* IPcnf;
|
||||
Mariadb_nodes * mdn[2];
|
||||
char * IPcnf;
|
||||
mdn[0] = repl;
|
||||
mdn[1] = galera;
|
||||
int i, j;
|
||||
int mdn_n = galera ? 2 : 1;
|
||||
|
||||
for (int j = 0; j < mdn_n; j++)
|
||||
for (j = 0; j < mdn_n; j++)
|
||||
{
|
||||
for (int i = 0; i < mdn[j]->N; i++)
|
||||
if (mdn[j])
|
||||
{
|
||||
if (mdn[j]->use_ipv6)
|
||||
for (i = 0; i < mdn[j]->N; i++)
|
||||
{
|
||||
IPcnf = mdn[j]->IP6[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
IPcnf = mdn[j]->IP[i];
|
||||
}
|
||||
sprintf(str,
|
||||
" -e \"s/###%s_server_IP_%0d###/%s/\" ",
|
||||
mdn[j]->prefix,
|
||||
i + 1,
|
||||
IPcnf);
|
||||
ss << str;
|
||||
if (mdn[j]->use_ipv6)
|
||||
{
|
||||
IPcnf = mdn[j]->IP6[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
IPcnf = mdn[j]->IP[i];
|
||||
}
|
||||
sprintf(str, "sed -i \"s/###%s_server_IP_%0d###/%s/\" maxscale.cnf",
|
||||
mdn[j]->prefix, i + 1, IPcnf);
|
||||
system(str);
|
||||
|
||||
sprintf(str,
|
||||
" -e \"s/###%s_server_port_%0d###/%d/\" ",
|
||||
mdn[j]->prefix,
|
||||
i + 1,
|
||||
mdn[j]->port[i]);
|
||||
ss << str;
|
||||
sprintf(str, "sed -i \"s/###%s_server_port_%0d###/%d/\" maxscale.cnf",
|
||||
mdn[j]->prefix, i + 1, mdn[j]->port[i]);
|
||||
system(str);
|
||||
}
|
||||
|
||||
mdn[j]->connect();
|
||||
execute_query(mdn[j]->nodes[0], (char *) "CREATE DATABASE IF NOT EXISTS test");
|
||||
mdn[j]->close_connections();
|
||||
}
|
||||
|
||||
mdn[j]->connect();
|
||||
execute_query(mdn[j]->nodes[0], "CREATE DATABASE IF NOT EXISTS test");
|
||||
mdn[j]->close_connections();
|
||||
}
|
||||
|
||||
sprintf(str, " -e \"s/###access_user###/%s/g\" ", maxscales->access_user[m]);
|
||||
ss << str;
|
||||
sprintf(str, "sed -i \"s/###access_user###/%s/g\" maxscale.cnf", maxscales->access_user[m]);
|
||||
system(str);
|
||||
|
||||
sprintf(str, " -e \"s|###access_homedir###|%s|g\" ", maxscales->access_homedir[m]);
|
||||
ss << str;
|
||||
sprintf(str, "sed -i \"s|###access_homedir###|%s|g\" maxscale.cnf", maxscales->access_homedir[m]);
|
||||
system(str);
|
||||
|
||||
ss << template_file << " > maxscale.cnf";
|
||||
call_system(ss.str().c_str());
|
||||
|
||||
maxscales->copy_to_node_legacy("maxscale.cnf", dest, m);
|
||||
// The config will now be in ~/maxscale.cnf and is moved into /etc before restarting maxscale
|
||||
if (repl && repl->v51)
|
||||
{
|
||||
system("sed -i \"s/###repl51###/mysql51_replication=true/g\" maxscale.cnf");
|
||||
}
|
||||
maxscales->copy_to_node_legacy((char *) "maxscale.cnf", (char *) dest, m);
|
||||
}
|
||||
|
||||
void TestConnections::init_maxscales()
|
||||
@ -764,10 +830,7 @@ void TestConnections::init_maxscales()
|
||||
|
||||
void TestConnections::init_maxscale(int m)
|
||||
{
|
||||
const char* template_name = get_template_name(test_name);
|
||||
|
||||
process_template(m, template_name, maxscales->access_homedir[m]);
|
||||
|
||||
if (maxscales->ssh_node_f(m, true, "test -d %s/certs", maxscales->access_homedir[m]))
|
||||
{
|
||||
tprintf("SSL certificates not found, copying to maxscale");
|
||||
@ -807,7 +870,7 @@ void TestConnections::init_maxscale(int m)
|
||||
}
|
||||
}
|
||||
|
||||
void TestConnections::copy_one_mariadb_log(int i, std::string filename)
|
||||
void TestConnections::copy_one_mariadb_log(Mariadb_nodes* nrepl, int i, std::string filename)
|
||||
{
|
||||
auto log_retrive_commands =
|
||||
{
|
||||
@ -820,7 +883,7 @@ void TestConnections::copy_one_mariadb_log(int i, std::string filename)
|
||||
|
||||
for (auto cmd : log_retrive_commands)
|
||||
{
|
||||
auto output = repl->ssh_output(cmd, i).second;
|
||||
auto output = nrepl->ssh_output(cmd, i).second;
|
||||
|
||||
if (!output.empty())
|
||||
{
|
||||
@ -834,22 +897,22 @@ void TestConnections::copy_one_mariadb_log(int i, std::string filename)
|
||||
}
|
||||
}
|
||||
|
||||
int TestConnections::copy_mariadb_logs(Mariadb_nodes* repl,
|
||||
int TestConnections::copy_mariadb_logs(Mariadb_nodes* nrepl,
|
||||
const char* prefix,
|
||||
std::vector<std::thread>& threads)
|
||||
{
|
||||
int local_result = 0;
|
||||
|
||||
if (repl)
|
||||
if (nrepl)
|
||||
{
|
||||
for (int i = 0; i < repl->N; i++)
|
||||
for (int i = 0; i < nrepl->N; i++)
|
||||
{
|
||||
// Do not copy MariaDB logs in case of local backend
|
||||
if (strcmp(repl->IP[i], "127.0.0.1") != 0)
|
||||
if (strcmp(nrepl->IP[i], "127.0.0.1") != 0)
|
||||
{
|
||||
char str[4096];
|
||||
sprintf(str, "LOGS/%s/%s%d_mariadb_log", test_name, prefix, i);
|
||||
threads.emplace_back(&TestConnections::copy_one_mariadb_log, this, i, str);
|
||||
threads.emplace_back(&TestConnections::copy_one_mariadb_log, this, nrepl, i, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -951,7 +1014,6 @@ int TestConnections::copy_all_logs_periodic()
|
||||
int TestConnections::prepare_binlog(int m)
|
||||
{
|
||||
char version_str[1024] = "";
|
||||
|
||||
repl->connect();
|
||||
find_field(repl->nodes[0], "SELECT @@version", "@@version", version_str);
|
||||
tprintf("Master server version '%s'", version_str);
|
||||
@ -1059,9 +1121,7 @@ int TestConnections::start_binlog(int m)
|
||||
execute_query(repl->nodes[i], "reset slave all");
|
||||
execute_query(repl->nodes[i], "reset master");
|
||||
}
|
||||
|
||||
prepare_binlog(m);
|
||||
|
||||
tprintf("Testing binlog when MariaDB is started with '%s' option\n", cmd_opt);
|
||||
|
||||
if (!local_maxscale)
|
||||
@ -2115,6 +2175,103 @@ bool TestConnections::test_bad_config(int m, const char* config)
|
||||
"maxscale -U maxscale -lstdout &> /dev/null && sleep 1 && pkill -9 maxscale")
|
||||
== 0;
|
||||
}
|
||||
int TestConnections::call_mdbci(const char * options)
|
||||
{
|
||||
struct stat buf;
|
||||
if (stat(
|
||||
(mdbci_vm_path + std::string("/") + mdbci_config_name).c_str(),
|
||||
&buf)
|
||||
)
|
||||
{
|
||||
if (process_mdbci_template())
|
||||
{
|
||||
tprintf("Failed to generate MDBCI virtual machines template");
|
||||
return 1;
|
||||
}
|
||||
if (system((std::string("mdbci --override --template ") +
|
||||
vm_path +
|
||||
std::string(".json generate ") +
|
||||
std::string(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()))
|
||||
{
|
||||
tprintf("Failed to copy my.cnf files");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (system((std::string("mdbci up ") +
|
||||
std::string(mdbci_config_name) +
|
||||
std::string(" --labels ") +
|
||||
mdbci_labels +
|
||||
std::string(" ") +
|
||||
std::string(options)).c_str() ))
|
||||
{
|
||||
tprintf("MDBCI failed to bring up virtual machines");
|
||||
return 1;
|
||||
}
|
||||
read_env();
|
||||
if (repl)
|
||||
{
|
||||
repl->read_basic_env();
|
||||
}
|
||||
if (galera)
|
||||
{
|
||||
galera->read_basic_env();
|
||||
}
|
||||
if (maxscales)
|
||||
{
|
||||
maxscales->read_basic_env();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int TestConnections::process_mdbci_template()
|
||||
{
|
||||
char * product = readenv("product", "mariadb");
|
||||
char * box = readenv("box", "centos_7_libvirt");
|
||||
char * __attribute__((unused)) backend_box = readenv("backend_box", "%s", box);
|
||||
char * version = readenv("version", "10.3");
|
||||
char * __attribute__((unused)) target = readenv("target", "develop");
|
||||
char * __attribute__((unused)) vm_memory = readenv("vm_memory", "2048");
|
||||
char * __attribute__((unused)) galera_version = readenv("galera_version", "%s", version);
|
||||
|
||||
if (strcmp(product, "mysql") == 0 )
|
||||
{
|
||||
setenv("cnf_path",
|
||||
(vm_path + std::string("/cnf/mysql56/")).c_str(),
|
||||
1);
|
||||
}
|
||||
else
|
||||
{
|
||||
setenv("cnf_path",
|
||||
(vm_path + std::string("/cnf/")).c_str(),
|
||||
1);
|
||||
}
|
||||
|
||||
std::string name = std::string(test_dir) +
|
||||
std::string("/mdbci/templates/") +
|
||||
std::string(mdbci_template) +
|
||||
std::string(".json.template");
|
||||
|
||||
std::string sys = std::string("envsubst < ") +
|
||||
name +
|
||||
std::string(" > ") +
|
||||
vm_path +
|
||||
std::string(".json");
|
||||
if (verbose)
|
||||
{
|
||||
std::cout << sys << std::endl;
|
||||
}
|
||||
return system(sys.c_str());
|
||||
}
|
||||
|
||||
std::string dump_status(const StringSet& current, const StringSet& expected)
|
||||
{
|
||||
@ -2137,3 +2294,31 @@ std::string dump_status(const StringSet& current, const StringSet& expected)
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
int TestConnections::reinstall_maxscales()
|
||||
{
|
||||
char sys[strlen(target) +
|
||||
strlen(mdbci_config_name) +
|
||||
strlen(maxscales->prefix) +
|
||||
70];
|
||||
for (int i = 0; i < maxscales->N; i++)
|
||||
{
|
||||
printf("Installing Maxscale on node %d\n", i);
|
||||
//TODO: make it via MDBCI and compatible with any distro
|
||||
maxscales->ssh_node(i, "yum remove maxscale -y", true);
|
||||
maxscales->ssh_node(i, "yum clean all", true);
|
||||
|
||||
sprintf(sys, "mdbci setup_repo --product maxscale_ci --product-version %s %s/%s_%03d",
|
||||
target, mdbci_config_name, maxscales->prefix, i);
|
||||
if (system(sys))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
sprintf(sys, "mdbci install_product --product maxscale_ci --product-version %s %s/%s_%03d",
|
||||
target, mdbci_config_name, maxscales->prefix, i);
|
||||
if (system(sys))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user