From 0d3a2358519351bd59250c332b8541870e7d57c7 Mon Sep 17 00:00:00 2001 From: Johan Wikman Date: Wed, 22 May 2019 10:13:02 +0300 Subject: [PATCH] MXS-2481 Allow [un]block-commands to be overriden In the case of Clustrix, there are other ports to block as well. --- maxscale-system-test/mariadb_nodes.cpp | 42 ++++++++++++++++++++------ maxscale-system-test/mariadb_nodes.h | 12 ++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/maxscale-system-test/mariadb_nodes.cpp b/maxscale-system-test/mariadb_nodes.cpp index 0b8c27a25..fd709f57d 100644 --- a/maxscale-system-test/mariadb_nodes.cpp +++ b/maxscale-system-test/mariadb_nodes.cpp @@ -489,26 +489,50 @@ int Mariadb_nodes::clean_iptables(int node) port[node]); } +std::string Mariadb_nodes::block_command(int node) const +{ + const char FORMAT[] = + "iptables -I INPUT -p tcp --dport %d -j REJECT;" + "ip6tables -I INPUT -p tcp --dport %d -j REJECT"; + + char command[sizeof(FORMAT) + 20]; + + sprintf(command, FORMAT, port[node], port[node]); + + return command; +} + +std::string Mariadb_nodes::unblock_command(int node) const +{ + const char FORMAT[] = + "iptables -I INPUT -p tcp --dport %d -j ACCEPT;" + "ip6tables -I INPUT -p tcp --dport %d -j ACCEPT"; + + char command[sizeof(FORMAT) + 20]; + + sprintf(command, FORMAT, port[node], port[node]); + + return command; +} + int Mariadb_nodes::block_node(int node) { - int local_result = 0; + std::string command = block_command(node); + + int local_result = 0; + local_result += ssh_node_f(node, true, "%s", command.c_str()); - local_result += ssh_node_f(node, true, - "iptables -I INPUT -p tcp --dport %d -j REJECT;" - "ip6tables -I INPUT -p tcp --dport %d -j REJECT", - port[node], port[node]); blocked[node] = true; return local_result; } int Mariadb_nodes::unblock_node(int node) { + std::string command = unblock_command(node); + int local_result = 0; local_result += clean_iptables(node); - local_result += ssh_node_f(node, true, - "iptables -I INPUT -p tcp --dport %d -j ACCEPT;" - "ip6tables -I INPUT -p tcp --dport %d -j ACCEPT", - port[node], port[node]); + local_result += ssh_node_f(node, true, "%s", command.c_str()); blocked[node] = false; return local_result; diff --git a/maxscale-system-test/mariadb_nodes.h b/maxscale-system-test/mariadb_nodes.h index 60093e785..39c3e1ff5 100644 --- a/maxscale-system-test/mariadb_nodes.h +++ b/maxscale-system-test/mariadb_nodes.h @@ -240,6 +240,18 @@ public: // Create the default users used by all tests void create_users(int node); + /** + * @param node Index of node to block. + * @return The command used for blocking a node. + */ + virtual std::string block_command(int node) const; + + /** + * @param node Index of node to unblock. + * @return The command used for unblocking a node. + */ + virtual std::string unblock_command(int node) const; + /** * @brif BlockNode setup firewall on a backend node to block MariaDB port * @param node Index of node to block