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:
Johan Wikman 2019-08-21 13:16:06 +03:00
parent 52df969e13
commit 855b8d876a
7 changed files with 68 additions and 36 deletions

View File

@ -35,31 +35,37 @@ void Mariadb_nodes::require_gtid(bool value)
g_require_gtid = value;
}
Mariadb_nodes::Mariadb_nodes(const char *pref, const char *test_cwd, bool verbose,
std::string network_config):
v51(false)
Mariadb_nodes::Mariadb_nodes(const char* pref,
const char* test_cwd,
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(blocked, 0, sizeof(blocked));
no_set_pos = false;
this->verbose = verbose;
this->network_config = network_config;
strcpy(test_dir, test_cwd);
memset(this->blocked, 0, sizeof(this->blocked));
strcpy(this->test_dir, test_cwd);
if (strcmp(this->prefix, "node") == 0)
{
cnf_server_name = std::string("server");
}
if (strcmp(this->prefix, "galera") == 0)
{
cnf_server_name = std::string("gserver");
}
}
bool Mariadb_nodes::setup()
{
read_env();
truncate_mariadb_logs();
flush_hosts();
close_active_connections();
cnf_server_name = std::string(prefix) + std::string("_server");
if (strcmp(prefix, "node") == 0)
{
cnf_server_name = std::string("server");
}
if (strcmp(prefix, "galera") == 0)
{
cnf_server_name = std::string("gserver");
}
return true;
}
Mariadb_nodes::~Mariadb_nodes()

View File

@ -35,7 +35,9 @@ public:
* @brief Constructor
* @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();
@ -525,8 +527,8 @@ class Galera_nodes : public Mariadb_nodes
{
public:
Galera_nodes(const char *pref, const char *test_cwd, bool verbose, std::string network_config) :
Mariadb_nodes(pref, test_cwd, verbose, 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) { }
int start_galera();

View File

@ -4,15 +4,19 @@
#include <string>
#include "envv.h"
Maxscales::Maxscales(const char *pref, const char *test_cwd, bool verbose,
std::string network_config)
Maxscales::Maxscales(const char *pref,
const char *test_cwd,
bool verbose,
const std::string& network_config)
: Nodes(pref, network_config, verbose)
, valgring_log_num(0)
{
strcpy(prefix, pref);
this->verbose = verbose;
valgring_log_num = 0;
strcpy(test_dir, test_cwd);
this->network_config = network_config;
read_env();
strcpy(this->test_dir, test_cwd);
}
bool Maxscales::setup()
{
read_env(); // Sets e.g. use_valgrind.
if (this->use_valgrind)
{
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");
}
}
return true;
}
int Maxscales::read_env()

View File

@ -21,7 +21,9 @@ public:
};
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();

View File

@ -9,8 +9,13 @@
#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)

View File

@ -14,7 +14,12 @@ typedef std::set<std::string> StringSet;
class Nodes
{
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];
/**
@ -31,7 +36,7 @@ public:
* @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;
bool use_ipv6 = false;
/**
* @brief Path to ssh key for every backend node
@ -205,6 +210,11 @@ public:
*/
int stop_vm(int node);
protected:
Nodes(const char* pref,
const std::string& network_config,
bool verbose);
private:
bool check_node_ssh(int node);
};

View File

@ -371,6 +371,7 @@ TestConnections::TestConnections(int argc, char* argv[])
if (!no_repl)
{
repl = new Mariadb_nodes("node", test_dir, verbose, network_config);
repl->setup();
repl->use_ipv6 = use_ipv6;
repl->take_snapshot_command = take_snapshot_command;
repl->revert_snapshot_command = revert_snapshot_command;
@ -384,7 +385,7 @@ TestConnections::TestConnections(int argc, char* argv[])
if (!no_galera)
{
galera = new Galera_nodes("galera", test_dir, verbose, network_config);
//galera->use_ipv6 = use_ipv6;
galera->setup();
galera->use_ipv6 = false;
galera->take_snapshot_command = take_snapshot_command;
galera->revert_snapshot_command = revert_snapshot_command;
@ -398,7 +399,7 @@ TestConnections::TestConnections(int argc, char* argv[])
if (!no_clustrix)
{
clustrix = new Clustrix_nodes("clustrix", test_dir, verbose, network_config);
//galera->use_ipv6 = use_ipv6;
clustrix->setup();
clustrix->use_ipv6 = false;
clustrix->take_snapshot_command = take_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->setup();
bool maxscale_ok = maxscales->check_nodes();
bool repl_ok = no_repl || repl_future.get();