nixos/cassandra: Port test to python
This commit is contained in:
parent
75a8cd9930
commit
25c2506095
@ -1,4 +1,4 @@
|
|||||||
import ./make-test.nix ({ pkgs, lib, ... }:
|
import ./make-test-python.nix ({ pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
# Change this to test a different version of Cassandra:
|
# Change this to test a different version of Cassandra:
|
||||||
testPackage = pkgs.cassandra;
|
testPackage = pkgs.cassandra;
|
||||||
@ -9,13 +9,16 @@ let
|
|||||||
jmxRolesFile = ./cassandra-jmx-roles;
|
jmxRolesFile = ./cassandra-jmx-roles;
|
||||||
jmxAuthArgs = "-u ${(builtins.elemAt jmxRoles 0).username} -pw ${(builtins.elemAt jmxRoles 0).password}";
|
jmxAuthArgs = "-u ${(builtins.elemAt jmxRoles 0).username} -pw ${(builtins.elemAt jmxRoles 0).password}";
|
||||||
jmxPort = 7200; # Non-standard port so it doesn't accidentally work
|
jmxPort = 7200; # Non-standard port so it doesn't accidentally work
|
||||||
|
jmxPortStr = toString jmxPort;
|
||||||
|
|
||||||
# Would usually be assigned to 512M
|
# Would usually be assigned to 512M.
|
||||||
|
# Set it to a different value, so that we can check whether our config
|
||||||
|
# actually changes it.
|
||||||
numMaxHeapSize = "400";
|
numMaxHeapSize = "400";
|
||||||
getHeapLimitCommand = ''
|
getHeapLimitCommand = ''
|
||||||
nodetool info -p ${toString jmxPort} | grep "^Heap Memory" | awk \'{print $NF}\'
|
nodetool info -p ${jmxPortStr} | grep "^Heap Memory" | awk '{print $NF}'
|
||||||
'';
|
'';
|
||||||
checkHeapLimitCommand = ''
|
checkHeapLimitCommand = pkgs.writeShellScript "check-heap-limit.sh" ''
|
||||||
[ 1 -eq "$(echo "$(${getHeapLimitCommand}) < ${numMaxHeapSize}" | ${pkgs.bc}/bin/bc)" ]
|
[ 1 -eq "$(echo "$(${getHeapLimitCommand}) < ${numMaxHeapSize}" | ${pkgs.bc}/bin/bc)" ]
|
||||||
'';
|
'';
|
||||||
|
|
||||||
@ -44,7 +47,10 @@ let
|
|||||||
};
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
name = "cassandra-ci";
|
name = "cassandra";
|
||||||
|
meta = {
|
||||||
|
maintainers = with lib.maintainers; [ johnazoidberg ];
|
||||||
|
};
|
||||||
|
|
||||||
nodes = {
|
nodes = {
|
||||||
cass0 = nodeCfg "192.168.1.1" {};
|
cass0 = nodeCfg "192.168.1.1" {};
|
||||||
@ -52,66 +58,74 @@ in
|
|||||||
cass2 = nodeCfg "192.168.1.3" { jvmOpts = [ "-Dcassandra.replace_address=cass1" ]; };
|
cass2 = nodeCfg "192.168.1.3" { jvmOpts = [ "-Dcassandra.replace_address=cass1" ]; };
|
||||||
};
|
};
|
||||||
|
|
||||||
testScript = let
|
testScript = ''
|
||||||
jmxPortS = toString jmxPort;
|
|
||||||
in ''
|
|
||||||
# Check configuration
|
# Check configuration
|
||||||
subtest "Timers exist", sub {
|
with subtest("Timers exist"):
|
||||||
$cass0->succeed("systemctl list-timers | grep cassandra-full-repair.timer");
|
cass0.succeed("systemctl list-timers | grep cassandra-full-repair.timer")
|
||||||
$cass0->succeed("systemctl list-timers | grep cassandra-incremental-repair.timer");
|
cass0.succeed("systemctl list-timers | grep cassandra-incremental-repair.timer")
|
||||||
};
|
|
||||||
subtest "Can connect via cqlsh", sub {
|
with subtest("Can connect via cqlsh"):
|
||||||
$cass0->waitForUnit("cassandra.service");
|
cass0.wait_for_unit("cassandra.service")
|
||||||
$cass0->waitUntilSucceeds("nc -z cass0 9042");
|
cass0.wait_until_succeeds("nc -z cass0 9042")
|
||||||
$cass0->succeed("echo 'show version;' | cqlsh cass0");
|
cass0.succeed("echo 'show version;' | cqlsh cass0")
|
||||||
};
|
|
||||||
subtest "Nodetool is operational", sub {
|
with subtest("Nodetool is operational"):
|
||||||
$cass0->waitForUnit("cassandra.service");
|
cass0.wait_for_unit("cassandra.service")
|
||||||
$cass0->waitUntilSucceeds("nc -z localhost ${jmxPortS}");
|
cass0.wait_until_succeeds("nc -z localhost ${jmxPortStr}")
|
||||||
$cass0->succeed("nodetool status -p ${jmxPortS} --resolve-ip | egrep '^UN[[:space:]]+cass0'");
|
cass0.succeed("nodetool status -p ${jmxPortStr} --resolve-ip | egrep '^UN[[:space:]]+cass0'")
|
||||||
};
|
|
||||||
subtest "Cluster name was set", sub {
|
with subtest("Cluster name was set"):
|
||||||
$cass0->waitForUnit("cassandra.service");
|
cass0.wait_for_unit("cassandra.service")
|
||||||
$cass0->waitUntilSucceeds("nc -z localhost ${jmxPortS}");
|
cass0.wait_until_succeeds("nc -z localhost ${jmxPortStr}")
|
||||||
$cass0->waitUntilSucceeds("nodetool describecluster -p ${jmxPortS} | grep 'Name: ${clusterName}'");
|
cass0.wait_until_succeeds(
|
||||||
};
|
"nodetool describecluster -p ${jmxPortStr} | grep 'Name: ${clusterName}'"
|
||||||
subtest "Heap limit set correctly", sub {
|
)
|
||||||
# Nodetool takes a while until it can display info
|
|
||||||
$cass0->waitUntilSucceeds('nodetool info -p ${jmxPortS}');
|
with subtest("Heap limit set correctly"):
|
||||||
$cass0->succeed('${checkHeapLimitCommand}');
|
# Nodetool takes a while until it can display info
|
||||||
};
|
cass0.wait_until_succeeds("nodetool info -p ${jmxPortStr}")
|
||||||
|
cass0.succeed("${checkHeapLimitCommand}")
|
||||||
|
|
||||||
# Check cluster interaction
|
# Check cluster interaction
|
||||||
subtest "Bring up cluster", sub {
|
with subtest("Bring up cluster"):
|
||||||
$cass1->waitForUnit("cassandra.service");
|
cass1.wait_for_unit("cassandra.service")
|
||||||
$cass1->waitUntilSucceeds("nodetool -p ${jmxPortS} ${jmxAuthArgs} status | egrep -c '^UN' | grep 2");
|
cass1.wait_until_succeeds(
|
||||||
$cass0->succeed("nodetool status -p ${jmxPortS} --resolve-ip | egrep '^UN[[:space:]]+cass1'");
|
"nodetool -p ${jmxPortStr} ${jmxAuthArgs} status | egrep -c '^UN' | grep 2"
|
||||||
};
|
)
|
||||||
|
cass0.succeed("nodetool status -p ${jmxPortStr} --resolve-ip | egrep '^UN[[:space:]]+cass1'")
|
||||||
'' + lib.optionalString testRemoteAuth ''
|
'' + lib.optionalString testRemoteAuth ''
|
||||||
subtest "Remote authenticated jmx", sub {
|
with subtest("Remote authenticated jmx"):
|
||||||
# Doesn't work if not enabled
|
# Doesn't work if not enabled
|
||||||
$cass0->waitUntilSucceeds("nc -z localhost ${jmxPortS}");
|
cass0.wait_until_succeeds("nc -z localhost ${jmxPortStr}")
|
||||||
$cass1->fail("nc -z 192.168.1.1 ${toString jmxPort}");
|
cass1.fail("nc -z 192.168.1.1 ${jmxPortStr}")
|
||||||
$cass1->fail("nodetool -p ${jmxPortS} -h 192.168.1.1 status");
|
cass1.fail("nodetool -p ${jmxPortStr} -h 192.168.1.1 status")
|
||||||
|
|
||||||
# Works if enabled
|
# Works if enabled
|
||||||
$cass1->waitUntilSucceeds("nc -z localhost ${toString jmxPort}");
|
cass1.wait_until_succeeds("nc -z localhost ${jmxPortStr}")
|
||||||
$cass0->succeed("nodetool -p ${jmxPortS} -h 192.168.1.2 ${jmxAuthArgs} status");
|
cass0.succeed("nodetool -p ${jmxPortStr} -h 192.168.1.2 ${jmxAuthArgs} status")
|
||||||
};
|
|
||||||
'' + ''
|
'' + ''
|
||||||
subtest "Break and fix node", sub {
|
with subtest("Break and fix node"):
|
||||||
$cass1->block;
|
cass1.block()
|
||||||
$cass0->waitUntilSucceeds("nodetool status -p ${jmxPortS} --resolve-ip | egrep -c '^DN[[:space:]]+cass1'");
|
cass0.wait_until_succeeds(
|
||||||
$cass0->succeed("nodetool status -p ${jmxPortS} | egrep -c '^UN' | grep 1");
|
"nodetool status -p ${jmxPortStr} --resolve-ip | egrep -c '^DN[[:space:]]+cass1'"
|
||||||
$cass1->unblock;
|
)
|
||||||
$cass1->waitUntilSucceeds("nodetool -p ${jmxPortS} ${jmxAuthArgs} status | egrep -c '^UN' | grep 2");
|
cass0.succeed("nodetool status -p ${jmxPortStr} | egrep -c '^UN' | grep 1")
|
||||||
$cass0->succeed("nodetool status -p ${jmxPortS} | egrep -c '^UN' | grep 2");
|
cass1.unblock()
|
||||||
};
|
cass1.wait_until_succeeds(
|
||||||
subtest "Replace crashed node", sub {
|
"nodetool -p ${jmxPortStr} ${jmxAuthArgs} status | egrep -c '^UN' | grep 2"
|
||||||
$cass1->crash;
|
)
|
||||||
$cass2->waitForUnit("cassandra.service");
|
cass0.succeed("nodetool status -p ${jmxPortStr} | egrep -c '^UN' | grep 2")
|
||||||
$cass0->waitUntilFails("nodetool status -p ${jmxPortS} --resolve-ip | egrep '^UN[[:space:]]+cass1'");
|
|
||||||
$cass0->waitUntilSucceeds("nodetool status -p ${jmxPortS} --resolve-ip | egrep '^UN[[:space:]]+cass2'");
|
with subtest("Replace crashed node"):
|
||||||
};
|
cass1.block() # .crash() waits until it's fully shutdown
|
||||||
|
cass2.start()
|
||||||
|
cass0.wait_until_fails(
|
||||||
|
"nodetool status -p ${jmxPortStr} --resolve-ip | egrep '^UN[[:space:]]+cass1'"
|
||||||
|
)
|
||||||
|
|
||||||
|
cass2.wait_for_unit("cassandra.service")
|
||||||
|
cass0.wait_until_succeeds(
|
||||||
|
"nodetool status -p ${jmxPortStr} --resolve-ip | egrep '^UN[[:space:]]+cass2'"
|
||||||
|
)
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user