2019-04-25 23:13:26 +00:00
|
|
|
import ./make-test.nix ({ pkgs, lib, ... }:
|
2016-07-22 17:29:35 +00:00
|
|
|
let
|
2017-11-07 13:11:56 +00:00
|
|
|
# Change this to test a different version of Cassandra:
|
|
|
|
testPackage = pkgs.cassandra;
|
2019-04-23 03:02:30 +00:00
|
|
|
clusterName = "NixOS Automated-Test Cluster";
|
2019-04-23 02:59:53 +00:00
|
|
|
|
2019-04-25 23:13:26 +00:00
|
|
|
testRemoteAuth = lib.versionAtLeast testPackage.version "3.11";
|
2019-04-23 03:05:39 +00:00
|
|
|
jmxRoles = [{ username = "me"; password = "password"; }];
|
2019-04-25 23:13:26 +00:00
|
|
|
jmxRolesFile = ./cassandra-jmx-roles;
|
2019-04-23 03:05:39 +00:00
|
|
|
jmxAuthArgs = "-u ${(builtins.elemAt jmxRoles 0).username} -pw ${(builtins.elemAt jmxRoles 0).password}";
|
|
|
|
|
|
|
|
# Would usually be assigned to 512M
|
2019-04-23 03:05:06 +00:00
|
|
|
numMaxHeapSize = "400";
|
|
|
|
getHeapLimitCommand = ''
|
|
|
|
nodetool info | grep "^Heap Memory" | awk \'{print $NF}\'
|
|
|
|
'';
|
|
|
|
checkHeapLimitCommand = ''
|
|
|
|
[ 1 -eq "$(echo "$(${getHeapLimitCommand}) < ${numMaxHeapSize}" | ${pkgs.bc}/bin/bc)" ]
|
|
|
|
'';
|
|
|
|
|
2019-04-23 02:59:53 +00:00
|
|
|
cassandraCfg = ipAddress:
|
2017-11-07 13:11:56 +00:00
|
|
|
{ enable = true;
|
2019-04-23 03:02:30 +00:00
|
|
|
inherit clusterName;
|
2019-04-23 02:59:53 +00:00
|
|
|
listenAddress = ipAddress;
|
|
|
|
rpcAddress = ipAddress;
|
2019-04-23 03:03:07 +00:00
|
|
|
seedAddresses = [ "192.168.1.1" ];
|
2017-11-07 13:11:56 +00:00
|
|
|
package = testPackage;
|
2019-04-23 03:05:06 +00:00
|
|
|
maxHeapSize = "${numMaxHeapSize}M";
|
|
|
|
heapNewSize = "100M";
|
2017-11-07 13:11:56 +00:00
|
|
|
};
|
2019-04-23 02:59:53 +00:00
|
|
|
nodeCfg = ipAddress: extra: {pkgs, config, ...}:
|
2017-11-07 13:11:56 +00:00
|
|
|
{ environment.systemPackages = [ testPackage ];
|
2019-04-23 03:03:41 +00:00
|
|
|
networking = {
|
|
|
|
firewall.allowedTCPPorts = [ 7000 7199 9042 ];
|
|
|
|
useDHCP = false;
|
|
|
|
interfaces.eth1.ipv4.addresses = pkgs.lib.mkOverride 0 [
|
|
|
|
{ address = ipAddress; prefixLength = 24; }
|
|
|
|
];
|
|
|
|
};
|
2019-04-23 02:59:53 +00:00
|
|
|
services.cassandra = cassandraCfg ipAddress // extra;
|
2016-07-22 17:29:35 +00:00
|
|
|
virtualisation.memorySize = 1024;
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
name = "cassandra-ci";
|
|
|
|
|
|
|
|
nodes = {
|
2019-04-09 02:02:49 +00:00
|
|
|
cass0 = nodeCfg "192.168.1.1" {};
|
2019-04-25 23:13:26 +00:00
|
|
|
cass1 = nodeCfg "192.168.1.2" (lib.optionalAttrs testRemoteAuth { inherit jmxRoles; remoteJmx = true; });
|
2019-04-09 02:02:49 +00:00
|
|
|
cass2 = nodeCfg "192.168.1.3" { jvmOpts = [ "-Dcassandra.replace_address=cass1" ]; };
|
2016-07-22 17:29:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2019-04-23 02:59:53 +00: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 02:59:53 +00:00
|
|
|
subtest "Can connect via cqlsh", sub {
|
2016-07-22 17:29:35 +00: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 17:29:35 +00:00
|
|
|
};
|
2019-04-23 02:59:53 +00: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 03:02:30 +00: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 17:29:35 +00:00
|
|
|
};
|
2019-04-23 03:05:06 +00:00
|
|
|
subtest "Heap limit set correctly", sub {
|
|
|
|
# Nodetool takes a while until it can display info
|
|
|
|
$cass0->waitUntilSucceeds('nodetool info');
|
|
|
|
$cass0->succeed('${checkHeapLimitCommand}');
|
|
|
|
};
|
2019-04-23 02:59:53 +00:00
|
|
|
|
|
|
|
# Check cluster interaction
|
|
|
|
subtest "Bring up cluster", sub {
|
2016-07-22 17:29:35 +00:00
|
|
|
$cass1->waitForUnit("cassandra.service");
|
2019-04-23 03:05:39 +00:00
|
|
|
$cass1->waitUntilSucceeds("nodetool ${jmxAuthArgs} status | egrep -c '^UN' | grep 2");
|
2017-11-07 13:11:56 +00:00
|
|
|
$cass0->succeed("nodetool status --resolve-ip | egrep '^UN[[:space:]]+cass1'");
|
2016-07-22 17:29:35 +00:00
|
|
|
};
|
2019-04-25 23:13:26 +00:00
|
|
|
'' + lib.optionalString testRemoteAuth ''
|
2019-04-23 03:05:39 +00:00
|
|
|
subtest "Remote authenticated jmx", sub {
|
|
|
|
# Doesn't work if not enabled
|
|
|
|
$cass0->waitUntilSucceeds("nc -z localhost 7199");
|
|
|
|
$cass1->fail("nc -z 192.168.1.1 7199");
|
|
|
|
$cass1->fail("nodetool -h 192.168.1.1 status");
|
|
|
|
|
|
|
|
# Works if enabled
|
|
|
|
$cass1->waitUntilSucceeds("nc -z localhost 7199");
|
|
|
|
$cass0->succeed("nodetool -h 192.168.1.2 ${jmxAuthArgs} status");
|
|
|
|
};
|
2019-04-25 23:13:26 +00:00
|
|
|
'' + ''
|
2019-04-23 02:59:53 +00: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;
|
2019-04-23 03:05:39 +00:00
|
|
|
$cass1->waitUntilSucceeds("nodetool ${jmxAuthArgs} status | egrep -c '^UN' | grep 2");
|
2017-11-07 13:11:56 +00:00
|
|
|
$cass0->succeed("nodetool status | egrep -c '^UN' | grep 2");
|
2016-07-22 17:29:35 +00:00
|
|
|
};
|
2019-04-23 02:59:53 +00:00
|
|
|
subtest "Replace crashed node", sub {
|
2016-07-22 17:29:35 +00: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 17:29:35 +00:00
|
|
|
};
|
|
|
|
'';
|
|
|
|
})
|