2016-07-22 18:29:35 +01:00
|
|
|
import ./make-test.nix ({ pkgs, ...}:
|
|
|
|
let
|
2017-11-07 13:11:56 +00:00
|
|
|
# Change this to test a different version of Cassandra:
|
|
|
|
testPackage = pkgs.cassandra;
|
2019-04-23 04:02:30 +01:00
|
|
|
clusterName = "NixOS Automated-Test Cluster";
|
2019-04-23 03:59:53 +01:00
|
|
|
|
|
|
|
cassandraCfg = ipAddress:
|
2017-11-07 13:11:56 +00:00
|
|
|
{ enable = true;
|
2019-04-23 04:02:30 +01:00
|
|
|
inherit clusterName;
|
2019-04-23 03:59:53 +01:00
|
|
|
listenAddress = ipAddress;
|
|
|
|
rpcAddress = ipAddress;
|
2019-04-23 04:03:07 +01:00
|
|
|
seedAddresses = [ "192.168.1.1" ];
|
2017-11-07 13:11:56 +00:00
|
|
|
package = testPackage;
|
|
|
|
};
|
2019-04-23 03:59:53 +01:00
|
|
|
nodeCfg = ipAddress: extra: {pkgs, config, ...}:
|
2017-11-07 13:11:56 +00:00
|
|
|
{ environment.systemPackages = [ testPackage ];
|
|
|
|
networking.firewall.enable = false;
|
2019-04-23 03:59:53 +01:00
|
|
|
services.cassandra = cassandraCfg ipAddress // extra;
|
2016-07-22 18:29:35 +01:00
|
|
|
virtualisation.memorySize = 1024;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "cassandra-ci";
|
|
|
|
|
|
|
|
nodes = {
|
2019-04-09 03:02:49 +01:00
|
|
|
cass0 = nodeCfg "192.168.1.1" {};
|
|
|
|
cass1 = nodeCfg "192.168.1.2" {};
|
|
|
|
cass2 = nodeCfg "192.168.1.3" { jvmOpts = [ "-Dcassandra.replace_address=cass1" ]; };
|
2016-07-22 18:29:35 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2019-04-23 03:59:53 +01:00
|
|
|
# Check configuration
|
|
|
|
subtest "Timers exist", sub {
|
2017-11-07 13:11:56 +00:00
|
|
|
$cass0->succeed("systemctl list-timers | grep cassandra-full-repair.timer");
|
|
|
|
$cass0->succeed("systemctl list-timers | grep cassandra-incremental-repair.timer");
|
|
|
|
};
|
2019-04-23 03:59:53 +01:00
|
|
|
subtest "Can connect via cqlsh", sub {
|
2016-07-22 18:29:35 +01:00
|
|
|
$cass0->waitForUnit("cassandra.service");
|
2017-11-07 13:11:56 +00:00
|
|
|
$cass0->waitUntilSucceeds("nc -z cass0 9042");
|
|
|
|
$cass0->succeed("echo 'show version;' | cqlsh cass0");
|
2016-07-22 18:29:35 +01:00
|
|
|
};
|
2019-04-23 03:59:53 +01:00
|
|
|
subtest "Nodetool is operational", sub {
|
2017-11-07 13:11:56 +00:00
|
|
|
$cass0->waitForUnit("cassandra.service");
|
|
|
|
$cass0->waitUntilSucceeds("nc -z localhost 7199");
|
|
|
|
$cass0->succeed("nodetool status --resolve-ip | egrep '^UN[[:space:]]+cass0'");
|
2019-04-23 04:02:30 +01:00
|
|
|
};
|
|
|
|
subtest "Cluster name was set", sub {
|
|
|
|
$cass0->waitForUnit("cassandra.service");
|
|
|
|
$cass0->waitUntilSucceeds("nc -z localhost 7199");
|
|
|
|
$cass0->waitUntilSucceeds("nodetool describecluster | grep 'Name: ${clusterName}'");
|
2016-07-22 18:29:35 +01:00
|
|
|
};
|
2019-04-23 03:59:53 +01:00
|
|
|
|
|
|
|
# Check cluster interaction
|
|
|
|
subtest "Bring up cluster", sub {
|
2016-07-22 18:29:35 +01:00
|
|
|
$cass1->waitForUnit("cassandra.service");
|
2017-11-07 13:11:56 +00:00
|
|
|
$cass1->waitUntilSucceeds("nodetool status | egrep -c '^UN' | grep 2");
|
|
|
|
$cass0->succeed("nodetool status --resolve-ip | egrep '^UN[[:space:]]+cass1'");
|
2016-07-22 18:29:35 +01:00
|
|
|
};
|
2019-04-23 03:59:53 +01:00
|
|
|
subtest "Break and fix node", sub {
|
2017-11-07 13:11:56 +00:00
|
|
|
$cass1->block;
|
|
|
|
$cass0->waitUntilSucceeds("nodetool status --resolve-ip | egrep -c '^DN[[:space:]]+cass1'");
|
|
|
|
$cass0->succeed("nodetool status | egrep -c '^UN' | grep 1");
|
|
|
|
$cass1->unblock;
|
|
|
|
$cass1->waitUntilSucceeds("nodetool status | egrep -c '^UN' | grep 2");
|
|
|
|
$cass0->succeed("nodetool status | egrep -c '^UN' | grep 2");
|
2016-07-22 18:29:35 +01:00
|
|
|
};
|
2019-04-23 03:59:53 +01:00
|
|
|
subtest "Replace crashed node", sub {
|
2016-07-22 18:29:35 +01:00
|
|
|
$cass1->crash;
|
|
|
|
$cass2->waitForUnit("cassandra.service");
|
2017-11-07 13:11:56 +00:00
|
|
|
$cass0->waitUntilFails("nodetool status --resolve-ip | egrep '^UN[[:space:]]+cass1'");
|
|
|
|
$cass0->waitUntilSucceeds("nodetool status --resolve-ip | egrep '^UN[[:space:]]+cass2'");
|
2016-07-22 18:29:35 +01:00
|
|
|
};
|
|
|
|
'';
|
|
|
|
})
|