From 855b8d876a727956f135729b078a978216aa4e5f Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 21 Aug 2019 13:16:06 +0300 Subject: [PATCH] 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. --- maxscale-system-test/mariadb_nodes.cpp | 44 ++++++++++++++---------- maxscale-system-test/mariadb_nodes.h | 8 +++-- maxscale-system-test/maxscales.cpp | 21 ++++++----- maxscale-system-test/maxscales.h | 4 ++- maxscale-system-test/nodes.cpp | 7 +++- maxscale-system-test/nodes.h | 14 ++++++-- maxscale-system-test/testconnections.cpp | 6 ++-- 7 files changed, 68 insertions(+), 36 deletions(-) diff --git a/maxscale-system-test/mariadb_nodes.cpp b/maxscale-system-test/mariadb_nodes.cpp index 55d4d7f01..4dcb2c7ac 100644 --- a/maxscale-system-test/mariadb_nodes.cpp +++ b/maxscale-system-test/mariadb_nodes.cpp @@ -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() diff --git a/maxscale-system-test/mariadb_nodes.h b/maxscale-system-test/mariadb_nodes.h index 39c3e1ff5..75202a76b 100644 --- a/maxscale-system-test/mariadb_nodes.h +++ b/maxscale-system-test/mariadb_nodes.h @@ -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(); diff --git a/maxscale-system-test/maxscales.cpp b/maxscale-system-test/maxscales.cpp index 092187c5e..255fafbe9 100644 --- a/maxscale-system-test/maxscales.cpp +++ b/maxscale-system-test/maxscales.cpp @@ -4,15 +4,19 @@ #include #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() diff --git a/maxscale-system-test/maxscales.h b/maxscale-system-test/maxscales.h index 491d51997..54ec92b78 100644 --- a/maxscale-system-test/maxscales.h +++ b/maxscale-system-test/maxscales.h @@ -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(); diff --git a/maxscale-system-test/nodes.cpp b/maxscale-system-test/nodes.cpp index 7c23011a9..e50b04ccf 100644 --- a/maxscale-system-test/nodes.cpp +++ b/maxscale-system-test/nodes.cpp @@ -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) diff --git a/maxscale-system-test/nodes.h b/maxscale-system-test/nodes.h index 5dc45583d..f343ad47a 100644 --- a/maxscale-system-test/nodes.h +++ b/maxscale-system-test/nodes.h @@ -14,7 +14,12 @@ typedef std::set 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); }; diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index 139fa8a55..913760723 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -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();