MXS-2644 Move ci setup from constructor to setup() function
By moving the setting up of the test environment from the constructor to a separate setup()-function, it is possible to introduce virtual functions and make it easier to do things differently depending on whether the backend is MariaDB, Galera och Clustrix.
This commit is contained in:
@ -35,31 +35,37 @@ void Mariadb_nodes::require_gtid(bool value)
|
|||||||
g_require_gtid = value;
|
g_require_gtid = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mariadb_nodes::Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose,
|
Mariadb_nodes::Mariadb_nodes(const char* pref,
|
||||||
std::string network_config):
|
const char* test_cwd,
|
||||||
v51(false)
|
bool verbose,
|
||||||
|
const std::string& network_config)
|
||||||
|
: Nodes(pref, network_config, verbose)
|
||||||
|
, no_set_pos(false)
|
||||||
|
, v51(false)
|
||||||
|
, cnf_server_name(std::string(this->prefix) + std::string("_server"))
|
||||||
{
|
{
|
||||||
use_ipv6 = false;
|
|
||||||
strcpy(prefix, pref);
|
|
||||||
memset(this->nodes, 0, sizeof(this->nodes));
|
memset(this->nodes, 0, sizeof(this->nodes));
|
||||||
memset(blocked, 0, sizeof(blocked));
|
memset(this->blocked, 0, sizeof(this->blocked));
|
||||||
no_set_pos = false;
|
strcpy(this->test_dir, test_cwd);
|
||||||
this->verbose = verbose;
|
|
||||||
this->network_config = network_config;
|
if (strcmp(this->prefix, "node") == 0)
|
||||||
strcpy(test_dir, test_cwd);
|
{
|
||||||
|
cnf_server_name = std::string("server");
|
||||||
|
}
|
||||||
|
if (strcmp(this->prefix, "galera") == 0)
|
||||||
|
{
|
||||||
|
cnf_server_name = std::string("gserver");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Mariadb_nodes::setup()
|
||||||
|
{
|
||||||
read_env();
|
read_env();
|
||||||
truncate_mariadb_logs();
|
truncate_mariadb_logs();
|
||||||
flush_hosts();
|
flush_hosts();
|
||||||
close_active_connections();
|
close_active_connections();
|
||||||
cnf_server_name = std::string(prefix) + std::string("_server");
|
|
||||||
if (strcmp(prefix, "node") == 0)
|
return true;
|
||||||
{
|
|
||||||
cnf_server_name = std::string("server");
|
|
||||||
}
|
|
||||||
if (strcmp(prefix, "galera") == 0)
|
|
||||||
{
|
|
||||||
cnf_server_name = std::string("gserver");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Mariadb_nodes::~Mariadb_nodes()
|
Mariadb_nodes::~Mariadb_nodes()
|
||||||
|
|||||||
@ -35,7 +35,9 @@ public:
|
|||||||
* @brief Constructor
|
* @brief Constructor
|
||||||
* @param pref name of backend setup (like 'repl' or 'galera')
|
* @param pref name of backend setup (like 'repl' or 'galera')
|
||||||
*/
|
*/
|
||||||
Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose, std::string network_config);
|
Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose, const std::string& network_config);
|
||||||
|
|
||||||
|
bool setup() override;
|
||||||
|
|
||||||
virtual ~Mariadb_nodes();
|
virtual ~Mariadb_nodes();
|
||||||
|
|
||||||
@ -525,8 +527,8 @@ class Galera_nodes : public Mariadb_nodes
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Galera_nodes(const char *pref, const char *test_cwd, bool verbose, std::string network_config) :
|
Galera_nodes(const char *pref, const char *test_cwd, bool verbose, const std::string& network_config)
|
||||||
Mariadb_nodes(pref, test_cwd, verbose, network_config) { }
|
: Mariadb_nodes(pref, test_cwd, verbose, network_config) { }
|
||||||
|
|
||||||
int start_galera();
|
int start_galera();
|
||||||
|
|
||||||
|
|||||||
@ -4,15 +4,19 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include "envv.h"
|
#include "envv.h"
|
||||||
|
|
||||||
Maxscales::Maxscales(const char *pref, const char *test_cwd, bool verbose,
|
Maxscales::Maxscales(const char *pref,
|
||||||
std::string network_config)
|
const char *test_cwd,
|
||||||
|
bool verbose,
|
||||||
|
const std::string& network_config)
|
||||||
|
: Nodes(pref, network_config, verbose)
|
||||||
|
, valgring_log_num(0)
|
||||||
{
|
{
|
||||||
strcpy(prefix, pref);
|
strcpy(this->test_dir, test_cwd);
|
||||||
this->verbose = verbose;
|
}
|
||||||
valgring_log_num = 0;
|
|
||||||
strcpy(test_dir, test_cwd);
|
bool Maxscales::setup()
|
||||||
this->network_config = network_config;
|
{
|
||||||
read_env();
|
read_env(); // Sets e.g. use_valgrind.
|
||||||
if (this->use_valgrind)
|
if (this->use_valgrind)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < N; i++)
|
for (int i = 0; i < N; i++)
|
||||||
@ -23,6 +27,7 @@ Maxscales::Maxscales(const char *pref, const char *test_cwd, bool verbose,
|
|||||||
ssh_node_f(i, true, "rm -rf /var/cache/maxscale/maxscale.lock");
|
ssh_node_f(i, true, "rm -rf /var/cache/maxscale/maxscale.lock");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Maxscales::read_env()
|
int Maxscales::read_env()
|
||||||
|
|||||||
@ -21,7 +21,9 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Maxscales(const char *pref, const char *test_cwd, bool verbose,
|
Maxscales(const char *pref, const char *test_cwd, bool verbose,
|
||||||
std::string network_config);
|
const std::string& network_config);
|
||||||
|
|
||||||
|
bool setup() override;
|
||||||
|
|
||||||
int read_env();
|
int read_env();
|
||||||
|
|
||||||
|
|||||||
@ -9,8 +9,13 @@
|
|||||||
|
|
||||||
#include "envv.h"
|
#include "envv.h"
|
||||||
|
|
||||||
Nodes::Nodes()
|
Nodes::Nodes(const char* pref,
|
||||||
|
const std::string& network_config,
|
||||||
|
bool verbose)
|
||||||
|
: network_config(network_config)
|
||||||
|
, verbose(verbose)
|
||||||
{
|
{
|
||||||
|
strcpy(this->prefix, pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Nodes::check_node_ssh(int node)
|
bool Nodes::check_node_ssh(int node)
|
||||||
|
|||||||
@ -14,7 +14,12 @@ typedef std::set<std::string> StringSet;
|
|||||||
class Nodes
|
class Nodes
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Nodes();
|
/**
|
||||||
|
* Sets up the nodes. *Must* be called before instance is used.
|
||||||
|
*
|
||||||
|
* @return True, if the instance could be setup, false otherwise.
|
||||||
|
*/
|
||||||
|
virtual bool setup() = 0;
|
||||||
|
|
||||||
char * IP[256];
|
char * IP[256];
|
||||||
/**
|
/**
|
||||||
@ -31,7 +36,7 @@ public:
|
|||||||
* @brief use_ipv6 If true IPv6 addresses will be used to connect Maxscale and backed
|
* @brief use_ipv6 If true IPv6 addresses will be used to connect Maxscale and backed
|
||||||
* Also IPv6 addresses go to maxscale.cnf
|
* Also IPv6 addresses go to maxscale.cnf
|
||||||
*/
|
*/
|
||||||
bool use_ipv6;
|
bool use_ipv6 = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Path to ssh key for every backend node
|
* @brief Path to ssh key for every backend node
|
||||||
@ -205,6 +210,11 @@ public:
|
|||||||
*/
|
*/
|
||||||
int stop_vm(int node);
|
int stop_vm(int node);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Nodes(const char* pref,
|
||||||
|
const std::string& network_config,
|
||||||
|
bool verbose);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool check_node_ssh(int node);
|
bool check_node_ssh(int node);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -371,6 +371,7 @@ TestConnections::TestConnections(int argc, char* argv[])
|
|||||||
if (!no_repl)
|
if (!no_repl)
|
||||||
{
|
{
|
||||||
repl = new Mariadb_nodes("node", test_dir, verbose, network_config);
|
repl = new Mariadb_nodes("node", test_dir, verbose, network_config);
|
||||||
|
repl->setup();
|
||||||
repl->use_ipv6 = use_ipv6;
|
repl->use_ipv6 = use_ipv6;
|
||||||
repl->take_snapshot_command = take_snapshot_command;
|
repl->take_snapshot_command = take_snapshot_command;
|
||||||
repl->revert_snapshot_command = revert_snapshot_command;
|
repl->revert_snapshot_command = revert_snapshot_command;
|
||||||
@ -384,7 +385,7 @@ TestConnections::TestConnections(int argc, char* argv[])
|
|||||||
if (!no_galera)
|
if (!no_galera)
|
||||||
{
|
{
|
||||||
galera = new Galera_nodes("galera", test_dir, verbose, network_config);
|
galera = new Galera_nodes("galera", test_dir, verbose, network_config);
|
||||||
//galera->use_ipv6 = use_ipv6;
|
galera->setup();
|
||||||
galera->use_ipv6 = false;
|
galera->use_ipv6 = false;
|
||||||
galera->take_snapshot_command = take_snapshot_command;
|
galera->take_snapshot_command = take_snapshot_command;
|
||||||
galera->revert_snapshot_command = revert_snapshot_command;
|
galera->revert_snapshot_command = revert_snapshot_command;
|
||||||
@ -398,7 +399,7 @@ TestConnections::TestConnections(int argc, char* argv[])
|
|||||||
if (!no_clustrix)
|
if (!no_clustrix)
|
||||||
{
|
{
|
||||||
clustrix = new Clustrix_nodes("clustrix", test_dir, verbose, network_config);
|
clustrix = new Clustrix_nodes("clustrix", test_dir, verbose, network_config);
|
||||||
//galera->use_ipv6 = use_ipv6;
|
clustrix->setup();
|
||||||
clustrix->use_ipv6 = false;
|
clustrix->use_ipv6 = false;
|
||||||
clustrix->take_snapshot_command = take_snapshot_command;
|
clustrix->take_snapshot_command = take_snapshot_command;
|
||||||
clustrix->revert_snapshot_command = revert_snapshot_command;
|
clustrix->revert_snapshot_command = revert_snapshot_command;
|
||||||
@ -410,6 +411,7 @@ TestConnections::TestConnections(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
maxscales = new Maxscales("maxscale", test_dir, verbose, network_config);
|
maxscales = new Maxscales("maxscale", test_dir, verbose, network_config);
|
||||||
|
maxscales->setup();
|
||||||
|
|
||||||
bool maxscale_ok = maxscales->check_nodes();
|
bool maxscale_ok = maxscales->check_nodes();
|
||||||
bool repl_ok = no_repl || repl_future.get();
|
bool repl_ok = no_repl || repl_future.get();
|
||||||
|
|||||||
Reference in New Issue
Block a user