Commit e8595bce authored by Georgios Bitzes's avatar Georgios Bitzes
Browse files

Implement IptablesHelper to ease blocking / unblocking a port

parent 36f411c6
Pipeline #1344704 canceled with stages
in 9 minutes and 12 seconds
# Changelog
## Unreleased
### New features
- Possibility to choose between three different journal fsync policies through
``RAFT-SET-FSYNC-POLICY`` command.
- Implementation of ``CLIENT GETNAME``, and automatic tagging of intercluster
connections.
### Improvements
- Automatic fsync of the raft journal once per second.
- Better resilience in case of sudden machine powercuts.
## 0.4.0 (2019-12-06)
### Bug fixes
......
Subproject commit 0da6445cf5c0c7793b82f703d27d53be72442b2b
Subproject commit b14f94b6506cee945e3ccdad98251610af385ee1
......@@ -30,6 +30,12 @@ using namespace quarkdb;
class Poweroff : public TestCluster3NodesFixture {};
TEST_F(Poweroff, WithDataLoss) {
IptablesHelper iptables;
ASSERT_TRUE(iptables.singleAcceptPackets(nodes()[0].port));
ASSERT_TRUE(iptables.singleAcceptPackets(nodes()[1].port));
ASSERT_TRUE(iptables.singleAcceptPackets(nodes()[2].port));
spinup(0); spinup(1); spinup(2);
RETRY_ASSERT_TRUE(checkStateConsensus(0, 1, 2));
......@@ -47,13 +53,13 @@ TEST_F(Poweroff, WithDataLoss) {
int follower = (leaderID + 1) % 3;
int followerPort = nodes()[follower].port;
ASSERT_EQ(system(SSTR("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport " << followerPort << " -j DROP").c_str()), 0);
ASSERT_TRUE(iptables.singleDropPackets(followerPort));
spindown(follower);
ASSERT_TRUE(journal(follower)->simulateDataLoss(3));
ASSERT_EQ(journal(follower)->getLogSize(), journal(leaderID)->getLogSize() - 3);
ASSERT_EQ(system(SSTR("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport " << followerPort << " -j ACCEPT").c_str()), 0);
ASSERT_TRUE(iptables.singleAcceptPackets(followerPort));
spinup(follower);
// ensure the leader restores the missing entries
......
......@@ -21,12 +21,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.*
************************************************************************/
#include "../test-utils.hh"
#include <qclient/QClient.hh>
#include <gtest/gtest.h>
#include <chrono>
using namespace quarkdb;
TEST(QClient, HostDroppingIncomingPacketsConstructor) {
ASSERT_EQ(system("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport 56789 -j DROP"), 0);
IptablesHelper iptables;
ASSERT_TRUE(iptables.singleDropPackets(56789));
qclient::Options opts;
std::unique_ptr<qclient::QClient> qcl;
......@@ -50,11 +55,12 @@ TEST(QClient, HostDroppingIncomingPacketsConstructor) {
std::cout << "Destructor took " << destructorDuration.count() << " ms" << std::endl;
ASSERT_LE(destructorDuration, std::chrono::milliseconds(50));
ASSERT_EQ(system("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport 56789 -j ACCEPT"), 0);
ASSERT_TRUE(iptables.singleAcceptPackets(56789));
}
TEST(QClient, HostDroppingIncomingPacketsFutureTimeout) {
ASSERT_EQ(system("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport 56789 -j DROP"), 0);
IptablesHelper iptables;
ASSERT_TRUE(iptables.singleDropPackets(56789));
qclient::Options opts;
opts.tcpTimeout = std::chrono::seconds(3);
......@@ -72,6 +78,6 @@ TEST(QClient, HostDroppingIncomingPacketsFutureTimeout) {
ASSERT_GE(dur, std::chrono::seconds(3));
ASSERT_LE(dur, std::chrono::seconds(4));
ASSERT_EQ(system("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport 56789 -j ACCEPT"), 0);
ASSERT_TRUE(iptables.singleAcceptPackets(56789));
}
......@@ -398,4 +398,13 @@ void TestNode::spindown() {
shard()->spindown();
}
bool IptablesHelper::singleDropPackets(int port) {
return system(SSTR("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport " << port << " -j DROP").c_str()) == 0;
}
bool IptablesHelper::singleAcceptPackets(int port) {
return system(SSTR("iptables -I OUTPUT -p tcp --dest 127.0.0.1 --dport " << port << " -j ACCEPT").c_str()) == 0;
}
}
......@@ -519,6 +519,12 @@ public:
}
};
class IptablesHelper {
public:
bool singleDropPackets(int port);
bool singleAcceptPackets(int port);
};
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment