diff --git a/maxscale-system-test/mariadb_nodes.cpp b/maxscale-system-test/mariadb_nodes.cpp index 0fa2b7ee6..9bf8efdd1 100644 --- a/maxscale-system-test/mariadb_nodes.cpp +++ b/maxscale-system-test/mariadb_nodes.cpp @@ -18,6 +18,8 @@ #include #include #include +#include +#include #include "envv.h" using std::cout; @@ -1084,19 +1086,22 @@ std::string Mariadb_nodes::get_lowest_version() int Mariadb_nodes::truncate_mariadb_logs() { - int local_result = 0; + std::vector> results; + for (int node = 0; node < N; node++) { if (strcmp(IP[node], "127.0.0.1") != 0) { - local_result += ssh_node_f(node, true, - "truncate -s 0 /var/lib/mysql/*.err;" - "truncate -s 0 /var/log/syslog;" - "truncate -s 0 /var/log/messages;" - "rm -f /etc/my.cnf.d/binlog_enc*;"); + auto f = std::async(std::launch::async, &Nodes::ssh_node_f, this, node, true, + "truncate -s 0 /var/lib/mysql/*.err;" + "truncate -s 0 /var/log/syslog;" + "truncate -s 0 /var/log/messages;" + "rm -f /etc/my.cnf.d/binlog_enc*;"); + results.push_back(std::move(f)); } } - return local_result; + + return std::count_if(results.begin(), results.end(), std::mem_fn(&std::future::get)); } int Mariadb_nodes::configure_ssl(bool require) diff --git a/maxscale-system-test/nodes.cpp b/maxscale-system-test/nodes.cpp index 048fc97a8..412fcafee 100644 --- a/maxscale-system-test/nodes.cpp +++ b/maxscale-system-test/nodes.cpp @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include #include "envv.h" @@ -9,36 +12,29 @@ Nodes::Nodes() { } -int Nodes::check_node_ssh(int node) +bool Nodes::check_node_ssh(int node) { - int res = 0; + bool res = true; - if (ssh_node(node, (char*) "ls > /dev/null", false) != 0) + if (ssh_node(node, "ls > /dev/null", false) != 0) { - printf("Node %d is not available\n", node); - fflush(stdout); - res = 1; - } - else - { - fflush(stdout); + std::cout << "Node " << node << " is not available" << std::endl; + res = false; } + return res; } -int Nodes::check_nodes() +bool Nodes::check_nodes() { - std::cout << "Checking nodes..." << std::endl; + std::vector> f; for (int i = 0; i < N; i++) { - if (check_node_ssh(i) != 0) - { - return 1; - } + f.push_back(std::async(std::launch::async, &Nodes::check_node_ssh, this, i)); } - return 0; + return std::all_of(f.begin(), f.end(), std::mem_fn(&std::future::get)); } void Nodes::generate_ssh_cmd(char* cmd, int node, const char* ssh, bool sudo) diff --git a/maxscale-system-test/nodes.h b/maxscale-system-test/nodes.h index 615fee934..ba2b26192 100644 --- a/maxscale-system-test/nodes.h +++ b/maxscale-system-test/nodes.h @@ -168,9 +168,9 @@ public: /** * @brief Check node via ssh and restart it if it is not resposible * @param node Node index - * @return 0 if node is ok, 1 if start failed + * @return True if node is ok, false if start failed */ - int check_nodes(); + bool check_nodes(); /** * @brief read_basic_env Read IP, sshkey, etc - common parameters for all kinds of nodes @@ -206,5 +206,5 @@ public: int stop_vm(int node); private: - int check_node_ssh(int node); + bool check_node_ssh(int node); }; diff --git a/maxscale-system-test/testconnections.cpp b/maxscale-system-test/testconnections.cpp index 28661e152..a57126054 100644 --- a/maxscale-system-test/testconnections.cpp +++ b/maxscale-system-test/testconnections.cpp @@ -343,7 +343,7 @@ TestConnections::TestConnections(int argc, char* argv[]) repl->use_ipv6 = use_ipv6; repl->take_snapshot_command = take_snapshot_command; repl->revert_snapshot_command = revert_snapshot_command; - if (repl->check_nodes()) + if (!repl->check_nodes()) { if (call_mdbci("--recreate")) { @@ -363,7 +363,7 @@ TestConnections::TestConnections(int argc, char* argv[]) galera->use_ipv6 = false; galera->take_snapshot_command = take_snapshot_command; galera->revert_snapshot_command = revert_snapshot_command; - if (galera->check_nodes()) + if (!galera->check_nodes()) { if (call_mdbci("--recreate")) { @@ -377,7 +377,7 @@ TestConnections::TestConnections(int argc, char* argv[]) } maxscales = new Maxscales("maxscale", test_dir, verbose, use_valgrind, network_config); - if (maxscales->check_nodes() || + if (!maxscales->check_nodes() || ((maxscales->N < 2) && (mdbci_labels.find(std::string("SECOND_MAXSCALE")) != std::string::npos)) ) {